cloudcms-util
Advanced tools
Comparing version 2.0.3 to 2.0.4
@@ -25,3 +25,3 @@ { | ||
"create-definition", | ||
"-f", "xx" | ||
"-f", "data" | ||
] | ||
@@ -32,2 +32,16 @@ }, | ||
"request": "launch", | ||
"name": "npx cloudcms-util create-instance-node", | ||
"program": "${workspaceFolder}/bin/cloudcms-util.js", | ||
"cwd": "${workspaceFolder}", | ||
"args": [ | ||
"create-instance-node", | ||
"-q", "test:test", | ||
"-t", "test title", | ||
"-d", "test description", | ||
"-i", "test-id-002" | ||
] | ||
}, | ||
{ | ||
"type": "node", | ||
"request": "launch", | ||
"name": "npx cloudcms-util create-node", | ||
@@ -38,3 +52,7 @@ "program": "${workspaceFolder}/bin/cloudcms-util.js", | ||
"create-node", | ||
"-f", "xx" | ||
"-q", "test:test", | ||
"-t", "test title", | ||
"-d", "test description", | ||
"-i", "test-id-001", | ||
"-f", "data" | ||
] | ||
@@ -41,0 +59,0 @@ }, |
@@ -12,2 +12,3 @@ #!/usr/bin/env node | ||
var changeCase = require('change-case'); | ||
var randomString = require('random-string-simple'); | ||
var SC_SEPARATOR = "__"; | ||
@@ -37,2 +38,5 @@ | ||
return; | ||
} else if (script === "create-instance-node") { | ||
createNode(handleOptions(script), true); | ||
return; | ||
} else if (script === "create-node") { | ||
@@ -51,3 +55,3 @@ createNode(handleOptions(script)); | ||
function printHelp() { | ||
console.log(chalk.blue("Supported commands are: ") + chalk.green("\n\tinit\n\timport\n\texport\n\texport-users\n\tcreate-definition\n\tcreate-form-fields\n\tcreate-node")); | ||
console.log(chalk.blue("Supported commands are: ") + chalk.green("\n\tinit\n\timport\n\texport\n\texport-users\n\tcreate-definition\n\tcreate-form-fields\n\tcreate-node\n\tcreate-instance-node")); | ||
} | ||
@@ -61,24 +65,24 @@ | ||
var normalizedDataPath = path.resolve(process.cwd(), path.normalize(dataPath)); | ||
if (dataPath) { | ||
wrench.mkdirSyncRecursive(path.resolve(process.cwd(), path.normalize(dataPath), 'nodes')); | ||
wrench.mkdirSyncRecursive(path.resolve(process.cwd(), path.normalize(dataPath), 'definitions')); | ||
wrench.mkdirSyncRecursive(path.resolve(process.cwd(), path.normalize(dataPath), 'related')); | ||
wrench.mkdirSyncRecursive(path.resolve(normalizedDataPath, 'nodes')); | ||
wrench.mkdirSyncRecursive(path.resolve(normalizedDataPath, 'instances')); | ||
wrench.mkdirSyncRecursive(path.resolve(normalizedDataPath, 'definitions')); | ||
wrench.mkdirSyncRecursive(path.resolve(normalizedDataPath, 'related')); | ||
} else { | ||
console.log(chalk.red("bad path: " + dataPath)); | ||
} | ||
return { | ||
data: normalizedDataPath, | ||
nodes: path.resolve(normalizedDataPath, 'nodes'), | ||
instances: path.resolve(normalizedDataPath, 'instances'), | ||
definitions: path.resolve(normalizedDataPath, 'definitions'), | ||
related: path.resolve(normalizedDataPath, 'related') | ||
}; | ||
} | ||
function createDefinition(options) { | ||
var dataPath = options['data-path'] || "data"; | ||
var defPath; | ||
var defPath = init(options).definitions; | ||
if (dataPath) { | ||
defPath = path.resolve(process.cwd(), path.normalize(dataPath), 'definitions'); | ||
wrench.mkdirSyncRecursive(defPath); | ||
wrench.mkdirSyncRecursive(path.resolve(process.cwd(), path.normalize(dataPath), 'nodes')); | ||
wrench.mkdirSyncRecursive(path.resolve(process.cwd(), path.normalize(dataPath), 'related')); | ||
} else { | ||
console.log(chalk.red("bad path: " + dataPath)); | ||
} | ||
var node = emptyDefinitionNode(); | ||
@@ -103,3 +107,3 @@ node._qname = option_prompt('Enter qname: '); | ||
function createFormFields(options) { | ||
var dataPath = options['data-path'] || "data"; | ||
var defPath = init(options).definitions; | ||
var definitionQName = options["definition-qname"]; | ||
@@ -112,3 +116,3 @@ var overwrite = options["overwrite"]; | ||
var defPath = path.resolve(process.cwd(), path.normalize(dataPath), 'definitions', definitionQName.replace(':', SC_SEPARATOR)); | ||
var defPath = path.resolve(dataPath, 'definitions', definitionQName.replace(':', SC_SEPARATOR)); | ||
var definition = require(path.resolve(defPath, "node.json")); | ||
@@ -122,3 +126,2 @@ var formPath = path.resolve(defPath, "forms", "master.json"); | ||
writeFields(definition.properties, form.fields, overwrite); | ||
// console.log(JSON.stringify(form, null, 2)); | ||
@@ -204,3 +207,3 @@ writeJsonFile.sync(formPath, form); | ||
field.type = "related-content"; | ||
field.uploadPat = "/images"; | ||
field.uploadPath = "/images"; | ||
if (property.type === "array") { | ||
@@ -221,22 +224,18 @@ field.maxNumberOfFiles = 5; | ||
function createNode(options) { | ||
var dataPath = options['data-path'] || "data"; | ||
function createNode(options, instanceNode) { | ||
var paths = init(options); | ||
var defPath; | ||
if (dataPath) { | ||
defPath = path.resolve(process.cwd(), path.normalize(dataPath), 'nodes'); | ||
wrench.mkdirSyncRecursive(defPath); | ||
wrench.mkdirSyncRecursive(path.resolve(process.cwd(), path.normalize(dataPath), 'definitions')); | ||
wrench.mkdirSyncRecursive(path.resolve(process.cwd(), path.normalize(dataPath), 'related')); | ||
var node = emptyNode(); | ||
node._type = options.qname || option_prompt('Enter type qname: '); | ||
node.title = options.title || option_prompt('Enter title: '); | ||
node.description = options.description || option_prompt('Enter description: '); | ||
var id = options.id || option_prompt('Enter (optional) id: '); | ||
if (instanceNode) { | ||
defPath = path.resolve(paths.instances, node._type.replace(':', SC_SEPARATOR), id || randomString(10, 'abcdefghijklmnopqrstuv0123456789')); | ||
} else { | ||
console.log(chalk.red("bad path: " + dataPath)); | ||
defPath = path.resolve(paths.nodes, node._type.replace(':', SC_SEPARATOR), id || randomString(10, 'abcdefghijklmnopqrstuv0123456789')); | ||
} | ||
var node = emptyNode(); | ||
node._type = option_prompt('Enter type qname: '); | ||
node.title = option_prompt('Enter title: '); | ||
node.description = option_prompt('Enter description: '); | ||
defPath = path.resolve(defPath, node._type.replace(':', SC_SEPARATOR)); | ||
wrench.mkdirSyncRecursive(defPath); | ||
@@ -256,4 +255,2 @@ writeJsonFile.sync(path.resolve(defPath, "node.json"), node); | ||
"properties": { | ||
}, | ||
"mandatoryFeatures": { | ||
} | ||
@@ -272,2 +269,4 @@ }; | ||
"properties": { | ||
}, | ||
"mandatoryFeatures": { | ||
} | ||
@@ -290,3 +289,7 @@ }; | ||
{name: 'help', alias: 'h', type: Boolean}, | ||
{name: 'data-path', alias: 'f', type: String, defaultValue: './data', description: 'data folder path. defaults to ./data'} | ||
{name: 'data-path', alias: 'f', type: String, defaultValue: './data', description: 'data folder path. defaults to ./data'}, | ||
{name: 'qname', alias: 'q', type: String, description: 'qname'}, | ||
{name: 'title', alias: 't', type: String, defaultValue: '', description: 'title'}, | ||
{name: 'description', alias: 'd', type: String, defaultValue: '', description: 'description'}, | ||
{name: 'id', alias: 'i', type: String, description: 'identifier for a node. must be unique from other nodes in the data/nodes or data/instances folder'} | ||
]; | ||
@@ -293,0 +296,0 @@ |
{ | ||
"name": "cloudcms-util", | ||
"version": "2.0.3", | ||
"version": "2.0.4", | ||
"description": "Various Cloud CMS command line utilities. Currently supports import and export of Cloud CMS nodes or definitions", | ||
@@ -24,2 +24,3 @@ "bin": { | ||
"prompt-sync": "^4.1.4", | ||
"random-string-simple": "^1.0.1", | ||
"request": "^2.88.0", | ||
@@ -26,0 +27,0 @@ "underscore": "^1.9.1", |
197161
4971
15
+ Addedrandom-string-simple@^1.0.1
+ Addedrandom-string-simple@1.0.1(transitive)