@contentstack/cli-cm-export 1.1.0 → 1.2.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
@@ -38,7 +38,7 @@ $ npm install -g @contentstack/cli-cm-export
38
38
  $ csdx COMMAND
39
39
  running command...
40
40
  $ csdx (-v|--version|version)
41
- @contentstack/cli-cm-export/1.1.0 darwin-arm64 node-v16.17.0
41
+ @contentstack/cli-cm-export/1.2.0 darwin-arm64 node-v18.11.0
42
42
  $ csdx --help [COMMAND]
43
43
  USAGE
44
44
  $ csdx COMMAND
@@ -83,5 +83,5 @@ EXAMPLES
83
83
  csdx cm:stacks:export --branch [optional] branch name
84
84
  ```
85
85
 
86
- _See code: [src/commands/cm/stacks/export.js](https://github.com/contentstack/cli/blob/v1.1.0/packages/contentstack-export/src/commands/cm/stacks/export.js)_
86
+ _See code: [src/commands/cm/stacks/export.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-export/src/commands/cm/stacks/export.js)_
87
87
  <!-- commandsstop -->
@@ -1 +1 @@
1
- {"version":"1.1.0","commands":{"cm:stacks:export":{"id":"cm:stacks:export","description":"Export content from a stack","usage":"cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]","pluginName":"@contentstack/cli-cm-export","pluginType":"core","aliases":["cm:export"],"examples":["csdx cm:stacks:export --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>","csdx cm:stacks:export --config <path/to/config/dir>","csdx cm:stacks:export --alias <management_token_alias>","csdx cm:stacks:export --alias <management_token_alias> --data-dir <path/to/export/destination/dir>","csdx cm:stacks:export --alias <management_token_alias> --config <path/to/config/file>","csdx cm:stacks:export --module <single module name>","csdx cm:stacks:export --branch [optional] branch name"],"flags":{"config":{"name":"config","type":"option","char":"c","description":"[optional] path of the config"},"stack-uid":{"name":"stack-uid","type":"option","char":"s","description":"API key of the source stack","hidden":true},"stack-api-key":{"name":"stack-api-key","type":"option","char":"k","description":"API key of the source stack"},"data":{"name":"data","type":"option","description":"path or location to store the data","hidden":true},"data-dir":{"name":"data-dir","type":"option","char":"d","description":"path or location to store the data"},"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"},"content-types":{"name":"content-types","type":"option","char":"t","description":"[optional] content type"},"branch":{"name":"branch","type":"option","char":"B","description":"[optional] branch name"},"secured-assets":{"name":"secured-assets","type":"boolean","description":"[optional] use when assets are secured","allowNo":false}},"args":[]}}}
1
+ {"version":"1.2.0","commands":{"cm:stacks:export":{"id":"cm:stacks:export","description":"Export content from a stack","usage":"cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]","pluginName":"@contentstack/cli-cm-export","pluginType":"core","aliases":["cm:export"],"examples":["csdx cm:stacks:export --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>","csdx cm:stacks:export --config <path/to/config/dir>","csdx cm:stacks:export --alias <management_token_alias>","csdx cm:stacks:export --alias <management_token_alias> --data-dir <path/to/export/destination/dir>","csdx cm:stacks:export --alias <management_token_alias> --config <path/to/config/file>","csdx cm:stacks:export --module <single module name>","csdx cm:stacks:export --branch [optional] branch name"],"flags":{"config":{"name":"config","type":"option","char":"c","description":"[optional] path of the config"},"stack-uid":{"name":"stack-uid","type":"option","char":"s","description":"API key of the source stack","hidden":true},"stack-api-key":{"name":"stack-api-key","type":"option","char":"k","description":"API key of the source stack"},"data":{"name":"data","type":"option","description":"path or location to store the data","hidden":true},"data-dir":{"name":"data-dir","type":"option","char":"d","description":"path or location to store the data"},"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"},"content-types":{"name":"content-types","type":"option","char":"t","description":"[optional] content type"},"branch":{"name":"branch","type":"option","char":"B","description":"[optional] branch name"},"secured-assets":{"name":"secured-assets","type":"boolean","description":"[optional] use when assets are secured","allowNo":false}},"args":[]}}}
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "@contentstack/cli-cm-export",
3
3
  "description": "Contentstack CLI plugin to export content from stack",
4
- "version": "1.1.0",
4
+ "version": "1.2.0",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-command": "^1.0.1",
9
- "@contentstack/cli-utilities": "^1.0.2",
8
+ "@contentstack/cli-command": "^1.0.2",
9
+ "@contentstack/cli-utilities": "^1.0.3",
10
10
  "@contentstack/management": "^1.3.0",
11
11
  "@oclif/command": "^1.8.16",
12
12
  "@oclif/config": "^1.18.3",
13
13
  "async": "^3.2.4",
14
+ "big-json": "^3.2.0",
14
15
  "bluebird": "^3.7.2",
15
16
  "fs": "0.0.1-security",
16
17
  "is-valid-path": "^0.1.1",
@@ -18,15 +19,21 @@
18
19
  "mkdirp": "^1.0.4",
19
20
  "path": "^0.12.7",
20
21
  "progress-stream": "^2.0.0",
22
+ "promise-limit": "^2.7.0",
21
23
  "proxyquire": "^2.1.3",
22
24
  "winston": "^3.7.2"
23
25
  },
24
26
  "devDependencies": {
27
+ "@contentstack/cli-auth": "^1.0.3",
28
+ "@contentstack/cli-config": "^1.0.2",
29
+ "@contentstack/cli-dev-dependencies": "^1.0.0",
25
30
  "@oclif/dev-cli": "^1.22.2",
26
31
  "@oclif/plugin-help": "^5.1.12",
27
32
  "@oclif/test": "^1.2.6",
28
33
  "assert": "^2.0.0",
29
34
  "chai": "^4.2.0",
35
+ "dotenv": "^16.0.1",
36
+ "dotenv-expand": "^9.0.0",
30
37
  "eslint": "^8.18.0",
31
38
  "eslint-config-oclif": "^3.1.0",
32
39
  "globby": "^10.0.2",
@@ -54,7 +61,9 @@
54
61
  "postpack": "rm -f oclif.manifest.json",
55
62
  "prepack": "oclif-dev manifest && oclif-dev readme",
56
63
  "test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
57
- "version": "oclif-dev readme && git add README.md"
64
+ "version": "oclif-dev readme && git add README.md",
65
+ "test:integration": "mocha --forbid-only \"test/run.test.js\" --integration-test",
66
+ "test:unit": "mocha --forbid-only \"test/unit/*.test.js\" --unit-test"
58
67
  },
59
68
  "oclif": {
60
69
  "commands": "./src/commands",
@@ -62,7 +71,7 @@
62
71
  "devPlugins": [
63
72
  "@oclif/plugin-help"
64
73
  ],
65
- "repositoryPrefix": "<%- repo %>/blob/v<%- version %>/packages/contentstack-export/<%- commandPath %>"
74
+ "repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-export/<%- commandPath %>"
66
75
  },
67
76
  "csdxConfig": {
68
77
  "expiredCommands": {
package/src/app.js CHANGED
@@ -3,9 +3,11 @@ const _ = require('lodash');
3
3
  const path = require('path');
4
4
  const chalk = require('chalk');
5
5
  const util = require('./lib/util');
6
+ const { formatError } = require('./lib/util');
6
7
  const login = require('./lib/util/login');
7
8
  const setupBranches = require('./lib/util/setup-branches');
8
9
  const { addlogs, unlinkFileLogger } = require('./lib/util/log');
10
+ const stack = require('./lib/util/contentstack-management-sdk');
9
11
 
10
12
  exports.initial = async function (config) {
11
13
  return new Promise(async function (resolve, reject) {
@@ -29,7 +31,7 @@ exports.initial = async function (config) {
29
31
  await allExport(config, types, branch.uid);
30
32
  }
31
33
  } catch (error) {
32
- console.log('failed export branch', branch.uid, error);
34
+ addlogs(config, `failed export contents ${branch.uid} ${formatError(error)}`, 'error');
33
35
  }
34
36
  }
35
37
  } else {
@@ -40,10 +42,10 @@ exports.initial = async function (config) {
40
42
  await allExport(config, types);
41
43
  }
42
44
  } catch (error) {
43
- console.log('failed export contents', error && error.message);
45
+ addlogs(config, `failed export contents ${formatError(error)}`, 'error');
44
46
  }
45
47
  }
46
- }
48
+ };
47
49
 
48
50
  // try {
49
51
  if (
@@ -55,8 +57,12 @@ exports.initial = async function (config) {
55
57
  .login(config)
56
58
  .then(async function () {
57
59
  // setup branches
58
- await fetchBranchAndExport()
59
- unlinkFileLogger();
60
+ try {
61
+ await fetchBranchAndExport();
62
+ unlinkFileLogger();
63
+ } catch (error) {
64
+ addlogs(config, `${formatError(error)}`, 'error');
65
+ }
60
66
  resolve();
61
67
  })
62
68
  .catch((error) => {
@@ -65,12 +71,16 @@ exports.initial = async function (config) {
65
71
  addlogs(config, chalk.red('Stack Api key ' + error.errors.api_key[0], 'Please enter valid Key', 'error'));
66
72
  addlogs(config, 'The log for this is stored at ' + config.data + '/export/logs', 'success');
67
73
  } else {
68
- console.log('Stack fail to export');
74
+ addlogs(config, `${formatError(error)}`, 'error');
69
75
  }
70
- reject(error);
76
+ // reject(error);
71
77
  });
72
78
  } else if (config.management_token) {
73
- await fetchBranchAndExport()
79
+ try {
80
+ await fetchBranchAndExport();
81
+ } catch (error) {
82
+ addlogs(config, `${formatError(error)}`, 'error');
83
+ }
74
84
  resolve();
75
85
  }
76
86
  });
@@ -78,6 +88,9 @@ exports.initial = async function (config) {
78
88
 
79
89
  const singleExport = async (moduleName, types, config, branchName) => {
80
90
  try {
91
+ const stackClient = stack
92
+ .Client(config)
93
+ .stack({ api_key: config.source_stack, management_token: config.management_token });
81
94
  if (types.indexOf(moduleName) > -1) {
82
95
  let iterateList;
83
96
  if (config.modules.dependency && config.modules.dependency[moduleName]) {
@@ -87,12 +100,9 @@ const singleExport = async (moduleName, types, config, branchName) => {
87
100
  }
88
101
  iterateList.push(moduleName);
89
102
 
90
- for (const element of iterateList) {
91
- let exportedModule = require('./lib/export/' + element);
92
- const result = await exportedModule.start(config, branchName)
93
- .catch((error) => {
94
- console.log(error && error.message)
95
- });
103
+ for (let element of iterateList) {
104
+ const ExportModule = require('./lib/export/' + element);
105
+ const result = await new ExportModule(config, stackClient).start(config, branchName);
96
106
  if (result && element === 'stack') {
97
107
  let master_locale = {
98
108
  master_locale: { code: result.code },
@@ -107,44 +117,41 @@ const singleExport = async (moduleName, types, config, branchName) => {
107
117
  }
108
118
  return true;
109
119
  } catch (error) {
120
+ addlogs(config, `${formatError(error)}`, 'error');
110
121
  addlogs(config, 'Failed to migrate ' + moduleName, 'error');
111
- addlogs(config, error, 'error');
112
122
  addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'error');
113
- throw error;
114
123
  }
115
124
  };
116
125
 
117
126
  const allExport = async (config, types, branchName) => {
118
- return new Promise(async (resolve, reject) => {
119
- try {
120
- for (const type of types) {
121
- const exportedModule = require('./lib/export/' + type);
122
- const result = await exportedModule.start(config, branchName)
123
- .catch((error) => {
124
- console.log(error && error.message)
125
- });
127
+ try {
128
+ const stackClient = stack
129
+ .Client(config)
130
+ .stack({ api_key: config.source_stack, management_token: config.management_token });
126
131
 
127
- if (result && type === 'stack') {
128
- let master_locale = { master_locale: { code: result.code } };
129
- config = _.merge(config, master_locale);
130
- }
132
+ for (let type of types) {
133
+ const ExportModule = require('./lib/export/' + type);
134
+ const result = await new ExportModule(config, stackClient).start(config, branchName);
135
+
136
+ if (result && type === 'stack') {
137
+ let master_locale = { master_locale: { code: result.code } };
138
+ config = _.merge(config, master_locale);
131
139
  }
132
- addlogs(
133
- config,
134
- chalk.green('The content of the ' + config.source_stack + ' has been exported successfully!'),
135
- 'success',
136
- );
137
- addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'success');
138
- return resolve();
139
- } catch (error) {
140
- addlogs(
141
- config,
142
- chalk.red('Failed to migrate stack: ' + config.source_stack + '. Please check error logs for more info'),
143
- 'error',
144
- );
145
- addlogs(config, chalk.red(error && error.errorMessage), 'error');
146
- addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'error');
147
- return reject(error);
148
140
  }
149
- });
141
+ addlogs(
142
+ config,
143
+ chalk.green('The content of the ' + config.source_stack + ' has been exported successfully!'),
144
+ 'success',
145
+ );
146
+ addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'success');
147
+ return true;
148
+ } catch (error) {
149
+ addlogs(config, `${formatError(error)}`, 'error');
150
+ addlogs(
151
+ config,
152
+ chalk.red('Failed to migrate stack: ' + config.source_stack + '. Please check error logs for more info'),
153
+ 'error',
154
+ );
155
+ addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'error');
156
+ }
150
157
  };
@@ -79,9 +79,9 @@ class ExportCommand extends Command {
79
79
  }
80
80
  } else if (_authToken) {
81
81
  if (extConfig) {
82
- configWithAuthToken(extConfig, _authToken, moduleName, host, contentTypes, branchName, securedAssets);
82
+ await configWithAuthToken(extConfig, _authToken, moduleName, host, contentTypes, branchName, securedAssets);
83
83
  } else if (sourceStack && data) {
84
- return parametersWithAuthToken(
84
+ return await parametersWithAuthToken(
85
85
  _authToken,
86
86
  sourceStack,
87
87
  data,
@@ -92,7 +92,7 @@ class ExportCommand extends Command {
92
92
  securedAssets,
93
93
  );
94
94
  } else if (data === undefined && sourceStack === undefined) {
95
- withoutParametersWithAuthToken(_authToken, moduleName, host, contentTypes, branchName, securedAssets);
95
+ await withoutParametersWithAuthToken(_authToken, moduleName, host, contentTypes, branchName, securedAssets);
96
96
  } else {
97
97
  this.log('Please provide a valid command. Run "csdx cm:export --help" command to view the command usage');
98
98
  }
@@ -6,7 +6,7 @@ module.exports = {
6
6
  'https://api.contentstack.io': 'https://developerhub-api.contentstack.com',
7
7
  'https://eu-api.contentstack.com': 'https://eu-developerhub-api.contentstack.com',
8
8
  'https://azure-na-api.contentstack.com': 'https://azure-na-developerhub-api.contentstack.com',
9
- 'https://stag-api.csnonprod.com': 'https://stag-developerhub-api.csnonprod.com'
9
+ 'https://stag-api.csnonprod.com': 'https://stag-developerhub-api.csnonprod.com',
10
10
  },
11
11
  // use below hosts for eu region
12
12
  // host:'https://eu-api.contentstack.com/v3',
@@ -26,7 +26,7 @@ module.exports = {
26
26
  'workflows',
27
27
  'entries',
28
28
  'labels',
29
- 'marketplace-apps'
29
+ 'marketplace-apps',
30
30
  ],
31
31
  locales: {
32
32
  dirName: 'locales',
@@ -75,7 +75,7 @@ module.exports = {
75
75
  host: 'https://images.contentstack.io',
76
76
  invalidKeys: ['created_at', 'updated_at', 'created_by', 'updated_by', '_metadata', 'published'],
77
77
  // no of asset version files (of a single asset) that'll be downloaded parallelly
78
- downloadLimit: 5,
78
+ downloadLimit: 3,
79
79
  enableDownloadStatus: false,
80
80
  },
81
81
  content_types: {
@@ -117,8 +117,8 @@ module.exports = {
117
117
  },
118
118
  marketplace_apps: {
119
119
  dirName: 'marketplace_apps',
120
- fileName: 'marketplace_apps.json'
121
- }
120
+ fileName: 'marketplace_apps.json',
121
+ },
122
122
  },
123
123
  languagesCode: [
124
124
  'af-za',
@@ -344,5 +344,7 @@ module.exports = {
344
344
  webhooks: '/webhooks/',
345
345
  stacks: '/stacks/',
346
346
  },
347
- preserveStackVersion: false
347
+ preserveStackVersion: false,
348
+ fetchConcurrency: 5,
349
+ writeConcurrency: 5,
348
350
  };