Skip to content

Commit

Permalink
Merge branch 'development' into bugfix/CS-43668
Browse files Browse the repository at this point in the history
  • Loading branch information
cs-raj authored Jan 25, 2024
2 parents caebb7c + 803422f commit 9829ca6
Show file tree
Hide file tree
Showing 14 changed files with 86 additions and 60 deletions.
39 changes: 16 additions & 23 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion packages/contentstack-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli-audit/1.3.4 darwin-arm64 node-v18.12.1
@contentstack/cli-audit/1.3.4 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-branches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-branches
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-branches/1.0.21 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-branches/1.0.22 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-bulk-publish/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-cm-bulk-publish
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-bulk-publish/1.4.0 darwin-arm64 node-v20.10.0
@contentstack/cli-cm-bulk-publish/1.4.0 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
4 changes: 3 additions & 1 deletion packages/contentstack-clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-clone
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-clone/1.9.0 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-clone/1.10.0 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down Expand Up @@ -51,6 +51,7 @@ USAGE
[--destination-stack-api-key <value>] [--import-webhook-status disable|current]
FLAGS
-c, --config=<value> Path for the external configuration
-n, --stack-name=<value> Name for the new stack to store the cloned content.
-y, --yes [Optional] Override marketplace prompts
--destination-management-token-alias=<value> Source API key of the target stack token alias.
Expand Down Expand Up @@ -101,6 +102,7 @@ USAGE
[--destination-stack-api-key <value>] [--import-webhook-status disable|current]
FLAGS
-c, --config=<value> Path for the external configuration
-n, --stack-name=<value> Name for the new stack to store the cloned content.
-y, --yes [Optional] Override marketplace prompts
--destination-management-token-alias=<value> Source API key of the target stack token alias.
Expand Down
6 changes: 4 additions & 2 deletions packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@contentstack/cli-cm-clone",
"description": "Contentstack stack clone plugin",
"version": "1.9.0",
"version": "1.10.0",
"author": "Contentstack",
"bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues",
"dependencies": {
Expand All @@ -18,7 +18,9 @@
"ora": "^5.1.0",
"prompt": "^1.3.0",
"rimraf": "^3.0.2",
"winston": "^3.7.2"
"winston": "^3.7.2",
"merge": "^2.1.1",
"lodash": "^4.17.20"
},
"devDependencies": {
"@oclif/test": "^1.2.7",
Expand Down
14 changes: 13 additions & 1 deletion packages/contentstack-clone/src/commands/cm/stacks/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ const { configHandler, flags, isAuthenticated, managementSDKClient } = require('
const { CloneHandler } = require('../../../lib/util/clone-handler');
const path = require('path');
const rimraf = require('rimraf');
const merge = require("merge")
let pathdir = path.join(__dirname.split('src')[0], 'contents');
const { readdirSync } = require('fs');
const { readdirSync, readFileSync } = require('fs');
let config = {};

class StackCloneCommand extends Command {
Expand All @@ -23,11 +24,17 @@ class StackCloneCommand extends Command {
'source-management-token-alias': sourceManagementTokenAlias,
'destination-management-token-alias': destinationManagementTokenAlias,
'import-webhook-status': importWebhookStatus,
'config': externalConfigPath
} = cloneCommandFlags;

const handleClone = async () => {
const listOfTokens = configHandler.get('tokens');

if (externalConfigPath) {
let externalConfig = readFileSync(externalConfigPath, 'utf-8')
externalConfig = JSON.parse(externalConfig);
config = merge.recursive(config, externalConfig);
}
config.forceStopMarketplaceAppsPrompt = yes;
config.skipAudit = cloneCommandFlags['skip-audit'];

Expand Down Expand Up @@ -249,6 +256,11 @@ b) Structure with content (all modules including entries & assets)
'skip-audit': flags.boolean({
description: 'Skips the audit fix.',
}),
'config': flags.string({
char: 'c',
required: false,
description: 'Path for the external configuration',
}),
};

StackCloneCommand.usage =
Expand Down
57 changes: 35 additions & 22 deletions packages/contentstack-clone/src/lib/util/clone-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ let { default: importCmd } = require('@contentstack/cli-cm-import');
const { CustomAbortController } = require('./abort-controller');
const prompt = require('prompt');
const colors = require('@colors/colors/safe');
const cloneDeep = require("lodash/cloneDeep")

const {
HandleOrgCommand,
Expand Down Expand Up @@ -616,51 +617,63 @@ class CloneHandler {

async cmdExport() {
return new Promise((resolve, reject) => {
const cmd = ['-k', config.source_stack, '-d', __dirname.split('src')[0] + 'contents'];
if (config.cloneType === 'a') {
config.filteredModules = ['stack'].concat(structureList);
cmd.push('-c');
cmd.push(path.join(__dirname, 'dummyConfig.json'));
// Creating export specific config by merging external configurations
let exportConfig = Object.assign({}, cloneDeep(config), {...config?.export});
delete exportConfig.import;
delete exportConfig.export;

const cmd = ['-k', exportConfig.source_stack, '-d', __dirname.split('src')[0] + 'contents'];
if (exportConfig.cloneType === 'a') {
exportConfig.filteredModules = ['stack'].concat(structureList);
}

if (config.source_alias) {
cmd.push('-a', config.source_alias);
if (exportConfig.source_alias) {
cmd.push('-a', exportConfig.source_alias);
}
if (config.sourceStackBranch) {
cmd.push('--branch', config.sourceStackBranch);
if (exportConfig.sourceStackBranch) {
cmd.push('--branch', exportConfig.sourceStackBranch);
}

if (config.forceStopMarketplaceAppsPrompt) cmd.push('-y');
if (exportConfig.forceStopMarketplaceAppsPrompt) cmd.push('-y');

fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(config));
cmd.push('-c');
cmd.push(path.join(__dirname, 'dummyConfig.json'));

fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(exportConfig));
let exportData = exportCmd.run(cmd);
exportData.then(() => resolve(true)).catch(reject);
});
}

async cmdImport() {
return new Promise(async (resolve, _reject) => {
// Creating export specific config by merging external configurations
let importConfig = Object.assign({}, cloneDeep(config), {...config?.import});
delete importConfig.import;
delete importConfig.export;

const cmd = ['-c', path.join(__dirname, 'dummyConfig.json')];

if (config.destination_alias) {
cmd.push('-a', config.destination_alias);
if (importConfig.destination_alias) {
cmd.push('-a', importConfig.destination_alias);
}
if (!config.data && config.sourceStackBranch) {
cmd.push('-d', path.join(config.pathDir, config.sourceStackBranch));
if (!importConfig.data && importConfig.sourceStackBranch) {
cmd.push('-d', path.join(importConfig.pathDir, importConfig.sourceStackBranch));
}
if (config.targetStackBranch) {
cmd.push('--branch', config.targetStackBranch);
if (importConfig.targetStackBranch) {
cmd.push('--branch', importConfig.targetStackBranch);
}
if (config.importWebhookStatus) {
cmd.push('--import-webhook-status', config.importWebhookStatus);
if (importConfig.importWebhookStatus) {
cmd.push('--import-webhook-status', importConfig.importWebhookStatus);
}

if (config.skipAudit) cmd.push('--skip-audit');
if (importConfig.skipAudit) cmd.push('--skip-audit');

if (config.forceStopMarketplaceAppsPrompt) cmd.push('-y');
if (importConfig.forceStopMarketplaceAppsPrompt) cmd.push('-y');

fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(config));
fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(importConfig));
await importCmd.run(cmd);
fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify({}))
return resolve();
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $ npm install -g @contentstack/cli-config
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-config/1.5.1 darwin-arm64 node-v20.8.0
@contentstack/cli-config/1.6.0 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-export/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ $ npm install -g @contentstack/cli-cm-export
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-export/1.10.3 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-export/1.10.4 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-import/1.13.0 darwin-arm64 node-v20.8.0
@contentstack/cli-cm-import/1.13.2 darwin-arm64 node-v20.8.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
2 changes: 2 additions & 0 deletions packages/contentstack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2332,6 +2332,7 @@ USAGE
[--destination-stack-api-key <value>] [--import-webhook-status disable|current]
FLAGS
-c, --config=<value> Path for the external configuration
-n, --stack-name=<value> Name for the new stack to store the cloned content.
-y, --yes [Optional] Override marketplace prompts
--destination-management-token-alias=<value> Source API key of the target stack token alias.
Expand Down Expand Up @@ -2483,6 +2484,7 @@ USAGE
[--destination-stack-api-key <value>] [--import-webhook-status disable|current]
FLAGS
-c, --config=<value> Path for the external configuration
-n, --stack-name=<value> Name for the new stack to store the cloned content.
-y, --yes [Optional] Override marketplace prompts
--destination-management-token-alias=<value> Source API key of the target stack token alias.
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@contentstack/cli-cm-bootstrap": "~1.7.1",
"@contentstack/cli-cm-branches": "~1.0.22",
"@contentstack/cli-cm-bulk-publish": "~1.4.0",
"@contentstack/cli-cm-clone": "~1.9.0",
"@contentstack/cli-cm-clone": "~1.10.0",
"@contentstack/cli-cm-export": "~1.10.4",
"@contentstack/cli-cm-export-to-csv": "~1.6.2",
"@contentstack/cli-cm-import": "~1.13.3",
Expand Down
10 changes: 6 additions & 4 deletions pnpm-lock.yaml

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

0 comments on commit 9829ca6

Please sign in to comment.