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