@contentstack/cli-cm-clone 1.8.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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 Contentstack
3
+ Copyright (c) 2024 Contentstack
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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.8.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,12 +51,14 @@ 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.
57
58
  --destination-stack-api-key=<value> Destination stack API Key
58
59
  --import-webhook-status=<option> [default: disable] [Optional] Webhook state
59
60
  <options: disable|current>
61
+ --skip-audit Skips the audit fix.
60
62
  --source-branch=<value> Branch of the source stack.
61
63
  --source-management-token-alias=<value> Source API key of the target stack token alias.
62
64
  --source-stack-api-key=<value> Source stack API Key
@@ -100,12 +102,14 @@ USAGE
100
102
  [--destination-stack-api-key <value>] [--import-webhook-status disable|current]
101
103
 
102
104
  FLAGS
105
+ -c, --config=<value> Path for the external configuration
103
106
  -n, --stack-name=<value> Name for the new stack to store the cloned content.
104
107
  -y, --yes [Optional] Override marketplace prompts
105
108
  --destination-management-token-alias=<value> Source API key of the target stack token alias.
106
109
  --destination-stack-api-key=<value> Destination stack API Key
107
110
  --import-webhook-status=<option> [default: disable] [Optional] Webhook state
108
111
  <options: disable|current>
112
+ --skip-audit Skips the audit fix.
109
113
  --source-branch=<value> Branch of the source stack.
110
114
  --source-management-token-alias=<value> Source API key of the target stack token alias.
111
115
  --source-stack-api-key=<value> Source stack API Key
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.8.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.12.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.8",
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,12 +24,19 @@ 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;
39
+ config.skipAudit = cloneCommandFlags['skip-audit'];
32
40
 
33
41
  if (cloneType) {
34
42
  config.cloneType = cloneType;
@@ -245,6 +253,14 @@ b) Structure with content (all modules including entries & assets)
245
253
  required: false,
246
254
  description: '[Optional] Override marketplace prompts',
247
255
  }),
256
+ 'skip-audit': flags.boolean({
257
+ description: 'Skips the audit fix.',
258
+ }),
259
+ 'config': flags.string({
260
+ char: 'c',
261
+ required: false,
262
+ description: 'Path for the external configuration',
263
+ }),
248
264
  };
249
265
 
250
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,25 +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.forceStopMarketplaceAppsPrompt) cmd.push('-y');
670
+ if (importConfig.skipAudit) cmd.push('--skip-audit');
671
+
672
+ if (importConfig.forceStopMarketplaceAppsPrompt) cmd.push('-y');
659
673
 
660
- fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(config));
674
+ fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(importConfig));
661
675
  await importCmd.run(cmd);
676
+ fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify({}))
662
677
  return resolve();
663
678
  });
664
679
  }