From 3ae189350e11f91b6a2d77cd56a938d68d4b6ad4 Mon Sep 17 00:00:00 2001 From: Rohit Mishra Date: Fri, 19 Mar 2021 01:51:43 +0530 Subject: [PATCH 1/2] Made changes in some changes for workflow modules --- packages/contentstack-clone/package-lock.json | 58 +++++++++++++------ packages/contentstack-clone/package.json | 1 + .../src/commands/cm/stack-clone.js | 13 +++-- .../src/lib/util/clone-handler.js | 3 + packages/contentstack-import/src/app.js | 4 +- .../src/lib/import/workflows.js | 18 +++++- .../contentstack-import/src/lib/util/log.js | 6 +- 7 files changed, 74 insertions(+), 29 deletions(-) diff --git a/packages/contentstack-clone/package-lock.json b/packages/contentstack-clone/package-lock.json index ec8e08c213..fdabb26331 100644 --- a/packages/contentstack-clone/package-lock.json +++ b/packages/contentstack-clone/package-lock.json @@ -1753,8 +1753,7 @@ "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", - "dev": true + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, "base": { "version": "0.11.2", @@ -1849,7 +1848,6 @@ "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "dev": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -2375,8 +2373,7 @@ "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", - "dev": true + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" }, "configstore": { "version": "5.0.1", @@ -3728,8 +3725,7 @@ "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", - "dev": true + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "fsevents": { "version": "2.3.2", @@ -3817,7 +3813,6 @@ "version": "7.1.6", "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", - "dev": true, "requires": { "fs.realpath": "^1.0.0", "inflight": "^1.0.4", @@ -4094,7 +4089,6 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "dev": true, "requires": { "once": "^1.3.0", "wrappy": "1" @@ -5848,7 +5842,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "dev": true, "requires": { "brace-expansion": "^1.1.7" } @@ -6622,6 +6615,15 @@ "read-pkg": "^3.0.0" } }, + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, "semver": { "version": "6.3.0", "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", @@ -6785,7 +6787,6 @@ "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", - "dev": true, "requires": { "wrappy": "1" } @@ -6983,8 +6984,7 @@ "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", - "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", - "dev": true + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=" }, "path-is-inside": { "version": "1.0.2", @@ -7194,6 +7194,17 @@ "dev": true, "requires": { "rimraf": "^2.6.3" + }, + "dependencies": { + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + } } } } @@ -7530,10 +7541,9 @@ "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==" }, "rimraf": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", - "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", - "dev": true, + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", "requires": { "glob": "^7.1.3" } @@ -8117,6 +8127,17 @@ "rimraf": "^2.6.2", "signal-exit": "^3.0.2", "which": "^1.3.0" + }, + "dependencies": { + "rimraf": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", + "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + } } }, "spdx-correct": { @@ -8956,8 +8977,7 @@ "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", - "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", - "dev": true + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" }, "write": { "version": "1.0.3", diff --git a/packages/contentstack-clone/package.json b/packages/contentstack-clone/package.json index 781d234f0a..7e94d97491 100644 --- a/packages/contentstack-clone/package.json +++ b/packages/contentstack-clone/package.json @@ -17,6 +17,7 @@ "fancy-test": "^1.4.10", "inquirer": "^7.3.3", "ora": "^5.1.0", + "rimraf": "^3.0.2", "winston": "^3.3.3" }, "devDependencies": { diff --git a/packages/contentstack-clone/src/commands/cm/stack-clone.js b/packages/contentstack-clone/src/commands/cm/stack-clone.js index 1e993e4f07..52f254ead7 100644 --- a/packages/contentstack-clone/src/commands/cm/stack-clone.js +++ b/packages/contentstack-clone/src/commands/cm/stack-clone.js @@ -5,6 +5,7 @@ const {CloneHandler} = require('../../lib/util/clone-handler') let config = require('../../lib/util/dummyConfig.json') const path = require('path') const fs = require('fs'); +const rimraf = require('rimraf') class StackCloneCommand extends Command { async run() { @@ -15,12 +16,14 @@ class StackCloneCommand extends Command { config.cdn = this.cdaHost const cloneHandler = new CloneHandler(config) let result = await cloneHandler.start() - fs.rmdir(path.join(__dirname.split("src")[0], 'contents'), { recursive: true }, (err) => { - if (err) { - throw err; + var pathdir = path.join(__dirname.split("src")[0], 'contents') + rimraf(pathdir, function(err) { + if(err) { + console.log(err); + } else { + console.log("Stack cloning process have been completed successfully"); } - console.log(`Stack cloning process have been completed successfully`); - }); + }) } else { console.log("AuthToken is not present in local drive, Hence use 'csdx auth:login' command for login"); } diff --git a/packages/contentstack-clone/src/lib/util/clone-handler.js b/packages/contentstack-clone/src/lib/util/clone-handler.js index fb030126d6..60906425a6 100644 --- a/packages/contentstack-clone/src/lib/util/clone-handler.js +++ b/packages/contentstack-clone/src/lib/util/clone-handler.js @@ -59,6 +59,7 @@ class CloneHandler { .then(async (stackList)=> { let stackSelected = await inquirer.prompt(stackList) config.source_stack = stackUidList[stackSelected.stack] + config.sourceStackName = stackSelected.stack stackName.default = "Copy of " + stackSelected.stack let cmdExport = this.cmdExport() cmdExport.then(async () => { @@ -76,6 +77,7 @@ class CloneHandler { .then(async (stackList)=> { let stackSelected = await inquirer.prompt(stackList) config.target_stack = stackUidList[stackSelected.stack] + config.destinationStackName = stackSelected.stack this.cloneTypeSelection() .then((msgData)=>{ return resolve(msgData) @@ -184,6 +186,7 @@ class CloneHandler { .then(result => { spinner.succeed("New Stack created Successfully name as " + result.name) config.target_stack = result.api_key + config.destinationStackName = result.name master_locale = result.master_locale return resolve(result) }).catch(error => { diff --git a/packages/contentstack-import/src/app.js b/packages/contentstack-import/src/app.js index cee7560a90..6ee49420d3 100755 --- a/packages/contentstack-import/src/app.js +++ b/packages/contentstack-import/src/app.js @@ -87,6 +87,7 @@ let singleImport = async (moduleName, types, config) => { addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'success') return resolve() }).catch(function (error) { + console.log("Line no 90++++", error); addlogs(config, 'Failed to migrate ' + moduleName, 'error') addlogs(config, error, 'error') addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'error') @@ -169,10 +170,11 @@ let allImport = async (config, types) => { return }) } - addlogs(config, chalk.green('Stack: ' + config.stackName + ' has been imported succesfully!'), 'success') if (config.target_stack && config.source_stack) { + addlogs(config, chalk.green('The data of the ' + config.sourceStackName + 'stack has been imported into ' + config.destinationStackName + ' stack successfully!'), 'success') addlogs(config, 'The log for this is stored at' + path.join(config.data, 'logs', 'import'), 'success') } else { + addlogs(config, chalk.green('Stack: ' + config.sourceStackName + ' has been imported succesfully!'), 'success') addlogs(config, 'The log for this is stored at' + path.join(config.oldPath, 'logs', 'import'), 'success') } return resolve() diff --git a/packages/contentstack-import/src/lib/import/workflows.js b/packages/contentstack-import/src/lib/import/workflows.js index ed653f1ddc..15d9d89208 100644 --- a/packages/contentstack-import/src/lib/import/workflows.js +++ b/packages/contentstack-import/src/lib/import/workflows.js @@ -60,6 +60,20 @@ importWorkflows.prototype = { let workflow = self.workflows[workflowUid]; if (!self.workflowUidMapper.hasOwnProperty(workflowUid)) { + for (let index = 0; index < workflow.workflow_stages.length; index++) { + if (workflow.workflow_stages[index].SYS_ACL.users.uids.length > 0 && workflow.workflow_stages[index].SYS_ACL.users.uids[0] !== "$all") { + workflow.workflow_stages[index].SYS_ACL.users.uids = ["$all"] + } + + if (workflow.workflow_stages[index].SYS_ACL.roles.uids.length > 0) { + workflow.workflow_stages[index].SYS_ACL.roles.uids = [] + } + + if (workflow.workflow_stages[index].next_available_stages.length > 0) { + workflow.workflow_stages[index].next_available_stages = ["$all"] + } + } + let requestOption = { workflow: workflow }; @@ -73,8 +87,8 @@ importWorkflows.prototype = { self.fails.push(workflow); if (error.errors.name) { addlogs(config, chalk.red('workflow: \'' + workflow.name + '\' already exist'), 'error'); - } else if (error.errors.workflow_stages[0].roles) { - addlogs(config, chalk.red('We do not import roles modules and roles are attached with this workflow'), 'error'); + } else if (error.errors['workflow_stages.0.users']) { + addlogs(config, chalk.red("Failed to import Workflows as you've specified certain roles in the Stage transition and access rules section. We currently don't import roles to the stack."), 'error'); } else { addlogs(config, chalk.red('workflow: \'' + workflow.name + '\' already exist'), 'error'); } diff --git a/packages/contentstack-import/src/lib/util/log.js b/packages/contentstack-import/src/lib/util/log.js index 144b0bf622..083dd66f4d 100755 --- a/packages/contentstack-import/src/lib/util/log.js +++ b/packages/contentstack-import/src/lib/util/log.js @@ -91,9 +91,11 @@ function init (_logPath, logfileName) { } exports.addlogs = async (config, message, type) => { + var configLogPath + config.source_stack && config.target_stack ? configLogPath = config.data : configLogPath = config.oldPath if (type !== 'error') { - init(config.oldPath, type).log(message) + init(configLogPath, type).log(message) } else { - init(config.oldPath, type).error(message) + init(configLogPath, type).error(message) } } From e5608be782702f9b278b0ba4ac1e81c26f45e479 Mon Sep 17 00:00:00 2001 From: Rohit Mishra Date: Fri, 19 Mar 2021 11:42:03 +0530 Subject: [PATCH 2/2] Made changes for pointer --- packages/contentstack-import/src/commands/cm/import.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/contentstack-import/src/commands/cm/import.js b/packages/contentstack-import/src/commands/cm/import.js index 2c9337679d..0286c12d63 100644 --- a/packages/contentstack-import/src/commands/cm/import.js +++ b/packages/contentstack-import/src/commands/cm/import.js @@ -13,7 +13,8 @@ const {configWithMToken, class ImportCommand extends Command { async run() { - const {flags} = this.parse(ImportCommand) + let self = this + const {flags} = self.parse(ImportCommand) const extConfig = flags.config let targetStack = flags['stack-uid'] const data = flags.data @@ -22,11 +23,11 @@ class ImportCommand extends Command { const alias = flags['management-token-alias'] const authToken = flags['auth-token'] let _authToken = credStore.get('authtoken') - let host = this.cmaHost + let host = self.cmaHost return new Promise(function (resolve, reject) { if (alias && alias !== undefined) { - let managementTokens = this.getToken(alias) + let managementTokens = self.getToken(alias) if (managementTokens && managementTokens !== undefined) { if (extConfig && extConfig !== undefined && _authToken) {