@contentstack/cli-cm-import 0.1.1-beta.9 → 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.
@@ -0,0 +1,186 @@
1
+ const _ = require('lodash');
2
+ const defaultConfig = require('../../../config/default');
3
+ const { Command, flags } = require('@contentstack/cli-command');
4
+ const { configHandler } = require('@contentstack/cli-utilities');
5
+ const {
6
+ configWithMToken,
7
+ parameterWithMToken,
8
+ withoutParameterMToken,
9
+ configWithAuthToken,
10
+ parametersWithAuthToken,
11
+ withoutParametersWithAuthToken,
12
+ } = require('../../../lib/util/import-flags');
13
+ const { printFlagDeprecation } = require('@contentstack/cli-utilities');
14
+
15
+ class ImportCommand extends Command {
16
+ async run() {
17
+ let self = this;
18
+ const importCommandFlags = self.parse(ImportCommand).flags;
19
+ const extConfig = importCommandFlags.config;
20
+ let targetStack = importCommandFlags['stack-uid'] || importCommandFlags['stack-api-key'];
21
+ const data = importCommandFlags.data || importCommandFlags['data-dir'];
22
+ const moduleName = importCommandFlags.module;
23
+ const backupdir = importCommandFlags['backup-dir'];
24
+ const alias = importCommandFlags['alias'] || importCommandFlags['management-token-alias'];
25
+ let _authToken = configHandler.get('authtoken');
26
+ importCommandFlags.branchName = importCommandFlags.branch;
27
+ importCommandFlags.importWebhookStatus = importCommandFlags['import-webhook-status'];
28
+ delete importCommandFlags.branch;
29
+ delete importCommandFlags['import-webhook-status'];
30
+ let host = self.cmaHost;
31
+
32
+ return new Promise((resolve, reject) => {
33
+ if (data) {
34
+ defaultConfig.data = data;
35
+ }
36
+
37
+ if (alias) {
38
+ let managementTokens = self.getToken(alias);
39
+
40
+ if (managementTokens) {
41
+ let result;
42
+
43
+ if ((extConfig && _authToken) || alias) {
44
+ result = configWithMToken(
45
+ extConfig,
46
+ managementTokens,
47
+ moduleName,
48
+ host,
49
+ _authToken,
50
+ backupdir,
51
+ importCommandFlags,
52
+ );
53
+ } else if (data) {
54
+ result = parameterWithMToken(
55
+ managementTokens,
56
+ data,
57
+ moduleName,
58
+ host,
59
+ _authToken,
60
+ backupdir,
61
+ importCommandFlags,
62
+ );
63
+ } else {
64
+ result = withoutParameterMToken(
65
+ managementTokens,
66
+ moduleName,
67
+ host,
68
+ _authToken,
69
+ backupdir,
70
+ importCommandFlags,
71
+ );
72
+ }
73
+
74
+ result.then(resolve).catch(reject);
75
+ } else {
76
+ console.log('management Token is not present please add managment token first');
77
+ }
78
+ } else if (_authToken) {
79
+ let result;
80
+
81
+ if (extConfig) {
82
+ result = configWithAuthToken(extConfig, _authToken, moduleName, host, backupdir, importCommandFlags);
83
+ } else if (targetStack && data) {
84
+ result = parametersWithAuthToken(
85
+ _authToken,
86
+ targetStack,
87
+ data,
88
+ moduleName,
89
+ host,
90
+ backupdir,
91
+ importCommandFlags,
92
+ );
93
+ } else {
94
+ result = withoutParametersWithAuthToken(_authToken, moduleName, host, backupdir, importCommandFlags);
95
+ }
96
+
97
+ result.then(resolve).catch(reject);
98
+ } else {
99
+ console.log('Login or provide the alias for management token');
100
+ }
101
+ });
102
+ }
103
+ }
104
+
105
+ ImportCommand.description = `Import script for importing the content into the new stack
106
+ ...
107
+ Once you export content from the source stack, import it to your destination stack by using the cm:stacks:import command.
108
+ `;
109
+ ImportCommand.examples = [
110
+ `csdx cm:stacks:import --stack-api-key <stack_api_key> --data-dir <path/of/export/destination/dir>`,
111
+ `csdx cm:stacks:import --config <path/of/config/dir>`,
112
+ `csdx cm:stacks:import --module <single module name>`,
113
+ `csdx cm:stacks:import --module <single module name> --backup-dir <backup dir>`,
114
+ `csdx cm:stacks:import --alias <management_token_alias>`,
115
+ `csdx cm:stacks:import --alias <management_token_alias> --data-dir <path/of/export/destination/dir>`,
116
+ `csdx cm:stacks:import --alias <management_token_alias> --config <path/of/config/file>`,
117
+ `csdx cm:stacks:import --branch <branch name>`,
118
+ ];
119
+ ImportCommand.flags = {
120
+ config: flags.string({
121
+ char: 'c',
122
+ description: '[optional] path of config file',
123
+ }),
124
+ 'stack-uid': flags.string({
125
+ char: 's',
126
+ description: 'API key of the target 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 target stack',
133
+ }),
134
+ data: flags.string({
135
+ description: 'path and location where data is stored',
136
+ hidden: true,
137
+ parse: printFlagDeprecation(['--data'], ['--data-dir']),
138
+ }),
139
+ 'data-dir': flags.string({
140
+ char: 'd',
141
+ description: 'path and location where data is stored',
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
+ parse: printFlagDeprecation(['-m'], ['--module']),
162
+ }),
163
+ 'backup-dir': flags.string({
164
+ char: 'b',
165
+ description: '[optional] backup directory name when using specific module',
166
+ parse: printFlagDeprecation(['-b'], ['--backup-dir']),
167
+ }),
168
+ branch: flags.string({
169
+ char: 'B',
170
+ description: '[optional] branch name',
171
+ parse: printFlagDeprecation(['-B'], ['--branch']),
172
+ }),
173
+ 'import-webhook-status': flags.string({
174
+ description: 'Webhook state',
175
+ options: ['disable', 'current'],
176
+ required: false,
177
+ default: 'disable',
178
+ }),
179
+ };
180
+
181
+ ImportCommand.aliases = ['cm:import'];
182
+
183
+ ImportCommand.usage =
184
+ 'cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>] [--branch <value>] [--import-webhook-status disable|current]';
185
+
186
+ module.exports = ImportCommand;
@@ -1,5 +1,9 @@
1
1
  module.exports = {
2
2
  versioning: false,
3
+ // use below hosts for eu region
4
+ // host:'https://eu-api.contentstack.com/v3',
5
+ // use below hosts for azure-na region
6
+ // host:'https://azure-na-api.contentstack.com/v3',
3
7
  // pass locale, only to migrate entries from that locale
4
8
  // not passing `locale` will migrate all the locales present
5
9
  // locales: ['fr-fr'],
@@ -10,22 +14,17 @@ module.exports = {
10
14
  'environments',
11
15
  'assets',
12
16
  'extensions',
13
- 'webhooks',
14
17
  'global-fields',
15
18
  'content-types',
16
19
  'workflows',
17
20
  'entries',
18
21
  'labels',
22
+ 'webhooks',
19
23
  ],
20
24
  locales: {
21
25
  dirName: 'locales',
22
26
  fileName: 'locales.json',
23
- requiredKeys: [
24
- 'code',
25
- 'uid',
26
- 'name',
27
- 'fallback_locale'
28
- ],
27
+ requiredKeys: ['code', 'uid', 'name', 'fallback_locale'],
29
28
  },
30
29
  environments: {
31
30
  dirName: 'environments',
@@ -46,26 +45,12 @@ module.exports = {
46
45
  releases: {
47
46
  dirName: 'releases',
48
47
  fileName: 'releases.json',
49
- invalidKeys: [
50
- 'stackHeaders',
51
- 'urlPath',
52
- 'created_at',
53
- 'updated_at',
54
- 'created_by',
55
- 'updated_by',
56
- ],
48
+ invalidKeys: ['stackHeaders', 'urlPath', 'created_at', 'updated_at', 'created_by', 'updated_by'],
57
49
  },
58
50
  workflows: {
59
51
  dirName: 'workflows',
60
52
  fileName: 'workflows.json',
61
- invalidKeys: [
62
- 'stackHeaders',
63
- 'urlPath',
64
- 'created_at',
65
- 'updated_at',
66
- 'created_by',
67
- 'updated_by',
68
- ],
53
+ invalidKeys: ['stackHeaders', 'urlPath', 'created_at', 'updated_at', 'created_by', 'updated_by'],
69
54
  },
70
55
  assets: {
71
56
  dirName: 'assets',
@@ -73,38 +58,19 @@ module.exports = {
73
58
  // This is the total no. of asset objects fetched in each 'get assets' call
74
59
  limit: 100,
75
60
  host: 'https://api.contentstack.io',
76
- validKeys: [
77
- 'uid',
78
- 'filename',
79
- 'url',
80
- 'status',
81
- ],
61
+ validKeys: ['uid', 'filename', 'url', 'status'],
82
62
  assetBatchLimit: 1,
83
63
  },
84
64
  content_types: {
85
65
  dirName: 'content_types',
86
66
  fileName: 'content_types.json',
87
- validKeys: [
88
- 'title',
89
- 'uid',
90
- 'schema',
91
- 'options',
92
- 'singleton',
93
- 'description',
94
- ],
67
+ validKeys: ['title', 'uid', 'schema', 'options', 'singleton', 'description'],
95
68
  limit: 100,
96
69
  },
97
70
  entries: {
98
71
  dirName: 'entries',
99
72
  fileName: 'entries.json',
100
- invalidKeys: [
101
- 'created_at',
102
- 'updated_at',
103
- 'created_by',
104
- 'updated_by',
105
- '_metadata',
106
- 'published',
107
- ],
73
+ invalidKeys: ['created_at', 'updated_at', 'created_by', 'updated_by', '_metadata', 'published'],
108
74
  limit: 50,
109
75
  assetBatchLimit: 5,
110
76
  },
@@ -112,14 +78,7 @@ module.exports = {
112
78
  globalfields: {
113
79
  dirName: 'global_fields',
114
80
  fileName: 'globalfields.json',
115
- validKeys: [
116
- 'title',
117
- 'uid',
118
- 'schema',
119
- 'options',
120
- 'singleton',
121
- 'description',
122
- ],
81
+ validKeys: ['title', 'uid', 'schema', 'options', 'singleton', 'description'],
123
82
  limit: 100,
124
83
  },
125
84
  stack: {
@@ -335,7 +294,8 @@ module.exports = {
335
294
  'lt-uz-uz',
336
295
  'vi-vn',
337
296
  'xh',
338
- 'zu'],
297
+ 'zu',
298
+ ],
339
299
 
340
300
  apis: {
341
301
  userSession: '/user-session/',
@@ -354,7 +314,7 @@ module.exports = {
354
314
  rateLimit: 5,
355
315
  preserveStackVersion: false,
356
316
  entriesPublish: true,
357
- concurrency: 1
358
- // ,useBackedupDir: '_backup_397'
317
+ concurrency: 1,
318
+ // ,useBackedupDir: '_backup_397'
359
319
  // backupConcurrency: 10,
360
- }
320
+ };