@contentstack/cli-cm-clone 1.9.0 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -16,7 +16,7 @@ $ npm install -g @contentstack/cli-cm-clone
16
16
  $ csdx COMMAND
17
17
  running command...
18
18
  $ csdx (--version)
19
- @contentstack/cli-cm-clone/1.9.0 darwin-arm64 node-v20.8.0
19
+ @contentstack/cli-cm-clone/1.10.0 darwin-arm64 node-v20.8.0
20
20
  $ csdx --help [COMMAND]
21
21
  USAGE
22
22
  $ csdx COMMAND
@@ -51,6 +51,7 @@ USAGE
51
51
  [--destination-stack-api-key <value>] [--import-webhook-status disable|current]
52
52
 
53
53
  FLAGS
54
+ -c, --config=<value> Path for the external configuration
54
55
  -n, --stack-name=<value> Name for the new stack to store the cloned content.
55
56
  -y, --yes [Optional] Override marketplace prompts
56
57
  --destination-management-token-alias=<value> Source API key of the target stack token alias.
@@ -101,6 +102,7 @@ USAGE
101
102
  [--destination-stack-api-key <value>] [--import-webhook-status disable|current]
102
103
 
103
104
  FLAGS
105
+ -c, --config=<value> Path for the external configuration
104
106
  -n, --stack-name=<value> Name for the new stack to store the cloned content.
105
107
  -y, --yes [Optional] Override marketplace prompts
106
108
  --destination-management-token-alias=<value> Source API key of the target stack token alias.
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-clone",
3
3
  "description": "Contentstack stack clone plugin",
4
- "version": "1.9.0",
4
+ "version": "1.10.0",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-cm-export": "~1.10.2",
9
- "@contentstack/cli-cm-import": "~1.13.0",
8
+ "@contentstack/cli-cm-export": "~1.10.4",
9
+ "@contentstack/cli-cm-import": "~1.13.3",
10
10
  "@contentstack/cli-command": "~1.2.16",
11
- "@contentstack/cli-utilities": "~1.5.10",
11
+ "@contentstack/cli-utilities": "~1.5.11",
12
12
  "@colors/colors": "^1.5.0",
13
13
  "async": "^3.2.4",
14
14
  "chalk": "^4.1.0",
@@ -18,10 +18,12 @@
18
18
  "ora": "^5.1.0",
19
19
  "prompt": "^1.3.0",
20
20
  "rimraf": "^3.0.2",
21
- "winston": "^3.7.2"
21
+ "winston": "^3.7.2",
22
+ "merge": "^2.1.1",
23
+ "lodash": "^4.17.20"
22
24
  },
23
25
  "devDependencies": {
24
- "@oclif/test": "^1.2.7",
26
+ "@oclif/test": "^2.5.6",
25
27
  "chai": "^4.2.0",
26
28
  "eslint": "^8.18.0",
27
29
  "eslint-config-oclif": "^4.0.0",
@@ -70,4 +72,4 @@
70
72
  "cm:stack-clone": "O-CLN"
71
73
  }
72
74
  }
73
- }
75
+ }
@@ -3,8 +3,9 @@ const { configHandler, flags, isAuthenticated, managementSDKClient } = require('
3
3
  const { CloneHandler } = require('../../../lib/util/clone-handler');
4
4
  const path = require('path');
5
5
  const rimraf = require('rimraf');
6
+ const merge = require("merge")
6
7
  let pathdir = path.join(__dirname.split('src')[0], 'contents');
7
- const { readdirSync } = require('fs');
8
+ const { readdirSync, readFileSync } = require('fs');
8
9
  let config = {};
9
10
 
10
11
  class StackCloneCommand extends Command {
@@ -23,11 +24,17 @@ class StackCloneCommand extends Command {
23
24
  'source-management-token-alias': sourceManagementTokenAlias,
24
25
  'destination-management-token-alias': destinationManagementTokenAlias,
25
26
  'import-webhook-status': importWebhookStatus,
27
+ 'config': externalConfigPath
26
28
  } = cloneCommandFlags;
27
29
 
28
30
  const handleClone = async () => {
29
31
  const listOfTokens = configHandler.get('tokens');
30
32
 
33
+ if (externalConfigPath) {
34
+ let externalConfig = readFileSync(externalConfigPath, 'utf-8')
35
+ externalConfig = JSON.parse(externalConfig);
36
+ config = merge.recursive(config, externalConfig);
37
+ }
31
38
  config.forceStopMarketplaceAppsPrompt = yes;
32
39
  config.skipAudit = cloneCommandFlags['skip-audit'];
33
40
 
@@ -249,6 +256,11 @@ b) Structure with content (all modules including entries & assets)
249
256
  'skip-audit': flags.boolean({
250
257
  description: 'Skips the audit fix.',
251
258
  }),
259
+ 'config': flags.string({
260
+ char: 'c',
261
+ required: false,
262
+ description: 'Path for the external configuration',
263
+ }),
252
264
  };
253
265
 
254
266
  StackCloneCommand.usage =
@@ -8,6 +8,7 @@ let { default: importCmd } = require('@contentstack/cli-cm-import');
8
8
  const { CustomAbortController } = require('./abort-controller');
9
9
  const prompt = require('prompt');
10
10
  const colors = require('@colors/colors/safe');
11
+ const cloneDeep = require("lodash/cloneDeep")
11
12
 
12
13
  const {
13
14
  HandleOrgCommand,
@@ -616,23 +617,29 @@ class CloneHandler {
616
617
 
617
618
  async cmdExport() {
618
619
  return new Promise((resolve, reject) => {
619
- const cmd = ['-k', config.source_stack, '-d', __dirname.split('src')[0] + 'contents'];
620
- if (config.cloneType === 'a') {
621
- config.filteredModules = ['stack'].concat(structureList);
622
- cmd.push('-c');
623
- cmd.push(path.join(__dirname, 'dummyConfig.json'));
620
+ // Creating export specific config by merging external configurations
621
+ let exportConfig = Object.assign({}, cloneDeep(config), {...config?.export});
622
+ delete exportConfig.import;
623
+ delete exportConfig.export;
624
+
625
+ const cmd = ['-k', exportConfig.source_stack, '-d', __dirname.split('src')[0] + 'contents'];
626
+ if (exportConfig.cloneType === 'a') {
627
+ exportConfig.filteredModules = ['stack'].concat(structureList);
624
628
  }
625
629
 
626
- if (config.source_alias) {
627
- cmd.push('-a', config.source_alias);
630
+ if (exportConfig.source_alias) {
631
+ cmd.push('-a', exportConfig.source_alias);
628
632
  }
629
- if (config.sourceStackBranch) {
630
- cmd.push('--branch', config.sourceStackBranch);
633
+ if (exportConfig.sourceStackBranch) {
634
+ cmd.push('--branch', exportConfig.sourceStackBranch);
631
635
  }
632
636
 
633
- if (config.forceStopMarketplaceAppsPrompt) cmd.push('-y');
637
+ if (exportConfig.forceStopMarketplaceAppsPrompt) cmd.push('-y');
634
638
 
635
- fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(config));
639
+ cmd.push('-c');
640
+ cmd.push(path.join(__dirname, 'dummyConfig.json'));
641
+
642
+ fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(exportConfig));
636
643
  let exportData = exportCmd.run(cmd);
637
644
  exportData.then(() => resolve(true)).catch(reject);
638
645
  });
@@ -640,27 +647,33 @@ class CloneHandler {
640
647
 
641
648
  async cmdImport() {
642
649
  return new Promise(async (resolve, _reject) => {
650
+ // Creating export specific config by merging external configurations
651
+ let importConfig = Object.assign({}, cloneDeep(config), {...config?.import});
652
+ delete importConfig.import;
653
+ delete importConfig.export;
654
+
643
655
  const cmd = ['-c', path.join(__dirname, 'dummyConfig.json')];
644
656
 
645
- if (config.destination_alias) {
646
- cmd.push('-a', config.destination_alias);
657
+ if (importConfig.destination_alias) {
658
+ cmd.push('-a', importConfig.destination_alias);
647
659
  }
648
- if (!config.data && config.sourceStackBranch) {
649
- cmd.push('-d', path.join(config.pathDir, config.sourceStackBranch));
660
+ if (!importConfig.data && importConfig.sourceStackBranch) {
661
+ cmd.push('-d', path.join(importConfig.pathDir, importConfig.sourceStackBranch));
650
662
  }
651
- if (config.targetStackBranch) {
652
- cmd.push('--branch', config.targetStackBranch);
663
+ if (importConfig.targetStackBranch) {
664
+ cmd.push('--branch', importConfig.targetStackBranch);
653
665
  }
654
- if (config.importWebhookStatus) {
655
- cmd.push('--import-webhook-status', config.importWebhookStatus);
666
+ if (importConfig.importWebhookStatus) {
667
+ cmd.push('--import-webhook-status', importConfig.importWebhookStatus);
656
668
  }
657
669
 
658
- if (config.skipAudit) cmd.push('--skip-audit');
670
+ if (importConfig.skipAudit) cmd.push('--skip-audit');
659
671
 
660
- if (config.forceStopMarketplaceAppsPrompt) cmd.push('-y');
672
+ if (importConfig.forceStopMarketplaceAppsPrompt) cmd.push('-y');
661
673
 
662
- fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(config));
674
+ fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(importConfig));
663
675
  await importCmd.run(cmd);
676
+ fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify({}))
664
677
  return resolve();
665
678
  });
666
679
  }