@contentstack/cli-cm-export 0.1.1-beta.7 → 1.0.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/LICENSE +21 -0
- package/README.md +44 -24
- package/oclif.manifest.json +1 -1
- package/package.json +72 -68
- package/src/app.js +120 -66
- package/src/commands/cm/stacks/export.js +177 -0
- package/src/config/default.js +18 -58
- package/src/lib/export/assets.js +325 -223
- package/src/lib/export/content-types.js +76 -66
- package/src/lib/export/entries.js +190 -135
- package/src/lib/export/environments.js +52 -45
- package/src/lib/export/extensions.js +50 -43
- package/src/lib/export/global-fields.js +92 -80
- package/src/lib/export/labels.js +52 -44
- package/src/lib/export/locales.js +74 -41
- package/src/lib/export/stack.js +72 -47
- package/src/lib/export/webhooks.js +58 -48
- package/src/lib/export/workflows.js +55 -44
- package/src/lib/util/contentstack-management-sdk.js +30 -4
- package/src/lib/util/export-flags.js +158 -87
- package/src/lib/util/helper.js +20 -20
- package/src/lib/util/index.js +32 -19
- package/src/lib/util/log.js +109 -53
- package/src/lib/util/login.js +56 -41
- package/src/lib/util/setup-branches.js +53 -0
- package/src/commands/cm/export.js +0 -123
- package/src/lib/util/request.js +0 -83
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/* eslint-disable complexity */
|
|
2
|
+
const { Command, flags } = require('@contentstack/cli-command');
|
|
3
|
+
const { printFlagDeprecation } = require('@contentstack/cli-utilities');
|
|
4
|
+
|
|
5
|
+
const {
|
|
6
|
+
configWithMToken,
|
|
7
|
+
parameterWithMToken,
|
|
8
|
+
withoutParameterMToken,
|
|
9
|
+
configWithAuthToken,
|
|
10
|
+
parametersWithAuthToken,
|
|
11
|
+
withoutParametersWithAuthToken,
|
|
12
|
+
} = require('../../../lib/util/export-flags');
|
|
13
|
+
const { configHandler } = require('@contentstack/cli-utilities');
|
|
14
|
+
|
|
15
|
+
class ExportCommand extends Command {
|
|
16
|
+
async run() {
|
|
17
|
+
const exportCommandFlags = this.parse(ExportCommand).flags;
|
|
18
|
+
const extConfig = exportCommandFlags.config;
|
|
19
|
+
let sourceStack = exportCommandFlags['stack-uid'] || exportCommandFlags['stack-api-key'];
|
|
20
|
+
const alias = exportCommandFlags['alias'] || exportCommandFlags['management-token-alias'];
|
|
21
|
+
const securedAssets = exportCommandFlags['secured-assets'];
|
|
22
|
+
const data = exportCommandFlags.data || exportCommandFlags['data-dir'];
|
|
23
|
+
const moduleName = exportCommandFlags.module;
|
|
24
|
+
const contentTypes = exportCommandFlags['content-types'];
|
|
25
|
+
const branchName = exportCommandFlags.branch;
|
|
26
|
+
let _authToken = configHandler.get('authtoken');
|
|
27
|
+
let host = this.region;
|
|
28
|
+
let cmaHost = host.cma.split('//');
|
|
29
|
+
let cdaHost = host.cda.split('//');
|
|
30
|
+
host.cma = cmaHost[1];
|
|
31
|
+
host.cda = cdaHost[1];
|
|
32
|
+
|
|
33
|
+
if (alias) {
|
|
34
|
+
let managementTokens = this.getToken(alias);
|
|
35
|
+
if (managementTokens) {
|
|
36
|
+
if (extConfig) {
|
|
37
|
+
await configWithMToken(
|
|
38
|
+
extConfig,
|
|
39
|
+
managementTokens,
|
|
40
|
+
host,
|
|
41
|
+
contentTypes,
|
|
42
|
+
branchName,
|
|
43
|
+
securedAssets,
|
|
44
|
+
moduleName,
|
|
45
|
+
);
|
|
46
|
+
} else if (data) {
|
|
47
|
+
await parameterWithMToken(
|
|
48
|
+
managementTokens,
|
|
49
|
+
data,
|
|
50
|
+
moduleName,
|
|
51
|
+
host,
|
|
52
|
+
_authToken,
|
|
53
|
+
contentTypes,
|
|
54
|
+
branchName,
|
|
55
|
+
securedAssets,
|
|
56
|
+
);
|
|
57
|
+
} else if (data === undefined && sourceStack === undefined) {
|
|
58
|
+
await withoutParameterMToken(
|
|
59
|
+
managementTokens,
|
|
60
|
+
moduleName,
|
|
61
|
+
host,
|
|
62
|
+
_authToken,
|
|
63
|
+
contentTypes,
|
|
64
|
+
branchName,
|
|
65
|
+
securedAssets,
|
|
66
|
+
);
|
|
67
|
+
} else {
|
|
68
|
+
this.log('Please provide a valid command. Run "csdx cm:export --help" command to view the command usage');
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
this.log(alias + ' management token is not present, please add managment token first');
|
|
72
|
+
}
|
|
73
|
+
} else if (_authToken) {
|
|
74
|
+
if (extConfig) {
|
|
75
|
+
configWithAuthToken(extConfig, _authToken, moduleName, host, contentTypes, branchName, securedAssets);
|
|
76
|
+
} else if (sourceStack && data) {
|
|
77
|
+
return parametersWithAuthToken(
|
|
78
|
+
_authToken,
|
|
79
|
+
sourceStack,
|
|
80
|
+
data,
|
|
81
|
+
moduleName,
|
|
82
|
+
host,
|
|
83
|
+
contentTypes,
|
|
84
|
+
branchName,
|
|
85
|
+
securedAssets,
|
|
86
|
+
);
|
|
87
|
+
} else if (data === undefined && sourceStack === undefined) {
|
|
88
|
+
withoutParametersWithAuthToken(_authToken, moduleName, host, contentTypes, branchName, securedAssets);
|
|
89
|
+
} else {
|
|
90
|
+
this.log('Please provide a valid command. Run "csdx cm:export --help" command to view the command usage');
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
this.log('Login or provide the alias for management token');
|
|
94
|
+
}
|
|
95
|
+
// return
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
ExportCommand.description = `Export content from a stack`;
|
|
100
|
+
ExportCommand.examples = [
|
|
101
|
+
'csdx cm:stacks:export --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>',
|
|
102
|
+
'csdx cm:stacks:export --config <path/to/config/dir>',
|
|
103
|
+
'csdx cm:stacks:export --alias <management_token_alias>',
|
|
104
|
+
'csdx cm:stacks:export --alias <management_token_alias> --data-dir <path/to/export/destination/dir>',
|
|
105
|
+
'csdx cm:stacks:export --alias <management_token_alias> --config <path/to/config/file>',
|
|
106
|
+
'csdx cm:stacks:export --module <single module name>',
|
|
107
|
+
'csdx cm:stacks:export --branch [optional] branch name',
|
|
108
|
+
];
|
|
109
|
+
ExportCommand.usage =
|
|
110
|
+
'cm:stacks:export [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--content-types <value>] [--branch <value>] [--secured-assets]';
|
|
111
|
+
|
|
112
|
+
ExportCommand.flags = {
|
|
113
|
+
config: flags.string({
|
|
114
|
+
char: 'c',
|
|
115
|
+
description: '[optional] path of the config',
|
|
116
|
+
}),
|
|
117
|
+
'stack-uid': flags.string({
|
|
118
|
+
char: 's',
|
|
119
|
+
description: 'API key of the source stack',
|
|
120
|
+
hidden: true,
|
|
121
|
+
parse: printFlagDeprecation(['-s', '--stack-uid'], ['-k', '--stack-api-key']),
|
|
122
|
+
}),
|
|
123
|
+
'stack-api-key': flags.string({
|
|
124
|
+
char: 'k',
|
|
125
|
+
description: 'API key of the source stack',
|
|
126
|
+
}),
|
|
127
|
+
data: flags.string({
|
|
128
|
+
description: 'path or location to store the data',
|
|
129
|
+
hidden: true,
|
|
130
|
+
parse: printFlagDeprecation(['--data'], ['--data-dir']),
|
|
131
|
+
}),
|
|
132
|
+
'data-dir': flags.string({
|
|
133
|
+
char: 'd',
|
|
134
|
+
description: 'path or location to store the data',
|
|
135
|
+
}),
|
|
136
|
+
alias: flags.string({
|
|
137
|
+
char: 'a',
|
|
138
|
+
description: 'alias of the management token',
|
|
139
|
+
}),
|
|
140
|
+
'management-token-alias': flags.string({
|
|
141
|
+
description: 'alias of the management token',
|
|
142
|
+
hidden: true,
|
|
143
|
+
parse: printFlagDeprecation(['--management-token-alias'], ['-a', '--alias']),
|
|
144
|
+
}),
|
|
145
|
+
'auth-token': flags.boolean({
|
|
146
|
+
char: 'A',
|
|
147
|
+
description: 'to use auth token',
|
|
148
|
+
hidden: true,
|
|
149
|
+
parse: printFlagDeprecation(['-A', '--auth-token']),
|
|
150
|
+
}),
|
|
151
|
+
module: flags.string({
|
|
152
|
+
char: 'm',
|
|
153
|
+
description: '[optional] specific module name',
|
|
154
|
+
exclusive: ['content-types'],
|
|
155
|
+
parse: printFlagDeprecation(['-m'], ['--module']),
|
|
156
|
+
}),
|
|
157
|
+
'content-types': flags.string({
|
|
158
|
+
char: 't',
|
|
159
|
+
description: '[optional] content type',
|
|
160
|
+
multiple: true,
|
|
161
|
+
exclusive: ['module'],
|
|
162
|
+
parse: printFlagDeprecation(['-t'], ['--content-types']),
|
|
163
|
+
}),
|
|
164
|
+
branch: flags.string({
|
|
165
|
+
char: 'B',
|
|
166
|
+
// default: 'main',
|
|
167
|
+
description: '[optional] branch name',
|
|
168
|
+
parse: printFlagDeprecation(['-B'], ['--branch']),
|
|
169
|
+
}),
|
|
170
|
+
'secured-assets': flags.boolean({
|
|
171
|
+
description: '[optional] use when assets are secured',
|
|
172
|
+
}),
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
ExportCommand.aliases = ['cm:export'];
|
|
176
|
+
|
|
177
|
+
module.exports = ExportCommand;
|
package/src/config/default.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
versioning: false,
|
|
3
|
+
host: 'https://api.contentstack.io/v3',
|
|
4
|
+
// use below hosts for eu region
|
|
5
|
+
// host:'https://eu-api.contentstack.com/v3',
|
|
6
|
+
// use below hosts for azure-na region
|
|
7
|
+
// host:'https://azure-na-api.contentstack.com/v3',
|
|
3
8
|
modules: {
|
|
4
9
|
types: [
|
|
5
10
|
'stack',
|
|
@@ -17,12 +22,7 @@ module.exports = {
|
|
|
17
22
|
locales: {
|
|
18
23
|
dirName: 'locales',
|
|
19
24
|
fileName: 'locales.json',
|
|
20
|
-
requiredKeys: [
|
|
21
|
-
'code',
|
|
22
|
-
'uid',
|
|
23
|
-
'name',
|
|
24
|
-
'fallback_locale',
|
|
25
|
-
],
|
|
25
|
+
requiredKeys: ['code', 'uid', 'name', 'fallback_locale'],
|
|
26
26
|
},
|
|
27
27
|
environments: {
|
|
28
28
|
dirName: 'environments',
|
|
@@ -31,15 +31,7 @@ module.exports = {
|
|
|
31
31
|
labels: {
|
|
32
32
|
dirName: 'labels',
|
|
33
33
|
fileName: 'labels.json',
|
|
34
|
-
invalidKeys: [
|
|
35
|
-
'stackHeaders',
|
|
36
|
-
'uid',
|
|
37
|
-
'urlPath',
|
|
38
|
-
'created_at',
|
|
39
|
-
'updated_at',
|
|
40
|
-
'created_by',
|
|
41
|
-
'updated_by',
|
|
42
|
-
],
|
|
34
|
+
invalidKeys: ['stackHeaders', 'uid', 'urlPath', 'created_at', 'updated_at', 'created_by', 'updated_by'],
|
|
43
35
|
},
|
|
44
36
|
webhooks: {
|
|
45
37
|
dirName: 'webhooks',
|
|
@@ -49,68 +41,33 @@ module.exports = {
|
|
|
49
41
|
dirName: 'releases',
|
|
50
42
|
fileName: 'releases.json',
|
|
51
43
|
releasesList: 'releasesList.json',
|
|
52
|
-
invalidKeys: [
|
|
53
|
-
'stackHeaders',
|
|
54
|
-
'urlPath',
|
|
55
|
-
'created_at',
|
|
56
|
-
'updated_at',
|
|
57
|
-
'created_by',
|
|
58
|
-
'updated_by',
|
|
59
|
-
],
|
|
44
|
+
invalidKeys: ['stackHeaders', 'urlPath', 'created_at', 'updated_at', 'created_by', 'updated_by'],
|
|
60
45
|
},
|
|
61
46
|
workflows: {
|
|
62
47
|
dirName: 'workflows',
|
|
63
48
|
fileName: 'workflows.json',
|
|
64
|
-
invalidKeys: [
|
|
65
|
-
'stackHeaders',
|
|
66
|
-
'urlPath',
|
|
67
|
-
'created_at',
|
|
68
|
-
'updated_at',
|
|
69
|
-
'created_by',
|
|
70
|
-
'updated_by',
|
|
71
|
-
],
|
|
49
|
+
invalidKeys: ['stackHeaders', 'urlPath', 'created_at', 'updated_at', 'created_by', 'updated_by'],
|
|
72
50
|
},
|
|
73
51
|
globalfields: {
|
|
74
52
|
dirName: 'global_fields',
|
|
75
53
|
fileName: 'globalfields.json',
|
|
76
|
-
validKeys: [
|
|
77
|
-
'title',
|
|
78
|
-
'uid',
|
|
79
|
-
'schema',
|
|
80
|
-
'options',
|
|
81
|
-
'singleton',
|
|
82
|
-
'description',
|
|
83
|
-
],
|
|
54
|
+
validKeys: ['title', 'uid', 'schema', 'options', 'singleton', 'description'],
|
|
84
55
|
},
|
|
85
56
|
assets: {
|
|
86
57
|
dirName: 'assets',
|
|
87
58
|
fileName: 'assets.json',
|
|
88
59
|
// This is the total no. of asset objects fetched in each 'get assets' call
|
|
89
60
|
batchLimit: 20,
|
|
90
|
-
host: 'https://
|
|
91
|
-
invalidKeys: [
|
|
92
|
-
'created_at',
|
|
93
|
-
'updated_at',
|
|
94
|
-
'created_by',
|
|
95
|
-
'updated_by',
|
|
96
|
-
'_metadata',
|
|
97
|
-
'published',
|
|
98
|
-
],
|
|
61
|
+
host: 'https://images.contentstack.io',
|
|
62
|
+
invalidKeys: ['created_at', 'updated_at', 'created_by', 'updated_by', '_metadata', 'published'],
|
|
99
63
|
// no of asset version files (of a single asset) that'll be downloaded parallelly
|
|
100
64
|
downloadLimit: 5,
|
|
65
|
+
enableDownloadStatus: false,
|
|
101
66
|
},
|
|
102
67
|
content_types: {
|
|
103
68
|
dirName: 'content_types',
|
|
104
69
|
fileName: 'content_types.json',
|
|
105
|
-
validKeys: [
|
|
106
|
-
'title',
|
|
107
|
-
'uid',
|
|
108
|
-
'field_rules',
|
|
109
|
-
'schema',
|
|
110
|
-
'options',
|
|
111
|
-
'singleton',
|
|
112
|
-
'description',
|
|
113
|
-
],
|
|
70
|
+
validKeys: ['title', 'uid', 'field_rules', 'schema', 'options', 'singleton', 'description'],
|
|
114
71
|
// total no of content types fetched in each 'get content types' call
|
|
115
72
|
limit: 100,
|
|
116
73
|
},
|
|
@@ -141,6 +98,9 @@ module.exports = {
|
|
|
141
98
|
dirName: 'stack',
|
|
142
99
|
fileName: 'stack.json',
|
|
143
100
|
},
|
|
101
|
+
dependency: {
|
|
102
|
+
entries: ['stack', 'locales', 'content-types'],
|
|
103
|
+
},
|
|
144
104
|
},
|
|
145
105
|
languagesCode: [
|
|
146
106
|
'af-za',
|
|
@@ -367,4 +327,4 @@ module.exports = {
|
|
|
367
327
|
stacks: '/stacks/',
|
|
368
328
|
},
|
|
369
329
|
preserveStackVersion: false,
|
|
370
|
-
}
|
|
330
|
+
};
|