@contentstack/cli-migration 0.1.1-beta.3 → 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.
- package/LICENSE +21 -0
- package/README.md +22 -27
- package/oclif.manifest.json +1 -1
- package/package.json +16 -11
- package/src/actions/action-list.js +11 -11
- package/src/actions/index.js +33 -34
- package/src/commands/cm/{migration.js → stacks/migration.js} +102 -74
- package/src/config/api-config.js +8 -9
- package/src/config/default-options.js +2 -2
- package/src/config/index.js +2 -2
- package/src/config/master-locale.js +2 -2
- package/src/modules/base.js +33 -33
- package/src/modules/content-types.js +76 -76
- package/src/modules/fields.js +73 -73
- package/src/modules/index.js +2 -2
- package/src/modules/locale.js +13 -13
- package/src/modules/migration.js +45 -46
- package/src/modules/parser.js +65 -52
- package/src/services/content-types.js +160 -163
- package/src/services/index.js +2 -2
- package/src/services/locales.js +33 -35
- package/src/utils/auto-retry.js +14 -12
- package/src/utils/callsite.js +14 -14
- package/src/utils/constants.js +108 -115
- package/src/utils/contentstack-sdk.js +42 -43
- package/src/utils/error-handler.js +8 -8
- package/src/utils/error-helper.js +41 -40
- package/src/utils/fs-helper.js +12 -12
- package/src/utils/get-batches.js +4 -4
- package/src/utils/get-config.js +6 -6
- package/src/utils/group-by.js +17 -17
- package/src/utils/index.js +2 -2
- package/src/utils/logger.js +42 -52
- package/src/utils/object-helper.js +7 -7
- package/src/utils/safe-promise.js +2 -2
- package/src/utils/schema-helper.js +12 -12
- package/src/utils/success-handler.js +5 -5
- package/src/validators/api-error.js +10 -8
- package/src/validators/base-validator.js +14 -14
- package/src/validators/create-content-type-validator.js +21 -25
- package/src/validators/edit-content-type-validator.js +21 -24
- package/src/validators/field-validator.js +10 -8
- package/src/validators/index.js +2 -2
- package/src/validators/migration-error.js +9 -7
- package/src/validators/schema-validator.js +11 -9
- package/src/validators/type-error.js +11 -10
package/src/utils/callsite.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const getCallsites = require('callsites')
|
|
4
|
-
const {parse, resolve} = require('path')
|
|
3
|
+
const getCallsites = require('callsites');
|
|
4
|
+
const { parse, resolve } = require('path');
|
|
5
5
|
|
|
6
6
|
function getFileDirectory(path) {
|
|
7
|
-
const parentPath = resolve(path, '../') // Assuming that will be 2 folders up
|
|
8
|
-
return parse(parentPath).dir
|
|
7
|
+
const parentPath = resolve(path, '../'); // Assuming that will be 2 folders up
|
|
8
|
+
return parse(parentPath).dir;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
module.exports = () => {
|
|
12
|
-
const thisDir = getFileDirectory(__filename)
|
|
13
|
-
const callsites = getCallsites()
|
|
12
|
+
const thisDir = getFileDirectory(__filename);
|
|
13
|
+
const callsites = getCallsites();
|
|
14
14
|
|
|
15
|
-
const externalFile = callsites.find(callsite => {
|
|
16
|
-
const currentDir = getFileDirectory(callsite.getFileName())
|
|
17
|
-
const isNotThisDir = thisDir !== currentDir
|
|
18
|
-
return isNotThisDir
|
|
19
|
-
})
|
|
15
|
+
const externalFile = callsites.find((callsite) => {
|
|
16
|
+
const currentDir = getFileDirectory(callsite.getFileName());
|
|
17
|
+
const isNotThisDir = thisDir !== currentDir;
|
|
18
|
+
return isNotThisDir;
|
|
19
|
+
});
|
|
20
20
|
|
|
21
|
-
return externalFile
|
|
22
|
-
}
|
|
21
|
+
return externalFile;
|
|
22
|
+
};
|
package/src/utils/constants.js
CHANGED
|
@@ -1,228 +1,221 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
exports.mapObject = new Map();
|
|
4
4
|
|
|
5
5
|
exports.version = 3; // TODO: Fetch it from CMA
|
|
6
6
|
|
|
7
|
-
exports.defaultDataType =
|
|
7
|
+
exports.defaultDataType = 'text';
|
|
8
8
|
|
|
9
|
-
exports.MANAGEMENT_SDK =
|
|
10
|
-
exports.MANAGEMENT_CLIENT =
|
|
11
|
-
exports.
|
|
12
|
-
exports.AUTH_TOKEN =
|
|
13
|
-
exports.API_KEY =
|
|
14
|
-
exports.BRANCH =
|
|
15
|
-
exports.SOURCE_BRANCH =
|
|
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
16
|
|
|
17
|
-
exports.data_type =
|
|
18
|
-
exports.mandatory =
|
|
19
|
-
exports._default =
|
|
20
|
-
exports.unique =
|
|
21
|
-
exports.display_name =
|
|
22
|
-
exports.reference_to =
|
|
23
|
-
exports.field_metadata =
|
|
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
24
|
|
|
25
25
|
exports.actions = {
|
|
26
|
-
CUSTOM_TASK:
|
|
27
|
-
CREATE_CT:
|
|
28
|
-
DELETE_CT:
|
|
29
|
-
EDIT_CT:
|
|
30
|
-
LOCALES:
|
|
31
|
-
EDIT_FIELD:
|
|
32
|
-
DELETE_FIELD:
|
|
33
|
-
MOVE_FIELD:
|
|
26
|
+
CUSTOM_TASK: 'CUSTOM_TASK',
|
|
27
|
+
CREATE_CT: 'CREATE_CT',
|
|
28
|
+
DELETE_CT: 'DELETE_CT',
|
|
29
|
+
EDIT_CT: 'EDIT_CT',
|
|
30
|
+
LOCALES: 'LOCALES',
|
|
31
|
+
EDIT_FIELD: 'EDIT_FIELD',
|
|
32
|
+
DELETE_FIELD: 'DELETE_FIELD',
|
|
33
|
+
MOVE_FIELD: 'MOVE_FIELD',
|
|
34
34
|
};
|
|
35
35
|
|
|
36
36
|
// Http call max retry
|
|
37
37
|
exports.MAX_RETRY = 3;
|
|
38
38
|
|
|
39
39
|
// This key holds the value for http objects in map
|
|
40
|
-
exports.requests =
|
|
40
|
+
exports.requests = 'REQUESTS';
|
|
41
41
|
|
|
42
42
|
exports.limit = 1; // Limit for concurrent tasks executed parallely
|
|
43
43
|
|
|
44
|
-
exports.nonWritableMethods = [
|
|
44
|
+
exports.nonWritableMethods = ['GET', 'DELETE'];
|
|
45
45
|
|
|
46
|
-
exports.ContentType =
|
|
47
|
-
exports.Entry =
|
|
46
|
+
exports.ContentType = 'Content type';
|
|
47
|
+
exports.Entry = 'Entry';
|
|
48
48
|
|
|
49
49
|
exports.errorMessageHandler = {
|
|
50
|
-
POST:
|
|
51
|
-
GET:
|
|
52
|
-
PUT:
|
|
53
|
-
DELETE:
|
|
50
|
+
POST: 'saving',
|
|
51
|
+
GET: 'fetching',
|
|
52
|
+
PUT: 'updating',
|
|
53
|
+
DELETE: 'deleting',
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
exports.successMessageHandler = {
|
|
57
|
-
POST:
|
|
58
|
-
GET:
|
|
59
|
-
PUT:
|
|
60
|
-
DELETE:
|
|
57
|
+
POST: 'saved',
|
|
58
|
+
GET: 'fetched',
|
|
59
|
+
PUT: 'updated',
|
|
60
|
+
DELETE: 'deleted',
|
|
61
61
|
};
|
|
62
62
|
// map key
|
|
63
|
-
exports.actionMapper =
|
|
63
|
+
exports.actionMapper = 'actions';
|
|
64
64
|
|
|
65
65
|
exports.batchLimit = 20;
|
|
66
66
|
|
|
67
|
-
exports.contentTypeProperties = [
|
|
68
|
-
"description",
|
|
69
|
-
"title",
|
|
70
|
-
"uid",
|
|
71
|
-
"options",
|
|
72
|
-
"force",
|
|
73
|
-
"schema",
|
|
74
|
-
];
|
|
67
|
+
exports.contentTypeProperties = ['description', 'title', 'uid', 'options', 'force', 'schema'];
|
|
75
68
|
|
|
76
69
|
exports.validationAction = {
|
|
77
|
-
create:
|
|
78
|
-
edit:
|
|
79
|
-
customTask:
|
|
80
|
-
transformEntries:
|
|
81
|
-
deriveLinkedEntries:
|
|
82
|
-
transformEntriesToType:
|
|
83
|
-
typeError:
|
|
84
|
-
apiError:
|
|
85
|
-
schema:
|
|
86
|
-
__migrationError:
|
|
87
|
-
field:
|
|
70
|
+
create: 'create',
|
|
71
|
+
edit: 'edit',
|
|
72
|
+
customTask: 'customTask',
|
|
73
|
+
transformEntries: 'transformEntries',
|
|
74
|
+
deriveLinkedEntries: 'deriveLinkedEntries',
|
|
75
|
+
transformEntriesToType: 'transformEntriesToType',
|
|
76
|
+
typeError: 'typeError',
|
|
77
|
+
apiError: 'apiError',
|
|
78
|
+
schema: 'schema',
|
|
79
|
+
__migrationError: 'migrationError',
|
|
80
|
+
field: 'field',
|
|
88
81
|
};
|
|
89
82
|
|
|
90
83
|
exports.transformEntriesProperties = [
|
|
91
84
|
{
|
|
92
|
-
name:
|
|
93
|
-
type:
|
|
85
|
+
name: 'contentType',
|
|
86
|
+
type: 'string',
|
|
94
87
|
mandatory: true,
|
|
95
88
|
},
|
|
96
89
|
{
|
|
97
|
-
name:
|
|
98
|
-
type:
|
|
90
|
+
name: 'from',
|
|
91
|
+
type: 'array',
|
|
99
92
|
mandatory: true,
|
|
100
93
|
},
|
|
101
94
|
{
|
|
102
|
-
name:
|
|
103
|
-
type:
|
|
95
|
+
name: 'to',
|
|
96
|
+
type: 'array',
|
|
104
97
|
mandatory: true,
|
|
105
98
|
},
|
|
106
99
|
{
|
|
107
|
-
name:
|
|
108
|
-
type:
|
|
100
|
+
name: 'shouldPublish',
|
|
101
|
+
type: 'boolean',
|
|
109
102
|
mandatory: false,
|
|
110
|
-
dependsOn:
|
|
103
|
+
dependsOn: 'environments',
|
|
111
104
|
},
|
|
112
105
|
{
|
|
113
|
-
name:
|
|
114
|
-
type:
|
|
106
|
+
name: 'environments',
|
|
107
|
+
type: 'array',
|
|
115
108
|
mandatory: false,
|
|
116
109
|
},
|
|
117
110
|
{
|
|
118
|
-
name:
|
|
119
|
-
type:
|
|
111
|
+
name: 'transformEntryForLocale',
|
|
112
|
+
type: 'function',
|
|
120
113
|
mandatory: true,
|
|
121
114
|
},
|
|
122
115
|
];
|
|
123
116
|
|
|
124
117
|
exports.deriveLinkedEntriesProperties = [
|
|
125
118
|
{
|
|
126
|
-
name:
|
|
127
|
-
type:
|
|
119
|
+
name: 'contentType',
|
|
120
|
+
type: 'string',
|
|
128
121
|
mandatory: true,
|
|
129
122
|
},
|
|
130
123
|
{
|
|
131
|
-
name:
|
|
132
|
-
type:
|
|
124
|
+
name: 'derivedContentType',
|
|
125
|
+
type: 'string',
|
|
133
126
|
mandatory: true,
|
|
134
127
|
},
|
|
135
128
|
{
|
|
136
|
-
name:
|
|
137
|
-
type:
|
|
129
|
+
name: 'from',
|
|
130
|
+
type: 'array',
|
|
138
131
|
mandatory: true,
|
|
139
132
|
},
|
|
140
133
|
{
|
|
141
|
-
name:
|
|
142
|
-
type:
|
|
134
|
+
name: 'toReferenceField',
|
|
135
|
+
type: 'string',
|
|
143
136
|
mandatory: true,
|
|
144
137
|
},
|
|
145
138
|
{
|
|
146
|
-
name:
|
|
147
|
-
type:
|
|
139
|
+
name: 'derivedFields',
|
|
140
|
+
type: 'array',
|
|
148
141
|
mandatory: true,
|
|
149
142
|
},
|
|
150
143
|
{
|
|
151
|
-
name:
|
|
152
|
-
type:
|
|
144
|
+
name: 'identityKey',
|
|
145
|
+
type: 'function',
|
|
153
146
|
mandatory: true,
|
|
154
147
|
},
|
|
155
148
|
{
|
|
156
|
-
name:
|
|
157
|
-
type:
|
|
149
|
+
name: 'shouldPublish',
|
|
150
|
+
type: 'boolean',
|
|
158
151
|
mandatory: false,
|
|
159
|
-
dependsOn:
|
|
152
|
+
dependsOn: 'environments',
|
|
160
153
|
},
|
|
161
154
|
{
|
|
162
|
-
name:
|
|
163
|
-
type:
|
|
155
|
+
name: 'environments',
|
|
156
|
+
type: 'array',
|
|
164
157
|
mandatory: false,
|
|
165
158
|
},
|
|
166
159
|
{
|
|
167
|
-
name:
|
|
168
|
-
type:
|
|
160
|
+
name: 'deriveEntryForLocale',
|
|
161
|
+
type: 'function',
|
|
169
162
|
mandatory: true,
|
|
170
163
|
},
|
|
171
164
|
];
|
|
172
165
|
|
|
173
166
|
exports.transformEntriesToTypeProperties = [
|
|
174
167
|
{
|
|
175
|
-
name:
|
|
176
|
-
type:
|
|
168
|
+
name: 'sourceContentType',
|
|
169
|
+
type: 'string',
|
|
177
170
|
mandatory: true,
|
|
178
171
|
},
|
|
179
172
|
{
|
|
180
|
-
name:
|
|
181
|
-
type:
|
|
173
|
+
name: 'targetContentType',
|
|
174
|
+
type: 'string',
|
|
182
175
|
mandatory: true,
|
|
183
176
|
},
|
|
184
177
|
{
|
|
185
|
-
name:
|
|
186
|
-
type:
|
|
178
|
+
name: 'from',
|
|
179
|
+
type: 'array',
|
|
187
180
|
mandatory: true,
|
|
188
181
|
},
|
|
189
182
|
{
|
|
190
|
-
name:
|
|
191
|
-
type:
|
|
183
|
+
name: 'shouldPublish',
|
|
184
|
+
type: 'boolean',
|
|
192
185
|
mandatory: false,
|
|
193
|
-
dependsOn:
|
|
186
|
+
dependsOn: 'environments',
|
|
194
187
|
},
|
|
195
188
|
{
|
|
196
|
-
name:
|
|
197
|
-
type:
|
|
189
|
+
name: 'environments',
|
|
190
|
+
type: 'array',
|
|
198
191
|
mandatory: false,
|
|
199
192
|
},
|
|
200
193
|
{
|
|
201
|
-
name:
|
|
202
|
-
type:
|
|
194
|
+
name: 'removeOldEntries',
|
|
195
|
+
type: 'boolean',
|
|
203
196
|
mandatory: false,
|
|
204
197
|
},
|
|
205
198
|
{
|
|
206
|
-
name:
|
|
207
|
-
type:
|
|
199
|
+
name: 'identityKey',
|
|
200
|
+
type: 'function',
|
|
208
201
|
mandatory: true,
|
|
209
202
|
},
|
|
210
203
|
{
|
|
211
|
-
name:
|
|
212
|
-
type:
|
|
204
|
+
name: 'transformEntryForLocale',
|
|
205
|
+
type: 'function',
|
|
213
206
|
mandatory: true,
|
|
214
207
|
},
|
|
215
208
|
];
|
|
216
209
|
|
|
217
210
|
exports.SDK_ACTIONS = {
|
|
218
|
-
CONTENTTYPE_GET:
|
|
219
|
-
CONTENTTYPE_POST:
|
|
220
|
-
CONTENTTYPE_DELETE:
|
|
221
|
-
CONTENTTYPE_PUT:
|
|
222
|
-
LOCALES_GET:
|
|
223
|
-
ENTRY_GET:
|
|
224
|
-
ENTRY_POST:
|
|
225
|
-
ENTRY_PUT:
|
|
226
|
-
ENTRY_DELETE:
|
|
227
|
-
ENTRY_PUBLISH:
|
|
211
|
+
CONTENTTYPE_GET: 'CONTENTTYPE_GET',
|
|
212
|
+
CONTENTTYPE_POST: 'CONTENTTYPE_POST',
|
|
213
|
+
CONTENTTYPE_DELETE: 'CONTENTTYPE_GET',
|
|
214
|
+
CONTENTTYPE_PUT: 'CONTENTTYPE_PUT',
|
|
215
|
+
LOCALES_GET: 'LOCALES_GET',
|
|
216
|
+
ENTRY_GET: 'ENTRY_GET',
|
|
217
|
+
ENTRY_POST: 'ENTRY_POST',
|
|
218
|
+
ENTRY_PUT: 'ENTRY_PUT',
|
|
219
|
+
ENTRY_DELETE: 'ENTRY_DELETE',
|
|
220
|
+
ENTRY_PUBLISH: 'ENTRY_PUBLISH',
|
|
228
221
|
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
/** Dependencies */
|
|
3
3
|
|
|
4
4
|
// Map helper
|
|
5
|
-
const {getMapInstance, getDataWithAction, get} = require('./map')
|
|
5
|
+
const { getMapInstance, getDataWithAction, get } = require('./map');
|
|
6
6
|
// Constants
|
|
7
|
-
const {MANAGEMENT_SDK, SDK_ACTIONS} = require('./constants')
|
|
7
|
+
const { MANAGEMENT_SDK, SDK_ACTIONS } = require('./constants');
|
|
8
8
|
// List of actions
|
|
9
9
|
const {
|
|
10
10
|
CONTENTTYPE_DELETE,
|
|
@@ -17,55 +17,54 @@ const {
|
|
|
17
17
|
ENTRY_POST,
|
|
18
18
|
ENTRY_PUBLISH,
|
|
19
19
|
ENTRY_PUT,
|
|
20
|
-
} = SDK_ACTIONS
|
|
20
|
+
} = SDK_ACTIONS;
|
|
21
21
|
|
|
22
|
-
module.exports = ({action, id, sdkAction}) => {
|
|
23
|
-
return async _data => {
|
|
24
|
-
_data = getData(_data, id, action)
|
|
22
|
+
module.exports = ({ action, id, sdkAction }) => {
|
|
23
|
+
return async (_data) => {
|
|
24
|
+
_data = getData(_data, id, action);
|
|
25
25
|
|
|
26
|
-
const mapInstance = getMapInstance()
|
|
27
|
-
const managementSdk = get(MANAGEMENT_SDK, mapInstance)
|
|
28
|
-
const {stack} = managementSdk
|
|
26
|
+
const mapInstance = getMapInstance();
|
|
27
|
+
const managementSdk = get(MANAGEMENT_SDK, mapInstance);
|
|
28
|
+
const { stack } = managementSdk;
|
|
29
29
|
|
|
30
|
-
let response
|
|
30
|
+
let response;
|
|
31
31
|
|
|
32
32
|
switch (sdkAction) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
59
|
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
62
|
|
|
63
63
|
function getData(_data, id, action) {
|
|
64
|
-
let mapInstance = getMapInstance()
|
|
64
|
+
let mapInstance = getMapInstance();
|
|
65
65
|
|
|
66
|
-
let data = _data ? _data : getDataWithAction(id, mapInstance, action)
|
|
66
|
+
let data = _data ? _data : getDataWithAction(id, mapInstance, action);
|
|
67
67
|
|
|
68
68
|
// return stringify(data);
|
|
69
|
-
return data
|
|
69
|
+
return data;
|
|
70
70
|
}
|
|
71
|
-
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const {error} = require('./logger')
|
|
4
|
-
const {errorMessageHandler} = require('./constants')
|
|
3
|
+
const { error } = require('./logger');
|
|
4
|
+
const { errorMessageHandler } = require('./constants');
|
|
5
5
|
|
|
6
6
|
module.exports = (data, type, method, err) => {
|
|
7
7
|
if (data && type && method) {
|
|
8
|
-
error(`Error occurred while ${errorMessageHandler[method]} ${type}: ${data}.`)
|
|
8
|
+
error(`Error occurred while ${errorMessageHandler[method]} ${type}: ${data}.`);
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
if (err.errorMessage) {
|
|
12
|
-
error(err.errorMessage)
|
|
12
|
+
error(err.errorMessage);
|
|
13
13
|
}
|
|
14
14
|
if (err instanceof Error && err && err.message && err.stack) {
|
|
15
|
-
error(err.message)
|
|
15
|
+
error(err.message);
|
|
16
16
|
// error(err.stack)
|
|
17
17
|
} else {
|
|
18
|
-
error(err)
|
|
18
|
+
error(err);
|
|
19
19
|
}
|
|
20
20
|
// throw new Error(err);
|
|
21
|
-
}
|
|
21
|
+
};
|
|
@@ -1,53 +1,54 @@
|
|
|
1
|
+
const { highlight } = require('cardinal');
|
|
2
|
+
const { keys } = Object;
|
|
3
|
+
const chalk = require('chalk');
|
|
1
4
|
|
|
2
|
-
const {
|
|
3
|
-
const
|
|
4
|
-
const chalk = require('chalk')
|
|
5
|
-
|
|
6
|
-
const {readFile} = require('./fs-helper')
|
|
7
|
-
const groupBy = require('./group-by')
|
|
5
|
+
const { readFile } = require('./fs-helper');
|
|
6
|
+
const groupBy = require('./group-by');
|
|
8
7
|
|
|
9
8
|
const getLineWithContext = (lines, lineNumber, context) => {
|
|
10
|
-
const line =
|
|
9
|
+
const line = lineNumber - 1;
|
|
11
10
|
|
|
12
|
-
const firstLine =
|
|
13
|
-
const lastLine =
|
|
11
|
+
const firstLine = line > context ? line - context : 0;
|
|
12
|
+
const lastLine = line + context < lines.length ? line + context : lines.length;
|
|
14
13
|
|
|
15
14
|
return {
|
|
16
15
|
before: lines.slice(firstLine, line),
|
|
17
16
|
line: lines[line],
|
|
18
17
|
after: lines.slice(line + 1, lastLine + 1),
|
|
19
|
-
}
|
|
20
|
-
}
|
|
18
|
+
};
|
|
19
|
+
};
|
|
21
20
|
|
|
22
|
-
module.exports = errors => {
|
|
23
|
-
const errorsByFile = groupBy(errors, 'file')
|
|
24
|
-
const messages = []
|
|
21
|
+
module.exports = (errors) => {
|
|
22
|
+
const errorsByFile = groupBy(errors, 'file');
|
|
23
|
+
const messages = [];
|
|
25
24
|
for (const file of keys(errorsByFile)) {
|
|
26
|
-
const fileContents = readFile(file)
|
|
27
|
-
const highlightedCode = highlight(fileContents, {linenos: true})
|
|
28
|
-
const lines = highlightedCode.split('\n')
|
|
29
|
-
|
|
30
|
-
const fileErrorsMessage = chalk`{red Errors in ${file}}\n\n
|
|
31
|
-
const errorMessages = errorsByFile[file]
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
25
|
+
const fileContents = readFile(file);
|
|
26
|
+
const highlightedCode = highlight(fileContents, { linenos: true });
|
|
27
|
+
const lines = highlightedCode.split('\n');
|
|
28
|
+
|
|
29
|
+
const fileErrorsMessage = chalk`{red Errors in ${file}}\n\n`;
|
|
30
|
+
const errorMessages = errorsByFile[file]
|
|
31
|
+
.map((error) => {
|
|
32
|
+
const callsite = error.meta.callsite;
|
|
33
|
+
const context = 2;
|
|
34
|
+
const { before, line, after } = getLineWithContext(lines, callsite.line, context);
|
|
35
|
+
|
|
36
|
+
const beforeLines = before.map((_line) => chalk`${_line}\n`);
|
|
37
|
+
const afterLines = after.map((_line) => chalk`${_line}\n`);
|
|
38
|
+
const highlightedLine = chalk`{bold ${line}}\n`;
|
|
39
|
+
|
|
40
|
+
const formattedCode = beforeLines + highlightedLine + afterLines;
|
|
41
|
+
if (error.payload.apiError) {
|
|
42
|
+
return chalk`{red Line ${String(callsite.line)}:} {bold ${error.payload.apiError.message}}\n${formattedCode}`;
|
|
43
|
+
}
|
|
44
|
+
if (error.message) {
|
|
45
|
+
return chalk`{red Line ${String(callsite.line)}:} {bold ${error.message}}\n${formattedCode}`;
|
|
46
|
+
}
|
|
47
|
+
return chalk`{red Line ${String(callsite.line)}:} {bold something went wrong here.}\n${formattedCode}`;
|
|
48
|
+
})
|
|
49
|
+
.join('\n');
|
|
50
|
+
|
|
51
|
+
messages.push(`${fileErrorsMessage}${errorMessages}`);
|
|
51
52
|
}
|
|
52
53
|
// eslint-disable-next-line
|
|
53
54
|
// console.error(chalk`{red.bold Validation failed}\n\n`);
|
|
@@ -55,4 +56,4 @@ module.exports = errors => {
|
|
|
55
56
|
console.log(messages.join('\n'));
|
|
56
57
|
// eslint-disable-next-line
|
|
57
58
|
console.log(chalk`{bold.red Migration unsuccessful}`);
|
|
58
|
-
}
|
|
59
|
+
};
|
package/src/utils/fs-helper.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
const { existsSync, mkdirSync, readFileSync, readFile } = require('fs')
|
|
4
|
-
const path = require(
|
|
3
|
+
const { existsSync, mkdirSync, readFileSync, readFile } = require('fs');
|
|
4
|
+
const path = require('path');
|
|
5
5
|
|
|
6
|
-
exports.makeDir = dirname => {
|
|
7
|
-
!this.existsSync(dirname) && mkdirSync(dirname)
|
|
8
|
-
}
|
|
6
|
+
exports.makeDir = (dirname) => {
|
|
7
|
+
!this.existsSync(dirname) && mkdirSync(dirname);
|
|
8
|
+
};
|
|
9
9
|
|
|
10
|
-
exports.existsSync = filePath => existsSync(filePath)
|
|
10
|
+
exports.existsSync = (filePath) => existsSync(filePath);
|
|
11
11
|
|
|
12
|
-
exports.readFile = filePath => {
|
|
13
|
-
if (!existsSync(filePath)) throw new Error('File does not exist')
|
|
14
|
-
return readFileSync(filePath, 'utf-8')
|
|
15
|
-
}
|
|
12
|
+
exports.readFile = (filePath) => {
|
|
13
|
+
if (!existsSync(filePath)) throw new Error('File does not exist');
|
|
14
|
+
return readFileSync(filePath, 'utf-8');
|
|
15
|
+
};
|
|
16
16
|
|
|
17
17
|
exports.readJSONFile = (filePath) => {
|
|
18
18
|
return new Promise((resolve, reject) => {
|
|
@@ -25,4 +25,4 @@ exports.readJSONFile = (filePath) => {
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
|
-
};
|
|
28
|
+
};
|
package/src/utils/get-batches.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
'use strict'
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports = (count, batchLimit) => {
|
|
4
|
-
const partitions = Math.ceil(count / batchLimit)
|
|
4
|
+
const partitions = Math.ceil(count / batchLimit);
|
|
5
5
|
// Returns array filled with indexes
|
|
6
|
-
return new Array(partitions).fill(null).map((_, i) => i)
|
|
7
|
-
}
|
|
6
|
+
return new Array(partitions).fill(null).map((_, i) => i);
|
|
7
|
+
};
|