@contentstack/cli-cm-import 1.1.0 → 1.2.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
@@ -37,7 +37,7 @@ $ npm install -g @contentstack/cli-cm-import
37
37
  $ csdx COMMAND
38
38
  running command...
39
39
  $ csdx (-v|--version|version)
40
- @contentstack/cli-cm-import/1.1.0 darwin-arm64 node-v16.17.0
40
+ @contentstack/cli-cm-import/1.2.1 darwin-arm64 node-v18.11.0
41
41
  $ csdx --help [COMMAND]
42
42
  USAGE
43
43
  $ csdx COMMAND
@@ -67,6 +67,7 @@ OPTIONS
67
67
  -d, --data-dir=data-dir path and location where data is stored
68
68
  -k, --stack-api-key=stack-api-key API key of the target stack
69
69
  -m, --module=module [optional] specific module name
70
+ -y, --yes [optional] Override marketplace prompts
70
71
  --import-webhook-status=disable|current [default: disable] Webhook state
71
72
 
72
73
  DESCRIPTION
@@ -85,8 +86,8 @@ EXAMPLES
85
86
  csdx cm:stacks:import --alias <management_token_alias>
86
87
  csdx cm:stacks:import --alias <management_token_alias> --data-dir <path/of/export/destination/dir>
87
88
  csdx cm:stacks:import --alias <management_token_alias> --config <path/of/config/file>
88
- csdx cm:stacks:import --branch <branch name>
89
+ csdx cm:stacks:import --branch <branch name> --yes
89
90
  ```
90
91
 
91
- _See code: [src/commands/cm/stacks/import.js](https://github.com/contentstack/cli/blob/v1.1.0/packages/contentstack-import/src/commands/cm/stacks/import.js)_
92
+ _See code: [src/commands/cm/stacks/import.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-import/src/commands/cm/stacks/import.js)_
92
93
  <!-- commandsstop -->
@@ -1 +1 @@
1
- {"version":"1.1.0","commands":{"cm:stacks:import":{"id":"cm:stacks:import","description":"Import script for importing the content into the new stack\n...\nOnce you export content from the source stack, import it to your destination stack by using the cm:stacks:import command.\n","usage":"cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>] [--branch <value>] [--import-webhook-status disable|current]","pluginName":"@contentstack/cli-cm-import","pluginType":"core","aliases":["cm:import"],"examples":["csdx cm:stacks:import --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>","csdx cm:stacks:import --config <path/of/config/dir>","csdx cm:stacks:import --module <single module name>","csdx cm:stacks:import --module <single module name> --backup-dir <backup dir>","csdx cm:stacks:import --alias <management_token_alias>","csdx cm:stacks:import --alias <management_token_alias> --data-dir <path/of/export/destination/dir>","csdx cm:stacks:import --alias <management_token_alias> --config <path/of/config/file>","csdx cm:stacks:import --branch <branch name>"],"flags":{"config":{"name":"config","type":"option","char":"c","description":"[optional] path of config file"},"stack-uid":{"name":"stack-uid","type":"option","char":"s","description":"API key of the target stack","hidden":true},"stack-api-key":{"name":"stack-api-key","type":"option","char":"k","description":"API key of the target stack"},"data":{"name":"data","type":"option","description":"path and location where data is stored","hidden":true},"data-dir":{"name":"data-dir","type":"option","char":"d","description":"path and location where data is stored"},"alias":{"name":"alias","type":"option","char":"a","description":"alias of the management token"},"management-token-alias":{"name":"management-token-alias","type":"option","description":"alias of the management token","hidden":true},"auth-token":{"name":"auth-token","type":"boolean","char":"A","description":"to use auth token","hidden":true,"allowNo":false},"module":{"name":"module","type":"option","char":"m","description":"[optional] specific module name"},"backup-dir":{"name":"backup-dir","type":"option","char":"b","description":"[optional] backup directory name when using specific module"},"branch":{"name":"branch","type":"option","char":"B","description":"[optional] branch name"},"import-webhook-status":{"name":"import-webhook-status","type":"option","description":"Webhook state","required":false,"options":["disable","current"],"default":"disable"}},"args":[]}}}
1
+ {"version":"1.2.1","commands":{"cm:stacks:import":{"id":"cm:stacks:import","description":"Import script for importing the content into the new stack\n...\nOnce you export content from the source stack, import it to your destination stack by using the cm:stacks:import command.\n","usage":"cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>] [--branch <value>] [--import-webhook-status disable|current]","pluginName":"@contentstack/cli-cm-import","pluginType":"core","aliases":["cm:import"],"examples":["csdx cm:stacks:import --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>","csdx cm:stacks:import --config <path/of/config/dir>","csdx cm:stacks:import --module <single module name>","csdx cm:stacks:import --module <single module name> --backup-dir <backup dir>","csdx cm:stacks:import --alias <management_token_alias>","csdx cm:stacks:import --alias <management_token_alias> --data-dir <path/of/export/destination/dir>","csdx cm:stacks:import --alias <management_token_alias> --config <path/of/config/file>","csdx cm:stacks:import --branch <branch name> --yes"],"flags":{"config":{"name":"config","type":"option","char":"c","description":"[optional] path of config file"},"stack-uid":{"name":"stack-uid","type":"option","char":"s","description":"API key of the target stack","hidden":true},"stack-api-key":{"name":"stack-api-key","type":"option","char":"k","description":"API key of the target stack"},"data":{"name":"data","type":"option","description":"path and location where data is stored","hidden":true},"data-dir":{"name":"data-dir","type":"option","char":"d","description":"path and location where data is stored"},"alias":{"name":"alias","type":"option","char":"a","description":"alias of the management token"},"management-token-alias":{"name":"management-token-alias","type":"option","description":"alias of the management token","hidden":true},"auth-token":{"name":"auth-token","type":"boolean","char":"A","description":"to use auth token","hidden":true,"allowNo":false},"module":{"name":"module","type":"option","char":"m","description":"[optional] specific module name"},"backup-dir":{"name":"backup-dir","type":"option","char":"b","description":"[optional] backup directory name when using specific module"},"branch":{"name":"branch","type":"option","char":"B","description":"[optional] branch name"},"import-webhook-status":{"name":"import-webhook-status","type":"option","description":"Webhook state","required":false,"options":["disable","current"],"default":"disable"},"yes":{"name":"yes","type":"boolean","char":"y","description":"[optional] Override marketplace prompts","required":false,"allowNo":false}},"args":[]}}}
package/package.json CHANGED
@@ -1,22 +1,23 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-import",
3
3
  "description": "Contentstack CLI plugin to import content into stack",
4
- "version": "1.1.0",
4
+ "version": "1.2.1",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-command": "^1.0.1",
8
+ "@contentstack/cli-command": "^1.0.2",
9
9
  "@contentstack/management": "^1.3.0",
10
- "@contentstack/cli-utilities": "^1.0.2",
11
- "@contentstack/cli-cm-export": "^1.1.0",
10
+ "@contentstack/cli-utilities": "^1.0.3",
12
11
  "@oclif/command": "^1.8.16",
13
12
  "@oclif/config": "^1.18.3",
14
- "bluebird": "3.5.1",
13
+ "big-json": "^3.2.0",
14
+ "bluebird": "^3.7.2",
15
15
  "debug": "^4.1.0",
16
16
  "lodash": "^4.17.20",
17
17
  "marked": "^4.0.17",
18
18
  "mkdirp": "^1.0.4",
19
- "ncp": "2.0.0",
19
+ "ncp": "^2.0.0",
20
+ "promise-limit": "^2.7.0",
20
21
  "winston": "^3.7.2"
21
22
  },
22
23
  "devDependencies": {
@@ -65,7 +66,7 @@
65
66
  "devPlugins": [
66
67
  "@oclif/plugin-help"
67
68
  ],
68
- "repositoryPrefix": "<%- repo %>/blob/v<%- version %>/packages/contentstack-import/<%- commandPath %>"
69
+ "repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-import/<%- commandPath %>"
69
70
  },
70
71
  "repository": "https://github.com/contentstack/cli"
71
72
  }
package/src/app.js CHANGED
@@ -10,9 +10,11 @@ let _ = require('lodash');
10
10
  let path = require('path');
11
11
  const chalk = require('chalk');
12
12
  let util = require('./lib/util/index');
13
+ let { formatError } = require('./lib/util');
13
14
  let login = require('./lib/util/login');
14
15
  let { addlogs } = require('./lib/util/log');
15
16
  const { HttpClient } = require('@contentstack/cli-utilities');
17
+ const stack = require('./lib/util/contentstack-management-sdk');
16
18
 
17
19
  exports.initial = function (configData) {
18
20
  return new Promise(async function (resolve, reject) {
@@ -20,10 +22,9 @@ exports.initial = function (configData) {
20
22
  config.oldPath = config.data;
21
23
 
22
24
  if (configData.branchName) {
23
- await validateIfBranchExist(configData, configData.branchName)
24
- .catch(() => {
25
- process.exit()
26
- })
25
+ await validateIfBranchExist(configData, configData.branchName).catch(() => {
26
+ process.exit();
27
+ });
27
28
  }
28
29
 
29
30
  const backupAndImportData = async () => {
@@ -33,21 +34,21 @@ exports.initial = function (configData) {
33
34
  .then((basePath) => {
34
35
  config.data = basePath;
35
36
  return util.sanitizeStack(config);
36
- }).then(() => {
37
- let importRes
38
- const types = config.modules.types
37
+ })
38
+ .then(() => {
39
+ let importRes;
40
+ const types = config.modules.types;
39
41
 
40
42
  if (config.moduleName) {
41
- importRes = singleImport(config.moduleName, types, config)
43
+ importRes = singleImport(config.moduleName, types, config);
42
44
  } else {
43
- importRes = allImport(config, types)
45
+ importRes = allImport(config, types);
44
46
  }
45
47
 
46
- importRes
47
- .then(resolve)
48
- .catch(reject)
49
- }).catch((e) => {
50
- console.error(e);
48
+ importRes.then(resolve).catch(reject);
49
+ })
50
+ .catch((error) => {
51
+ addlogs(config, `Failed to import contents ${formatError(error)}`, 'error');
51
52
  reject(e);
52
53
  process.exit(1);
53
54
  });
@@ -55,25 +56,24 @@ exports.initial = function (configData) {
55
56
  let filename = path.basename(config.data);
56
57
  addlogs(config, chalk.red(filename + ' Folder does not Exist'), 'error');
57
58
  }
58
- }
59
+ };
59
60
 
60
61
  if (config) {
61
- if (
62
- (config.email && config.password) ||
63
- (config.auth_token)
64
- ) {
65
- login(config)
66
- .then(backupAndImportData)
67
- .catch(reject);
62
+ if ((config.email && config.password) || config.auth_token) {
63
+ login(config).then(backupAndImportData).catch(reject);
68
64
  } else if (config.management_token) {
69
- await backupAndImportData()
65
+ await backupAndImportData();
70
66
  }
71
67
  }
72
68
  });
73
69
  };
74
70
 
75
71
  let singleImport = async (moduleName, types, config) => {
76
- return new Promise(async (resolve, reject) => {
72
+ try {
73
+ const stackClient = stack
74
+ .Client(config)
75
+ .stack({ api_key: config.target_stack, management_token: config.management_token });
76
+
77
77
  if (types.indexOf(moduleName) > -1) {
78
78
  if (!config.master_locale) {
79
79
  try {
@@ -81,88 +81,75 @@ let singleImport = async (moduleName, types, config) => {
81
81
  let master_locale = { code: masterLocalResponse.code };
82
82
  config['master_locale'] = master_locale;
83
83
  } catch (error) {
84
- console.log('Error to fetch the stack details' + error);
84
+ addlogs(config, `Failed to get master locale detail from the stack ${formatError(error)}`, 'error');
85
85
  }
86
86
  }
87
- let exportedModule = require('./lib/import/' + moduleName);
88
- exportedModule
89
- .start(config)
90
- .then(async function (data) {
91
- if (moduleName === 'content-types') {
92
- let ctPath = path.resolve(config.data, config.modules.content_types.dirName);
93
- let fieldPath = path.join(ctPath + '/field_rules_uid.json');
94
- if (fieldPath) {
95
- await util.field_rules_update(config, ctPath);
96
- }
97
- }
98
- if (!(data && data.empty)) {
99
- addlogs(config, moduleName + ' imported successfully!', 'success');
100
- }
101
- addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'success');
102
- return resolve();
103
- })
104
- .catch(function (error) {
105
- addlogs(config, 'Failed to migrate ' + moduleName, 'error');
106
- addlogs(config, error, 'error');
107
- addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'error');
108
- return reject(error);
109
- });
87
+ let ImportModule = require('./lib/import/' + moduleName);
88
+ const importResponse = await new ImportModule(config, stackClient).start(config);
89
+ if (moduleName === 'content-types') {
90
+ let ctPath = path.resolve(config.data, config.modules.content_types.dirName);
91
+ let fieldPath = path.join(ctPath + '/field_rules_uid.json');
92
+ if (fieldPath) {
93
+ await util.field_rules_update(config, ctPath);
94
+ }
95
+ }
96
+ if (!(importResponse && importResponse.empty)) {
97
+ addlogs(config, moduleName + ' imported successfully!', 'success');
98
+ }
99
+ addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'success');
100
+ return true;
110
101
  } else {
111
102
  addlogs(config, 'Please provide valid module name.', 'error');
112
- return reject();
113
103
  }
114
- });
104
+ } catch (error) {
105
+ addlogs(config, 'Failed to migrate ' + moduleName, 'error');
106
+ addlogs(config, formatError(error), 'error');
107
+ addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'error');
108
+ }
115
109
  };
116
110
 
117
111
  let allImport = async (config, types) => {
118
- return new Promise(async (resolve, reject) => {
119
- try {
120
- for (let i = 0; i < types.length; i++) {
121
- let type = types[i];
122
- let exportedModule = require('./lib/import/' + type);
123
- if (i === 0 && !config.master_locale) {
124
- let masterLocalResponse = await util.masterLocalDetails(config);
125
- let master_locale = { code: masterLocalResponse.code };
126
- config['master_locale'] = master_locale;
127
- }
128
- await exportedModule.start(config).then((_result) => {
129
- return
130
- }).catch(function (error) {
131
- addlogs(config, 'Failed to migrate ' + type, 'error');
132
- addlogs(config, error, 'error');
133
- addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'error');
134
- return reject(error);
135
- });
112
+ try {
113
+ const stackClient = stack
114
+ .Client(config)
115
+ .stack({ api_key: config.target_stack, management_token: config.management_token });
116
+ for (let i = 0; i < types.length; i++) {
117
+ let type = types[i];
118
+ if (i === 0 && !config.master_locale) {
119
+ let masterLocalResponse = await util.masterLocalDetails(config);
120
+ let master_locale = { code: masterLocalResponse.code };
121
+ config['master_locale'] = master_locale;
136
122
  }
137
- if (config.target_stack && config.source_stack) {
138
- addlogs(
139
- config,
140
- chalk.green(
141
- 'The data of the ' +
123
+ let ImportModule = require('./lib/import/' + type);
124
+ await new ImportModule(config, stackClient).start(config);
125
+ }
126
+ if (config.target_stack && config.source_stack) {
127
+ addlogs(
128
+ config,
129
+ chalk.green(
130
+ 'The data of the ' +
142
131
  (config.sourceStackName || config.source_stack) +
143
132
  ' stack has been imported into ' +
144
133
  (config.destinationStackName || config.target_stack) +
145
134
  ' stack successfully!',
146
- ),
147
- 'success',
148
- );
149
- addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'import'), 'success');
150
- } else {
151
- addlogs(config, chalk.green('Stack: ' + config.target_stack + ' has been imported succesfully!'), 'success');
152
- addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'success');
153
- }
154
- return resolve();
155
- } catch (error) {
156
- addlogs(
157
- config,
158
- chalk.red('Failed to migrate stack: ' + config.target_stack + '. Please check error logs for more info'),
159
- 'error',
135
+ ),
136
+ 'success',
160
137
  );
161
- addlogs(config, error, 'error');
162
- addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'error');
163
- return reject(error);
138
+ addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'import'), 'success');
139
+ } else {
140
+ addlogs(config, chalk.green('Stack: ' + config.target_stack + ' has been imported succesfully!'), 'success');
141
+ addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'success');
164
142
  }
165
- });
143
+ return true;
144
+ } catch (error) {
145
+ addlogs(
146
+ config,
147
+ chalk.red('Failed to migrate stack: ' + config.target_stack + '. Please check error logs for more info'),
148
+ 'error',
149
+ );
150
+ addlogs(config, formatError(error), 'error');
151
+ addlogs(config, 'The log for this is stored at ' + path.join(config.oldPath, 'logs', 'import'), 'error');
152
+ }
166
153
  };
167
154
 
168
155
  function createBackup(backupDirPath, config) {
@@ -191,32 +178,29 @@ function createBackup(backupDirPath, config) {
191
178
 
192
179
  const validateIfBranchExist = async (config, branch) => {
193
180
  return new Promise(async function (resolve, reject) {
194
- const headers = { api_key: config.target_stack, authtoken: config.auth_token }
195
- const httpClient = new HttpClient().headers(headers)
181
+ const headers = { api_key: config.target_stack, authtoken: config.auth_token };
182
+ const httpClient = new HttpClient().headers(headers);
196
183
  const result = await httpClient
197
184
  .get(`https://${config.host}/v3/stacks/branches/${branch}`)
198
185
  .then(({ data }) => {
199
186
  if (data.error_message) {
200
187
  addlogs(config, chalk.red(data.error_message), 'error');
201
188
  addlogs(config, chalk.red('No branch found with the name ' + branch), 'error');
202
- reject()
189
+ reject();
203
190
  }
204
191
 
205
- return data
206
- }).catch((err) => {
207
- console.log(err)
208
- addlogs(config, chalk.red('No branch found with the name ' + branch), 'error');
209
- reject()
192
+ return data;
210
193
  })
194
+ .catch((err) => {
195
+ console.log(err);
196
+ addlogs(config, chalk.red('No branch found with the name ' + branch), 'error');
197
+ reject();
198
+ });
211
199
 
212
- if (
213
- result &&
214
- typeof result === 'object' &&
215
- typeof result.branch === 'object'
216
- ) {
217
- resolve(result.branch)
200
+ if (result && typeof result === 'object' && typeof result.branch === 'object') {
201
+ resolve(result.branch);
218
202
  } else {
219
- reject({ message: 'No branch found with the name ' + branch })
203
+ reject({ message: 'No branch found with the name ' + branch });
220
204
  }
221
205
  });
222
206
  };
@@ -34,6 +34,8 @@ class ImportCommand extends Command {
34
34
  defaultConfig.data = data;
35
35
  }
36
36
 
37
+ defaultConfig.forceMarketplaceAppsImport = importCommandFlags.yes
38
+
37
39
  if (alias) {
38
40
  let managementTokens = self.getToken(alias);
39
41
 
@@ -114,7 +116,7 @@ ImportCommand.examples = [
114
116
  `csdx cm:stacks:import --alias <management_token_alias>`,
115
117
  `csdx cm:stacks:import --alias <management_token_alias> --data-dir <path/of/export/destination/dir>`,
116
118
  `csdx cm:stacks:import --alias <management_token_alias> --config <path/of/config/file>`,
117
- `csdx cm:stacks:import --branch <branch name>`,
119
+ `csdx cm:stacks:import --branch <branch name> --yes`,
118
120
  ];
119
121
  ImportCommand.flags = {
120
122
  config: flags.string({
@@ -176,6 +178,11 @@ ImportCommand.flags = {
176
178
  required: false,
177
179
  default: 'disable',
178
180
  }),
181
+ yes: flags.boolean({
182
+ char: 'y',
183
+ required: false,
184
+ description: '[optional] Override marketplace prompts'
185
+ })
179
186
  };
180
187
 
181
188
  ImportCommand.aliases = ['cm:import'];
@@ -13,7 +13,7 @@ module.exports = {
13
13
  'https://api.contentstack.io': 'https://developerhub-api.contentstack.com',
14
14
  'https://eu-api.contentstack.com': 'https://eu-developerhub-api.contentstack.com',
15
15
  'https://azure-na-api.contentstack.com': 'https://azure-na-developerhub-api.contentstack.com',
16
- 'https://stag-api.csnonprod.com': 'https://stag-developerhub-api.csnonprod.com'
16
+ 'https://stag-api.csnonprod.com': 'https://stag-developerhub-api.csnonprod.com',
17
17
  },
18
18
  modules: {
19
19
  types: [
@@ -74,6 +74,8 @@ module.exports = {
74
74
  host: 'https://api.contentstack.io',
75
75
  validKeys: ['uid', 'filename', 'url', 'status'],
76
76
  assetBatchLimit: 1,
77
+ uploadAssetsConcurrency: 1,
78
+ importFoldersConcurrency: 1,
77
79
  },
78
80
  content_types: {
79
81
  dirName: 'content_types',
@@ -100,8 +102,8 @@ module.exports = {
100
102
  },
101
103
  marketplace_apps: {
102
104
  dirName: 'marketplace_apps',
103
- fileName: 'marketplace_apps.json'
104
- }
105
+ fileName: 'marketplace_apps.json',
106
+ },
105
107
  },
106
108
  languagesCode: [
107
109
  'af-za',
@@ -331,6 +333,9 @@ module.exports = {
331
333
  preserveStackVersion: false,
332
334
  entriesPublish: true,
333
335
  concurrency: 1,
334
- // ,useBackedupDir: '_backup_397'
336
+ importConcurrency: 5,
337
+ fetchConcurrency: 5,
338
+ writeConcurrency: 5,
339
+ // useBackedupDir: '',
335
340
  // backupConcurrency: 10,
336
341
  };