@contentstack/cli-migration 2.0.0-beta.2 → 2.0.0-beta.4

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 (47) hide show
  1. package/README.md +51 -4
  2. package/package.json +20 -13
  3. package/src/actions/action-list.js +0 -32
  4. package/src/actions/index.js +0 -217
  5. package/src/commands/cm/stacks/migration.js +0 -283
  6. package/src/config/api-config.js +0 -18
  7. package/src/config/default-options.js +0 -7
  8. package/src/config/index.js +0 -7
  9. package/src/config/master-locale.js +0 -10
  10. package/src/modules/base.js +0 -95
  11. package/src/modules/content-types.js +0 -208
  12. package/src/modules/fields.js +0 -340
  13. package/src/modules/index.js +0 -8
  14. package/src/modules/locale.js +0 -33
  15. package/src/modules/migration.js +0 -112
  16. package/src/modules/parser.js +0 -105
  17. package/src/services/content-types.js +0 -317
  18. package/src/services/index.js +0 -6
  19. package/src/services/locales.js +0 -71
  20. package/src/utils/auto-retry.js +0 -32
  21. package/src/utils/callsite.js +0 -23
  22. package/src/utils/constants.js +0 -223
  23. package/src/utils/contentstack-sdk.js +0 -70
  24. package/src/utils/error-helper.js +0 -105
  25. package/src/utils/fs-helper.js +0 -29
  26. package/src/utils/get-batches.js +0 -7
  27. package/src/utils/get-config.js +0 -13
  28. package/src/utils/group-by.js +0 -38
  29. package/src/utils/index.js +0 -21
  30. package/src/utils/logger.js +0 -75
  31. package/src/utils/map.js +0 -40
  32. package/src/utils/migration-logger.js +0 -21
  33. package/src/utils/modules.js +0 -134
  34. package/src/utils/object-helper.js +0 -9
  35. package/src/utils/request.js +0 -95
  36. package/src/utils/safe-promise.js +0 -3
  37. package/src/utils/schema-helper.js +0 -35
  38. package/src/utils/success-handler.js +0 -12
  39. package/src/validators/api-error.js +0 -20
  40. package/src/validators/base-validator.js +0 -39
  41. package/src/validators/create-content-type-validator.js +0 -54
  42. package/src/validators/edit-content-type-validator.js +0 -53
  43. package/src/validators/field-validator.js +0 -21
  44. package/src/validators/index.js +0 -11
  45. package/src/validators/migration-error.js +0 -20
  46. package/src/validators/schema-validator.js +0 -23
  47. package/src/validators/type-error.js +0 -22
@@ -1,33 +0,0 @@
1
- 'use strict';
2
-
3
- // Service
4
- const { LocaleService } = require('../services');
5
-
6
- // Config
7
- const { masterLocale } = require('../config');
8
-
9
- // Utils
10
- const { safePromise } = require('../utils');
11
-
12
- class Locale {
13
- constructor() {
14
- this.localeService = new LocaleService();
15
- }
16
-
17
- async fetchLocales(callback) {
18
- let { master_locale } = masterLocale;
19
-
20
- let { localeService } = this;
21
- let [err, result] = await safePromise(localeService.getLocale());
22
-
23
- if (err) throw new Error(err);
24
-
25
- // Use default code, if no result is found
26
- result = result.length ? result : [master_locale];
27
-
28
- if (callback) return callback(null, result);
29
- return result;
30
- }
31
- }
32
-
33
- module.exports = Locale;
@@ -1,112 +0,0 @@
1
- 'use strict';
2
-
3
- const { map: _map, getCallsite, constants, safePromise } = require('../utils');
4
- const Listr = require('listr');
5
- const { waterfall } = require('async');
6
- const { requests } = constants;
7
-
8
- // Properties
9
- const { getMapInstance, set, get } = _map;
10
-
11
- const ContentType = require('./content-types');
12
-
13
- // Merge all classes containing migration methods into a single class
14
- const _Migration = (_Class) => class extends _Class {};
15
-
16
- /**
17
- * Migration class
18
- * @class Migration
19
- */
20
- class Migration extends _Migration(ContentType) {
21
- /**
22
- * Adds custom task in migration to execute.
23
- * @param {Object} taskDescription Task title and task function to execute
24
- * @param {string} taskDescription.title Title for custom task
25
- * @param {array} taskDescription.task async function to be executed
26
- * @param {string} taskDescription.failMessage message to be printed when task fails
27
- * @param {string} taskDescription.successMessage message to be printed when task succeeds
28
- * @example
29
- *
30
- * let first = 'binding glue'
31
- * let second = 'second glue'
32
- * let tasks = {
33
- * title:'My First custom task',
34
- * successMessage: 'Custom success message',
35
- * failMessage: 'Custom fail message'
36
- * task: async (params)=>{
37
- * const {first, second} = params
38
- * const a = await stackSDKInstance.fetch();
39
- * },
40
- * }
41
- * migration.addTask(task)
42
- */
43
- addTask(taskDescription) {
44
- const { title, failMessage, successMessage } = taskDescription;
45
- let { tasks, task } = taskDescription;
46
- const callsite = getCallsite();
47
- const mapInstance = getMapInstance();
48
- // eslint-disable-next-line no-warning-comments
49
- // TODO: Make it better to accept only single task
50
- if (tasks && !Array.isArray(tasks)) tasks = [tasks];
51
- if (task && !Array.isArray(task)) {
52
- tasks = [task];
53
- }
54
- this.contentTypeService.base.dispatch(callsite, null, null, tasks);
55
- let _requests = get(requests, mapInstance);
56
- const req = {
57
- title: title,
58
- failedTitle: failMessage || `Failed to execute task: ${title}`,
59
- successTitle: successMessage || `Successfully executed task: ${title}`,
60
- tasks,
61
- };
62
- _requests.push(req);
63
- set(requests, mapInstance, _requests);
64
- }
65
-
66
- async run() {
67
- const mapInstance = getMapInstance();
68
- let _requests = get(requests, mapInstance);
69
- // Make calls from here
70
- const tasks = await this.getTasks(_requests);
71
- const listr = new Listr(tasks);
72
- await listr.run().catch((error) => {
73
- this.handleErrors(error);
74
- // When the process is child, send error message to parent
75
- if (process.send) process.send({ errorOccurred: true });
76
- });
77
- }
78
-
79
- async getTasks(_requests) {
80
- const _tasks = [];
81
- const results = [];
82
- const taskFn = (reqObj) => {
83
- const { failedTitle, successTitle, tasks } = reqObj;
84
-
85
- return async (ctx, _task) => {
86
- const [err, result] = await safePromise(waterfall(tasks));
87
- if (err) {
88
- ctx.error = true;
89
- _task.title = failedTitle;
90
- throw err;
91
- }
92
- result && results.push(result);
93
- _task.title = successTitle;
94
- return result;
95
- }
96
- }
97
-
98
- for (const element of _requests) {
99
- let reqObj = element;
100
- const { title } = reqObj;
101
- const task = {
102
- title: title,
103
- task: taskFn(reqObj)
104
- };
105
- _tasks.push(task);
106
- }
107
-
108
- return _tasks;
109
- }
110
- }
111
-
112
- module.exports = Migration;
@@ -1,105 +0,0 @@
1
- 'use strict';
2
-
3
- const Migration = require('./migration');
4
-
5
- const { CreateContentTypeValidator, EditContentTypeValidator, _TypeError, FieldValidator } = require('../validators');
6
- // eslint-disable-next-line no-warning-comments
7
- // TODO: Need a better way to combine classes
8
- const Base = require('./base');
9
-
10
- const { ActionList } = require('../actions');
11
- // Utils
12
- const { map: _map, constants, fsHelper } = require('../utils');
13
- // map properties
14
- const { getMapInstance, get } = _map;
15
- // Constants
16
- const {
17
- actionMapper,
18
- MANAGEMENT_SDK,
19
- MANAGEMENT_TOKEN,
20
- AUTH_TOKEN,
21
- API_KEY,
22
- BRANCH,
23
- MANAGEMENT_CLIENT,
24
- SOURCE_BRANCH,
25
- } = constants;
26
-
27
- class Parser {
28
- async getMigrationParser(migrationFunc) {
29
- const migration = new Migration();
30
- const mapInstance = getMapInstance();
31
- const parseResult = {};
32
- let typeErrors = [];
33
- // migrations
34
- try {
35
- const stackSDKInstance = get(MANAGEMENT_SDK, mapInstance);
36
- const managementToken = get(MANAGEMENT_TOKEN, mapInstance);
37
- const authToken = get(AUTH_TOKEN, mapInstance);
38
- const apiKey = get(API_KEY, mapInstance);
39
- const branch = get(BRANCH, mapInstance);
40
- const managementAPIClient = get(MANAGEMENT_CLIENT, mapInstance);
41
- const externalConfigPath = get('config-path', mapInstance);
42
- const externalConfig = get('config', mapInstance);
43
- let externalFileConfig;
44
- if (typeof externalConfigPath == 'string') {
45
- externalFileConfig = await fsHelper.readJSONFile(externalConfigPath);
46
- }
47
- const config = Object.assign({}, externalFileConfig, externalConfig);
48
- await migrationFunc({
49
- migration,
50
- stackSDKInstance,
51
- managementAPIClient,
52
- managementToken,
53
- authToken,
54
- apiKey,
55
- branch,
56
- config,
57
- });
58
- } catch (error) {
59
- if (error instanceof TypeError) {
60
- if (error.message.includes('is not a function')) {
61
- const base = new Base();
62
- // eslint-disable-next-line
63
- const [, filename, line] = error.stack.match(/\/([\/\w-_\.]+\.js):(\d*):(\d*)/);
64
- const callsite = {
65
- getFileName: () => `/${filename}`,
66
- getLineNumber: () => line,
67
- };
68
- const errMsgString = error.message.split(' ');
69
- const typeErrorFirstStr = errMsgString[0].split('.');
70
- const typeErrorFunction = typeErrorFirstStr[typeErrorFirstStr.length - 1];
71
- typeErrors.push(typeErrorFunction);
72
- base.dispatch(callsite, null, { typeErrors }, 'typeError');
73
- }
74
- } else {
75
- console.log('Error', error);
76
- // eslint-disable-next-line
77
- const [, filename, line] = error.stack.match(/\/([\/\w-_\.]+\.js):(\d*):(\d*)/);
78
- const callsite = {
79
- getFileName: () => `/${filename}`,
80
- getLineNumber: () => line,
81
- };
82
- const base = new Base();
83
- typeErrors = [error];
84
- base.dispatch(callsite, null, { typeErrors }, 'typeError');
85
- }
86
- }
87
- const actions = get(actionMapper, mapInstance);
88
- const actionList = new ActionList(actions);
89
-
90
- actionList.addValidators(new CreateContentTypeValidator());
91
- actionList.addValidators(new FieldValidator());
92
- actionList.addValidators(new _TypeError());
93
- actionList.addValidators(new EditContentTypeValidator());
94
-
95
- const hasErrors = actionList.validate();
96
-
97
- if (hasErrors.length > 0) {
98
- parseResult.hasErrors = hasErrors;
99
- return parseResult;
100
- }
101
- return parseResult;
102
- }
103
- }
104
-
105
- module.exports = Parser;
@@ -1,317 +0,0 @@
1
- /* eslint-disable unicorn/explicit-length-check */
2
- /* eslint-disable no-unused-expressions */
3
- 'use strict';
4
-
5
- const Base = require('../modules/base');
6
- // Utils
7
- const { map: _map, safePromise, successHandler, errorHandler, constants, errorHelper } = require('../utils');
8
- // Map methods
9
- const { get, getMapInstance, getDataWithAction } = _map;
10
- const mapInstance = getMapInstance();
11
- const { ContentType, MANAGEMENT_SDK, actions: _actions } = constants;
12
-
13
- class ContentTypeService {
14
- constructor() {
15
- // Stores actions required for moveField function
16
- this.moveFieldActions = [];
17
- this.base = new Base();
18
- this.stackSDKInstance = get(MANAGEMENT_SDK, mapInstance);
19
- }
20
-
21
- async fetchContentType(callsite, id) {
22
- const method = 'GET';
23
-
24
- const [err, result] = await safePromise(this.stackSDKInstance.contentType(id).fetch());
25
- if (err) {
26
- errorHelper(err);
27
- this.base.dispatch(callsite, id, err, 'apiError');
28
- throw err;
29
- }
30
- successHandler(id, ContentType, method);
31
-
32
- return result || {};
33
- }
34
-
35
- async postContentTypes(callsite, id, action) {
36
- const data = getDataWithAction(id, mapInstance, action);
37
- const [err, result] = await safePromise(this.stackSDKInstance.contentType().create(data));
38
- if (err) {
39
- errorHelper(err);
40
- this.base.dispatch(callsite, id, err, 'apiError');
41
- throw err;
42
- }
43
-
44
- successHandler(id, ContentType, 'POST');
45
- return result.content_type || {};
46
- }
47
-
48
- async editContentType(callsite, data) {
49
- const d = getDataWithAction(data.uid, mapInstance, _actions.EDIT_CT);
50
- data = { ...data, ...d.content_type };
51
- const method = 'PUT';
52
- const [err, result] = await safePromise(data.update());
53
- if (err) {
54
- errorHelper(err);
55
- this.base.dispatch(callsite, data.uid, err, 'apiError');
56
- throw err;
57
- }
58
-
59
- successHandler(data.uid, ContentType, method);
60
- return result.content_type || {};
61
- }
62
-
63
- async deleteContentType(callsite) {
64
- const { id } = this;
65
- const method = 'DELETE';
66
- const [err, result] = await safePromise(this.stackSDKInstance.contentType(id).delete());
67
-
68
- if (err) {
69
- errorHelper(err);
70
- this.base.dispatch(callsite, id, err, 'apiError');
71
- throw err;
72
- }
73
- successHandler(id, ContentType, method);
74
- return result.content_type || {};
75
- }
76
-
77
- applyActionsOnFields(callsite, data, cb) {
78
- const { schema } = data;
79
- const { moveFieldActions, mergeEditSchema } = this;
80
- let i = 0;
81
- let finalSchema;
82
- try {
83
- finalSchema = mergeEditSchema.call(this, schema);
84
- } catch (error) {
85
- this.base.dispatch(callsite, null, error, 'field');
86
- // Call the callback with error
87
- if (typeof cb === 'function') return cb(error);
88
- }
89
- data.schema = finalSchema;
90
- // Handle for no move field action required
91
- if (!moveFieldActions.length) return cb(null, data);
92
- // eslint-disable-next-line
93
- while (true) {
94
- /** VALIDATIONS */
95
- const validResult = this.getValidated(finalSchema, moveFieldActions[i]);
96
- if (!validResult.isValid) {
97
- const error = { message: `${validResult.missingField} does not exist in schema.` };
98
- this.base.dispatch(callsite, null, error, 'field');
99
- // Call the callback with error
100
- if (typeof cb === 'function') return cb(error);
101
- }
102
-
103
- finalSchema = this[moveFieldActions[i].action](finalSchema, moveFieldActions[i]);
104
- i++;
105
- if (!moveFieldActions[i]) break;
106
- }
107
- data.schema = finalSchema;
108
- if (cb) return cb(null, data);
109
- return data;
110
- }
111
-
112
- getActions(action) {
113
- this.moveFieldActions.push(action);
114
- }
115
-
116
- // Sets id and action for this instance
117
- setIdAndAction(id, action) {
118
- this.id = id;
119
- this.action = action;
120
- }
121
-
122
- // Merges the user specified with new fields with existing schema
123
- mergeEditSchema(schema = []) {
124
- const _mapInstance = getMapInstance();
125
-
126
- const { id, action } = this;
127
-
128
- const contentType = get(id, _mapInstance);
129
-
130
- let contentTypeSchema = contentType[action].content_type.schema;
131
- contentTypeSchema = contentTypeSchema || [];
132
-
133
- const indicesToRemoveFromNewSchema = [];
134
- const indicesToRemoveFromOldSchema = [];
135
-
136
- let isEditFieldValid = false;
137
- let isEditFieldPresent = false;
138
- let isDeleteFieldValid = false;
139
- let isDeleteFieldPresent = false;
140
- let fieldToRaiseExceptionAgainst;
141
-
142
- if (contentTypeSchema.length > 0 && schema.length > 0) {
143
- // If found a updated field replace the new field with the existing field
144
- contentTypeSchema.forEach((newSchema, i) => {
145
- schema.every((oldSchema, j) => {
146
- /** VALIDATIONS */
147
- if (newSchema.isEdit) {
148
- isEditFieldPresent = true;
149
- fieldToRaiseExceptionAgainst = newSchema.uid;
150
- newSchema.uid === oldSchema.uid && (isEditFieldValid = true);
151
- }
152
-
153
- if (newSchema.isDelete) {
154
- isDeleteFieldPresent = true;
155
- fieldToRaiseExceptionAgainst = newSchema.uid;
156
-
157
- newSchema.uid === oldSchema.uid && (isDeleteFieldValid = true);
158
- }
159
- /** VALIDATIONS ENDS */
160
-
161
- if (newSchema.uid === oldSchema.uid) {
162
- let tempObj = newSchema;
163
- indicesToRemoveFromNewSchema.push(i);
164
- // Handle delete action here
165
- if (newSchema.isDelete) {
166
- indicesToRemoveFromOldSchema.push(j);
167
- } else {
168
- schema.splice(j, 1, tempObj); // Replace the new schema with old schema
169
- }
170
- // break
171
- return false;
172
- }
173
- // continue
174
- return true;
175
- });
176
- });
177
- }
178
-
179
- // Raise exception if any of the following conditions are true
180
- if ((isEditFieldPresent && !isEditFieldValid) || (isDeleteFieldPresent && !isDeleteFieldValid)) {
181
- throw { message: `${fieldToRaiseExceptionAgainst} does not exist in the schema. Please check again` };
182
- }
183
-
184
- contentTypeSchema = contentTypeSchema.filter((_, i) => !indicesToRemoveFromNewSchema.includes(i));
185
-
186
- schema = schema.filter((_, i) => !indicesToRemoveFromOldSchema.includes(i));
187
-
188
- schema = schema.concat(contentTypeSchema);
189
- contentType[action].content_type.schema = schema;
190
- return schema;
191
- }
192
-
193
- toTheTop(schema, actionObj) {
194
- const { fieldToMove } = actionObj;
195
- let i = 0;
196
- // eslint-disable-next-line
197
- while (true) {
198
- if (schema[i].uid === fieldToMove) {
199
- let tempObj = schema[i];
200
- schema.splice(i, 1);
201
- schema.unshift(tempObj);
202
- break;
203
- }
204
- i++;
205
- if (!schema[i]) break; // Error handling required
206
- }
207
- return schema;
208
- }
209
-
210
- toTheBottom(schema, actionObj) {
211
- const { fieldToMove } = actionObj;
212
-
213
- let i = 0;
214
- // eslint-disable-next-line
215
- while (true) {
216
- if (schema[i].uid === fieldToMove) {
217
- let tempObj = schema[i];
218
- schema.splice(i, 1);
219
- schema.push(tempObj);
220
- break;
221
- }
222
- i++;
223
- if (!schema[i]) break;
224
- }
225
- return schema;
226
- }
227
-
228
- afterField(schema, actionObj) {
229
- const { fieldToMove, against } = actionObj;
230
- let i = 0;
231
- let indexToMove = 0;
232
- let tempObj;
233
- let found = 0;
234
- // eslint-disable-next-line
235
- while (true) {
236
- if (schema[i].uid === against) {
237
- indexToMove = i;
238
- found++;
239
- }
240
- if (schema[i].uid === fieldToMove) {
241
- tempObj = schema[i];
242
- schema.splice(i, 1);
243
- found++;
244
- }
245
- i++;
246
- if (found === 2) break;
247
- if (!schema[i]) break;
248
- }
249
- // TODO: Handle error
250
- found === 2 && schema.splice(indexToMove + 1, null, tempObj);
251
- return schema;
252
- }
253
-
254
- beforeField(schema, actionObj) {
255
- const { fieldToMove, against } = actionObj;
256
-
257
- let i = 0;
258
- let indexToMove = 0;
259
- let tempObj = 0;
260
- let found = 0;
261
- // eslint-disable-next-line
262
- while (true) {
263
- if (schema[i].uid === against) {
264
- indexToMove = i;
265
- found++;
266
- }
267
- if (schema[i].uid === fieldToMove) {
268
- tempObj = schema[i];
269
- schema.splice(i, 1);
270
- found++;
271
- }
272
- i++;
273
- if (found === 2) break;
274
- if (!schema[i]) break;
275
- }
276
- found === 2 && schema.splice(indexToMove, null, tempObj);
277
- return schema;
278
- }
279
-
280
- getValidated(schema, actionObj) {
281
- let isValid = true;
282
- let found = 0;
283
- let missingField = '';
284
- let i = 0;
285
-
286
- const { fieldToMove, against } = actionObj;
287
- const uids = [];
288
- // eslint-disable-next-line
289
- while (true) {
290
- uids.push(schema[i].uid);
291
-
292
- if (schema[i].uid === fieldToMove) {
293
- found++;
294
- }
295
- if (against === schema[i].uid) {
296
- found++;
297
- }
298
- i++;
299
- if (!schema[i]) break;
300
- }
301
- // TODO: Need a better way to handle this
302
- missingField = uids.includes(fieldToMove) ? null : fieldToMove;
303
-
304
- if (!missingField && against) {
305
- missingField = uids.includes(against) ? null : against;
306
- }
307
-
308
- // Handling both the scenarios
309
- if (found === 0 || (against && found === 1)) {
310
- isValid = false;
311
- }
312
-
313
- return { isValid, missingField };
314
- }
315
- }
316
-
317
- module.exports = ContentTypeService;
@@ -1,6 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- ContentTypeService: require('./content-types'),
5
- LocaleService: require('./locales'),
6
- };
@@ -1,71 +0,0 @@
1
- 'use strict';
2
-
3
- // Utils
4
- const { safePromise, constants, map: _map } = require('../utils');
5
- const { MANAGEMENT_SDK } = constants;
6
- const { get, getMapInstance } = _map;
7
- const mapInstance = getMapInstance();
8
-
9
- class LocaleService {
10
- constructor() {
11
- this.stackSDKInstance = get(MANAGEMENT_SDK, mapInstance);
12
- }
13
-
14
- async getLocale() {
15
- const [err, result] = await safePromise(this.stackSDKInstance.locale().query().find());
16
- if (err) throw err;
17
- let orderedResult = this.getOrderedResult(result);
18
- return orderedResult;
19
- }
20
-
21
- getOrderedResult(result) {
22
- if (result && result.items) {
23
- const locales = result.items;
24
-
25
- let i = 0;
26
- let noEventTookPlace = 0; // counter which tracks if the list is sorted by fallback language
27
- let len = locales.length;
28
-
29
- // Circular loop (Time complexity => Order of n^2, complexity of splice op is ignored)
30
- do {
31
- i = (i % len) + 1;
32
- noEventTookPlace++;
33
-
34
- let correctedI = i - 1;
35
-
36
- let a = locales[correctedI];
37
-
38
- if (a.fallback_locale) {
39
- let fallbackLangIndex = 0;
40
- let currentLangIndex = 0;
41
-
42
- for (let x = 0; x < len; x++) {
43
- if (locales[x].code === a.code) {
44
- currentLangIndex = x;
45
- }
46
- if (locales[x].code === a.fallback_locale) {
47
- fallbackLangIndex = x;
48
- }
49
- }
50
-
51
- // if index of fallback langauge is smaller no operation is required, it might be sorted
52
- if (currentLangIndex > fallbackLangIndex) {
53
- continue;
54
- }
55
- let temp = a;
56
- // remove the object
57
- locales.splice(correctedI, 1);
58
- // add the object at fallbackLangIndex cus size of locales is decremented
59
- locales.splice(fallbackLangIndex, 0, temp);
60
- i--;
61
- noEventTookPlace--;
62
- }
63
- } while (noEventTookPlace < len);
64
-
65
- return locales;
66
- }
67
- throw { message: 'Something went wrong.' };
68
- }
69
- }
70
-
71
- module.exports = LocaleService;
@@ -1,32 +0,0 @@
1
- 'use strict';
2
-
3
- const { MAX_RETRY } = require('./constants');
4
-
5
- const __safePromise = (promise, data) => {
6
- return promise(data)
7
- .then((res) => [null, res])
8
- .catch((err) => [err]);
9
- };
10
-
11
- async function autoRetry(promise, retryCount = 0) {
12
- /**
13
- * Entries functions needs to pass params directly to http object,
14
- * whereas for content types it fetches request params from global map object,
15
- * thus the handling
16
- */
17
- let data;
18
- this && (data = this.data);
19
-
20
- const [error, result] = await __safePromise(promise, data);
21
-
22
- if (error) {
23
- retryCount++;
24
- if (retryCount === MAX_RETRY) {
25
- throw error;
26
- }
27
- return await autoRetry(promise, retryCount);
28
- }
29
- return result;
30
- }
31
-
32
- module.exports = autoRetry;
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- const getCallsites = require('callsites');
4
- const { parse, resolve } = require('path');
5
- const { pathValidator, sanitizePath } = require('@contentstack/cli-utilities');
6
-
7
- function getFileDirectory(path) {
8
- const parentPath = pathValidator(resolve(sanitizePath(path), '../')); // Assuming that will be 2 folders up
9
- return parse(parentPath).dir;
10
- }
11
-
12
- module.exports = () => {
13
- const thisDir = getFileDirectory(__filename);
14
- const callsites = getCallsites();
15
-
16
- const externalFile = callsites.find((callsite) => {
17
- const currentDir = getFileDirectory(callsite.getFileName());
18
- const isNotThisDir = thisDir !== currentDir;
19
- return isNotThisDir;
20
- });
21
-
22
- return externalFile;
23
- };