@contentstack/cli-cm-export 1.0.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 +2 -2
- package/oclif.manifest.json +1 -1
- package/package.json +14 -5
- package/src/app.js +64 -51
- package/src/commands/cm/stacks/export.js +10 -3
- package/src/config/default.js +21 -1
- package/src/lib/export/assets.js +254 -228
- package/src/lib/export/content-types.js +72 -101
- package/src/lib/export/custom-roles.js +106 -0
- package/src/lib/export/entries.js +168 -225
- package/src/lib/export/environments.js +57 -52
- package/src/lib/export/extensions.js +50 -46
- package/src/lib/export/global-fields.js +64 -61
- package/src/lib/export/labels.js +57 -57
- package/src/lib/export/locales.js +57 -91
- package/src/lib/export/marketplace-apps.js +153 -0
- package/src/lib/export/stack.js +35 -22
- package/src/lib/export/webhooks.js +59 -54
- package/src/lib/export/workflows.js +94 -55
- package/src/lib/util/export-flags.js +7 -8
- package/src/lib/util/helper.js +83 -2
- package/src/lib/util/index.js +36 -1
- package/src/lib/util/log.js +6 -3
- package/src/lib/util/marketplace-app-helper.js +61 -0
- package/src/lib/util/setup-branches.js +5 -7
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.
|
|
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/
|
|
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 -->
|
package/oclif.manifest.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":"1.
|
|
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.
|
|
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.
|
|
9
|
-
"@contentstack/cli-utilities": "^1.0.
|
|
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/
|
|
74
|
+
"repositoryPrefix": "<%- repo %>/blob/main/packages/contentstack-export/<%- commandPath %>"
|
|
66
75
|
},
|
|
67
76
|
"csdxConfig": {
|
|
68
77
|
"expiredCommands": {
|
package/src/app.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
/* eslint-disable no-redeclare */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var { addlogs, unlinkFileLogger } = require('./lib/util/log');
|
|
5
|
-
const setupBranches = require('./lib/util/setup-branches');
|
|
2
|
+
const _ = require('lodash');
|
|
3
|
+
const path = require('path');
|
|
6
4
|
const chalk = require('chalk');
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const util = require('./lib/util');
|
|
6
|
+
const { formatError } = require('./lib/util');
|
|
7
|
+
const login = require('./lib/util/login');
|
|
8
|
+
const setupBranches = require('./lib/util/setup-branches');
|
|
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) {
|
|
@@ -17,7 +19,8 @@ exports.initial = async function (config) {
|
|
|
17
19
|
|
|
18
20
|
const fetchBranchAndExport = async () => {
|
|
19
21
|
await setupBranches(config, config.branchName);
|
|
20
|
-
|
|
22
|
+
let types = config.modules.types;
|
|
23
|
+
|
|
21
24
|
if (Array.isArray(config.branches) && config.branches.length > 0) {
|
|
22
25
|
for (let branch of config.branches) {
|
|
23
26
|
config.branchName = branch.uid;
|
|
@@ -28,7 +31,7 @@ exports.initial = async function (config) {
|
|
|
28
31
|
await allExport(config, types, branch.uid);
|
|
29
32
|
}
|
|
30
33
|
} catch (error) {
|
|
31
|
-
|
|
34
|
+
addlogs(config, `failed export contents ${branch.uid} ${formatError(error)}`, 'error');
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
37
|
} else {
|
|
@@ -39,10 +42,10 @@ exports.initial = async function (config) {
|
|
|
39
42
|
await allExport(config, types);
|
|
40
43
|
}
|
|
41
44
|
} catch (error) {
|
|
42
|
-
|
|
45
|
+
addlogs(config, `failed export contents ${formatError(error)}`, 'error');
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
|
-
}
|
|
48
|
+
};
|
|
46
49
|
|
|
47
50
|
// try {
|
|
48
51
|
if (
|
|
@@ -54,8 +57,12 @@ exports.initial = async function (config) {
|
|
|
54
57
|
.login(config)
|
|
55
58
|
.then(async function () {
|
|
56
59
|
// setup branches
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
try {
|
|
61
|
+
await fetchBranchAndExport();
|
|
62
|
+
unlinkFileLogger();
|
|
63
|
+
} catch (error) {
|
|
64
|
+
addlogs(config, `${formatError(error)}`, 'error');
|
|
65
|
+
}
|
|
59
66
|
resolve();
|
|
60
67
|
})
|
|
61
68
|
.catch((error) => {
|
|
@@ -64,19 +71,26 @@ exports.initial = async function (config) {
|
|
|
64
71
|
addlogs(config, chalk.red('Stack Api key ' + error.errors.api_key[0], 'Please enter valid Key', 'error'));
|
|
65
72
|
addlogs(config, 'The log for this is stored at ' + config.data + '/export/logs', 'success');
|
|
66
73
|
} else {
|
|
67
|
-
|
|
74
|
+
addlogs(config, `${formatError(error)}`, 'error');
|
|
68
75
|
}
|
|
69
|
-
reject(error);
|
|
76
|
+
// reject(error);
|
|
70
77
|
});
|
|
71
78
|
} else if (config.management_token) {
|
|
72
|
-
|
|
79
|
+
try {
|
|
80
|
+
await fetchBranchAndExport();
|
|
81
|
+
} catch (error) {
|
|
82
|
+
addlogs(config, `${formatError(error)}`, 'error');
|
|
83
|
+
}
|
|
73
84
|
resolve();
|
|
74
85
|
}
|
|
75
86
|
});
|
|
76
87
|
};
|
|
77
88
|
|
|
78
|
-
|
|
89
|
+
const singleExport = async (moduleName, types, config, branchName) => {
|
|
79
90
|
try {
|
|
91
|
+
const stackClient = stack
|
|
92
|
+
.Client(config)
|
|
93
|
+
.stack({ api_key: config.source_stack, management_token: config.management_token });
|
|
80
94
|
if (types.indexOf(moduleName) > -1) {
|
|
81
95
|
let iterateList;
|
|
82
96
|
if (config.modules.dependency && config.modules.dependency[moduleName]) {
|
|
@@ -86,10 +100,10 @@ var singleExport = async (moduleName, types, config, branchName) => {
|
|
|
86
100
|
}
|
|
87
101
|
iterateList.push(moduleName);
|
|
88
102
|
|
|
89
|
-
for (let
|
|
90
|
-
|
|
91
|
-
const result = await
|
|
92
|
-
if (result &&
|
|
103
|
+
for (let element of iterateList) {
|
|
104
|
+
const ExportModule = require('./lib/export/' + element);
|
|
105
|
+
const result = await new ExportModule(config, stackClient).start(config, branchName);
|
|
106
|
+
if (result && element === 'stack') {
|
|
93
107
|
let master_locale = {
|
|
94
108
|
master_locale: { code: result.code },
|
|
95
109
|
};
|
|
@@ -103,42 +117,41 @@ var singleExport = async (moduleName, types, config, branchName) => {
|
|
|
103
117
|
}
|
|
104
118
|
return true;
|
|
105
119
|
} catch (error) {
|
|
120
|
+
addlogs(config, `${formatError(error)}`, 'error');
|
|
106
121
|
addlogs(config, 'Failed to migrate ' + moduleName, 'error');
|
|
107
|
-
addlogs(config, error, 'error');
|
|
108
122
|
addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'error');
|
|
109
|
-
throw error;
|
|
110
123
|
}
|
|
111
124
|
};
|
|
112
125
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
126
|
+
const allExport = async (config, types, branchName) => {
|
|
127
|
+
try {
|
|
128
|
+
const stackClient = stack
|
|
129
|
+
.Client(config)
|
|
130
|
+
.stack({ api_key: config.source_stack, management_token: config.management_token });
|
|
131
|
+
|
|
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);
|
|
125
139
|
}
|
|
126
|
-
addlogs(
|
|
127
|
-
config,
|
|
128
|
-
chalk.green('The content of the ' + config.source_stack + ' has been exported successfully!'),
|
|
129
|
-
'success',
|
|
130
|
-
);
|
|
131
|
-
addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'success');
|
|
132
|
-
return resolve();
|
|
133
|
-
} catch (error) {
|
|
134
|
-
addlogs(
|
|
135
|
-
config,
|
|
136
|
-
chalk.red('Failed to migrate stack: ' + config.source_stack + '. Please check error logs for more info'),
|
|
137
|
-
'error',
|
|
138
|
-
);
|
|
139
|
-
addlogs(config, chalk.red(error && error.errorMessage), 'error');
|
|
140
|
-
addlogs(config, 'The log for this is stored at ' + path.join(config.data, 'logs', 'export'), 'error');
|
|
141
|
-
return reject(error);
|
|
142
140
|
}
|
|
143
|
-
|
|
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
|
+
}
|
|
144
157
|
};
|
|
@@ -10,6 +10,7 @@ const {
|
|
|
10
10
|
parametersWithAuthToken,
|
|
11
11
|
withoutParametersWithAuthToken,
|
|
12
12
|
} = require('../../../lib/util/export-flags');
|
|
13
|
+
const config = require('../../../config/default');
|
|
13
14
|
const { configHandler } = require('@contentstack/cli-utilities');
|
|
14
15
|
|
|
15
16
|
class ExportCommand extends Command {
|
|
@@ -32,6 +33,12 @@ class ExportCommand extends Command {
|
|
|
32
33
|
|
|
33
34
|
if (alias) {
|
|
34
35
|
let managementTokens = this.getToken(alias);
|
|
36
|
+
|
|
37
|
+
if (alias) {
|
|
38
|
+
const listOfTokens = configHandler.get('tokens');
|
|
39
|
+
config.management_token_data = listOfTokens[alias];
|
|
40
|
+
}
|
|
41
|
+
|
|
35
42
|
if (managementTokens) {
|
|
36
43
|
if (extConfig) {
|
|
37
44
|
await configWithMToken(
|
|
@@ -72,9 +79,9 @@ class ExportCommand extends Command {
|
|
|
72
79
|
}
|
|
73
80
|
} else if (_authToken) {
|
|
74
81
|
if (extConfig) {
|
|
75
|
-
configWithAuthToken(extConfig, _authToken, moduleName, host, contentTypes, branchName, securedAssets);
|
|
82
|
+
await configWithAuthToken(extConfig, _authToken, moduleName, host, contentTypes, branchName, securedAssets);
|
|
76
83
|
} else if (sourceStack && data) {
|
|
77
|
-
return parametersWithAuthToken(
|
|
84
|
+
return await parametersWithAuthToken(
|
|
78
85
|
_authToken,
|
|
79
86
|
sourceStack,
|
|
80
87
|
data,
|
|
@@ -85,7 +92,7 @@ class ExportCommand extends Command {
|
|
|
85
92
|
securedAssets,
|
|
86
93
|
);
|
|
87
94
|
} else if (data === undefined && sourceStack === undefined) {
|
|
88
|
-
withoutParametersWithAuthToken(_authToken, moduleName, host, contentTypes, branchName, securedAssets);
|
|
95
|
+
await withoutParametersWithAuthToken(_authToken, moduleName, host, contentTypes, branchName, securedAssets);
|
|
89
96
|
} else {
|
|
90
97
|
this.log('Please provide a valid command. Run "csdx cm:export --help" command to view the command usage');
|
|
91
98
|
}
|
package/src/config/default.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
versioning: false,
|
|
3
3
|
host: 'https://api.contentstack.io/v3',
|
|
4
|
+
developerHubUrls: {
|
|
5
|
+
// NOTE CDA url used as developer-hub url mapper to avoid conflict if user used any custom name
|
|
6
|
+
'https://api.contentstack.io': 'https://developerhub-api.contentstack.com',
|
|
7
|
+
'https://eu-api.contentstack.com': 'https://eu-developerhub-api.contentstack.com',
|
|
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',
|
|
10
|
+
},
|
|
4
11
|
// use below hosts for eu region
|
|
5
12
|
// host:'https://eu-api.contentstack.com/v3',
|
|
6
13
|
// use below hosts for azure-na region
|
|
@@ -15,15 +22,22 @@ module.exports = {
|
|
|
15
22
|
'webhooks',
|
|
16
23
|
'global-fields',
|
|
17
24
|
'content-types',
|
|
25
|
+
'custom-roles',
|
|
18
26
|
'workflows',
|
|
19
27
|
'entries',
|
|
20
28
|
'labels',
|
|
29
|
+
'marketplace-apps',
|
|
21
30
|
],
|
|
22
31
|
locales: {
|
|
23
32
|
dirName: 'locales',
|
|
24
33
|
fileName: 'locales.json',
|
|
25
34
|
requiredKeys: ['code', 'uid', 'name', 'fallback_locale'],
|
|
26
35
|
},
|
|
36
|
+
customRoles: {
|
|
37
|
+
dirName: 'custom-roles',
|
|
38
|
+
fileName: 'custom-roles.json',
|
|
39
|
+
customRolesLocalesFileName: 'custom-roles-locales.json',
|
|
40
|
+
},
|
|
27
41
|
environments: {
|
|
28
42
|
dirName: 'environments',
|
|
29
43
|
fileName: 'environments.json',
|
|
@@ -61,7 +75,7 @@ module.exports = {
|
|
|
61
75
|
host: 'https://images.contentstack.io',
|
|
62
76
|
invalidKeys: ['created_at', 'updated_at', 'created_by', 'updated_by', '_metadata', 'published'],
|
|
63
77
|
// no of asset version files (of a single asset) that'll be downloaded parallelly
|
|
64
|
-
downloadLimit:
|
|
78
|
+
downloadLimit: 3,
|
|
65
79
|
enableDownloadStatus: false,
|
|
66
80
|
},
|
|
67
81
|
content_types: {
|
|
@@ -101,6 +115,10 @@ module.exports = {
|
|
|
101
115
|
dependency: {
|
|
102
116
|
entries: ['stack', 'locales', 'content-types'],
|
|
103
117
|
},
|
|
118
|
+
marketplace_apps: {
|
|
119
|
+
dirName: 'marketplace_apps',
|
|
120
|
+
fileName: 'marketplace_apps.json',
|
|
121
|
+
},
|
|
104
122
|
},
|
|
105
123
|
languagesCode: [
|
|
106
124
|
'af-za',
|
|
@@ -327,4 +345,6 @@ module.exports = {
|
|
|
327
345
|
stacks: '/stacks/',
|
|
328
346
|
},
|
|
329
347
|
preserveStackVersion: false,
|
|
348
|
+
fetchConcurrency: 5,
|
|
349
|
+
writeConcurrency: 5,
|
|
330
350
|
};
|