@contentstack/cli-migration 2.0.0-beta.1 → 2.0.0-beta.10

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.
Files changed (184) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +51 -4
  3. package/lib/actions/action-list.d.ts +8 -0
  4. package/lib/actions/action-list.js +31 -0
  5. package/lib/actions/action-list.js.map +1 -0
  6. package/lib/actions/index.d.ts +180 -0
  7. package/lib/actions/index.js +207 -0
  8. package/lib/actions/index.js.map +1 -0
  9. package/lib/commands/cm/stacks/migration.d.ts +14 -0
  10. package/lib/commands/cm/stacks/migration.js +265 -0
  11. package/lib/commands/cm/stacks/migration.js.map +1 -0
  12. package/lib/config/api-config.d.ts +13 -0
  13. package/lib/config/api-config.js +19 -0
  14. package/lib/config/api-config.js.map +1 -0
  15. package/lib/config/default-options.d.ts +5 -0
  16. package/lib/config/default-options.js +8 -0
  17. package/lib/config/default-options.js.map +1 -0
  18. package/lib/config/index.d.ts +4 -0
  19. package/lib/config/index.js +11 -0
  20. package/lib/config/index.js.map +1 -0
  21. package/lib/config/master-locale.d.ts +7 -0
  22. package/lib/config/master-locale.js +11 -0
  23. package/lib/config/master-locale.js.map +1 -0
  24. package/lib/modules/base.d.ts +39 -0
  25. package/lib/modules/base.js +84 -0
  26. package/lib/modules/base.js.map +1 -0
  27. package/lib/modules/content-types.d.ts +61 -0
  28. package/lib/modules/content-types.js +173 -0
  29. package/lib/modules/content-types.js.map +1 -0
  30. package/lib/modules/fields.d.ts +179 -0
  31. package/lib/modules/fields.js +293 -0
  32. package/lib/modules/fields.js.map +1 -0
  33. package/lib/modules/index.d.ts +5 -0
  34. package/lib/modules/index.js +13 -0
  35. package/lib/modules/index.js.map +1 -0
  36. package/lib/modules/locale.d.ts +6 -0
  37. package/lib/modules/locale.js +27 -0
  38. package/lib/modules/locale.js.map +1 -0
  39. package/lib/modules/migration.d.ts +50 -0
  40. package/lib/modules/migration.js +109 -0
  41. package/lib/modules/migration.js.map +1 -0
  42. package/lib/modules/parser.d.ts +3 -0
  43. package/lib/modules/parser.js +93 -0
  44. package/lib/modules/parser.js.map +1 -0
  45. package/lib/services/content-types.d.ts +25 -0
  46. package/lib/services/content-types.js +302 -0
  47. package/lib/services/content-types.js.map +1 -0
  48. package/lib/services/index.d.ts +3 -0
  49. package/lib/services/index.js +9 -0
  50. package/lib/services/index.js.map +1 -0
  51. package/lib/services/locales.d.ts +6 -0
  52. package/lib/services/locales.js +68 -0
  53. package/lib/services/locales.js.map +1 -0
  54. package/lib/utils/auto-retry.d.ts +2 -0
  55. package/lib/utils/auto-retry.js +30 -0
  56. package/lib/utils/auto-retry.js.map +1 -0
  57. package/lib/utils/callsite.d.ts +2 -0
  58. package/lib/utils/callsite.js +21 -0
  59. package/lib/utils/callsite.js.map +1 -0
  60. package/lib/utils/constants.d.ts +108 -0
  61. package/lib/utils/constants.js +206 -0
  62. package/lib/utils/constants.js.map +1 -0
  63. package/lib/utils/contentstack-sdk.d.ts +7 -0
  64. package/lib/utils/contentstack-sdk.js +53 -0
  65. package/lib/utils/contentstack-sdk.js.map +1 -0
  66. package/lib/utils/error-helper.d.ts +2 -0
  67. package/lib/utils/error-helper.js +102 -0
  68. package/lib/utils/error-helper.js.map +1 -0
  69. package/lib/utils/fs-helper.d.ts +4 -0
  70. package/lib/utils/fs-helper.js +37 -0
  71. package/lib/utils/fs-helper.js.map +1 -0
  72. package/lib/utils/get-batches.d.ts +2 -0
  73. package/lib/utils/get-batches.js +8 -0
  74. package/lib/utils/get-batches.js.map +1 -0
  75. package/lib/utils/get-config.d.ts +6 -0
  76. package/lib/utils/get-config.js +11 -0
  77. package/lib/utils/get-config.js.map +1 -0
  78. package/lib/utils/group-by.d.ts +1 -0
  79. package/lib/utils/group-by.js +41 -0
  80. package/lib/utils/group-by.js.map +1 -0
  81. package/lib/utils/index.d.ts +18 -0
  82. package/lib/utils/index.js +39 -0
  83. package/lib/utils/index.js.map +1 -0
  84. package/lib/utils/logger.d.ts +4 -0
  85. package/lib/utils/logger.js +68 -0
  86. package/lib/utils/logger.js.map +1 -0
  87. package/lib/utils/map.d.ts +7 -0
  88. package/lib/utils/map.js +40 -0
  89. package/lib/utils/map.js.map +1 -0
  90. package/lib/utils/migration-logger.d.ts +7 -0
  91. package/lib/utils/migration-logger.js +26 -0
  92. package/lib/utils/migration-logger.js.map +1 -0
  93. package/lib/utils/modules.d.ts +2 -0
  94. package/lib/utils/modules.js +118 -0
  95. package/lib/utils/modules.js.map +1 -0
  96. package/lib/utils/object-helper.d.ts +1 -0
  97. package/lib/utils/object-helper.js +12 -0
  98. package/lib/utils/object-helper.js.map +1 -0
  99. package/lib/utils/request.d.ts +9 -0
  100. package/lib/utils/request.js +78 -0
  101. package/lib/utils/request.js.map +1 -0
  102. package/lib/utils/safe-promise.d.ts +2 -0
  103. package/lib/utils/safe-promise.js +6 -0
  104. package/lib/utils/safe-promise.js.map +1 -0
  105. package/lib/utils/schema-helper.d.ts +5 -0
  106. package/lib/utils/schema-helper.js +36 -0
  107. package/lib/utils/schema-helper.js.map +1 -0
  108. package/lib/utils/success-handler.d.ts +2 -0
  109. package/lib/utils/success-handler.js +12 -0
  110. package/lib/utils/success-handler.js.map +1 -0
  111. package/lib/validators/api-error.d.ts +4 -0
  112. package/lib/validators/api-error.js +17 -0
  113. package/lib/validators/api-error.js.map +1 -0
  114. package/lib/validators/base-validator.d.ts +4 -0
  115. package/lib/validators/base-validator.js +34 -0
  116. package/lib/validators/base-validator.js.map +1 -0
  117. package/lib/validators/create-content-type-validator.d.ts +7 -0
  118. package/lib/validators/create-content-type-validator.js +45 -0
  119. package/lib/validators/create-content-type-validator.js.map +1 -0
  120. package/lib/validators/edit-content-type-validator.d.ts +7 -0
  121. package/lib/validators/edit-content-type-validator.js +44 -0
  122. package/lib/validators/edit-content-type-validator.js.map +1 -0
  123. package/lib/validators/field-validator.d.ts +4 -0
  124. package/lib/validators/field-validator.js +17 -0
  125. package/lib/validators/field-validator.js.map +1 -0
  126. package/lib/validators/index.d.ts +8 -0
  127. package/lib/validators/index.js +19 -0
  128. package/lib/validators/index.js.map +1 -0
  129. package/lib/validators/migration-error.d.ts +4 -0
  130. package/lib/validators/migration-error.js +16 -0
  131. package/lib/validators/migration-error.js.map +1 -0
  132. package/lib/validators/schema-validator.d.ts +4 -0
  133. package/lib/validators/schema-validator.js +19 -0
  134. package/lib/validators/schema-validator.js.map +1 -0
  135. package/lib/validators/type-error.d.ts +5 -0
  136. package/lib/validators/type-error.js +18 -0
  137. package/lib/validators/type-error.js.map +1 -0
  138. package/oclif.manifest.json +142 -0
  139. package/package.json +24 -15
  140. package/src/actions/action-list.js +0 -32
  141. package/src/actions/index.js +0 -217
  142. package/src/commands/cm/stacks/migration.js +0 -283
  143. package/src/config/api-config.js +0 -18
  144. package/src/config/default-options.js +0 -7
  145. package/src/config/index.js +0 -7
  146. package/src/config/master-locale.js +0 -10
  147. package/src/modules/base.js +0 -95
  148. package/src/modules/content-types.js +0 -208
  149. package/src/modules/fields.js +0 -340
  150. package/src/modules/index.js +0 -8
  151. package/src/modules/locale.js +0 -33
  152. package/src/modules/migration.js +0 -112
  153. package/src/modules/parser.js +0 -105
  154. package/src/services/content-types.js +0 -317
  155. package/src/services/index.js +0 -6
  156. package/src/services/locales.js +0 -71
  157. package/src/utils/auto-retry.js +0 -32
  158. package/src/utils/callsite.js +0 -23
  159. package/src/utils/constants.js +0 -223
  160. package/src/utils/contentstack-sdk.js +0 -70
  161. package/src/utils/error-helper.js +0 -105
  162. package/src/utils/fs-helper.js +0 -29
  163. package/src/utils/get-batches.js +0 -7
  164. package/src/utils/get-config.js +0 -13
  165. package/src/utils/group-by.js +0 -38
  166. package/src/utils/index.js +0 -21
  167. package/src/utils/logger.js +0 -75
  168. package/src/utils/map.js +0 -40
  169. package/src/utils/migration-logger.js +0 -21
  170. package/src/utils/modules.js +0 -134
  171. package/src/utils/object-helper.js +0 -9
  172. package/src/utils/request.js +0 -95
  173. package/src/utils/safe-promise.js +0 -3
  174. package/src/utils/schema-helper.js +0 -35
  175. package/src/utils/success-handler.js +0 -12
  176. package/src/validators/api-error.js +0 -20
  177. package/src/validators/base-validator.js +0 -39
  178. package/src/validators/create-content-type-validator.js +0 -54
  179. package/src/validators/edit-content-type-validator.js +0 -53
  180. package/src/validators/field-validator.js +0 -21
  181. package/src/validators/index.js +0 -11
  182. package/src/validators/migration-error.js +0 -20
  183. package/src/validators/schema-validator.js +0 -23
  184. package/src/validators/type-error.js +0 -22
@@ -1,217 +0,0 @@
1
- 'use strict';
2
-
3
- // Utils
4
- const { constants } = require('../utils');
5
- // Properties
6
- const { actions, validationAction } = constants;
7
- const {
8
- create,
9
- customTask,
10
- edit,
11
- transformEntries,
12
- deriveLinkedEntries,
13
- transformEntriesToType,
14
- typeError,
15
- apiError,
16
- schema,
17
- __migrationError,
18
- field,
19
- } = validationAction;
20
-
21
- const actionCreators = {
22
- customTasks: (callsite, opts) => {
23
- const { CUSTOM_TASK } = actions;
24
- return {
25
- type: customTask,
26
- meta: {
27
- callsite: {
28
- file: callsite.getFileName(),
29
- line: callsite.getLineNumber(),
30
- },
31
- },
32
- payload: {
33
- options: opts,
34
- action: CUSTOM_TASK,
35
- },
36
- };
37
- },
38
- contentType: {
39
- create: (callsite, id, opts) => {
40
- const { CREATE_CT } = actions;
41
- return {
42
- type: create,
43
- meta: {
44
- callsite: {
45
- file: callsite.getFileName(),
46
- line: callsite.getLineNumber(),
47
- },
48
- },
49
- payload: {
50
- contentTypeId: id,
51
- options: opts,
52
- action: CREATE_CT,
53
- },
54
- };
55
- },
56
- edit: (callsite, id, opts) => {
57
- const { EDIT_CT } = actions;
58
-
59
- return {
60
- type: edit,
61
- meta: {
62
- callsite: {
63
- file: callsite.getFileName(),
64
- line: callsite.getLineNumber(),
65
- },
66
- },
67
- payload: {
68
- contentTypeId: id,
69
- options: opts,
70
- action: EDIT_CT,
71
- },
72
- };
73
- },
74
- // delete: () => { },
75
- transformEntries: (callsite, id, opts) => {
76
- return {
77
- type: transformEntries,
78
- meta: {
79
- callsite: {
80
- file: callsite.getFileName(),
81
- line: callsite.getLineNumber(),
82
- },
83
- },
84
- payload: {
85
- options: opts,
86
- },
87
- };
88
- },
89
- deriveLinkedEntries: (callsite, id, opts) => {
90
- return {
91
- type: deriveLinkedEntries,
92
- meta: {
93
- callsite: {
94
- file: callsite.getFileName(),
95
- line: callsite.getLineNumber(),
96
- },
97
- },
98
- payload: {
99
- options: opts,
100
- },
101
- };
102
- },
103
- transformEntriesToType: (callsite, id, opts) => {
104
- return {
105
- type: transformEntriesToType,
106
- meta: {
107
- callsite: {
108
- file: callsite.getFileName(),
109
- line: callsite.getLineNumber(),
110
- },
111
- },
112
- payload: {
113
- options: opts,
114
- },
115
- };
116
- },
117
- typeError: (callsite, id, { typeErrors }) => {
118
- return {
119
- type: typeError,
120
- meta: {
121
- callsite: {
122
- file: callsite.getFileName(),
123
- line: callsite.getLineNumber(),
124
- },
125
- },
126
- payload: { typeErrors },
127
- };
128
- },
129
- apiError: (callsite, id, opts) => {
130
- return {
131
- type: apiError,
132
- meta: {
133
- callsite: {
134
- file: callsite.getFileName(),
135
- line: callsite.getLineNumber(),
136
- },
137
- },
138
- payload: { apiError: opts },
139
- };
140
- },
141
- fromFields: (callsite, id, opts) => {
142
- return {
143
- type: schema,
144
- meta: {
145
- callsite: {
146
- file: callsite.getFileName(),
147
- line: callsite.getLineNumber(),
148
- },
149
- },
150
- payload: { fromField: opts.fromField },
151
- };
152
- },
153
- toFields: (callsite, id, opts) => {
154
- return {
155
- type: schema,
156
- meta: {
157
- callsite: {
158
- file: callsite.getFileName(),
159
- line: callsite.getLineNumber(),
160
- },
161
- },
162
- payload: { toField: opts.toField },
163
- };
164
- },
165
- toReferenceFields: (callsite, id, opts) => {
166
- return {
167
- type: schema,
168
- meta: {
169
- callsite: {
170
- file: callsite.getFileName(),
171
- line: callsite.getLineNumber(),
172
- },
173
- },
174
- payload: { toField: opts.toReferenceField },
175
- };
176
- },
177
- deriveFields: (callsite, id, opts) => {
178
- return {
179
- type: schema,
180
- meta: {
181
- callsite: {
182
- file: callsite.getFileName(),
183
- line: callsite.getLineNumber(),
184
- },
185
- },
186
- payload: { deriveField: opts.deriveField },
187
- };
188
- },
189
- migrationError: (callsite, id, opts) => {
190
- return {
191
- type: __migrationError,
192
- meta: {
193
- callsite: {
194
- file: callsite.getFileName(),
195
- line: callsite.getLineNumber(),
196
- },
197
- },
198
- payload: { migrationError: opts },
199
- };
200
- },
201
- field: (callsite, id, opts) => {
202
- return {
203
- type: field,
204
- meta: {
205
- callsite: {
206
- file: callsite.getFileName(),
207
- line: callsite.getLineNumber(),
208
- },
209
- },
210
- payload: { field: opts },
211
- };
212
- },
213
- },
214
- };
215
-
216
- exports.actionCreators = actionCreators;
217
- exports.ActionList = require('./action-list');
@@ -1,283 +0,0 @@
1
- /* eslint-disable no-unused-expressions */
2
- /* eslint-disable no-warning-comments */
3
- /* eslint-disable camelcase */
4
- 'use strict';
5
-
6
- // Dependencies
7
- const Listr = require('listr');
8
- const { resolve, extname } = require('path');
9
- const { Command } = require('@contentstack/cli-command');
10
- const { waterfall } = require('async');
11
- const { Parser } = require('../../../modules');
12
- const { ActionList } = require('../../../actions');
13
- const fs = require('fs');
14
- const chalk = require('chalk');
15
- const isEmpty = require('lodash/isEmpty');
16
- const {
17
- managementSDKClient,
18
- flags,
19
- isAuthenticated,
20
- pathValidator,
21
- sanitizePath,
22
- } = require('@contentstack/cli-utilities');
23
-
24
- const { ApiError, SchemaValidator, MigrationError, FieldValidator } = require('../../../validators');
25
-
26
- // Utils
27
- const { map: _map, constants, safePromise, errorHelper, installModules } = require('../../../utils');
28
- // Properties
29
- const { get, set, getMapInstance, resetMapInstance } = _map;
30
- const {
31
- requests: _requests,
32
- actionMapper,
33
- MANAGEMENT_SDK,
34
- MANAGEMENT_TOKEN,
35
- AUTH_TOKEN,
36
- API_KEY,
37
- BRANCH,
38
- MANAGEMENT_CLIENT,
39
- } = constants;
40
-
41
- class MigrationCommand extends Command {
42
- static examples = [
43
- '$ csdx cm:migration --file-path <migration/script/file/path> --stack-api-key <stack-api-key>',
44
- '$ csdx cm:migration --file-path <migration/script/file/path> --stack-api-key <stack-api-key> --branch <target branch name>',
45
- '$ csdx cm:migration --config <key1>:<value1> <key2>:<value2> ... --file-path <migration/script/file/path>',
46
- '$ csdx cm:migration --config-file <path/to/json/config/file> --file-path <migration/script/file/path>',
47
- '$ csdx cm:migration --multiple --file-path <migration/scripts/dir/path> ',
48
- '$ csdx cm:migration --alias <management-token-alias> --file-path <migration/script/file/path>',
49
- ];
50
-
51
- async run() {
52
- // TODO: filePath validation required.
53
- const { flags: migrationCommandFlags } = await this.parse(MigrationCommand);
54
- const { branch } = migrationCommandFlags || {};
55
- const filePath = migrationCommandFlags['file-path'] || migrationCommandFlags.filePath;
56
- const multi = migrationCommandFlags.multiple || migrationCommandFlags.multi;
57
- const authtoken = isAuthenticated();
58
- const apiKey = migrationCommandFlags['api-key'] || migrationCommandFlags['stack-api-key'];
59
- const alias = migrationCommandFlags['alias'] || migrationCommandFlags['management-token-alias'];
60
- const config = migrationCommandFlags['config'];
61
-
62
- if (!authtoken && !alias) {
63
- this.log(
64
- "AuthToken is not present in local drive, Hence use 'csdx auth:login' command for login or provide management token alias",
65
- );
66
- this.exit();
67
- }
68
-
69
- if (!filePath || !fs.existsSync(filePath)) {
70
- this.log('Please provide the migration script file path, use --file-path flag');
71
- this.exit();
72
- }
73
-
74
- // Reset map instance
75
- const mapInstance = getMapInstance();
76
- resetMapInstance(mapInstance);
77
- if (migrationCommandFlags['config-file']) {
78
- set('config-path', mapInstance, migrationCommandFlags['config-file']);
79
- }
80
-
81
- if (Array.isArray(config) && config.length > 0) {
82
- let configObj = config.reduce((a, v) => {
83
- //NOTE: Temp code to handle only one spilt(Window absolute path issue).Need to replace with hardcoded config key
84
- let [key, ...value] = v.split(':');
85
- value = value?.length > 1 ? value?.join(':') : value?.join();
86
- return { ...a, [key]: value };
87
- }, {});
88
- set('config', mapInstance, configObj);
89
- }
90
-
91
- const APIClient = await managementSDKClient({ host: this.cmaHost });
92
- let stackSDKInstance;
93
- if (branch) {
94
- set(BRANCH, mapInstance, branch);
95
- }
96
-
97
- if (alias) {
98
- let managementToken = this.getToken(alias);
99
- if (managementToken) {
100
- set(MANAGEMENT_TOKEN, mapInstance, managementToken);
101
- set(API_KEY, mapInstance, managementToken.apiKey);
102
- if (branch) {
103
- stackSDKInstance = APIClient.stack({
104
- management_token: managementToken.token,
105
- api_key: managementToken.apiKey,
106
- branch_uid: branch,
107
- });
108
- } else {
109
- stackSDKInstance = APIClient.stack({
110
- management_token: managementToken.token,
111
- api_key: managementToken.apiKey,
112
- });
113
- }
114
- }
115
- } else if (authtoken) {
116
- set(AUTH_TOKEN, mapInstance, authtoken);
117
- set(API_KEY, mapInstance, apiKey);
118
- if (branch) {
119
- stackSDKInstance = APIClient.stack({
120
- api_key: apiKey,
121
- branch_uid: branch,
122
- });
123
- } else {
124
- stackSDKInstance = APIClient.stack({ api_key: apiKey });
125
- }
126
- }
127
-
128
- set(MANAGEMENT_SDK, mapInstance, stackSDKInstance);
129
- set(MANAGEMENT_CLIENT, mapInstance, APIClient);
130
-
131
- if (!(await installModules(filePath, multi))) {
132
- this.log(`Error: Failed to install dependencies for the specified scripts.`);
133
- process.exit(1);
134
- }
135
-
136
- if (multi) {
137
- await this.execMultiFiles(filePath, mapInstance);
138
- } else {
139
- await this.execSingleFile(filePath, mapInstance);
140
- }
141
- const errLogPath = `${process.cwd()}/migration-logs`;
142
- if (fs.existsSync(errLogPath)) {
143
- this.log(`The log has been stored at: `, errLogPath);
144
- }
145
- }
146
-
147
- async execSingleFile(filePath, mapInstance) {
148
- // Resolved absolute path
149
- const resolvedMigrationPath = pathValidator(filePath);
150
- // User provided migration function
151
- const migrationFunc = require(resolvedMigrationPath);
152
-
153
- const parser = new Parser();
154
-
155
- try {
156
- const migrationParser = await parser.getMigrationParser(migrationFunc);
157
- if (migrationParser.hasErrors) {
158
- errorHelper(migrationParser.hasErrors);
159
- // When the process is child, send error message to parent
160
- if (process.send) process.send({ errorOccurred: true });
161
- this.exit(1);
162
- }
163
-
164
- // Make calls from here
165
- const requests = get(_requests, mapInstance);
166
- // Fetches tasks array
167
- const tasks = this.getTasks(requests);
168
-
169
- const listr = new Listr(tasks);
170
-
171
- await listr.run();
172
- requests.splice(0, requests.length);
173
- } catch (error) {
174
- errorHelper(error, filePath);
175
- if (process.send) process.send({ errorOccurred: true });
176
- }
177
- }
178
-
179
- async execMultiFiles(filePath, mapInstance) {
180
- // Resolved absolute path
181
- const resolvedMigrationPath = pathValidator(filePath);
182
- try {
183
- const files = fs.readdirSync(resolvedMigrationPath);
184
- for (const element of files) {
185
- const file = element;
186
- if (extname(file) === '.js') {
187
- // eslint-disable-next-line no-await-in-loop
188
- await this.execSingleFile(pathValidator(resolve(sanitizePath(filePath), sanitizePath(file))), mapInstance);
189
- }
190
- }
191
- } catch (error) {
192
- errorHelper(error);
193
- }
194
- }
195
-
196
- getTasks(requests) {
197
- const _tasks = [];
198
- const results = [];
199
-
200
- const taskFn = (reqObj) => {
201
- const { failedTitle, successTitle, tasks } = reqObj;
202
-
203
- return async (ctx, task) => {
204
- const [err, result] = await safePromise(waterfall(tasks));
205
- if (err) {
206
- ctx.error = true;
207
- task.title = failedTitle;
208
- throw err;
209
- }
210
- result && results.push(result);
211
- task.title = successTitle;
212
- return result;
213
- };
214
- };
215
-
216
- for (const element of requests) {
217
- let reqObj = element;
218
- const { title } = reqObj;
219
- const taskObj = {
220
- title: title,
221
- task: taskFn(reqObj),
222
- };
223
- _tasks.push(taskObj);
224
- }
225
- return _tasks;
226
- }
227
-
228
- handleErrors() {
229
- const mapInstance = getMapInstance();
230
- const actions = get(actionMapper, mapInstance);
231
- const actionList = new ActionList(actions);
232
-
233
- actionList.addValidators(new ApiError());
234
- actionList.addValidators(new SchemaValidator());
235
- actionList.addValidators(new MigrationError());
236
- actionList.addValidators(new FieldValidator());
237
-
238
- const errors = actionList.validate();
239
- errorHelper(errors);
240
- }
241
- }
242
-
243
- MigrationCommand.description = 'Contentstack migration script.';
244
-
245
- MigrationCommand.flags = {
246
- 'stack-api-key': flags.string({
247
- char: 'k',
248
- description:
249
- 'Use this flag to add the API key of your stack. You must use either the --stack-api-key flag or the --alias flag.',
250
- exclusive: ['alias'],
251
- }),
252
- alias: flags.string({
253
- char: 'a',
254
- description:
255
- 'Use this flag to add the management token alias. You must use either the --alias flag or the --stack-api-key flag.',
256
- exclusive: ['stack-api-key'],
257
- }),
258
- 'file-path': flags.string({
259
- description: 'Use this flag to provide the path of the file of the migration script.',
260
- }),
261
- branch: flags.string({
262
- description: 'Use this flag to add the branch name where you want to perform the migration. (target branch name)',
263
- }),
264
- 'config-file': flags.string({
265
- description: '[optional] Path of the JSON configuration file.',
266
- }),
267
- config: flags.string({
268
- description:
269
- '[optional] Inline configuration, <key1>:<value1>. Passing an external configuration makes the script re-usable.',
270
- multiple: true,
271
- }),
272
- multiple: flags.boolean({
273
- description:
274
- 'This flag helps you to migrate multiple content files in a single instance. Mention the folder path where your migration script files are stored.',
275
- }),
276
- };
277
-
278
- MigrationCommand.aliases = [];
279
-
280
- MigrationCommand.usage =
281
- 'cm:stacks:migration [-k <value>] [-a <value>] [--file-path <value>] [--branch <value>] [--config-file <value>] [--config <value>] [--multiple]';
282
-
283
- module.exports = MigrationCommand;
@@ -1,18 +0,0 @@
1
- /* eslint-disable camelcase */
2
- 'use strict';
3
-
4
- const { CONTENTSTACK_API_KEY, CONTENTSTACK_AUTHTOKEN } = process.env;
5
- const { version } = require('../../package.json');
6
- module.exports = {
7
- hostname: 'api.contentstack.io',
8
- version: '/v3',
9
- method: 'GET', // Default Http method
10
- headers: {
11
- 'Content-Type': 'application/json',
12
- 'Content-Length': null,
13
- 'X-User-Agent': `@contentstack-migration/v${version}`,
14
- authtoken: CONTENTSTACK_AUTHTOKEN,
15
- api_key: CONTENTSTACK_API_KEY,
16
- // management_token: CONTENTSTACK_MANAGEMENT_TOKEN
17
- },
18
- };
@@ -1,7 +0,0 @@
1
- /* eslint-disable camelcase */
2
- 'use strict';
3
-
4
- module.exports = {
5
- is_page: false,
6
- singleton: false,
7
- };
@@ -1,7 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- apiConfig: require('./api-config'),
5
- defaultOptions: require('./default-options'),
6
- masterLocale: require('./master-locale'),
7
- };
@@ -1,10 +0,0 @@
1
- /* eslint-disable camelcase */
2
- 'use strict';
3
-
4
- module.exports = {
5
- master_locale: {
6
- // master locale of the stack
7
- name: 'English - United States',
8
- code: 'en-us',
9
- },
10
- };
@@ -1,95 +0,0 @@
1
- 'use strict';
2
-
3
- // Utils
4
- const { map: _map, constants } = require('../utils');
5
- // Actions
6
- const { actionCreators } = require('../actions');
7
- // Utils properties
8
- const { getMapInstance, get } = _map;
9
- const { actionMapper } = constants;
10
-
11
- /**
12
- * Base class for module classes
13
- * @class Base
14
- * @ignore
15
- */
16
- class Base {
17
- constructor(id, action) {
18
- this.id = id;
19
- this.action = action;
20
- this.actions = [];
21
- }
22
-
23
- /**
24
- * Chained function which takes value for title
25
- * @param {string} value Title
26
- * @returns {Base} current instance of inherited class
27
- */
28
- title(value) {
29
- const mapInstance = getMapInstance();
30
- const { id, action } = this;
31
-
32
- const contentType = get(id, mapInstance);
33
-
34
- contentType[action].content_type.title = value;
35
-
36
- return this;
37
- }
38
-
39
- /**
40
- * Chained function which takes value for description
41
- * @param {string} value Description
42
- * @returns {Base} current instance of inherited class
43
- */
44
- description(value) {
45
- const mapInstance = getMapInstance();
46
- const { id, action } = this;
47
- const contentType = get(id, mapInstance);
48
- contentType[action].content_type.description = value;
49
- return this;
50
- }
51
-
52
- /**
53
- * Chained function takes boolean value for force while deleting content type
54
- * @param {boolean} value Force delete
55
- * @returns {Base} current instance of inherited class
56
- */
57
- force(value) {
58
- const mapInstance = getMapInstance();
59
- const { id, action } = this;
60
-
61
- const contentType = get(id, mapInstance);
62
-
63
- contentType[action].content_type.force = value;
64
-
65
- return this;
66
- }
67
-
68
- /**
69
- * Accumulates actions for validating user provided inputs
70
- * @ignore
71
- * @param {Object} callsite Gets the file location and file number of caller
72
- * @param {string} id unique id of action type
73
- * @param {Object} opts holds payload to be validated
74
- * @param {string} method type of action
75
- */
76
- dispatch(callsite, id, opts, method) {
77
- if (!id && !opts) {
78
- let mapInstance = getMapInstance();
79
- let actions = get(actionMapper, mapInstance); // Returns an array if empty
80
- let action = actionCreators.customTasks(callsite, opts);
81
- actions.push(action);
82
- } else {
83
- let mapInstance = getMapInstance();
84
- let actions = get(actionMapper, mapInstance); // Returns an array if empty
85
- let action = actionCreators.contentType[method](callsite, id, { ...opts, id });
86
- actions.push(action);
87
- }
88
- }
89
-
90
- getActions() {
91
- return this.actions;
92
- }
93
- }
94
-
95
- module.exports = Base;