@contentstack/cli-cm-import-setup 1.0.0-beta.1 → 1.0.1

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
@@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import-setup
47
47
  $ csdx COMMAND
48
48
  running command...
49
49
  $ csdx (--version)
50
- @contentstack/cli-cm-import-setup/1.0.0-beta.1 linux-x64 node-v18.20.5
50
+ @contentstack/cli-cm-import-setup/1.0.1 linux-x64 node-v18.20.6
51
51
  $ csdx --help [COMMAND]
52
52
  USAGE
53
53
  $ csdx COMMAND
@@ -63,52 +63,72 @@ USAGE
63
63
 
64
64
  ## `csdx cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]`
65
65
 
66
- Import content from a stack
66
+ Helps to generate mappers and backup folder for importing (overwriting) specific modules
67
67
 
68
68
  ```
69
69
  USAGE
70
70
  $ csdx cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]
71
71
 
72
72
  FLAGS
73
- -a, --alias=<value> alias of the management token
74
- -d, --data-dir=<value> path and location where data is stored
73
+ -B, --branch=<value> The name of the branch where you want to import your content. If you don't mention the
74
+ branch name, then by default the content will be imported to the main branch.
75
+ -a, --alias=<value> The management token of the destination stack where you will import the content.
76
+ -d, --data-dir=<value> The path or the location in your file system where the content, you intend to import, is
77
+ stored. For example, -d "C:\Users\Name\Desktop\cli\content". If the export folder has
78
+ branches involved, then the path should point till the particular branch. For example,
79
+ “-d "C:\Users\Name\Desktop\cli\content\branch_name"
75
80
  -k, --stack-api-key=<value> API key of the target stack
76
- --modules=<option> [optional] specific module name
77
- <options: content-types|entries|both>
81
+ --module=<option>... [optional] Specify the modules/module to import into the target stack. currently options
82
+ are global-fields, content-types, entries
83
+ <options: global-fields|content-types|entries>
78
84
 
79
85
  DESCRIPTION
80
- Import content from a stack
86
+ Helps to generate mappers and backup folder for importing (overwriting) specific modules
81
87
 
82
88
  ALIASES
83
89
  $ csdx cm:import-setup
84
90
 
85
91
  EXAMPLES
86
- $ csdx cm:stacks:import-setup --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>
92
+ $ csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>
93
+
94
+ $ csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name>
95
+
96
+ $ csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name> -b <branch_name>
87
97
  ```
88
98
 
89
99
  ## `csdx cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]`
90
100
 
91
- Import content from a stack
101
+ Helps to generate mappers and backup folder for importing (overwriting) specific modules
92
102
 
93
103
  ```
94
104
  USAGE
95
105
  $ csdx cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]
96
106
 
97
107
  FLAGS
98
- -a, --alias=<value> alias of the management token
99
- -d, --data-dir=<value> path and location where data is stored
108
+ -B, --branch=<value> The name of the branch where you want to import your content. If you don't mention the
109
+ branch name, then by default the content will be imported to the main branch.
110
+ -a, --alias=<value> The management token of the destination stack where you will import the content.
111
+ -d, --data-dir=<value> The path or the location in your file system where the content, you intend to import, is
112
+ stored. For example, -d "C:\Users\Name\Desktop\cli\content". If the export folder has
113
+ branches involved, then the path should point till the particular branch. For example,
114
+ “-d "C:\Users\Name\Desktop\cli\content\branch_name"
100
115
  -k, --stack-api-key=<value> API key of the target stack
101
- --modules=<option> [optional] specific module name
102
- <options: content-types|entries|both>
116
+ --module=<option>... [optional] Specify the modules/module to import into the target stack. currently options
117
+ are global-fields, content-types, entries
118
+ <options: global-fields|content-types|entries>
103
119
 
104
120
  DESCRIPTION
105
- Import content from a stack
121
+ Helps to generate mappers and backup folder for importing (overwriting) specific modules
106
122
 
107
123
  ALIASES
108
124
  $ csdx cm:import-setup
109
125
 
110
126
  EXAMPLES
111
- $ csdx cm:stacks:import-setup --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>
127
+ $ csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>
128
+
129
+ $ csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name>
130
+
131
+ $ csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name> -b <branch_name>
112
132
  ```
113
133
 
114
134
  _See code: [src/commands/cm/stacks/import-setup.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-import-setup/src/commands/cm/stacks/import-setup.ts)_
@@ -18,18 +18,20 @@ class ImportSetupCommand extends cli_command_1.Command {
18
18
  const managementAPIClient = await (0, cli_utilities_1.managementSDKClient)(importSetupConfig);
19
19
  const importSetup = new import_1.ImportSetup(importSetupConfig, managementAPIClient);
20
20
  await importSetup.start();
21
- (0, utils_1.log)(importSetupConfig, `Successfully created backup folder and mapper files for the stack with the API key ${importSetupConfig.apiKey}.`, 'success');
22
- (0, utils_1.log)(importSetupConfig, `The backup folder created at '${(0, cli_utilities_1.pathValidator)(node_path_1.default.join(importSetupConfig.backupDir))}'`, 'success');
21
+ (0, utils_1.log)(importSetupConfig, `Backup folder and mapper files have been successfully created for the stack using the API key ${importSetupConfig.apiKey}.`, 'success');
22
+ (0, utils_1.log)(importSetupConfig, `The backup folder has been created at '${(0, cli_utilities_1.pathValidator)(node_path_1.default.join(importSetupConfig.backupDir))}'.`, 'success');
23
23
  }
24
24
  catch (error) {
25
- (0, utils_1.log)({ data: '' }, `Failed to create backup folder and mapper files - ${(0, cli_utilities_1.formatError)(error)}`, 'error');
25
+ (0, utils_1.log)({ data: '' }, `Failed to create the backup folder and mapper files: ${(0, cli_utilities_1.formatError)(error)}`, 'error');
26
26
  }
27
27
  }
28
28
  }
29
29
  exports.default = ImportSetupCommand;
30
- ImportSetupCommand.description = cli_utilities_1.messageHandler.parse('Import content from a stack');
30
+ ImportSetupCommand.description = cli_utilities_1.messageHandler.parse('Helps to generate mappers and backup folder for importing (overwriting) specific modules');
31
31
  ImportSetupCommand.examples = [
32
- `csdx cm:stacks:import-setup --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>`,
32
+ `csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>`,
33
+ `csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name>`,
34
+ `csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name> -b <branch_name>`,
33
35
  ];
34
36
  ImportSetupCommand.flags = {
35
37
  'stack-api-key': cli_utilities_1.flags.string({
@@ -38,15 +40,21 @@ ImportSetupCommand.flags = {
38
40
  }),
39
41
  'data-dir': cli_utilities_1.flags.string({
40
42
  char: 'd',
41
- description: 'path and location where data is stored',
43
+ description: `The path or the location in your file system where the content, you intend to import, is stored. For example, -d "C:\\Users\\Name\\Desktop\\cli\\content". If the export folder has branches involved, then the path should point till the particular branch. For example, “-d "C:\\Users\\Name\\Desktop\\cli\\content\\branch_name"`,
42
44
  }),
43
45
  alias: cli_utilities_1.flags.string({
44
46
  char: 'a',
45
- description: 'alias of the management token',
47
+ description: 'The management token of the destination stack where you will import the content.',
46
48
  }),
47
- modules: cli_utilities_1.flags.string({
48
- options: ['content-types', 'entries', 'both'],
49
- description: '[optional] specific module name',
49
+ module: cli_utilities_1.flags.string({
50
+ options: ['global-fields', 'content-types', 'entries'],
51
+ description: '[optional] Specify the modules/module to import into the target stack. currently options are global-fields, content-types, entries',
52
+ multiple: true,
53
+ }),
54
+ branch: cli_utilities_1.flags.string({
55
+ char: 'B',
56
+ description: "The name of the branch where you want to import your content. If you don't mention the branch name, then by default the content will be imported to the main branch.",
57
+ parse: (0, cli_utilities_1.printFlagDeprecation)(['-B'], ['--branch']),
50
58
  }),
51
59
  };
52
60
  ImportSetupCommand.aliases = ['cm:import-setup'];
@@ -46,7 +46,7 @@ const config = {
46
46
  'global-fields': {
47
47
  dirName: 'global_fields',
48
48
  fileName: 'globalfields.json',
49
- dependencies: ['marketplace-apps'],
49
+ dependencies: ['extensions', 'marketplace-apps'],
50
50
  },
51
51
  'marketplace-apps': {
52
52
  dirName: 'marketplace_apps',
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const utils_1 = require("../utils");
27
- const cli_utilities_1 = require("@contentstack/cli-utilities");
27
+ const utils_2 = require("../utils");
28
28
  class ImportSetup {
29
29
  constructor(config, managementAPIClient) {
30
30
  this.dependencyTree = {};
@@ -41,20 +41,27 @@ class ImportSetup {
41
41
  * @returns {Promise<Array<void | string>>}
42
42
  */
43
43
  async generateDependencyTree() {
44
- const getAllDependencies = (module, visited = new Set()) => {
44
+ const visited = new Set();
45
+ const assignedDependencies = new Set(); // Track assigned dependencies
46
+ const getAllDependencies = (module) => {
45
47
  var _a;
46
48
  if (visited.has(module))
47
49
  return [];
48
50
  visited.add(module);
49
- let dependencies = ((_a = this.config.modules[module]) === null || _a === void 0 ? void 0 : _a.dependencies) || [];
51
+ const dependencies = ((_a = this.config.modules[module]) === null || _a === void 0 ? void 0 : _a.dependencies) || [];
52
+ let allDeps = [...dependencies];
50
53
  for (const dependency of dependencies) {
51
- dependencies = dependencies.concat(getAllDependencies(dependency, visited));
54
+ allDeps.push(...getAllDependencies(dependency));
52
55
  }
53
- return dependencies;
56
+ return allDeps;
54
57
  };
58
+ this.dependencyTree = {}; // Reset before building
55
59
  for (const module of this.config.selectedModules) {
56
- const allDependencies = getAllDependencies(module);
57
- this.dependencyTree[module] = Array.from(new Set(allDependencies));
60
+ let allDependencies = getAllDependencies(module);
61
+ allDependencies = allDependencies.filter((dep) => !assignedDependencies.has(dep)); // Remove assigned ones
62
+ this.dependencyTree[module] = allDependencies;
63
+ // Mark these dependencies as assigned so they won't be included in later modules
64
+ allDependencies.forEach((dep) => assignedDependencies.add(dep));
58
65
  }
59
66
  }
60
67
  /**
@@ -78,7 +85,7 @@ class ImportSetup {
78
85
  await moduleInstance.start();
79
86
  }
80
87
  catch (error) {
81
- (0, utils_1.log)(this.config, `Error importing '${moduleName}': ${(0, cli_utilities_1.formatError)(error)}`, 'error');
88
+ (0, utils_1.log)(this.config, `Error occurred while importing '${moduleName}'`, 'error');
82
89
  throw error;
83
90
  }
84
91
  }
@@ -100,6 +107,9 @@ class ImportSetup {
100
107
  if (backupDir) {
101
108
  this.config.backupDir = backupDir;
102
109
  }
110
+ if (this.config.branchName) {
111
+ await (0, utils_2.validateBranch)(this.stackAPIClient, this.config, this.config.branchName);
112
+ }
103
113
  await this.generateDependencyTree();
104
114
  await this.runModuleImports();
105
115
  }
@@ -29,10 +29,10 @@ class AssetImportSetup extends base_setup_1.default {
29
29
  try {
30
30
  utils_1.fsUtil.makeDirectory(this.mapperDirPath);
31
31
  await this.fetchAndMapAssets();
32
- (0, utils_1.log)(this.config, `Generated required setup files for asset`, 'success');
32
+ (0, utils_1.log)(this.config, `The required setup files for the asset have been generated successfully.`, 'success');
33
33
  }
34
34
  catch (error) {
35
- (0, utils_1.log)(this.config, `Error generating asset mapper: ${(0, cli_utilities_1.formatError)(error)}`, 'error');
35
+ (0, utils_1.log)(this.config, `Error occurred while generating the asset mapper: ${(0, cli_utilities_1.formatError)(error)}.`, 'error');
36
36
  }
37
37
  }
38
38
  /**
@@ -51,20 +51,20 @@ class AssetImportSetup extends base_setup_1.default {
51
51
  if (items.length === 1) {
52
52
  this.assetUidMapper[uid] = items[0].uid;
53
53
  this.assetUrlMapper[url] = items[0].url;
54
- (0, utils_1.log)(this.config, `Mapped asset: '${title}'`, 'info');
54
+ (0, utils_1.log)(this.config, `Mapped asset successfully: '${title}'`, 'info');
55
55
  }
56
56
  else if (items.length > 1) {
57
57
  this.duplicateAssets[uid] = items.map((asset) => {
58
58
  return { uid: asset.uid, title: asset.title, url: asset.url };
59
59
  });
60
- (0, utils_1.log)(this.config, `Multiple assets found with title '${title}'`, 'info');
60
+ (0, utils_1.log)(this.config, `Multiple assets found with the title '${title}'.`, 'info');
61
61
  }
62
62
  else {
63
63
  (0, utils_1.log)(this.config, `Asset with title '${title}' not found in the stack!`, 'info');
64
64
  }
65
65
  };
66
66
  const onReject = ({ error, apiData: { title } = undefined }) => {
67
- (0, utils_1.log)(this.config, `${title} asset mapping failed.!`, 'error');
67
+ (0, utils_1.log)(this.config, `Failed to map the asset '${title}'.`, 'error');
68
68
  (0, utils_1.log)(this.config, (0, cli_utilities_1.formatError)(error), 'error');
69
69
  };
70
70
  /* eslint-disable @typescript-eslint/no-unused-vars, guard-for-in */
@@ -95,7 +95,7 @@ class AssetImportSetup extends base_setup_1.default {
95
95
  }
96
96
  if (!(0, lodash_1.isEmpty)(this.duplicateAssets)) {
97
97
  utils_1.fsUtil.writeFile(this.duplicateAssetPath, this.duplicateAssets);
98
- (0, utils_1.log)(this.config, `Duplicate asset files store here ${this.duplicateAssetPath}`, 'info');
98
+ (0, utils_1.log)(this.config, `Duplicate asset files are stored at: ${this.duplicateAssetPath}.`, 'info');
99
99
  }
100
100
  }
101
101
  }
@@ -10,10 +10,10 @@ class ContentTypesImportSetup extends base_setup_1.default {
10
10
  async start() {
11
11
  try {
12
12
  await this.setupDependencies();
13
- (0, utils_1.log)(this.config, `Generate required setup files for content types`, 'success');
13
+ (0, utils_1.log)(this.config, `The required setup files for content types have been generated successfully.`, 'success');
14
14
  }
15
15
  catch (error) {
16
- (0, utils_1.log)(this.config, `Error generating ${error.message}`, 'error');
16
+ (0, utils_1.log)(this.config, `Error occurred while generating the content type mapper: ${error.message}.`, 'error');
17
17
  }
18
18
  }
19
19
  }
@@ -10,10 +10,10 @@ class EntriesImportSetup extends base_setup_1.default {
10
10
  async start() {
11
11
  try {
12
12
  await this.setupDependencies();
13
- (0, utils_1.log)(this.config, `Generate required setup files for entries`, 'success');
13
+ (0, utils_1.log)(this.config, `The required setup files for entries have been generated successfully.`, 'success');
14
14
  }
15
15
  catch (error) {
16
- (0, utils_1.log)(this.config, `Error generating ${error.message}`, 'error');
16
+ (0, utils_1.log)(this.config, `Error occurred while generating the entry mapper: ${error.message}.`, 'error');
17
17
  }
18
18
  }
19
19
  }
@@ -28,20 +28,20 @@ class ExtensionImportSetup {
28
28
  for (const extension of Object.values(extensions)) {
29
29
  const targetExtension = await this.getExtension(extension);
30
30
  if (!targetExtension) {
31
- (0, utils_1.log)(this.config, `Extension with title '${extension.title}' not found in the stack!`, 'info');
31
+ (0, utils_1.log)(this.config, `Extension with the title '${extension.title}' not found in the stack.`, 'info');
32
32
  continue;
33
33
  }
34
34
  this.extensionMapper[extension.uid] = targetExtension.uid;
35
35
  }
36
36
  await utils_1.fsUtil.writeFile(this.extUidMapperPath, this.extensionMapper);
37
- (0, utils_1.log)(this.config, `Generated required setup files for extension`, 'success');
37
+ (0, utils_1.log)(this.config, `The required setup files for extensions have been generated successfully.`, 'success');
38
38
  }
39
39
  else {
40
- (0, utils_1.log)(this.config, 'No extensions found in the content folder!', 'error');
40
+ (0, utils_1.log)(this.config, 'No extensions found in the content folder.', 'info');
41
41
  }
42
42
  }
43
43
  catch (error) {
44
- (0, utils_1.log)(this.config, `Error generating extension mapper: ${(0, cli_utilities_1.formatError)(error)}`, 'error');
44
+ (0, utils_1.log)(this.config, `Error occurred while generating the extension mapper: ${(0, cli_utilities_1.formatError)(error)}.`, 'error');
45
45
  }
46
46
  }
47
47
  async getExtension(extension) {
@@ -0,0 +1,6 @@
1
+ import { ModuleClassParams } from '../../types';
2
+ import BaseImportSetup from './base-setup';
3
+ export default class GlobalFieldsImportSetup extends BaseImportSetup {
4
+ constructor(options: ModuleClassParams);
5
+ start(): Promise<void>;
6
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const utils_1 = require("../../utils");
5
+ const base_setup_1 = tslib_1.__importDefault(require("./base-setup"));
6
+ class GlobalFieldsImportSetup extends base_setup_1.default {
7
+ constructor(options) {
8
+ super(options);
9
+ }
10
+ async start() {
11
+ try {
12
+ await this.setupDependencies();
13
+ (0, utils_1.log)(this.config, `The required setup files for global fields have been generated successfully.`, 'success');
14
+ }
15
+ catch (error) {
16
+ (0, utils_1.log)(this.config, `Error occurred while generating the global field mapper: ${error.message}.`, 'error');
17
+ }
18
+ }
19
+ }
20
+ exports.default = GlobalFieldsImportSetup;
@@ -30,14 +30,14 @@ class marketplaceAppImportSetup {
30
30
  const targetMarketplaceApps = await this.getMarketplaceApps();
31
31
  this.createMapper(sourceMarketplaceApps, targetMarketplaceApps);
32
32
  await utils_1.fsUtil.writeFile((0, path_1.join)(this.marketplaceAppsUidMapperPath, 'uid-mapping.json'), this.marketplaceAppMapper);
33
- (0, utils_1.log)(this.config, `Generated required setup files for marketplaceApp`, 'success');
33
+ (0, utils_1.log)(this.config, `The required setup files for Marketplace apps have been generated successfully.`, 'success');
34
34
  }
35
35
  else {
36
- (0, utils_1.log)(this.config, 'No marketplaceApps found in the content folder!', 'info');
36
+ (0, utils_1.log)(this.config, 'No Marketplace apps found in the content folder.', 'info');
37
37
  }
38
38
  }
39
39
  catch (error) {
40
- (0, utils_1.log)(this.config, `Error generating marketplaceApp mapper: ${(0, cli_utilities_1.formatError)(error)}`, 'error');
40
+ (0, utils_1.log)(this.config, `Error occurred while generating the Marketplace app mapper: ${error.message}.`, 'error');
41
41
  }
42
42
  }
43
43
  async getMarketplaceApps() {
@@ -56,7 +56,12 @@ class marketplaceAppImportSetup {
56
56
  createMapper(sourceMarketplaceApps, targetMarketplaceApps) {
57
57
  sourceMarketplaceApps.forEach((sourceApp) => {
58
58
  // Find matching target item based on manifest.name
59
- const targetApp = targetMarketplaceApps.find((targetApp) => (0, lodash_1.get)(targetApp, 'manifest.name') === (0, lodash_1.get)(sourceApp, 'manifest.name'));
59
+ // TBD: This logic is not foolproof, need to find a better way to match source and target apps
60
+ // Reason: While importing apps, if an app exist in the target with the same name, it will be a conflict and will not be imported
61
+ // So, import command gives an option to import the app with a different name by appending ◈ to the app name. Considering this we are matching the app name without the ◈ character
62
+ const getAppName = (app) => (0, lodash_1.get)(app, 'manifest.name', '').split('◈')[0];
63
+ const sourceAppName = getAppName(sourceApp);
64
+ const targetApp = targetMarketplaceApps.find((app) => getAppName(app) === sourceAppName);
60
65
  if (targetApp) {
61
66
  // Map app_uid from source and target
62
67
  this.marketplaceAppMapper.app_uid[sourceApp.manifest.uid] = targetApp.manifest.uid;
@@ -75,6 +80,9 @@ class marketplaceAppImportSetup {
75
80
  }
76
81
  });
77
82
  }
83
+ else {
84
+ (0, utils_1.log)(this.config, `No matching Marketplace app found in the target stack with name ${sourceAppName}`, 'info');
85
+ }
78
86
  });
79
87
  }
80
88
  }
@@ -51,10 +51,10 @@ class TaxonomiesImportSetup {
51
51
  if (this.termsMapper !== undefined && !(0, isEmpty_1.default)(this.termsMapper)) {
52
52
  utils_1.fsUtil.writeFile(this.termsSuccessPath, this.termsMapper);
53
53
  }
54
- (0, utils_1.log)(this.config, `Generated required setup files for taxonomies`, 'success');
54
+ (0, utils_1.log)(this.config, `The required setup files for taxonomies have been generated successfully.`, 'success');
55
55
  }
56
56
  else {
57
- (0, utils_1.log)(this.config, 'No taxonomies found in the content folder!', 'info');
57
+ (0, utils_1.log)(this.config, 'No taxonomies found in the content folder.', 'info');
58
58
  }
59
59
  }
60
60
  catch (error) {
@@ -0,0 +1,2 @@
1
+ import { ImportConfig } from 'src/types';
2
+ export declare const validateBranch: (stackAPIClient: any, config: ImportConfig, branch: any) => Promise<unknown>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateBranch = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
+ const utils_1 = require("../utils");
7
+ const validateBranch = async (stackAPIClient, config, branch) => {
8
+ return new Promise(async (resolve, reject) => {
9
+ try {
10
+ const data = await stackAPIClient.branch(branch).fetch();
11
+ if (data && typeof data === 'object') {
12
+ if (data.error_message) {
13
+ (0, utils_1.log)(config, chalk_1.default.red(data.error_message), 'error');
14
+ (0, utils_1.log)(config, chalk_1.default.red('No branch found with the name ' + branch), 'error');
15
+ reject({ message: 'No branch found with the name ' + branch, error: data.error_message });
16
+ }
17
+ else {
18
+ resolve(data);
19
+ }
20
+ }
21
+ else {
22
+ reject({ message: 'No branch found with the name ' + branch, error: {} });
23
+ }
24
+ }
25
+ catch (error) {
26
+ (0, utils_1.log)(config, chalk_1.default.red('No branch found with the name ' + branch), 'error');
27
+ reject({ message: 'No branch found with the name ' + branch, error });
28
+ }
29
+ });
30
+ };
31
+ exports.validateBranch = validateBranch;
@@ -74,15 +74,8 @@ const setupConfig = async (importCmdFlags) => {
74
74
  // config.skipPrivateAppRecreationIfExist = importCmdFlags['skip-app-recreation'];
75
75
  if (importCmdFlags['branch']) {
76
76
  config.branchName = importCmdFlags['branch'];
77
- config.branchDir = path.join((0, cli_utilities_1.sanitizePath)(config.contentDir), (0, cli_utilities_1.sanitizePath)(config.branchName));
78
- }
79
- const selectedModule = importCmdFlags['modules'] || (await (0, interactive_1.askSelectedModules)());
80
- if (selectedModule === 'both') {
81
- config.selectedModules = ['content-types', 'entries'];
82
- }
83
- else {
84
- config.selectedModules = [selectedModule];
85
77
  }
78
+ config.selectedModules = importCmdFlags['module'] || [await (0, interactive_1.askSelectedModules)()];
86
79
  if (importCmdFlags['backup-dir']) {
87
80
  config.useBackedupDir = importCmdFlags['backup-dir'];
88
81
  }
@@ -5,3 +5,4 @@ export { fsUtil } from './file-helper';
5
5
  export { default as backupHandler } from './backup-handler';
6
6
  export { log, unlinkFileLogger } from './logger';
7
7
  export * from './log';
8
+ export * from './common-helper';
@@ -14,3 +14,4 @@ var logger_1 = require("./logger");
14
14
  Object.defineProperty(exports, "log", { enumerable: true, get: function () { return logger_1.log; } });
15
15
  Object.defineProperty(exports, "unlinkFileLogger", { enumerable: true, get: function () { return logger_1.unlinkFileLogger; } });
16
16
  tslib_1.__exportStar(require("./log"), exports);
17
+ tslib_1.__exportStar(require("./common-helper"), exports);
@@ -19,11 +19,11 @@ const askSelectedModules = async () => {
19
19
  return cli_utilities_1.cliux.inquire({
20
20
  type: 'list',
21
21
  name: 'selectedModule',
22
- message: 'Please select a module to generate the mapper files',
22
+ message: 'Please select a module to generate the mapper files.',
23
23
  choices: [
24
+ { name: 'Global Fields', value: 'global-fields' },
24
25
  { name: 'Content types', value: 'content-types' },
25
26
  { name: 'Entries', value: 'entries' },
26
- { name: 'Both', value: 'both' },
27
27
  ],
28
28
  });
29
29
  };
@@ -1,9 +1,9 @@
1
1
  {
2
- "version": "1.0.0-beta.1",
2
+ "version": "1.0.1",
3
3
  "commands": {
4
4
  "cm:stacks:import-setup": {
5
5
  "id": "cm:stacks:import-setup",
6
- "description": "Import content from a stack",
6
+ "description": "Helps to generate mappers and backup folder for importing (overwriting) specific modules",
7
7
  "strict": true,
8
8
  "usage": "cm:stacks:import-setup [-k <value>] [-d <value>] [-a <value>] [--modules <value,value>]",
9
9
  "pluginName": "@contentstack/cli-cm-import-setup",
@@ -14,7 +14,9 @@
14
14
  ],
15
15
  "hiddenAliases": [],
16
16
  "examples": [
17
- "csdx cm:stacks:import-setup --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>"
17
+ "csdx cm:stacks:import-setup --stack-api-key <target_stack_api_key> --data-dir <path/of/export/destination/dir> --modules <module_name, module_name>",
18
+ "csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name>",
19
+ "csdx cm:stacks:import-setup -k <target_stack_api_key> -d <path/of/export/destination/dir> --modules <module_name, module_name> -b <branch_name>"
18
20
  ],
19
21
  "flags": {
20
22
  "stack-api-key": {
@@ -28,26 +30,33 @@
28
30
  "name": "data-dir",
29
31
  "type": "option",
30
32
  "char": "d",
31
- "description": "path and location where data is stored",
33
+ "description": "The path or the location in your file system where the content, you intend to import, is stored. For example, -d \"C:\\Users\\Name\\Desktop\\cli\\content\". If the export folder has branches involved, then the path should point till the particular branch. For example, “-d \"C:\\Users\\Name\\Desktop\\cli\\content\\branch_name\"",
32
34
  "multiple": false
33
35
  },
34
36
  "alias": {
35
37
  "name": "alias",
36
38
  "type": "option",
37
39
  "char": "a",
38
- "description": "alias of the management token",
40
+ "description": "The management token of the destination stack where you will import the content.",
39
41
  "multiple": false
40
42
  },
41
- "modules": {
42
- "name": "modules",
43
+ "module": {
44
+ "name": "module",
43
45
  "type": "option",
44
- "description": "[optional] specific module name",
45
- "multiple": false,
46
+ "description": "[optional] Specify the modules/module to import into the target stack. currently options are global-fields, content-types, entries",
47
+ "multiple": true,
46
48
  "options": [
49
+ "global-fields",
47
50
  "content-types",
48
- "entries",
49
- "both"
51
+ "entries"
50
52
  ]
53
+ },
54
+ "branch": {
55
+ "name": "branch",
56
+ "type": "option",
57
+ "char": "B",
58
+ "description": "The name of the branch where you want to import your content. If you don't mention the branch name, then by default the content will be imported to the main branch.",
59
+ "multiple": false
51
60
  }
52
61
  },
53
62
  "args": {}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-import-setup",
3
3
  "description": "Contentstack CLI plugin to setup the mappers and configurations for the import command",
4
- "version": "1.0.0-beta.1",
4
+ "version": "1.0.1",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
@@ -23,7 +23,7 @@
23
23
  "winston": "^3.17.0"
24
24
  },
25
25
  "devDependencies": {
26
- "@oclif/test": "^4.1.3",
26
+ "@oclif/test": "^4.1.6",
27
27
  "@types/big-json": "^3.2.5",
28
28
  "@types/bluebird": "^3.5.42",
29
29
  "@types/chai": "^4.3.20",