@contentstack/cli-cm-export 1.2.3 → 1.3.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
@@ -37,8 +37,8 @@ For switching to AZURE-NA region update the hosts at config/default.js
37
37
  $ npm install -g @contentstack/cli-cm-export
38
38
  $ csdx COMMAND
39
39
  running command...
40
- $ csdx (-v|--version|version)
41
- @contentstack/cli-cm-export/1.2.3 linux-x64 node-v16.18.1
40
+ $ csdx (--version)
41
+ @contentstack/cli-cm-export/1.3.0 linux-x64 node-v16.19.0
42
42
  $ csdx --help [COMMAND]
43
43
  USAGE
44
44
  $ csdx COMMAND
@@ -50,6 +50,7 @@ USAGE
50
50
 
51
51
  <!-- commands -->
52
52
  * [`csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]`](#csdx-cmstacksexport--c-value--k-value--d-value--a-value---module-value---content-types-value---branch-value---secured-assets)
53
+ * [`csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]`](#csdx-cmstacksexport--c-value--k-value--d-value--a-value---module-value---content-types-value---branch-value---secured-assets-1)
53
54
 
54
55
  ## `csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]`
55
56
 
@@ -57,31 +58,82 @@ Export content from a stack
57
58
 
58
59
  ```
59
60
  USAGE
60
- $ csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types
61
- <value>] [--branch <value>] [--secured-assets]
62
-
63
- OPTIONS
64
- -B, --branch=branch [optional] branch name
65
- -a, --alias=alias alias of the management token
66
- -c, --config=config [optional] path of the config
67
- -d, --data-dir=data-dir path or location to store the data
68
- -k, --stack-api-key=stack-api-key API key of the source stack
69
- -m, --module=module [optional] specific module name
70
- -t, --content-types=content-types [optional] content type
71
- -y, --yes [optional] Override marketplace apps related prompts
72
- --secured-assets [optional] use when assets are secured
61
+ $ csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types
62
+ <value>] [--branch <value>] [--secured-assets]
63
+
64
+ FLAGS
65
+ -B, --branch=<value> [optional] branch name
66
+ -a, --alias=<value> alias of the management token
67
+ -c, --config=<value> [optional] path of the config
68
+ -d, --data-dir=<value> path or location to store the data
69
+ -k, --stack-api-key=<value> API key of the source stack
70
+ -m, --module=<value> [optional] specific module name
71
+ -t, --content-types=<value>... [optional] content type
72
+ -y, --yes [optional] Override marketplace apps related prompts
73
+ --secured-assets [optional] use when assets are secured
74
+
75
+ DESCRIPTION
76
+ Export content from a stack
73
77
 
74
78
  ALIASES
75
79
  $ csdx cm:export
76
80
 
77
81
  EXAMPLES
78
- csdx cm:stacks:export --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>
79
- csdx cm:stacks:export --config <path/to/config/dir>
80
- csdx cm:stacks:export --alias <management_token_alias>
81
- csdx cm:stacks:export --alias <management_token_alias> --data-dir <path/to/export/destination/dir>
82
- csdx cm:stacks:export --alias <management_token_alias> --config <path/to/config/file>
83
- csdx cm:stacks:export --module <single module name>
84
- csdx cm:stacks:export --branch [optional] branch name
82
+ $ csdx cm:stacks:export --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>
83
+
84
+ $ csdx cm:stacks:export --config <path/to/config/dir>
85
+
86
+ $ csdx cm:stacks:export --alias <management_token_alias>
87
+
88
+ $ csdx cm:stacks:export --alias <management_token_alias> --data-dir <path/to/export/destination/dir>
89
+
90
+ $ csdx cm:stacks:export --alias <management_token_alias> --config <path/to/config/file>
91
+
92
+ $ csdx cm:stacks:export --module <single module name>
93
+
94
+ $ csdx cm:stacks:export --branch [optional] branch name
95
+ ```
96
+
97
+ ## `csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]`
98
+
99
+ Export content from a stack
100
+
101
+ ```
102
+ USAGE
103
+ $ csdx cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types
104
+ <value>] [--branch <value>] [--secured-assets]
105
+
106
+ FLAGS
107
+ -B, --branch=<value> [optional] branch name
108
+ -a, --alias=<value> alias of the management token
109
+ -c, --config=<value> [optional] path of the config
110
+ -d, --data-dir=<value> path or location to store the data
111
+ -k, --stack-api-key=<value> API key of the source stack
112
+ -m, --module=<value> [optional] specific module name
113
+ -t, --content-types=<value>... [optional] content type
114
+ -y, --yes [optional] Override marketplace apps related prompts
115
+ --secured-assets [optional] use when assets are secured
116
+
117
+ DESCRIPTION
118
+ Export content from a stack
119
+
120
+ ALIASES
121
+ $ csdx cm:export
122
+
123
+ EXAMPLES
124
+ $ csdx cm:stacks:export --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>
125
+
126
+ $ csdx cm:stacks:export --config <path/to/config/dir>
127
+
128
+ $ csdx cm:stacks:export --alias <management_token_alias>
129
+
130
+ $ csdx cm:stacks:export --alias <management_token_alias> --data-dir <path/to/export/destination/dir>
131
+
132
+ $ csdx cm:stacks:export --alias <management_token_alias> --config <path/to/config/file>
133
+
134
+ $ csdx cm:stacks:export --module <single module name>
135
+
136
+ $ csdx cm:stacks:export --branch [optional] branch name
85
137
  ```
86
138
 
87
139
  _See code: [src/commands/cm/stacks/export.js](https://github.com/contentstack/cli/blob/main/packages/contentstack-export/src/commands/cm/stacks/export.js)_
@@ -1 +1,128 @@
1
- {"version":"1.2.3","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},"yes":{"name":"yes","type":"boolean","char":"y","description":"[optional] Override marketplace apps related prompts","required":false,"allowNo":false}},"args":[]}}}
1
+ {
2
+ "version": "1.3.0",
3
+ "commands": {
4
+ "cm:stacks:export": {
5
+ "id": "cm:stacks:export",
6
+ "description": "Export content from a stack",
7
+ "strict": true,
8
+ "usage": "cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]",
9
+ "pluginName": "@contentstack/cli-cm-export",
10
+ "pluginAlias": "@contentstack/cli-cm-export",
11
+ "pluginType": "core",
12
+ "aliases": [
13
+ "cm:export"
14
+ ],
15
+ "examples": [
16
+ "csdx cm:stacks:export --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>",
17
+ "csdx cm:stacks:export --config <path/to/config/dir>",
18
+ "csdx cm:stacks:export --alias <management_token_alias>",
19
+ "csdx cm:stacks:export --alias <management_token_alias> --data-dir <path/to/export/destination/dir>",
20
+ "csdx cm:stacks:export --alias <management_token_alias> --config <path/to/config/file>",
21
+ "csdx cm:stacks:export --module <single module name>",
22
+ "csdx cm:stacks:export --branch [optional] branch name"
23
+ ],
24
+ "flags": {
25
+ "config": {
26
+ "name": "config",
27
+ "type": "option",
28
+ "char": "c",
29
+ "description": "[optional] path of the config",
30
+ "multiple": false
31
+ },
32
+ "stack-uid": {
33
+ "name": "stack-uid",
34
+ "type": "option",
35
+ "char": "s",
36
+ "description": "API key of the source stack",
37
+ "hidden": true,
38
+ "multiple": false
39
+ },
40
+ "stack-api-key": {
41
+ "name": "stack-api-key",
42
+ "type": "option",
43
+ "char": "k",
44
+ "description": "API key of the source stack",
45
+ "multiple": false
46
+ },
47
+ "data": {
48
+ "name": "data",
49
+ "type": "option",
50
+ "description": "path or location to store the data",
51
+ "hidden": true,
52
+ "multiple": false
53
+ },
54
+ "data-dir": {
55
+ "name": "data-dir",
56
+ "type": "option",
57
+ "char": "d",
58
+ "description": "path or location to store the data",
59
+ "multiple": false
60
+ },
61
+ "alias": {
62
+ "name": "alias",
63
+ "type": "option",
64
+ "char": "a",
65
+ "description": "alias of the management token",
66
+ "multiple": false
67
+ },
68
+ "management-token-alias": {
69
+ "name": "management-token-alias",
70
+ "type": "option",
71
+ "description": "alias of the management token",
72
+ "hidden": true,
73
+ "multiple": false
74
+ },
75
+ "auth-token": {
76
+ "name": "auth-token",
77
+ "type": "boolean",
78
+ "char": "A",
79
+ "description": "to use auth token",
80
+ "hidden": true,
81
+ "allowNo": false
82
+ },
83
+ "module": {
84
+ "name": "module",
85
+ "type": "option",
86
+ "char": "m",
87
+ "description": "[optional] specific module name",
88
+ "multiple": false,
89
+ "exclusive": [
90
+ "content-types"
91
+ ]
92
+ },
93
+ "content-types": {
94
+ "name": "content-types",
95
+ "type": "option",
96
+ "char": "t",
97
+ "description": "[optional] content type",
98
+ "multiple": true,
99
+ "exclusive": [
100
+ "module"
101
+ ]
102
+ },
103
+ "branch": {
104
+ "name": "branch",
105
+ "type": "option",
106
+ "char": "B",
107
+ "description": "[optional] branch name",
108
+ "multiple": false
109
+ },
110
+ "secured-assets": {
111
+ "name": "secured-assets",
112
+ "type": "boolean",
113
+ "description": "[optional] use when assets are secured",
114
+ "allowNo": false
115
+ },
116
+ "yes": {
117
+ "name": "yes",
118
+ "type": "boolean",
119
+ "char": "y",
120
+ "description": "[optional] Override marketplace apps related prompts",
121
+ "required": false,
122
+ "allowNo": false
123
+ }
124
+ },
125
+ "args": {}
126
+ }
127
+ }
128
+ }
package/package.json CHANGED
@@ -1,19 +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.2.3",
4
+ "version": "1.3.0",
5
5
  "author": "Contentstack",
6
6
  "bugs": "https://github.com/contentstack/cli/issues",
7
7
  "dependencies": {
8
- "@contentstack/cli-command": "^1.0.4",
9
- "@contentstack/cli-utilities": "^1.0.5",
10
- "@contentstack/management": "^1.6.0",
8
+ "@contentstack/cli-command": "^1.1.0",
9
+ "@contentstack/cli-utilities": "^1.1.0",
11
10
  "@oclif/command": "^1.8.16",
12
11
  "@oclif/config": "^1.18.3",
13
12
  "async": "^3.2.4",
14
13
  "big-json": "^3.2.0",
15
14
  "bluebird": "^3.7.2",
16
- "fs": "0.0.1-security",
17
15
  "is-valid-path": "^0.1.1",
18
16
  "lodash": "^4.17.20",
19
17
  "mkdirp": "^1.0.4",
@@ -27,7 +25,8 @@
27
25
  "@contentstack/cli-auth": "^1.0.6",
28
26
  "@contentstack/cli-config": "^1.0.4",
29
27
  "@contentstack/cli-dev-dependencies": "^1.0.0",
30
- "@oclif/dev-cli": "^1.22.2",
28
+ "@oclif/dev-cli": "^1.26.10",
29
+ "@oclif/plugin-help": "^5.1.19",
31
30
  "@oclif/test": "^1.2.6",
32
31
  "assert": "^2.0.0",
33
32
  "chai": "^4.2.0",
@@ -38,7 +37,7 @@
38
37
  "globby": "^10.0.2",
39
38
  "mocha": "10.1.0",
40
39
  "nyc": "^15.1.0",
41
- "sinon": "^9.0.2"
40
+ "sinon": "^15.0.1"
42
41
  },
43
42
  "engines": {
44
43
  "node": ">=8.0.0"
@@ -58,9 +57,9 @@
58
57
  "license": "MIT",
59
58
  "scripts": {
60
59
  "postpack": "rm -f oclif.manifest.json",
61
- "prepack": "oclif-dev manifest && oclif-dev readme",
60
+ "prepack": "oclif manifest && oclif readme",
62
61
  "test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
63
- "version": "oclif-dev readme && git add README.md",
62
+ "version": "oclif readme && git add README.md",
64
63
  "test:integration": "mocha --forbid-only \"test/run.test.js\" --integration-test",
65
64
  "test:unit": "mocha --forbid-only \"test/unit/*.test.js\" --unit-test"
66
65
  },
package/src/app.js CHANGED
@@ -3,22 +3,27 @@ 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');
7
6
  const login = require('./lib/util/login');
8
7
  const setupBranches = require('./lib/util/setup-branches');
9
8
  const { addlogs, unlinkFileLogger } = require('./lib/util/log');
10
- const stack = require('./lib/util/contentstack-management-sdk');
9
+ const { managementSDKClient } = require('@contentstack/cli-utilities');
11
10
 
12
- exports.initial = async function (config) {
13
- return new Promise(async function (resolve, reject) {
11
+ exports.initial = async (config) => {
12
+ return new Promise(async (resolve, reject) => {
14
13
  config = util.buildAppConfig(config);
15
14
  util.validateConfig(config);
16
- exports.getConfig = function () {
15
+ exports.getConfig = () => {
17
16
  return config;
18
17
  };
19
18
 
20
- const fetchBranchAndExport = async () => {
21
- await setupBranches(config, config.branchName);
19
+ const APIClient = await managementSDKClient(config);
20
+ const stackAPIClient = APIClient.stack({
21
+ api_key: config.source_stack,
22
+ management_token: config.management_token,
23
+ });
24
+
25
+ const fetchBranchAndExport = async (APIClient, stackAPIClient) => {
26
+ await setupBranches(config, config.branchName, stackAPIClient);
22
27
  let types = config.modules.types;
23
28
 
24
29
  if (Array.isArray(config.branches) && config.branches.length > 0) {
@@ -26,23 +31,23 @@ exports.initial = async function (config) {
26
31
  config.branchName = branch.uid;
27
32
  try {
28
33
  if (config.moduleName) {
29
- await singleExport(config.moduleName, types, config, branch.uid);
34
+ await singleExport(APIClient, stackAPIClient, config.moduleName, types, config, branch.uid);
30
35
  } else {
31
- await allExport(config, types, branch.uid);
36
+ await allExport(APIClient, stackAPIClient, config, types, branch.uid);
32
37
  }
33
38
  } catch (error) {
34
- addlogs(config, `failed export contents ${branch.uid} ${formatError(error)}`, 'error');
39
+ addlogs(config, `failed export contents ${branch.uid} ${util.formatError(error)}`, 'error');
35
40
  }
36
41
  }
37
42
  } else {
38
43
  try {
39
44
  if (config.moduleName) {
40
- await singleExport(config.moduleName, types, config);
45
+ await singleExport(APIClient, stackAPIClient, config.moduleName, types, config);
41
46
  } else {
42
- await allExport(config, types);
47
+ await allExport(APIClient, stackAPIClient, config, types);
43
48
  }
44
49
  } catch (error) {
45
- addlogs(config, `failed export contents ${formatError(error)}`, 'error');
50
+ addlogs(config, `failed export contents ${util.formatError(error)}`, 'error');
46
51
  }
47
52
  }
48
53
  };
@@ -55,13 +60,13 @@ exports.initial = async function (config) {
55
60
  ) {
56
61
  login
57
62
  .login(config)
58
- .then(async function () {
63
+ .then(async () => {
59
64
  // setup branches
60
65
  try {
61
- await fetchBranchAndExport();
66
+ await fetchBranchAndExport(APIClient, stackAPIClient);
62
67
  unlinkFileLogger();
63
68
  } catch (error) {
64
- addlogs(config, `${formatError(error)}`, 'error');
69
+ addlogs(config, `${util.formatError(error)}`, 'error');
65
70
  }
66
71
  resolve();
67
72
  })
@@ -71,25 +76,22 @@ exports.initial = async function (config) {
71
76
  addlogs(config, chalk.red('Stack Api key ' + error.errors.api_key[0], 'Please enter valid Key', 'error'));
72
77
  addlogs(config, 'The log for this is stored at ' + config.data + '/export/logs', 'success');
73
78
  } else {
74
- addlogs(config, `${formatError(error)}`, 'error');
79
+ addlogs(config, `${util.formatError(error)}`, 'error');
75
80
  }
76
81
  });
77
82
  } else if (config.management_token) {
78
83
  try {
79
- await fetchBranchAndExport();
84
+ await fetchBranchAndExport(APIClient, stackAPIClient);
80
85
  } catch (error) {
81
- addlogs(config, formatError(error), 'error');
86
+ addlogs(config, util.formatError(error), 'error');
82
87
  }
83
88
  resolve();
84
89
  }
85
90
  });
86
91
  };
87
92
 
88
- const singleExport = async (moduleName, types, config, branchName) => {
93
+ const singleExport = async (APIClient, stackAPIClient, moduleName, types, config, branchName) => {
89
94
  try {
90
- const stackClient = stack
91
- .Client(config)
92
- .stack({ api_key: config.source_stack, management_token: config.management_token });
93
95
  if (types.indexOf(moduleName) > -1) {
94
96
  let iterateList;
95
97
  if (config.modules.dependency && config.modules.dependency[moduleName]) {
@@ -101,7 +103,7 @@ const singleExport = async (moduleName, types, config, branchName) => {
101
103
 
102
104
  for (let element of iterateList) {
103
105
  const ExportModule = require('./lib/export/' + element);
104
- const result = await new ExportModule(config, stackClient).start(config, branchName);
106
+ const result = await new ExportModule(config, stackAPIClient, APIClient).start(config, branchName);
105
107
  if (result && element === 'stack') {
106
108
  let master_locale = {
107
109
  master_locale: { code: result.code },
@@ -116,21 +118,17 @@ const singleExport = async (moduleName, types, config, branchName) => {
116
118
  }
117
119
  return true;
118
120
  } catch (error) {
119
- addlogs(config, `${formatError(error)}`, 'error');
121
+ addlogs(config, `${util.formatError(error)}`, 'error');
120
122
  addlogs(config, 'Failed to migrate ' + moduleName, 'error');
121
123
  addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'error');
122
124
  }
123
125
  };
124
126
 
125
- const allExport = async (config, types, branchName) => {
127
+ const allExport = async (APIClient, stackAPIClient, config, types, branchName) => {
126
128
  try {
127
- const stackClient = stack
128
- .Client(config)
129
- .stack({ api_key: config.source_stack, management_token: config.management_token });
130
-
131
129
  for (let type of types) {
132
130
  const ExportModule = require('./lib/export/' + type);
133
- const result = await new ExportModule(config, stackClient).start(config, branchName);
131
+ const result = await new ExportModule(config, stackAPIClient, APIClient).start(config, branchName);
134
132
 
135
133
  if (result && type === 'stack') {
136
134
  let master_locale = { master_locale: { code: result.code } };
@@ -147,7 +145,7 @@ const allExport = async (config, types, branchName) => {
147
145
  addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'success');
148
146
  return true;
149
147
  } catch (error) {
150
- addlogs(config, formatError(error), 'error');
148
+ addlogs(config, util.formatError(error), 'error');
151
149
  addlogs(
152
150
  config,
153
151
  chalk.red('Failed to migrate stack: ' + config.source_stack + '. Please check error logs for more info'),
@@ -15,7 +15,7 @@ const { configHandler } = require('@contentstack/cli-utilities');
15
15
 
16
16
  class ExportCommand extends Command {
17
17
  async run() {
18
- const exportCommandFlags = this.parse(ExportCommand).flags;
18
+ const { flags: exportCommandFlags } = await this.parse(ExportCommand);
19
19
  const extConfig = exportCommandFlags.config;
20
20
  let sourceStack = exportCommandFlags['stack-uid'] || exportCommandFlags['stack-api-key'];
21
21
  const alias = exportCommandFlags['alias'] || exportCommandFlags['management-token-alias'];