Skip to content

Commit

Permalink
Merge pull request #32 from contentstack/clone-stack
Browse files Browse the repository at this point in the history
Merge Clone stack branch
  • Loading branch information
rohitmishra209 authored Mar 19, 2021
2 parents 66c3e98 + e5608be commit 27aaaab
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 32 deletions.
58 changes: 39 additions & 19 deletions packages/contentstack-clone/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 8 additions & 5 deletions packages/contentstack-clone/src/commands/cm/stack-clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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");
}
Expand Down
3 changes: 3 additions & 0 deletions packages/contentstack-clone/src/lib/util/clone-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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)
Expand Down Expand Up @@ -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 => {
Expand Down
4 changes: 3 additions & 1 deletion packages/contentstack-import/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions packages/contentstack-import/src/commands/cm/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
18 changes: 16 additions & 2 deletions packages/contentstack-import/src/lib/import/workflows.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand All @@ -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');
}
Expand Down
6 changes: 4 additions & 2 deletions packages/contentstack-import/src/lib/util/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 27aaaab

Please sign in to comment.