cloudcms-util
Advanced tools
Comparing version 2.1.4 to 2.2.0
@@ -16,3 +16,4 @@ { | ||
"--folder-path", "/Users/harry/Documents/Projects/customers/MM/mm.cloudcms.admin/cms-definitions-prod", | ||
"--gitana-file-path", "./gitana/gitana-local-docker-harry.json" | ||
"--gitana-file-path", "./gitana/gitana-local-docker-harry.json", | ||
"-v" | ||
] | ||
@@ -19,0 +20,0 @@ }, |
@@ -52,2 +52,3 @@ #!/usr/bin/env node | ||
var option_allDefinitions = options["all-definitions"] || false; | ||
var option_skipDefinitionValidation = options["skip-definition-validation"] || false; | ||
var option_includeInstances = options["include-instances"] || false; | ||
@@ -167,4 +168,6 @@ var option_overwriteExistingInstances = options["overwrite-instances"] || false; | ||
allDefinitions: option_allDefinitions, | ||
skipDefinitionValidation: option_skipDefinitionValidation, | ||
importTypeQNames: option_definitionQNames || [], | ||
typeDefinitions: [], | ||
localTypeDefinitions: {}, | ||
dataFolderPath: option_dataFolderPath, | ||
@@ -183,3 +186,3 @@ includeRelated: option_includeRelated, | ||
async.apply(loadAllDefinitionsFromDisk, context), | ||
async.ensureAsync(getDefinitions), | ||
async.ensureAsync(getBranchDefinitions), | ||
async.ensureAsync(writeDefinitionsToBranch), | ||
@@ -652,3 +655,2 @@ async.ensureAsync(getDefinitionFormAssociations), | ||
var arr = {}; | ||
var definitionsPath = path.normalize(pathResolve(context.dataFolderPath, "definitions")); | ||
@@ -659,34 +661,43 @@ var files = util.findFiles(definitionsPath, "node.json"); | ||
var jsonNode = loadJsonFile.sync(files[i]); | ||
arr[jsonNode._qname] = jsonNode; | ||
// jsonNode.___localSourcePath = files[i]; | ||
context.localTypeDefinitions[jsonNode._qname] = jsonNode; | ||
} | ||
log.info("Type qnames found: \n" + Object.keys(arr).join("\n")); | ||
log.info("Type qnames found: \n" + Object.keys(context.localTypeDefinitions).join("\n")); | ||
log.info ("Checking for Circular Dependencies"); | ||
var white = new Set(Object.keys(arr)); | ||
var gray = new Set(); | ||
var black = new Set(); | ||
while (white.size > 0) { | ||
// var it = white.values(); | ||
var current = white.values().next().value; | ||
if(_detectCircularDependencies(arr, current, white, gray, black)) { | ||
callback("Circular Dependency detected", context); | ||
return; | ||
if (context.skipDefinitionValidation) { | ||
log.info("validation disabled. Skipping check for Circular Dependencies"); | ||
} else { | ||
log.info("Checking for Circular Dependencies"); | ||
var white = new Set(Object.keys(context.localTypeDefinitions)); | ||
var gray = new Set(); | ||
var black = new Set(); | ||
while (white.size > 0) { | ||
// var it = white.values(); | ||
var current = white.values().next().value; | ||
if(_detectCircularDependencies(context.localTypeDefinitions, current, white, gray, black)) { | ||
log.warn("Circular Dependency detected. The entire model may not import properly to a new project/branch in Cloud CMS"); | ||
// callback("Circular Dependency detected", context); | ||
// return; | ||
} | ||
} | ||
log.info("No Circular Dependencies detected"); | ||
} | ||
log.info ("No Circular Dependencies detected"); | ||
log.info ("Resolve Dependency Order"); | ||
log.info("Resolving Dependency Order"); | ||
var dependencyOrderedTypeDefinitions = []; | ||
var arrKeys = Object.keys(arr); | ||
var arrKeys = Object.keys(context.localTypeDefinitions); | ||
var keys = {}; | ||
for(i = 0; i < arrKeys.length; i++) { | ||
var node = arr[arrKeys[i]]; | ||
if (_resolveDependencyOrder(node, arr, arrKeys, dependencyOrderedTypeDefinitions, keys)) { | ||
callback("Dependency check failed", context); | ||
return; | ||
var node = context.localTypeDefinitions[arrKeys[i]]; | ||
if (_resolveDependencyOrder(node, context.localTypeDefinitions, arrKeys, dependencyOrderedTypeDefinitions, keys)) { | ||
log.warn("Missing type definitions detected when resolving Dependency Order"); | ||
// callback("Dependency check failed", context); | ||
// return; | ||
} | ||
} | ||
log.info("Dependency Order Resolved"); | ||
context.importTypeQNames = dependencyOrderedTypeDefinitions; | ||
log.info("Order of import: \n" + context.importTypeQNames.join("\n")); | ||
} | ||
@@ -733,5 +744,7 @@ | ||
var dependencies = []; | ||
if (arr[current]) { | ||
if (typeDefinion) { | ||
dependencies = _dependsOn(typeDefinion); | ||
} | ||
for(var i = 0; i < dependencies.length; i++) { | ||
@@ -741,3 +754,3 @@ var node = arr[dependencies[i]]; | ||
if (!node) { | ||
log.error("_resolveDependencyOrder() dependency node for definition:" + typeDefinion._qname + " not found for _qname: " + dependencies[i]); | ||
log.error("_resolveDependencyOrder() dependency for definition: " + typeDefinion._qname + " not found for _qname: " + dependencies[i]); | ||
return -1; | ||
@@ -757,4 +770,6 @@ } | ||
resolvedKeys[node._qname] = 1; | ||
resolved.push(node._qname); | ||
if (!resolvedKeys[node._qname]) { | ||
resolvedKeys[node._qname] = 1; | ||
resolved.push(node._qname); | ||
} | ||
} | ||
@@ -1282,3 +1297,3 @@ } | ||
context.finalDefinitionNodes.push(definitionNode); | ||
log.info("Created definition node " + definitionNode._doc); | ||
log.info("Created definition node " + definitionNode._doc + " " + definitionNode._qname + " " + definitionNode.title); | ||
callback(null, context); | ||
@@ -1291,2 +1306,7 @@ return; | ||
function loadDefinitionNodeFromDisk(context, definitionQname) { | ||
if (context.localTypeDefinitions[definitionQname]) { | ||
// already loaded this | ||
return context.localTypeDefinitions[definitionQname]; | ||
} | ||
try { | ||
@@ -1398,3 +1418,3 @@ var jsonNode = loadJsonFile.sync(buildDefinitionPath(context.dataFolderPath, {_qname: definitionQname})); | ||
getDefinitions(context, function(err, context) { | ||
getBranchDefinitions(context, function(err, context) { | ||
if (err) | ||
@@ -1469,3 +1489,3 @@ { | ||
function getDefinitions(context, callback) { | ||
function getBranchDefinitions(context, callback) { | ||
log.debug("getTypeDefinitionsByQname()"); | ||
@@ -1613,2 +1633,3 @@ | ||
{name: 'include-related', alias: 'r', type: Boolean, description: 'include instance records referred to in relators on instance records'}, | ||
{name: 'skip-definition-validation', alias: 'k', type: Boolean, description: 'do not perform dependency checks when using --all-definitions to import definitions'}, | ||
{name: 'overwrite-instances', alias: 'o', type: Boolean, description: 'overwrite instance records. by default only missing records will be created. this will cause existing records to be updated as well'}, | ||
@@ -1615,0 +1636,0 @@ {name: 'folder-path', alias: 'f', type: String, description: 'folder to store exported files. defaults to ./data'} |
{ | ||
"name": "cloudcms-util", | ||
"version": "2.1.4", | ||
"version": "2.2.0", | ||
"description": "Various Cloud CMS command line utilities. Currently supports import and export of Cloud CMS nodes or definitions", | ||
@@ -5,0 +5,0 @@ "bin": { |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
267498
5283
2