Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge clone stack in develop branch #26

Merged
merged 2 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/contentstack-clone/src/commands/cm/stack-clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ class StackCloneCommand extends Command {
const cloneHandler = new CloneHandler(config)
let result = await cloneHandler.start()
fs.rmdirSync(path.join(__dirname.split("src")[0], 'contents'), { recursive: true });
console.log(result);
} else {
console.log("AuthToken is not present in local drive, Hence use 'csdx auth:login' command for login");
}
}
}

StackCloneCommand.description = `This plugin allows you to perform content or only structure migration tasks
StackCloneCommand.description = `This command allows you to migrate data (structure or content or both) from one stack to another stack (either new or existing)
...
By using this plugin, you can automate the content export and import operations for your stacks in your organization.
Use this plugin to automate the process of cloning a stack in a few steps.
`

StackCloneCommand.examples = [
Expand Down
40 changes: 23 additions & 17 deletions packages/contentstack-clone/src/lib/util/clone-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ let config
let stackCreationConfirmation = [{
type: 'confirm',
name: 'stackCreate',
message: 'Do you want to create new stack ?',
message: 'Want to clone content into a new stack ?',
initial: true
}]

let stackName = {
type: 'input',
name: 'stack',
message: 'Please Enter New stack name, which you want to create for import ?',
message: 'Enter name for the new stack to store the cloned content ?',
default: "ABC"
}

Expand All @@ -36,6 +36,7 @@ let structureList = ['locales',
'global-fields',
'content-types',
'labels']
var oraMessage
let master_locale

class CloneHandler {
Expand All @@ -46,12 +47,14 @@ class CloneHandler {

async start() {
return new Promise(async (resolve, reject) => {
oraMessage = "Choose an organization where your source stack exists:"
// export section starts from here
let orgdetails = this.getOrganizationChoices()
let orgdetails = this.getOrganizationChoices(oraMessage)
orgdetails
.then(async (orgList)=>{
var stackMessage = 'Select the source stack'
var orgSelected = await inquirer.prompt(orgList)
let stackDetails = this.getStack(orgSelected)
let stackDetails = this.getStack(orgSelected, stackMessage)
stackDetails
.then(async (stackList)=> {
let stackSelected = await inquirer.prompt(stackList)
Expand All @@ -62,11 +65,13 @@ class CloneHandler {
//Import section starts from here
var stackCreateConfirmation = await inquirer.prompt(stackCreationConfirmation)
if (stackCreateConfirmation.stackCreate !== true) {
let orgdetails = this.getOrganizationChoices()
oraMessage = 'Choose an organization where the destination stack exists: '
let orgdetails = this.getOrganizationChoices(oraMessage)
orgdetails
.then(async (orgList)=>{
var stackMessage = 'Select the source stack'
var orgSelected = await inquirer.prompt(orgList)
let stackDetails = this.getStack(orgSelected)
let stackDetails = this.getStack(orgSelected, stackMessage)
stackDetails
.then(async (stackList)=> {
let stackSelected = await inquirer.prompt(stackList)
Expand All @@ -84,7 +89,8 @@ class CloneHandler {
return reject(error.errorMessage)
})
} else {
let orgdetails = this.getOrganizationChoices()
oraMessage = 'Choose an organization where you want to create a stack: '
let orgdetails = this.getOrganizationChoices(oraMessage)
orgdetails
.then(async (orgList)=>{
var orgSelected = await inquirer.prompt(orgList)
Expand Down Expand Up @@ -112,15 +118,15 @@ class CloneHandler {
})
}

getOrganizationChoices = async () => {
getOrganizationChoices = async (oraMessage) => {
let orgChoice = {
type: 'list',
name: 'Organization',
message: '',
message: oraMessage,
choices: [],
}
return new Promise(async (resolve, reject) => {
const spinner = ora('Fetching Organization').start()
const spinner = ora("Fetching Organization").start()
try {
let organizations = await client.organization().fetchAll({ limit: 100 })
spinner.succeed("Fetched Organization")
Expand All @@ -136,15 +142,15 @@ class CloneHandler {
})
}

getStack = async (answer) => {
getStack = async (answer, stkMessage) => {
return new Promise(async (resolve, reject) => {
let stackChoice = {
type: 'list',
name: 'stack',
message: 'Choose Stack ...',
message: stkMessage,
choices: [],
}
const spinner = ora('Fetching stack List').start()
const spinner = ora('Fetching stacks').start()
try {
let orgUid = orgUidList[answer.Organization]
let stackList = client.stack().query({ organization_uid: orgUid }).find()
Expand All @@ -154,7 +160,7 @@ class CloneHandler {
stackUidList[stacklist.items[j].name] = stacklist.items[j].api_key
stackChoice.choices.push(stacklist.items[j].name)
}
spinner.succeed("Fetched stack List")
spinner.succeed("Fetched stack")
return resolve(stackChoice)
}).catch(error => {
spinner.fail()
Expand Down Expand Up @@ -191,13 +197,13 @@ class CloneHandler {
let cloneTypeSelection = [{
type: 'list',
name: 'type',
message: 'Choose the type to clone the stack',
choices: ["structure", "structure and content"]
message: 'Choose the type of data to clone:',
choices: ["Structure (all modules except entries & assets)", "Structure with content (all modules including entries & assets)"]
}]
var selectedValue = await inquirer.prompt(cloneTypeSelection)
let cloneType = selectedValue.type
config['data'] = path.join(__dirname.split("src")[0], 'contents')
if (cloneType === "structure") {
if (cloneType === "Structure (all modules except entries & assets)") {
config['modules'] = structureList
let cmdImport = this.cmdImport()
cmdImport.then(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var allExport = async (config, types) => {
return
})
}
addlogs(config, chalk.green('Stack: ' + config.source_stack + ' has been exported succesfully!'), 'success')
addlogs(config, chalk.green('The content of the ' + config.source_stack + ' has been exported succesfully!'), 'success')
addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'success')
return resolve()
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export/src/lib/export/assets.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ExportAssets.prototype = {
return new Promise(function (resolve, reject) {
return self.getAssetCount().then(function (count) {
if (typeof count !== 'number' || count === 0) {
addlogs(config, 'There were no assets to be download', 'success')
addlogs(config, 'No assets found', 'success')
return resolve()
}
const assetBatches = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ ExportContentTypes.prototype = {
helper.writeFile(path.join(contentTypesFolderPath, content_type.uid + '.json'),
content_type)
})
addlogs(config, chalk.green('Content type export completed successfully'), 'success')
addlogs(config, chalk.green('Content type(s) exported successfully'), 'success')
return resolve()
})
},
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-export/src/lib/export/entries.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ exportEntries.prototype.getEntries = function (apiDetails) {
})
}
if (apiDetails.skip > entriesList.items.length) {
addlogs(config, 'Completed exporting ' + apiDetails.content_type +
' content type\'s entries in ' + apiDetails.locale + ' locale', 'success')
addlogs(config, 'Exported entries of ' + apiDetails.content_type +
' to the ' + apiDetails.locale + ' language successfully', 'success')
return resolve()
}
apiDetails.skip += limit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ExportEnvironments.prototype.start = function (mergConfig) {
return resolve()
}
if (environmentResponse.items.length === 0) {
addlogs(config, 'No environments were found in the Stack', 'success')
addlogs(config, 'No environments found', 'success')
return resolve()
}
}).catch(error => {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export/src/lib/export/extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ExportExtensions.prototype.start = function (mergeConfig) {
addlogs(config, chalk.green('All the extensions have been exported successfully'), 'success')
return resolve()
}
addlogs(config, 'No extensions were found in the Stack', 'success')
addlogs(config, 'No extensions found', 'success')
return resolve()
}).catch(error => {
addlogs(config, error, 'error')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ExportGlobalFields.prototype = {
.then(globalFieldResponse => {
try {
if (globalFieldResponse.items.length === 0) {
addlogs(config, 'No Global Fields were found in the Stack', 'success')
addlogs(config, 'No global fields found', 'success')
return resolve('No Global Fields')
}
globalFieldResponse.items.forEach(function (globalField) {
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export/src/lib/export/labels.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ExportLabels.prototype.start = function (credentialConfig) {
})
addlogs(config, chalk.green('All the labels have been exported successfully'), 'success')
} else {
addlogs(config, 'No labels, other than master-labels were found in the Stack', 'success')
addlogs(config, 'No labels found', 'success')
}
helper.writeFile(path.join(labelsFolderPath, labelConfig.fileName), self.labels)
return resolve()
Expand Down
4 changes: 2 additions & 2 deletions packages/contentstack-export/src/lib/export/locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ ExportLocales.prototype.start = function (credentialConfig) {
.then(localeResponse => {
if (localeResponse.items.length !== 0) {
localeResponse.items.forEach(function (locale) {
addlogs(credentialConfig, 'locale was exported successfully', 'success')
addlogs(credentialConfig, locale.name + ' locale was exported successfully', 'success')
for (const key in locale) {
if (requiredKeys.indexOf(key) === -1) {
delete locale.key
Expand All @@ -56,7 +56,7 @@ ExportLocales.prototype.start = function (credentialConfig) {
})
addlogs(credentialConfig, chalk.green('All the locales have been exported successfully'), 'success')
} else if (localeResponse.items.length === 0) {
addlogs(credentialConfig, 'No locales, other than master-locale were found in the Stack', 'success')
addlogs(credentialConfig, 'No languages found except the master language', 'success')
}
helper.writeFile(path.join(localesFolderPath, localeConfig.fileName), self.locales)
resolve()
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export/src/lib/export/webhooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ ExportWebhooks.prototype.start = function (credentialConfig) {
addlogs(config, chalk.green('All the webhooks have been exported successfully'), 'success')
return resolve()
}
addlogs(config, 'No webhooks were found in the Stack', 'success')
addlogs(config, 'No webhooks found', 'success')
return resolve()
}).catch(function (error) {
if (error.statusCode === 401) {
Expand Down
5 changes: 3 additions & 2 deletions packages/contentstack-import/src/lib/import/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,11 @@ importReleases.prototype = {
item.uid = self.entriesUids[item.uid]
}
response.item().create({item})
.then(() => {
.then((responseData) => {
// responseData.deploy({environment: ''})
// addlogs(config, chalk.white("Item added under "+ response.name), 'success')
}).catch((error) => {
addlogs(config, error, 'error')
addlogs(config, error, 'error')
addlogs(config, chalk.white("Fail to add items under "+ response.name), 'error')
})
})
Expand Down