@contentstack/cli-migration 1.10.2 → 1.11.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/lib/actions/action-list.d.ts +8 -0
- package/lib/actions/action-list.js +31 -0
- package/lib/actions/action-list.js.map +1 -0
- package/lib/actions/index.d.ts +180 -0
- package/lib/actions/index.js +207 -0
- package/lib/actions/index.js.map +1 -0
- package/lib/commands/cm/stacks/migration.d.ts +14 -0
- package/lib/commands/cm/stacks/migration.js +274 -0
- package/lib/commands/cm/stacks/migration.js.map +1 -0
- package/lib/config/api-config.d.ts +13 -0
- package/lib/config/api-config.js +19 -0
- package/lib/config/api-config.js.map +1 -0
- package/lib/config/default-options.d.ts +5 -0
- package/lib/config/default-options.js +8 -0
- package/lib/config/default-options.js.map +1 -0
- package/lib/config/index.d.ts +4 -0
- package/lib/config/index.js +11 -0
- package/lib/config/index.js.map +1 -0
- package/lib/config/master-locale.d.ts +7 -0
- package/lib/config/master-locale.js +11 -0
- package/lib/config/master-locale.js.map +1 -0
- package/lib/modules/base.d.ts +39 -0
- package/lib/modules/base.js +84 -0
- package/lib/modules/base.js.map +1 -0
- package/lib/modules/content-types.d.ts +61 -0
- package/lib/modules/content-types.js +173 -0
- package/lib/modules/content-types.js.map +1 -0
- package/lib/modules/fields.d.ts +179 -0
- package/lib/modules/fields.js +292 -0
- package/lib/modules/fields.js.map +1 -0
- package/lib/modules/index.d.ts +5 -0
- package/lib/modules/index.js +13 -0
- package/lib/modules/index.js.map +1 -0
- package/lib/modules/locale.d.ts +6 -0
- package/lib/modules/locale.js +27 -0
- package/lib/modules/locale.js.map +1 -0
- package/lib/modules/migration.d.ts +50 -0
- package/lib/modules/migration.js +109 -0
- package/lib/modules/migration.js.map +1 -0
- package/lib/modules/parser.d.ts +3 -0
- package/lib/modules/parser.js +93 -0
- package/lib/modules/parser.js.map +1 -0
- package/lib/services/content-types.d.ts +25 -0
- package/lib/services/content-types.js +302 -0
- package/lib/services/content-types.js.map +1 -0
- package/lib/services/index.d.ts +3 -0
- package/lib/services/index.js +9 -0
- package/lib/services/index.js.map +1 -0
- package/lib/services/locales.d.ts +6 -0
- package/lib/services/locales.js +68 -0
- package/lib/services/locales.js.map +1 -0
- package/lib/utils/auto-retry.d.ts +2 -0
- package/lib/utils/auto-retry.js +30 -0
- package/lib/utils/auto-retry.js.map +1 -0
- package/lib/utils/callsite.d.ts +2 -0
- package/lib/utils/callsite.js +21 -0
- package/lib/utils/callsite.js.map +1 -0
- package/lib/utils/constants.d.ts +108 -0
- package/lib/utils/constants.js +206 -0
- package/lib/utils/constants.js.map +1 -0
- package/lib/utils/contentstack-sdk.d.ts +7 -0
- package/lib/utils/contentstack-sdk.js +53 -0
- package/lib/utils/contentstack-sdk.js.map +1 -0
- package/lib/utils/error-helper.d.ts +2 -0
- package/lib/utils/error-helper.js +102 -0
- package/lib/utils/error-helper.js.map +1 -0
- package/lib/utils/fs-helper.d.ts +4 -0
- package/lib/utils/fs-helper.js +37 -0
- package/lib/utils/fs-helper.js.map +1 -0
- package/lib/utils/get-batches.d.ts +2 -0
- package/lib/utils/get-batches.js +8 -0
- package/lib/utils/get-batches.js.map +1 -0
- package/lib/utils/get-config.d.ts +6 -0
- package/lib/utils/get-config.js +11 -0
- package/lib/utils/get-config.js.map +1 -0
- package/lib/utils/group-by.d.ts +1 -0
- package/lib/utils/group-by.js +41 -0
- package/lib/utils/group-by.js.map +1 -0
- package/lib/utils/index.d.ts +18 -0
- package/lib/utils/index.js +39 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/logger.d.ts +4 -0
- package/lib/utils/logger.js +68 -0
- package/lib/utils/logger.js.map +1 -0
- package/lib/utils/map.d.ts +7 -0
- package/lib/utils/map.js +40 -0
- package/lib/utils/map.js.map +1 -0
- package/lib/utils/migration-logger.d.ts +7 -0
- package/lib/utils/migration-logger.js +26 -0
- package/lib/utils/migration-logger.js.map +1 -0
- package/lib/utils/modules.d.ts +2 -0
- package/lib/utils/modules.js +118 -0
- package/lib/utils/modules.js.map +1 -0
- package/lib/utils/object-helper.d.ts +1 -0
- package/lib/utils/object-helper.js +12 -0
- package/lib/utils/object-helper.js.map +1 -0
- package/lib/utils/request.d.ts +9 -0
- package/lib/utils/request.js +78 -0
- package/lib/utils/request.js.map +1 -0
- package/lib/utils/safe-promise.d.ts +2 -0
- package/lib/utils/safe-promise.js +6 -0
- package/lib/utils/safe-promise.js.map +1 -0
- package/lib/utils/schema-helper.d.ts +5 -0
- package/lib/utils/schema-helper.js +36 -0
- package/lib/utils/schema-helper.js.map +1 -0
- package/lib/utils/success-handler.d.ts +2 -0
- package/lib/utils/success-handler.js +12 -0
- package/lib/utils/success-handler.js.map +1 -0
- package/lib/validators/api-error.d.ts +4 -0
- package/lib/validators/api-error.js +17 -0
- package/lib/validators/api-error.js.map +1 -0
- package/lib/validators/base-validator.d.ts +4 -0
- package/lib/validators/base-validator.js +34 -0
- package/lib/validators/base-validator.js.map +1 -0
- package/lib/validators/create-content-type-validator.d.ts +7 -0
- package/lib/validators/create-content-type-validator.js +45 -0
- package/lib/validators/create-content-type-validator.js.map +1 -0
- package/lib/validators/edit-content-type-validator.d.ts +7 -0
- package/lib/validators/edit-content-type-validator.js +44 -0
- package/lib/validators/edit-content-type-validator.js.map +1 -0
- package/lib/validators/field-validator.d.ts +4 -0
- package/lib/validators/field-validator.js +17 -0
- package/lib/validators/field-validator.js.map +1 -0
- package/lib/validators/index.d.ts +8 -0
- package/lib/validators/index.js +19 -0
- package/lib/validators/index.js.map +1 -0
- package/lib/validators/migration-error.d.ts +4 -0
- package/lib/validators/migration-error.js +16 -0
- package/lib/validators/migration-error.js.map +1 -0
- package/lib/validators/schema-validator.d.ts +4 -0
- package/lib/validators/schema-validator.js +19 -0
- package/lib/validators/schema-validator.js.map +1 -0
- package/lib/validators/type-error.d.ts +5 -0
- package/lib/validators/type-error.js +18 -0
- package/lib/validators/type-error.js.map +1 -0
- package/oclif.manifest.json +145 -0
- package/package.json +22 -12
- package/src/actions/action-list.js +0 -32
- package/src/actions/index.js +0 -217
- package/src/commands/cm/stacks/migration.js +0 -316
- package/src/config/api-config.js +0 -18
- package/src/config/default-options.js +0 -7
- package/src/config/index.js +0 -7
- package/src/config/master-locale.js +0 -10
- package/src/modules/base.js +0 -95
- package/src/modules/content-types.js +0 -208
- package/src/modules/fields.js +0 -339
- package/src/modules/index.js +0 -8
- package/src/modules/locale.js +0 -33
- package/src/modules/migration.js +0 -112
- package/src/modules/parser.js +0 -105
- package/src/services/content-types.js +0 -317
- package/src/services/index.js +0 -6
- package/src/services/locales.js +0 -71
- package/src/utils/auto-retry.js +0 -32
- package/src/utils/callsite.js +0 -23
- package/src/utils/constants.js +0 -223
- package/src/utils/contentstack-sdk.js +0 -70
- package/src/utils/error-helper.js +0 -105
- package/src/utils/fs-helper.js +0 -29
- package/src/utils/get-batches.js +0 -7
- package/src/utils/get-config.js +0 -13
- package/src/utils/group-by.js +0 -38
- package/src/utils/index.js +0 -21
- package/src/utils/logger.js +0 -75
- package/src/utils/map.js +0 -40
- package/src/utils/migration-logger.js +0 -21
- package/src/utils/modules.js +0 -134
- package/src/utils/object-helper.js +0 -9
- package/src/utils/request.js +0 -95
- package/src/utils/safe-promise.js +0 -3
- package/src/utils/schema-helper.js +0 -35
- package/src/utils/success-handler.js +0 -12
- package/src/validators/api-error.js +0 -20
- package/src/validators/base-validator.js +0 -39
- package/src/validators/create-content-type-validator.js +0 -54
- package/src/validators/edit-content-type-validator.js +0 -53
- package/src/validators/field-validator.js +0 -21
- package/src/validators/index.js +0 -11
- package/src/validators/migration-error.js +0 -20
- package/src/validators/schema-validator.js +0 -23
- package/src/validators/type-error.js +0 -22
package/src/actions/index.js
DELETED
|
@@ -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,316 +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
|
-
printFlagDeprecation,
|
|
18
|
-
managementSDKClient,
|
|
19
|
-
flags,
|
|
20
|
-
isAuthenticated,
|
|
21
|
-
pathValidator,
|
|
22
|
-
sanitizePath,
|
|
23
|
-
} = require('@contentstack/cli-utilities');
|
|
24
|
-
|
|
25
|
-
const { ApiError, SchemaValidator, MigrationError, FieldValidator } = require('../../../validators');
|
|
26
|
-
|
|
27
|
-
// Utils
|
|
28
|
-
const { map: _map, constants, safePromise, errorHelper, installModules } = require('../../../utils');
|
|
29
|
-
// Properties
|
|
30
|
-
const { get, set, getMapInstance, resetMapInstance } = _map;
|
|
31
|
-
const {
|
|
32
|
-
requests: _requests,
|
|
33
|
-
actionMapper,
|
|
34
|
-
MANAGEMENT_SDK,
|
|
35
|
-
MANAGEMENT_TOKEN,
|
|
36
|
-
AUTH_TOKEN,
|
|
37
|
-
API_KEY,
|
|
38
|
-
BRANCH,
|
|
39
|
-
MANAGEMENT_CLIENT,
|
|
40
|
-
} = constants;
|
|
41
|
-
|
|
42
|
-
class MigrationCommand extends Command {
|
|
43
|
-
static examples = [
|
|
44
|
-
'$ csdx cm:migration --file-path <migration/script/file/path> -k <api-key>',
|
|
45
|
-
'$ csdx cm:migration --file-path <migration/script/file/path> -k <api-key> --branch <target branch name>',
|
|
46
|
-
'$ csdx cm:migration --config <key1>:<value1> <key2>:<value2> ... --file-path <migration/script/file/path>',
|
|
47
|
-
'$ csdx cm:migration --config-file <path/to/json/config/file> --file-path <migration/script/file/path>',
|
|
48
|
-
'$ csdx cm:migration --multiple --file-path <migration/scripts/dir/path> ',
|
|
49
|
-
'$ csdx cm:migration --alias --file-path <migration/script/file/path> -k <api-key>',
|
|
50
|
-
];
|
|
51
|
-
|
|
52
|
-
async run() {
|
|
53
|
-
// TODO: filePath validation required.
|
|
54
|
-
const { flags: migrationCommandFlags } = await this.parse(MigrationCommand);
|
|
55
|
-
const { branch } = migrationCommandFlags || {};
|
|
56
|
-
const filePath = migrationCommandFlags['file-path'] || migrationCommandFlags.filePath;
|
|
57
|
-
const multi = migrationCommandFlags.multiple || migrationCommandFlags.multi;
|
|
58
|
-
const authtoken = isAuthenticated();
|
|
59
|
-
const apiKey = migrationCommandFlags['api-key'] || migrationCommandFlags['stack-api-key'];
|
|
60
|
-
const alias = migrationCommandFlags['alias'] || migrationCommandFlags['management-token-alias'];
|
|
61
|
-
const config = migrationCommandFlags['config'];
|
|
62
|
-
|
|
63
|
-
if (!authtoken && !alias) {
|
|
64
|
-
this.log(
|
|
65
|
-
"AuthToken is not present in local drive, Hence use 'csdx auth:login' command for login or provide management token alias",
|
|
66
|
-
);
|
|
67
|
-
this.exit();
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (!filePath || !fs.existsSync(filePath)) {
|
|
71
|
-
this.log('Please provide the migration script file path, use --file-path flag');
|
|
72
|
-
this.exit();
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Reset map instance
|
|
76
|
-
const mapInstance = getMapInstance();
|
|
77
|
-
resetMapInstance(mapInstance);
|
|
78
|
-
if (migrationCommandFlags['config-file']) {
|
|
79
|
-
set('config-path', mapInstance, migrationCommandFlags['config-file']);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (Array.isArray(config) && config.length > 0) {
|
|
83
|
-
let configObj = config.reduce((a, v) => {
|
|
84
|
-
//NOTE: Temp code to handle only one spilt(Window absolute path issue).Need to replace with hardcoded config key
|
|
85
|
-
let [key, ...value] = v.split(':');
|
|
86
|
-
value = value?.length > 1 ? value?.join(':') : value?.join();
|
|
87
|
-
return { ...a, [key]: value };
|
|
88
|
-
}, {});
|
|
89
|
-
set('config', mapInstance, configObj);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const APIClient = await managementSDKClient({ host: this.cmaHost });
|
|
93
|
-
let stackSDKInstance;
|
|
94
|
-
if (branch) {
|
|
95
|
-
set(BRANCH, mapInstance, branch);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (alias) {
|
|
99
|
-
let managementToken = this.getToken(alias);
|
|
100
|
-
if (managementToken) {
|
|
101
|
-
set(MANAGEMENT_TOKEN, mapInstance, managementToken);
|
|
102
|
-
set(API_KEY, mapInstance, managementToken.apiKey);
|
|
103
|
-
if (branch) {
|
|
104
|
-
stackSDKInstance = APIClient.stack({
|
|
105
|
-
management_token: managementToken.token,
|
|
106
|
-
api_key: managementToken.apiKey,
|
|
107
|
-
branch_uid: branch,
|
|
108
|
-
});
|
|
109
|
-
} else {
|
|
110
|
-
stackSDKInstance = APIClient.stack({
|
|
111
|
-
management_token: managementToken.token,
|
|
112
|
-
api_key: managementToken.apiKey,
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
} else if (authtoken) {
|
|
117
|
-
set(AUTH_TOKEN, mapInstance, authtoken);
|
|
118
|
-
set(API_KEY, mapInstance, apiKey);
|
|
119
|
-
if (branch) {
|
|
120
|
-
stackSDKInstance = APIClient.stack({
|
|
121
|
-
api_key: apiKey,
|
|
122
|
-
branch_uid: branch,
|
|
123
|
-
});
|
|
124
|
-
} else {
|
|
125
|
-
stackSDKInstance = APIClient.stack({ api_key: apiKey });
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
set(MANAGEMENT_SDK, mapInstance, stackSDKInstance);
|
|
130
|
-
set(MANAGEMENT_CLIENT, mapInstance, APIClient);
|
|
131
|
-
|
|
132
|
-
if (!(await installModules(filePath, multi))) {
|
|
133
|
-
this.log(`Error: Failed to install dependencies for the specified scripts.`);
|
|
134
|
-
process.exit(1);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
if (multi) {
|
|
138
|
-
await this.execMultiFiles(filePath, mapInstance);
|
|
139
|
-
} else {
|
|
140
|
-
await this.execSingleFile(filePath, mapInstance);
|
|
141
|
-
}
|
|
142
|
-
const errLogPath = `${process.cwd()}/migration-logs`;
|
|
143
|
-
if (fs.existsSync(errLogPath)) {
|
|
144
|
-
this.log(`The log has been stored at: `, errLogPath);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
async execSingleFile(filePath, mapInstance) {
|
|
149
|
-
// Resolved absolute path
|
|
150
|
-
const resolvedMigrationPath = pathValidator(filePath);
|
|
151
|
-
// User provided migration function
|
|
152
|
-
const migrationFunc = require(resolvedMigrationPath);
|
|
153
|
-
|
|
154
|
-
const parser = new Parser();
|
|
155
|
-
|
|
156
|
-
try {
|
|
157
|
-
const migrationParser = await parser.getMigrationParser(migrationFunc);
|
|
158
|
-
if (migrationParser.hasErrors) {
|
|
159
|
-
errorHelper(migrationParser.hasErrors);
|
|
160
|
-
// When the process is child, send error message to parent
|
|
161
|
-
if (process.send) process.send({ errorOccurred: true });
|
|
162
|
-
this.exit(1);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// Make calls from here
|
|
166
|
-
const requests = get(_requests, mapInstance);
|
|
167
|
-
// Fetches tasks array
|
|
168
|
-
const tasks = this.getTasks(requests);
|
|
169
|
-
|
|
170
|
-
const listr = new Listr(tasks);
|
|
171
|
-
|
|
172
|
-
await listr.run();
|
|
173
|
-
requests.splice(0, requests.length);
|
|
174
|
-
} catch (error) {
|
|
175
|
-
errorHelper(error, filePath);
|
|
176
|
-
if (process.send) process.send({ errorOccurred: true });
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
async execMultiFiles(filePath, mapInstance) {
|
|
181
|
-
// Resolved absolute path
|
|
182
|
-
const resolvedMigrationPath = pathValidator(filePath);
|
|
183
|
-
try {
|
|
184
|
-
const files = fs.readdirSync(resolvedMigrationPath);
|
|
185
|
-
for (const element of files) {
|
|
186
|
-
const file = element;
|
|
187
|
-
if (extname(file) === '.js') {
|
|
188
|
-
// eslint-disable-next-line no-await-in-loop
|
|
189
|
-
await this.execSingleFile(pathValidator(resolve(sanitizePath(filePath), sanitizePath(file))), mapInstance);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
} catch (error) {
|
|
193
|
-
errorHelper(error);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
getTasks(requests) {
|
|
198
|
-
const _tasks = [];
|
|
199
|
-
const results = [];
|
|
200
|
-
|
|
201
|
-
const taskFn = (reqObj) => {
|
|
202
|
-
const { failedTitle, successTitle, tasks } = reqObj;
|
|
203
|
-
|
|
204
|
-
return async (ctx, task) => {
|
|
205
|
-
const [err, result] = await safePromise(waterfall(tasks));
|
|
206
|
-
if (err) {
|
|
207
|
-
ctx.error = true;
|
|
208
|
-
task.title = failedTitle;
|
|
209
|
-
throw err;
|
|
210
|
-
}
|
|
211
|
-
result && results.push(result);
|
|
212
|
-
task.title = successTitle;
|
|
213
|
-
return result;
|
|
214
|
-
};
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
for (const element of requests) {
|
|
218
|
-
let reqObj = element;
|
|
219
|
-
const { title } = reqObj;
|
|
220
|
-
const taskObj = {
|
|
221
|
-
title: title,
|
|
222
|
-
task: taskFn(reqObj),
|
|
223
|
-
};
|
|
224
|
-
_tasks.push(taskObj);
|
|
225
|
-
}
|
|
226
|
-
return _tasks;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
handleErrors() {
|
|
230
|
-
const mapInstance = getMapInstance();
|
|
231
|
-
const actions = get(actionMapper, mapInstance);
|
|
232
|
-
const actionList = new ActionList(actions);
|
|
233
|
-
|
|
234
|
-
actionList.addValidators(new ApiError());
|
|
235
|
-
actionList.addValidators(new SchemaValidator());
|
|
236
|
-
actionList.addValidators(new MigrationError());
|
|
237
|
-
actionList.addValidators(new FieldValidator());
|
|
238
|
-
|
|
239
|
-
const errors = actionList.validate();
|
|
240
|
-
errorHelper(errors);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
MigrationCommand.description = 'Contentstack migration script.';
|
|
245
|
-
|
|
246
|
-
MigrationCommand.flags = {
|
|
247
|
-
'stack-api-key': flags.string({
|
|
248
|
-
char: 'k',
|
|
249
|
-
description: '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: 'Use this flag to add the management token alias. You must use either the --alias flag or the --stack-api-key flag.',
|
|
255
|
-
}),
|
|
256
|
-
'file-path': flags.string({
|
|
257
|
-
description: 'Use this flag to provide the path of the file of the migration script.',
|
|
258
|
-
}),
|
|
259
|
-
branch: flags.string({
|
|
260
|
-
char: 'B',
|
|
261
|
-
description: 'Use this flag to add the branch name where you want to perform the migration. (target branch name)',
|
|
262
|
-
parse: printFlagDeprecation(['-B'], ['--branch']),
|
|
263
|
-
}),
|
|
264
|
-
'config-file': flags.string({
|
|
265
|
-
description: '[optional] Path of the JSON configuration file.',
|
|
266
|
-
}),
|
|
267
|
-
config: flags.string({
|
|
268
|
-
description: '[optional] Inline configuration, <key1>:<value1>. Passing an external configuration makes the script re-usable.',
|
|
269
|
-
multiple: true,
|
|
270
|
-
}),
|
|
271
|
-
multiple: flags.boolean({
|
|
272
|
-
description: 'This flag helps you to migrate multiple content files in a single instance. Mention the folder path where your migration script files are stored.',
|
|
273
|
-
}),
|
|
274
|
-
|
|
275
|
-
// To be deprecated
|
|
276
|
-
'api-key': flags.string({
|
|
277
|
-
char: 'k',
|
|
278
|
-
description: 'With this flag add the API key of your stack.',
|
|
279
|
-
// dependsOn: ['authtoken'],
|
|
280
|
-
exclusive: ['alias'],
|
|
281
|
-
parse: printFlagDeprecation(['--api-key'], ['-k', '--stack-api-key']),
|
|
282
|
-
hidden: true,
|
|
283
|
-
}),
|
|
284
|
-
authtoken: flags.boolean({
|
|
285
|
-
char: 'A',
|
|
286
|
-
description: 'Use this flag to use the auth token of the current session. After logging in CLI, an auth token is generated for each new session.',
|
|
287
|
-
dependsOn: ['api-key'],
|
|
288
|
-
exclusive: ['alias'],
|
|
289
|
-
parse: printFlagDeprecation(['-A', '--authtoken']),
|
|
290
|
-
hidden: true,
|
|
291
|
-
}),
|
|
292
|
-
'management-token-alias': flags.string({
|
|
293
|
-
description: 'Alias of the management token.',
|
|
294
|
-
exclusive: ['authtoken'],
|
|
295
|
-
hidden: true,
|
|
296
|
-
parse: printFlagDeprecation(['--management-token-alias'], ['-a', '--alias']),
|
|
297
|
-
}),
|
|
298
|
-
filePath: flags.string({
|
|
299
|
-
char: 'n',
|
|
300
|
-
description: 'Use this flag to provide the path of the file of the migration script provided by the user.',
|
|
301
|
-
parse: printFlagDeprecation(['-n', '--filePath'], ['--file-path']),
|
|
302
|
-
hidden: true,
|
|
303
|
-
}),
|
|
304
|
-
multi: flags.boolean({
|
|
305
|
-
description: 'This flag helps you to migrate multiple content files in a single instance.',
|
|
306
|
-
parse: printFlagDeprecation(['--multi'], ['--multiple']),
|
|
307
|
-
hidden: true,
|
|
308
|
-
}),
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
MigrationCommand.aliases = ['cm:migration'];
|
|
312
|
-
|
|
313
|
-
MigrationCommand.usage =
|
|
314
|
-
'cm:stacks:migration [-k <value>] [-a <value>] [--file-path <value>] [--branch <value>] [--config-file <value>] [--config <value>] [--multiple]';
|
|
315
|
-
|
|
316
|
-
module.exports = MigrationCommand;
|
package/src/config/api-config.js
DELETED
|
@@ -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
|
-
};
|
package/src/config/index.js
DELETED
package/src/modules/base.js
DELETED
|
@@ -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;
|