Comparing version 2.1.1 to 2.2.0
@@ -0,0 +0,0 @@ // jshint esversion: 6 |
@@ -0,0 +0,0 @@ // jshint esversion: 6 |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ // jshint esversion: 6 |
264
index.js
@@ -11,2 +11,4 @@ #!/usr/bin/env node | ||
const galleryUri = "https://plexiform.azurewebsites.net"; | ||
// --------------------------------------------------------------------- | ||
@@ -17,2 +19,3 @@ // Require path | ||
const fs = require('fs-extra'); | ||
const fetch = require('node-fetch'); | ||
@@ -28,3 +31,3 @@ /* The spec, build and templates are all 'require'd, and will be relative to your cwd, so push that (and node_modules sub-dir) onto our module paths list */ | ||
name: "Plexiform", | ||
version: "2.1.1", | ||
version: "2.2.0", | ||
author: "Raith" | ||
@@ -49,3 +52,3 @@ }; | ||
var recognisedCommands = { "init": true, "build": true }; | ||
var recognisedCommands = { "init": true, "build": true, "gallery": true }; | ||
@@ -103,4 +106,14 @@ var argv = require('process-argv')(); | ||
plexiform build [--save|-s] | ||
plexiform build --build|-b <build_name> [--spec|-c <spec_name>] [--process|-p <spec_processor>] [--output|-o <output_folder>] [--save|-s] | ||
plexiform build --build|-b <build_name> [--spec|-s <spec_name>] [--process|-p <spec_processor>] [--output|-o <output_folder>] [--save|-s] | ||
plexiform gallery list | ||
plexiform gallery query --spec <spec_name> --secret <secret> | ||
plexiform gallery new --spec <spec_name> --secret <secret> --description <description> | ||
plexiform gallery secret --spec <spec_name> --secret <secret> --newsecret <new_secret> | ||
plexiform gallery save --spec <spec_name> --secret <secret> --semver <sementic_version> --author <author_name> --details <details> [--file <file_path>] | ||
plexiform gallery publish --spec <spec_name> --secret <secret> [--rev <revision_number>] | ||
plexiform gallery fetch --spec <spec_name> --secret <secret> [--rev <revision_number>] | ||
=============================================================================== | ||
"plexiform init" | ||
@@ -117,4 +130,4 @@ Creates a ${plexiformconfigname} file. For subsequent use without needing parameters. | ||
<spec_name> | ||
This should refer to a file with extension ".json" in the CWD or modules path (for require). | ||
It will expose a specification object which is consumable by the build method. | ||
This should refer to a "json" or "md" file, relative to the CWD. | ||
It will expose a specification object, either directly (json) or post-processing (md), which is consumable by the build method. | ||
@@ -125,3 +138,3 @@ <spec_processor> | ||
NOTE: The spec_processor must *always* be specified, and is *only* invoked, if the spec_name extension is anything other than ".js" or ".json". | ||
NOTE: The spec_processor is *always* and *only* specified and invoked if the spec_name extension is anything other than ".js" or ".json". | ||
@@ -209,3 +222,3 @@ NOTE: If the --save switch is applied then the processed spec is stringified to a file with the original spec_name plus the ".json" extension, with FORCED overwriting! | ||
var specSaveName = spec_name + '.json'; | ||
fs.writeFileSync(specSaveName, JSON.stringify(spec)); | ||
fs.writeFileSync(specSaveName, JSON.stringify(spec, null, 4)); | ||
} | ||
@@ -238,2 +251,239 @@ | ||
if (argv.command == "gallery") { | ||
console.log(`Plexiform Gallery - ${argv.params[0] || "please specify a command"}`); | ||
// plexiform gallery publish --spec <spec_name> --secret <secret> [--rev <revision_number>] | ||
if (argv.params[0] == "publish") { | ||
var name = argv.options.spec || null; | ||
var secret = argv.options.secret || null; | ||
var revisionNumber = argv.options.rev || null; | ||
if (name && secret) { | ||
var payload = { | ||
specname: name, | ||
secret: secret, | ||
revisionNumber: revisionNumber | ||
}; | ||
fetch(`${galleryUri}/api/cmd/Publishing/Publish`, fetch_options(payload)) | ||
.then(res => res.json()).then(o => { | ||
if (o.isSuccess) { | ||
var spec = o.value.spec; | ||
if (spec) { | ||
console.log(`Published Revision #${spec.currentRevision} for Specification "${spec.name}"`); | ||
} else { | ||
console.log(`Not found Specification "${name}", or incorrect secret.`); | ||
} | ||
} else { | ||
dump(o); | ||
} | ||
}) | ||
.catch(exception_handler); | ||
} else { | ||
console.log("Invalid options."); | ||
console.log("Usage: plexiform gallery secret --spec <spec_name> --secret <secret> --newsecret <new_secret>"); | ||
} | ||
} | ||
// plexiform gallery secret --spec <spec_name> --secret <secret> --newsecret <new_secret> | ||
if (argv.params[0] == "secret") { | ||
var name = argv.options.spec || null; | ||
var secret = argv.options.secret || null; | ||
var newsecret = argv.options.newsecret || null; | ||
if (name && secret && newsecret) { | ||
var payload = { | ||
specname: name, | ||
secret: secret, | ||
newsecret: newsecret | ||
}; | ||
fetch(`${galleryUri}/api/cmd/Publishing/Secret`, fetch_options(payload)) | ||
.then(res => res.json()).then(o => { | ||
if (o.isSuccess) { | ||
if (o.value.result) { | ||
console.log(`Changed secret for Specification "${name}"`); | ||
} else { | ||
console.log(`Not found Specification "${name}", or incorrect secret.`); | ||
} | ||
} else { | ||
dump(o); | ||
} | ||
}) | ||
.catch(exception_handler); | ||
} else { | ||
console.log("Invalid options."); | ||
console.log("Usage: plexiform gallery secret --spec <spec_name> --secret <secret> --newsecret <new_secret>"); | ||
} | ||
} | ||
// plexiform gallery fetch --spec <spec_name> --secret <secret> [--rev <revision_number>] | ||
if (argv.params[0] == "fetch") { | ||
var name = argv.options.spec || null; | ||
var secret = argv.options.secret || null; | ||
var revisionNumber = argv.options.rev || null; | ||
if (name && secret) { | ||
fetch(`${galleryUri}/api/qry/Publishing/get/${name}/${secret}/${revisionNumber}`, fetch_options()) | ||
.then(res => res.json()).then(o => { | ||
if (o.isSuccess) { | ||
var rev = o.value[0]; | ||
if (rev) { | ||
fs.writeFileSync(`./${name}`, rev.content); | ||
console.log(`Fetched Revision #${rev.revisionNumber} of Specification "${rev.spec.name}"`); | ||
} else { | ||
console.log(`Not found Revision #${revisionNumber == null ? "current" : revisionNumber} for Specification "${name}", or incorrect secret.`); | ||
} | ||
} else { | ||
dump(o); | ||
} | ||
}) | ||
.catch(exception_handler); | ||
} else { | ||
console.log("Invalid options."); | ||
console.log("Usage: plexiform gallery fetch --spec <spec_name> --secret <secret> [--rev <revision_number>]"); | ||
} | ||
} | ||
// plexiform gallery save --spec <spec_name> --secret <secret> --semver <sementic_version> --author <author_name> --details <details> [--file <file_path>] | ||
if (argv.params[0] == "save") { | ||
var name = argv.options.spec || null; | ||
var secret = argv.options.secret || null; | ||
var semver = argv.options.semver || ""; | ||
var details = argv.options.details || ""; | ||
var author = argv.options.author || "unknown"; | ||
var file_path = argv.options.file || `./${name}`; | ||
if (name && secret) { | ||
var file_content = fs.readFileSync(file_path).toString(); | ||
var revObj = { | ||
ID: 0, | ||
revisionNumber: 0, | ||
revisionDate: (new Date()).toISOString(), | ||
revisionDetails: details, | ||
semver: semver, | ||
author: author, | ||
content: file_content | ||
}; | ||
var payload = { | ||
specname: name, | ||
secret: secret, | ||
rev: revObj | ||
}; | ||
fetch(`${galleryUri}/api/cmd/Publishing/Save`, fetch_options(payload)) | ||
.then(res => res.json()).then(o => { | ||
if (o.isSuccess) { | ||
var rev = o.value.rev; | ||
if (rev) { | ||
console.log(`Added new Revision #${rev.revisionNumber} with ID [${rev.ID}]`); | ||
} else { | ||
console.log(`Specification "${name}" not found, or incorrect secret.`); | ||
} | ||
} else { | ||
dump(o); | ||
} | ||
}) | ||
.catch(exception_handler); | ||
} else { | ||
console.log("Invalid options."); | ||
console.log("Usage: plexiform gallery save --spec <spec_name> --secret <secret> --semver <sementic_version> --author <author_name> --details <details> [--file <file_path>]"); | ||
} | ||
} | ||
// plexiform gallery query --spec <spec_name> --secret <secret> | ||
if (argv.params[0] == "query") { | ||
var name = argv.options.spec || null; | ||
var secret = argv.options.secret || null; | ||
if (name && secret) { | ||
fetch(`${galleryUri}/api/qry/Publishing/query/${name}/${secret}`, fetch_options()) | ||
.then(res => res.json()).then(o => { | ||
if (o.isSuccess) { | ||
var spec = o.value[0]; | ||
if (spec) { | ||
console.log(`${spec.labelL}\n\n${spec.revisions.length} Revision${spec.revisions.length == 1 ? "" : "s"}:`); | ||
for (var i = 0; i < spec.revisions.length; i++) { | ||
console.log(spec.revisions[i].labelL); | ||
} | ||
} else { | ||
console.log(`Specification "${name}" not found, or incorrect secret.`); | ||
} | ||
} else { | ||
dump(o); | ||
} | ||
}) | ||
.catch(exception_handler); | ||
} else { | ||
console.log("Invalid options."); | ||
console.log("Usage: plexiform gallery query --spec <spec_name> --secret <secret>"); | ||
} | ||
} | ||
// plexiform gallery new --spec <spec_name> --secret <secret> --description <description> | ||
if (argv.params[0] == "new") { | ||
var name = argv.options.spec || null; | ||
var secret = argv.options.secret || null; | ||
var description = argv.options.description || ""; | ||
if (name && secret && description) { | ||
var specObj = { | ||
ID: 0, | ||
name: name, | ||
secret: secret, | ||
description: description, | ||
logo: "", | ||
currentRevision: 0 | ||
}; | ||
var payload = { | ||
spec: specObj | ||
}; | ||
fetch(`${galleryUri}/api/cmd/Publishing/New`, fetch_options(payload)) | ||
.then(res => res.json()).then(o => { | ||
if (o.isSuccess) { | ||
var spec = o.value.spec; | ||
console.log(`Added new Specification "${spec.name}" with ID [${spec.ID}]`); | ||
} else { | ||
dump(o); | ||
} | ||
}) | ||
.catch(exception_handler); | ||
} else { | ||
console.log("Invalid options."); | ||
console.log("Usage: plexiform gallery new --spec <spec_name> --secret <secret> --description <description>"); | ||
} | ||
} | ||
// plexiform gallery list | ||
if (argv.params[0] == "list") { | ||
fetch(`${galleryUri}/api/qry/Publishing/list`, fetch_options()) | ||
.then(res => res.json()).then(o => { | ||
if (o && o.isSuccess) { | ||
var data = o.value; | ||
console.log(`Gallery has ${data.length} specification${data.length == 1 ? "" : "s"}:`); | ||
for (var i = 0; i < data.length; i++) { | ||
var spec = data[i]; | ||
console.log(`${("0000" + i).toString().substr(-4)} ${spec.labelL}`); | ||
} | ||
} | ||
}) | ||
.catch(exception_handler); | ||
} | ||
} | ||
function fetch_options(postdata = null, method = "GET") { | ||
var opts = { | ||
method: (postdata != null ? "POST" : method), | ||
headers: { | ||
"Accept": "application/json, text/plain, */*", | ||
"Content-Type": "application/json" | ||
} | ||
}; | ||
if (postdata) opts.body = JSON.stringify(postdata); | ||
return opts; | ||
} | ||
function exception_handler(e) { | ||
console.log("Oh dear, something went wrong! :("); | ||
console.log(e); | ||
} | ||
function dump() { | ||
for (var i = 0; i < arguments.length; i++) { | ||
console.log(JSON.stringify(arguments[i], null, 4)); | ||
} | ||
} | ||
// --------------------------------------------------------------------- |
{ | ||
"name": "plexiform", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "A very simple template-driven generator.", | ||
@@ -20,4 +20,5 @@ "main": "index.js", | ||
"fs-extra": "^4.0.2", | ||
"node-fetch": "^2.0.0-alpha.9", | ||
"process-argv": "^1.0.0" | ||
} | ||
} |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ { |
@@ -0,0 +0,0 @@ # Plexiform |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
34194
601
3
7
+ Addednode-fetch@^2.0.0-alpha.9
+ Addednode-fetch@2.7.0(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)