@contentstack/cli-migration 1.10.3 → 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 +21 -11
- 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/utils/constants.js
DELETED
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
exports.mapObject = new Map();
|
|
4
|
-
|
|
5
|
-
exports.version = 3; // TODO: Fetch it from CMA
|
|
6
|
-
|
|
7
|
-
exports.defaultDataType = 'text';
|
|
8
|
-
|
|
9
|
-
exports.MANAGEMENT_SDK = 'MANAGEMENT_SDK';
|
|
10
|
-
exports.MANAGEMENT_CLIENT = 'MANAGEMENT_CLIENT';
|
|
11
|
-
exports.MANAGEMENT_TOKEN = 'MANAGEMENT_TOKEN';
|
|
12
|
-
exports.AUTH_TOKEN = 'AUTH_TOKEN';
|
|
13
|
-
exports.API_KEY = 'API_KEY';
|
|
14
|
-
exports.BRANCH = 'BRANCH';
|
|
15
|
-
exports.SOURCE_BRANCH = 'SOURCE_BRANCH';
|
|
16
|
-
|
|
17
|
-
exports.data_type = 'data_type';
|
|
18
|
-
exports.mandatory = 'mandatory';
|
|
19
|
-
exports._default = 'default';
|
|
20
|
-
exports.unique = 'unique';
|
|
21
|
-
exports.display_name = 'display_name';
|
|
22
|
-
exports.reference_to = 'reference_to';
|
|
23
|
-
exports.field_metadata = 'field_metadata';
|
|
24
|
-
exports.taxonomies = 'taxonomies';
|
|
25
|
-
exports.multiple = 'multiple';
|
|
26
|
-
|
|
27
|
-
exports.actions = {
|
|
28
|
-
CUSTOM_TASK: 'CUSTOM_TASK',
|
|
29
|
-
CREATE_CT: 'CREATE_CT',
|
|
30
|
-
DELETE_CT: 'DELETE_CT',
|
|
31
|
-
EDIT_CT: 'EDIT_CT',
|
|
32
|
-
LOCALES: 'LOCALES',
|
|
33
|
-
EDIT_FIELD: 'EDIT_FIELD',
|
|
34
|
-
DELETE_FIELD: 'DELETE_FIELD',
|
|
35
|
-
MOVE_FIELD: 'MOVE_FIELD',
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
// Http call max retry
|
|
39
|
-
exports.MAX_RETRY = 3;
|
|
40
|
-
|
|
41
|
-
// This key holds the value for http objects in map
|
|
42
|
-
exports.requests = 'REQUESTS';
|
|
43
|
-
|
|
44
|
-
exports.limit = 1; // Limit for concurrent tasks executed parallely
|
|
45
|
-
|
|
46
|
-
exports.nonWritableMethods = ['GET', 'DELETE'];
|
|
47
|
-
|
|
48
|
-
exports.ContentType = 'Content type';
|
|
49
|
-
exports.Entry = 'Entry';
|
|
50
|
-
|
|
51
|
-
exports.errorMessageHandler = {
|
|
52
|
-
POST: 'saving',
|
|
53
|
-
GET: 'fetching',
|
|
54
|
-
PUT: 'updating',
|
|
55
|
-
DELETE: 'deleting',
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
exports.successMessageHandler = {
|
|
59
|
-
POST: 'saved',
|
|
60
|
-
GET: 'fetched',
|
|
61
|
-
PUT: 'updated',
|
|
62
|
-
DELETE: 'deleted',
|
|
63
|
-
};
|
|
64
|
-
// map key
|
|
65
|
-
exports.actionMapper = 'actions';
|
|
66
|
-
|
|
67
|
-
exports.batchLimit = 20;
|
|
68
|
-
|
|
69
|
-
exports.contentTypeProperties = ['description', 'title', 'uid', 'options', 'force', 'schema'];
|
|
70
|
-
|
|
71
|
-
exports.validationAction = {
|
|
72
|
-
create: 'create',
|
|
73
|
-
edit: 'edit',
|
|
74
|
-
customTask: 'customTask',
|
|
75
|
-
transformEntries: 'transformEntries',
|
|
76
|
-
deriveLinkedEntries: 'deriveLinkedEntries',
|
|
77
|
-
transformEntriesToType: 'transformEntriesToType',
|
|
78
|
-
typeError: 'typeError',
|
|
79
|
-
apiError: 'apiError',
|
|
80
|
-
schema: 'schema',
|
|
81
|
-
__migrationError: 'migrationError',
|
|
82
|
-
field: 'field',
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
exports.transformEntriesProperties = [
|
|
86
|
-
{
|
|
87
|
-
name: 'contentType',
|
|
88
|
-
type: 'string',
|
|
89
|
-
mandatory: true,
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
name: 'from',
|
|
93
|
-
type: 'array',
|
|
94
|
-
mandatory: true,
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
name: 'to',
|
|
98
|
-
type: 'array',
|
|
99
|
-
mandatory: true,
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
name: 'shouldPublish',
|
|
103
|
-
type: 'boolean',
|
|
104
|
-
mandatory: false,
|
|
105
|
-
dependsOn: 'environments',
|
|
106
|
-
},
|
|
107
|
-
{
|
|
108
|
-
name: 'environments',
|
|
109
|
-
type: 'array',
|
|
110
|
-
mandatory: false,
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
name: 'transformEntryForLocale',
|
|
114
|
-
type: 'function',
|
|
115
|
-
mandatory: true,
|
|
116
|
-
},
|
|
117
|
-
];
|
|
118
|
-
|
|
119
|
-
exports.deriveLinkedEntriesProperties = [
|
|
120
|
-
{
|
|
121
|
-
name: 'contentType',
|
|
122
|
-
type: 'string',
|
|
123
|
-
mandatory: true,
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
name: 'derivedContentType',
|
|
127
|
-
type: 'string',
|
|
128
|
-
mandatory: true,
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
name: 'from',
|
|
132
|
-
type: 'array',
|
|
133
|
-
mandatory: true,
|
|
134
|
-
},
|
|
135
|
-
{
|
|
136
|
-
name: 'toReferenceField',
|
|
137
|
-
type: 'string',
|
|
138
|
-
mandatory: true,
|
|
139
|
-
},
|
|
140
|
-
{
|
|
141
|
-
name: 'derivedFields',
|
|
142
|
-
type: 'array',
|
|
143
|
-
mandatory: true,
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
name: 'identityKey',
|
|
147
|
-
type: 'function',
|
|
148
|
-
mandatory: true,
|
|
149
|
-
},
|
|
150
|
-
{
|
|
151
|
-
name: 'shouldPublish',
|
|
152
|
-
type: 'boolean',
|
|
153
|
-
mandatory: false,
|
|
154
|
-
dependsOn: 'environments',
|
|
155
|
-
},
|
|
156
|
-
{
|
|
157
|
-
name: 'environments',
|
|
158
|
-
type: 'array',
|
|
159
|
-
mandatory: false,
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
name: 'deriveEntryForLocale',
|
|
163
|
-
type: 'function',
|
|
164
|
-
mandatory: true,
|
|
165
|
-
},
|
|
166
|
-
];
|
|
167
|
-
|
|
168
|
-
exports.transformEntriesToTypeProperties = [
|
|
169
|
-
{
|
|
170
|
-
name: 'sourceContentType',
|
|
171
|
-
type: 'string',
|
|
172
|
-
mandatory: true,
|
|
173
|
-
},
|
|
174
|
-
{
|
|
175
|
-
name: 'targetContentType',
|
|
176
|
-
type: 'string',
|
|
177
|
-
mandatory: true,
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
name: 'from',
|
|
181
|
-
type: 'array',
|
|
182
|
-
mandatory: true,
|
|
183
|
-
},
|
|
184
|
-
{
|
|
185
|
-
name: 'shouldPublish',
|
|
186
|
-
type: 'boolean',
|
|
187
|
-
mandatory: false,
|
|
188
|
-
dependsOn: 'environments',
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
name: 'environments',
|
|
192
|
-
type: 'array',
|
|
193
|
-
mandatory: false,
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
name: 'removeOldEntries',
|
|
197
|
-
type: 'boolean',
|
|
198
|
-
mandatory: false,
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
name: 'identityKey',
|
|
202
|
-
type: 'function',
|
|
203
|
-
mandatory: true,
|
|
204
|
-
},
|
|
205
|
-
{
|
|
206
|
-
name: 'transformEntryForLocale',
|
|
207
|
-
type: 'function',
|
|
208
|
-
mandatory: true,
|
|
209
|
-
},
|
|
210
|
-
];
|
|
211
|
-
|
|
212
|
-
exports.SDK_ACTIONS = {
|
|
213
|
-
CONTENTTYPE_GET: 'CONTENTTYPE_GET',
|
|
214
|
-
CONTENTTYPE_POST: 'CONTENTTYPE_POST',
|
|
215
|
-
CONTENTTYPE_DELETE: 'CONTENTTYPE_GET',
|
|
216
|
-
CONTENTTYPE_PUT: 'CONTENTTYPE_PUT',
|
|
217
|
-
LOCALES_GET: 'LOCALES_GET',
|
|
218
|
-
ENTRY_GET: 'ENTRY_GET',
|
|
219
|
-
ENTRY_POST: 'ENTRY_POST',
|
|
220
|
-
ENTRY_PUT: 'ENTRY_PUT',
|
|
221
|
-
ENTRY_DELETE: 'ENTRY_DELETE',
|
|
222
|
-
ENTRY_PUBLISH: 'ENTRY_PUBLISH',
|
|
223
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
/** Dependencies */
|
|
3
|
-
|
|
4
|
-
// Map helper
|
|
5
|
-
const { getMapInstance, getDataWithAction, get } = require('./map');
|
|
6
|
-
// Constants
|
|
7
|
-
const { MANAGEMENT_SDK, SDK_ACTIONS } = require('./constants');
|
|
8
|
-
// List of actions
|
|
9
|
-
const {
|
|
10
|
-
CONTENTTYPE_DELETE,
|
|
11
|
-
CONTENTTYPE_GET,
|
|
12
|
-
CONTENTTYPE_POST,
|
|
13
|
-
CONTENTTYPE_PUT,
|
|
14
|
-
LOCALES_GET,
|
|
15
|
-
ENTRY_DELETE,
|
|
16
|
-
ENTRY_GET,
|
|
17
|
-
ENTRY_POST,
|
|
18
|
-
ENTRY_PUBLISH,
|
|
19
|
-
ENTRY_PUT,
|
|
20
|
-
} = SDK_ACTIONS;
|
|
21
|
-
|
|
22
|
-
module.exports = ({ action, id, sdkAction }) => {
|
|
23
|
-
return async (_data) => {
|
|
24
|
-
_data = getData(_data, id, action);
|
|
25
|
-
|
|
26
|
-
const mapInstance = getMapInstance();
|
|
27
|
-
const managementSdk = get(MANAGEMENT_SDK, mapInstance);
|
|
28
|
-
const { stack } = managementSdk;
|
|
29
|
-
|
|
30
|
-
let response;
|
|
31
|
-
|
|
32
|
-
switch (sdkAction) {
|
|
33
|
-
case CONTENTTYPE_GET:
|
|
34
|
-
response = await stack.contentType(id).fetch();
|
|
35
|
-
return response;
|
|
36
|
-
case CONTENTTYPE_POST:
|
|
37
|
-
response = await stack.contentType().create(_data);
|
|
38
|
-
return response;
|
|
39
|
-
case CONTENTTYPE_PUT:
|
|
40
|
-
// const contentType = await stack.contentType(id).fetch();
|
|
41
|
-
response = await stack.contentType(_data).update();
|
|
42
|
-
return response;
|
|
43
|
-
case CONTENTTYPE_DELETE:
|
|
44
|
-
response = await stack.contentType(id).delete();
|
|
45
|
-
return response;
|
|
46
|
-
case LOCALES_GET:
|
|
47
|
-
return response;
|
|
48
|
-
case ENTRY_GET:
|
|
49
|
-
return response;
|
|
50
|
-
case ENTRY_POST:
|
|
51
|
-
return response;
|
|
52
|
-
case ENTRY_PUBLISH:
|
|
53
|
-
return response;
|
|
54
|
-
case ENTRY_DELETE:
|
|
55
|
-
return response;
|
|
56
|
-
case ENTRY_PUT:
|
|
57
|
-
return response;
|
|
58
|
-
default:
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
function getData(_data, id, action) {
|
|
64
|
-
let mapInstance = getMapInstance();
|
|
65
|
-
|
|
66
|
-
let data = _data ? _data : getDataWithAction(id, mapInstance, action);
|
|
67
|
-
|
|
68
|
-
// return stringify(data);
|
|
69
|
-
return data;
|
|
70
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
const { highlight } = require('cardinal');
|
|
2
|
-
const { keys } = Object;
|
|
3
|
-
const chalk = require('chalk');
|
|
4
|
-
const isEmpty = require('lodash/isEmpty');
|
|
5
|
-
const MigrationLogger = require('./migration-logger');
|
|
6
|
-
const fs = require('fs');
|
|
7
|
-
const { readFile } = require('./fs-helper');
|
|
8
|
-
const groupBy = require('./group-by');
|
|
9
|
-
|
|
10
|
-
const getLineWithContext = (lines, lineNumber, context) => {
|
|
11
|
-
const line = lineNumber - 1;
|
|
12
|
-
|
|
13
|
-
const firstLine = line > context ? line - context : 0;
|
|
14
|
-
const lastLine = line + context < lines.length ? line + context : lines.length;
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
before: lines.slice(firstLine, line),
|
|
18
|
-
line: lines[line],
|
|
19
|
-
after: lines.slice(line + 1, lastLine + 1),
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
function removeSpecialCharacter(str) {
|
|
24
|
-
return str.replace(/\u001b\[\d+m/g, '');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
module.exports = (errors, filePath) => {
|
|
28
|
-
const logger = new MigrationLogger(process.env.CS_CLI_LOG_PATH ?? process.cwd());
|
|
29
|
-
|
|
30
|
-
const errorsByFile = groupBy(errors, 'file');
|
|
31
|
-
const messages = [];
|
|
32
|
-
if (filePath) {
|
|
33
|
-
if (errors.request) {
|
|
34
|
-
errors.data = errors.request?.data;
|
|
35
|
-
delete errors.request;
|
|
36
|
-
}
|
|
37
|
-
if (errors.message) {
|
|
38
|
-
delete errors.message;
|
|
39
|
-
}
|
|
40
|
-
logger.log('error', { [filePath]: errors });
|
|
41
|
-
} else {
|
|
42
|
-
for (const file of keys(errorsByFile)) {
|
|
43
|
-
const errorLogs = {};
|
|
44
|
-
errorLogs[file] = {};
|
|
45
|
-
const fileContents = readFile(file);
|
|
46
|
-
const highlightedCode = highlight(fileContents, { linenos: true });
|
|
47
|
-
const lines = highlightedCode.split('\n');
|
|
48
|
-
|
|
49
|
-
const fileErrorsMessage = chalk`{red Errors in ${file}}\n\n`;
|
|
50
|
-
errorLogs[file].fileErrorsMessage = fileErrorsMessage.replace(/\u001b\[\d+m/g, '');
|
|
51
|
-
const errorMessages = errorsByFile[file]
|
|
52
|
-
.map((error) => {
|
|
53
|
-
const callsite = error.meta.callsite;
|
|
54
|
-
const context = 2;
|
|
55
|
-
let { before, line, after } = getLineWithContext(lines, callsite.line, context);
|
|
56
|
-
|
|
57
|
-
const beforeLines = before.map((_line) => chalk`${_line}\n`);
|
|
58
|
-
const afterLines = after.map((_line) => chalk`${_line}\n`);
|
|
59
|
-
const highlightedLine = chalk`{bold ${line}}\n`;
|
|
60
|
-
|
|
61
|
-
before = removeSpecialCharacter(before.join('\n'));
|
|
62
|
-
after = removeSpecialCharacter(after.join('\n'));
|
|
63
|
-
line = removeSpecialCharacter(line);
|
|
64
|
-
errorLogs[file].lines = { before, line, after };
|
|
65
|
-
if (error.request) {
|
|
66
|
-
error.data = error.request?.data;
|
|
67
|
-
delete error.request;
|
|
68
|
-
}
|
|
69
|
-
if (error.message) {
|
|
70
|
-
delete error.message;
|
|
71
|
-
}
|
|
72
|
-
const formattedCode = beforeLines + highlightedLine + afterLines;
|
|
73
|
-
if (error.payload?.apiError) {
|
|
74
|
-
errorLogs[file].apiError = true;
|
|
75
|
-
errorLogs[file].errorCode = error.payload.apiError.errorCode;
|
|
76
|
-
errorLogs[file].errors = error.payload.apiError.errors;
|
|
77
|
-
errorLogs[file].data = error.data;
|
|
78
|
-
}
|
|
79
|
-
if (error.message && !error.payload.apiError) {
|
|
80
|
-
errorLogs[file].apiError = false;
|
|
81
|
-
errorLogs[file].error = error.message;
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
.join('\n');
|
|
85
|
-
|
|
86
|
-
messages.push(`${fileErrorsMessage}${errorMessages}`);
|
|
87
|
-
logger.log('error', errorLogs);
|
|
88
|
-
}
|
|
89
|
-
if (errors?.request) {
|
|
90
|
-
errors.data = errors.request?.data;
|
|
91
|
-
delete errors.request;
|
|
92
|
-
}
|
|
93
|
-
if (errors?.message) {
|
|
94
|
-
delete errors.message;
|
|
95
|
-
}
|
|
96
|
-
if (isEmpty(messages) && errors !== undefined && isEmpty(errorsByFile)) {
|
|
97
|
-
logger.log('error', { errors: errors });
|
|
98
|
-
console.log(chalk`{bold.red migration unsuccessful}`);
|
|
99
|
-
} else {
|
|
100
|
-
logger.log('error', { error: messages.join('\n') });
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
// eslint-disable-next-line
|
|
104
|
-
// console.log(chalk`{bold.red Migration unsuccessful}`);
|
|
105
|
-
};
|
package/src/utils/fs-helper.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { existsSync, mkdirSync, readFileSync, readFile } = require('fs');
|
|
4
|
-
const path = require('path');
|
|
5
|
-
const { pathValidator } = require('@contentstack/cli-utilities');
|
|
6
|
-
|
|
7
|
-
exports.makeDir = (dirname) => {
|
|
8
|
-
!this.existsSync(dirname) && mkdirSync(dirname);
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
exports.existsSync = (filePath) => existsSync(filePath);
|
|
12
|
-
|
|
13
|
-
exports.readFile = (filePath) => {
|
|
14
|
-
if (!existsSync(filePath)) throw new Error('File does not exist');
|
|
15
|
-
return readFileSync(filePath, 'utf-8');
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
exports.readJSONFile = (filePath) => {
|
|
19
|
-
return new Promise((resolve, reject) => {
|
|
20
|
-
filePath = pathValidator(filePath);
|
|
21
|
-
readFile(filePath, 'utf-8', (error, data) => {
|
|
22
|
-
if (error) {
|
|
23
|
-
reject(error);
|
|
24
|
-
} else {
|
|
25
|
-
resolve(JSON.parse(data));
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
};
|
package/src/utils/get-batches.js
DELETED
package/src/utils/get-config.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { apiConfig } = require('../config');
|
|
4
|
-
|
|
5
|
-
module.exports = ({ method, path, sdkAction }) => {
|
|
6
|
-
return {
|
|
7
|
-
...apiConfig,
|
|
8
|
-
path: path ? `${apiConfig.version}${path}` : apiConfig.version,
|
|
9
|
-
method,
|
|
10
|
-
headers: { ...apiConfig.headers },
|
|
11
|
-
sdkAction,
|
|
12
|
-
};
|
|
13
|
-
};
|
package/src/utils/group-by.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = function groupBy(data, field, i = 0, finalObj = {}, originalArray = []) {
|
|
4
|
-
if (!data) return finalObj;
|
|
5
|
-
|
|
6
|
-
if (Array.isArray(data)) {
|
|
7
|
-
groupBy(data[i], field, 0, finalObj, data);
|
|
8
|
-
} else if (field in data) {
|
|
9
|
-
let dataField = data[field];
|
|
10
|
-
if (dataField in finalObj) {
|
|
11
|
-
finalObj[dataField].push(originalArray[i]);
|
|
12
|
-
} else {
|
|
13
|
-
finalObj[dataField] = [];
|
|
14
|
-
finalObj[dataField].push(originalArray[i]);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
i++;
|
|
18
|
-
|
|
19
|
-
// Breaks when i has been incremented more than length of original array
|
|
20
|
-
if (i !== 0 && i >= originalArray.length) return finalObj;
|
|
21
|
-
/**
|
|
22
|
-
* After the field is found only then increment i and inspect next item
|
|
23
|
-
* This will restrict iterating through array just to the length of array
|
|
24
|
-
*/
|
|
25
|
-
groupBy(originalArray[i], field, i, finalObj, originalArray);
|
|
26
|
-
} else {
|
|
27
|
-
for (let key in data) {
|
|
28
|
-
if (key) {
|
|
29
|
-
let dataKey = data[key];
|
|
30
|
-
if (!Array.isArray(dataKey) && typeof dataKey === 'object') {
|
|
31
|
-
groupBy(dataKey, field, i, finalObj, originalArray);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return finalObj;
|
|
38
|
-
};
|
package/src/utils/index.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
map: require('./map'),
|
|
5
|
-
constants: require('./constants'),
|
|
6
|
-
schemaHelper: require('./schema-helper'),
|
|
7
|
-
objectHelper: require('./object-helper'),
|
|
8
|
-
fsHelper: require('./fs-helper'),
|
|
9
|
-
logger: require('./logger'),
|
|
10
|
-
https: require('./request'),
|
|
11
|
-
safePromise: require('./safe-promise'),
|
|
12
|
-
getConfig: require('./get-config'),
|
|
13
|
-
successHandler: require('./success-handler'),
|
|
14
|
-
getCallsite: require('./callsite'),
|
|
15
|
-
errorHelper: require('./error-helper'),
|
|
16
|
-
groupBy: require('./group-by'),
|
|
17
|
-
getBatches: require('./get-batches'),
|
|
18
|
-
autoRetry: require('./auto-retry'),
|
|
19
|
-
contentstackSdk: require('./contentstack-sdk'),
|
|
20
|
-
installModules: require('./modules'),
|
|
21
|
-
};
|
package/src/utils/logger.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { createLogger, format, transports } = require('winston');
|
|
4
|
-
const { resolve, join } = require('path');
|
|
5
|
-
const { slice } = Array.prototype;
|
|
6
|
-
const { stringify } = JSON;
|
|
7
|
-
const { pathValidator, sanitizePath } = require('@contentstack/cli-utilities');
|
|
8
|
-
|
|
9
|
-
const { combine, label, printf, colorize } = format;
|
|
10
|
-
|
|
11
|
-
// FS helper
|
|
12
|
-
const { makeDir } = require('./fs-helper');
|
|
13
|
-
|
|
14
|
-
const { NODE_ENV } = process.env;
|
|
15
|
-
|
|
16
|
-
function getString(args) {
|
|
17
|
-
let str = '';
|
|
18
|
-
if (args && args.length > 0) {
|
|
19
|
-
str = args
|
|
20
|
-
.map((item) => (item && typeof item === 'object' ? stringify(item) : item))
|
|
21
|
-
.join(' ')
|
|
22
|
-
.trim();
|
|
23
|
-
}
|
|
24
|
-
return str;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const customFormat = printf(({ level, message }) => {
|
|
28
|
-
return `${level}: ${message}`;
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
function init(logFileName) {
|
|
32
|
-
const logsDir = resolve(process.env.CS_CLI_LOG_PATH?? process.cwd(),'logs');
|
|
33
|
-
// Create dir if does not exist
|
|
34
|
-
makeDir(logsDir);
|
|
35
|
-
|
|
36
|
-
const logPath = pathValidator(join(sanitizePath(logsDir), sanitizePath(logFileName) + '.log'));
|
|
37
|
-
const logger = createLogger({
|
|
38
|
-
format: combine(colorize(), label({ label: 'Migration' }), customFormat),
|
|
39
|
-
transports: [new transports.File({ filename: logPath })],
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
let args;
|
|
43
|
-
let logString;
|
|
44
|
-
|
|
45
|
-
return {
|
|
46
|
-
log: function () {
|
|
47
|
-
args = slice.call(arguments);
|
|
48
|
-
logString = getString(args);
|
|
49
|
-
logString && logger.log('info', logString);
|
|
50
|
-
},
|
|
51
|
-
warn: function () {
|
|
52
|
-
args = slice.call(arguments);
|
|
53
|
-
logString = getString(args);
|
|
54
|
-
logString && logger.log('warn', logString);
|
|
55
|
-
},
|
|
56
|
-
error: function () {
|
|
57
|
-
// args = slice.call(arguments);
|
|
58
|
-
// logString = getString(args);
|
|
59
|
-
// logString && logger.log('error', logString);
|
|
60
|
-
},
|
|
61
|
-
debug: function () {
|
|
62
|
-
args = slice.call(arguments);
|
|
63
|
-
logString = getString(args);
|
|
64
|
-
logString && logger.log('debug', logString);
|
|
65
|
-
},
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
exports.success = init('success').log;
|
|
70
|
-
if (NODE_ENV === 'test') {
|
|
71
|
-
exports.error = init('warn').warn;
|
|
72
|
-
} else {
|
|
73
|
-
exports.error = init('error').error;
|
|
74
|
-
}
|
|
75
|
-
exports.warn = init('warn').warn;
|
package/src/utils/map.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const {mapObject, actionMapper, requests} = require('./constants')
|
|
4
|
-
|
|
5
|
-
exports.getMapInstance = () => {
|
|
6
|
-
return mapObject
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
exports.get = (id, mapInstance, data = []) => {
|
|
10
|
-
// Create key if does not exist
|
|
11
|
-
let __data = mapInstance.get(id)
|
|
12
|
-
|
|
13
|
-
if (!__data) {
|
|
14
|
-
mapInstance.set(id, data)
|
|
15
|
-
__data = mapInstance.get(id)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return __data
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
exports.set = (id, mapInstance, data) => {
|
|
22
|
-
return mapInstance.set(id, data)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
exports.remove = (id, mapInstance) => {
|
|
26
|
-
return mapInstance.delete(id)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
exports.getDataWithAction = (id, mapInstance, action) => {
|
|
30
|
-
let data = this.get(id, mapInstance)
|
|
31
|
-
data = data[action]
|
|
32
|
-
return data
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
exports.resetMapInstance = mapInstance => {
|
|
36
|
-
this.set(actionMapper, mapInstance, [])
|
|
37
|
-
this.set(requests, mapInstance, [])
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
exports.delete = () => { }
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
const winston = require('winston');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const { sanitizePath } = require('@contentstack/cli-utilities');
|
|
4
|
-
module.exports = class MigrationLogger {
|
|
5
|
-
constructor(filePath) {
|
|
6
|
-
this.filePath = path.join(sanitizePath(filePath), 'migration-logs');
|
|
7
|
-
this.logger = winston.createLogger({
|
|
8
|
-
levels: { error: 1 },
|
|
9
|
-
transports: [
|
|
10
|
-
new winston.transports.File({
|
|
11
|
-
level: 'error',
|
|
12
|
-
filename: path.join(sanitizePath(this.filePath), 'error.logs'),
|
|
13
|
-
format: winston.format.combine(winston.format.timestamp(), winston.format.json()),
|
|
14
|
-
}),
|
|
15
|
-
],
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
log(level, message) {
|
|
19
|
-
this.logger.log('error', message);
|
|
20
|
-
}
|
|
21
|
-
};
|