@contentstack/cli-cm-import 1.5.10 → 1.6.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.
Files changed (110) hide show
  1. package/README.md +6 -14
  2. package/bin/dev +17 -0
  3. package/bin/dev.cmd +3 -0
  4. package/bin/run +6 -0
  5. package/bin/run.cmd +3 -0
  6. package/lib/commands/cm/stacks/import.d.ts +10 -0
  7. package/lib/commands/cm/stacks/import.js +111 -0
  8. package/lib/config/index.d.ts +3 -0
  9. package/lib/config/index.js +372 -0
  10. package/lib/import/index.d.ts +1 -0
  11. package/lib/import/index.js +8 -0
  12. package/lib/import/module-importer.d.ts +13 -0
  13. package/lib/import/module-importer.js +70 -0
  14. package/lib/import/modules/assets.d.ts +63 -0
  15. package/lib/import/modules/assets.js +265 -0
  16. package/lib/import/modules/base-class.d.ts +69 -0
  17. package/lib/import/modules/base-class.js +165 -0
  18. package/lib/import/modules/index.d.ts +2 -0
  19. package/lib/import/modules/index.js +19 -0
  20. package/lib/import/modules/locales.d.ts +31 -0
  21. package/lib/import/modules/locales.js +152 -0
  22. package/lib/import/modules-js/assets.d.ts +33 -0
  23. package/lib/import/modules-js/assets.js +415 -0
  24. package/lib/import/modules-js/content-types.d.ts +33 -0
  25. package/lib/import/modules-js/content-types.js +176 -0
  26. package/lib/import/modules-js/custom-roles.d.ts +15 -0
  27. package/lib/import/modules-js/custom-roles.js +141 -0
  28. package/lib/import/modules-js/entries.d.ts +54 -0
  29. package/lib/import/modules-js/entries.js +1260 -0
  30. package/lib/import/modules-js/environments.d.ts +13 -0
  31. package/lib/import/modules-js/environments.js +85 -0
  32. package/lib/import/modules-js/extensions.d.ts +17 -0
  33. package/lib/import/modules-js/extensions.js +86 -0
  34. package/lib/import/modules-js/global-fields.d.ts +13 -0
  35. package/lib/import/modules-js/global-fields.js +109 -0
  36. package/lib/import/modules-js/index.d.ts +1 -0
  37. package/lib/import/modules-js/index.js +33 -0
  38. package/lib/import/modules-js/labels.d.ts +20 -0
  39. package/lib/import/modules-js/labels.js +148 -0
  40. package/lib/import/modules-js/locales.d.ts +24 -0
  41. package/lib/import/modules-js/locales.js +196 -0
  42. package/lib/import/modules-js/marketplace-apps.d.ts +60 -0
  43. package/lib/import/modules-js/marketplace-apps.js +409 -0
  44. package/lib/import/modules-js/webhooks.d.ts +17 -0
  45. package/lib/import/modules-js/webhooks.js +85 -0
  46. package/lib/import/modules-js/workflows.d.ts +18 -0
  47. package/lib/import/modules-js/workflows.js +132 -0
  48. package/lib/types/default-config.d.ts +130 -0
  49. package/lib/types/default-config.js +2 -0
  50. package/lib/types/import-config.d.ts +51 -0
  51. package/lib/types/import-config.js +2 -0
  52. package/lib/types/index.d.ts +30 -0
  53. package/lib/types/index.js +2 -0
  54. package/lib/utils/asset-helper.d.ts +4 -0
  55. package/lib/utils/asset-helper.js +387 -0
  56. package/lib/utils/backup-handler.d.ts +2 -0
  57. package/lib/utils/backup-handler.js +31 -0
  58. package/lib/utils/common-helper.d.ts +20 -0
  59. package/lib/utils/common-helper.js +244 -0
  60. package/lib/utils/content-type-helper.d.ts +49 -0
  61. package/lib/utils/content-type-helper.js +143 -0
  62. package/lib/utils/entries-helper.d.ts +4 -0
  63. package/lib/utils/entries-helper.js +252 -0
  64. package/lib/utils/extension-helper.d.ts +10 -0
  65. package/lib/utils/extension-helper.js +72 -0
  66. package/lib/utils/file-helper.d.ts +14 -0
  67. package/lib/utils/file-helper.js +140 -0
  68. package/lib/utils/import-config-handler.d.ts +3 -0
  69. package/lib/utils/import-config-handler.js +73 -0
  70. package/lib/utils/index.d.ts +12 -0
  71. package/lib/utils/index.js +29 -0
  72. package/lib/utils/interactive.d.ts +2 -0
  73. package/lib/utils/interactive.js +23 -0
  74. package/lib/utils/logger.d.ts +8 -0
  75. package/lib/utils/logger.js +154 -0
  76. package/lib/utils/login-handler.d.ts +8 -0
  77. package/lib/utils/login-handler.js +53 -0
  78. package/lib/utils/marketplace-app-helper.d.ts +4 -0
  79. package/lib/utils/marketplace-app-helper.js +31 -0
  80. package/messages/index.json +1 -7
  81. package/oclif.manifest.json +2 -2
  82. package/package.json +47 -21
  83. package/src/app.js +0 -217
  84. package/src/commands/cm/stacks/import.js +0 -161
  85. package/src/config/default.js +0 -352
  86. package/src/lib/import/assets.js +0 -495
  87. package/src/lib/import/content-types.js +0 -201
  88. package/src/lib/import/custom-roles.js +0 -169
  89. package/src/lib/import/entries.js +0 -1480
  90. package/src/lib/import/environments.js +0 -106
  91. package/src/lib/import/extensions.js +0 -108
  92. package/src/lib/import/global-fields.js +0 -135
  93. package/src/lib/import/labels.js +0 -175
  94. package/src/lib/import/locales.js +0 -216
  95. package/src/lib/import/marketplace-apps.js +0 -542
  96. package/src/lib/import/webhooks.js +0 -113
  97. package/src/lib/import/workflows.js +0 -166
  98. package/src/lib/util/extensionsUidReplace.js +0 -67
  99. package/src/lib/util/fs.js +0 -124
  100. package/src/lib/util/import-flags.js +0 -187
  101. package/src/lib/util/index.js +0 -222
  102. package/src/lib/util/log.js +0 -144
  103. package/src/lib/util/login.js +0 -58
  104. package/src/lib/util/lookupReplaceAssets.js +0 -366
  105. package/src/lib/util/lookupReplaceEntries.js +0 -250
  106. package/src/lib/util/marketplace-app-helper.js +0 -31
  107. package/src/lib/util/removeReferenceFields.js +0 -59
  108. package/src/lib/util/schemaTemplate.js +0 -38
  109. package/src/lib/util/supress-mandatory-fields.js +0 -34
  110. package/src/lib/util/upload.js +0 -56
@@ -0,0 +1,387 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lookupAssets = exports.uploadAssetHelper = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const bluebird_1 = tslib_1.__importDefault(require("bluebird"));
6
+ const url = tslib_1.__importStar(require("url"));
7
+ const path = tslib_1.__importStar(require("path"));
8
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
9
+ const debug = require('debug')('util:requests');
10
+ let _ = require('lodash');
11
+ let { marked } = require('marked');
12
+ let helper = require('./file-helper');
13
+ const MAX_RETRY_LIMIT = 5;
14
+ function validate(req) {
15
+ if (typeof req !== 'object') {
16
+ throw new Error(`Invalid params passed for request\n${JSON.stringify(arguments)}`);
17
+ }
18
+ }
19
+ const uploadAssetHelper = function (config, req, fsPath, RETRY) {
20
+ return new bluebird_1.default(function (resolve, reject) {
21
+ try {
22
+ (0, cli_utilities_1.managementSDKClient)(config)
23
+ .then((APIClient) => {
24
+ validate(req);
25
+ if (typeof RETRY !== 'number') {
26
+ RETRY = 1;
27
+ }
28
+ else if (RETRY > MAX_RETRY_LIMIT) {
29
+ return reject(new Error('Max retry limit exceeded!'));
30
+ }
31
+ req.upload = fsPath;
32
+ const stackAPIClient = APIClient.stack({
33
+ api_key: config.target_stack,
34
+ management_token: config.management_token,
35
+ });
36
+ stackAPIClient
37
+ .asset()
38
+ .create(req)
39
+ .then((response) => {
40
+ return resolve(response);
41
+ })
42
+ .catch((error) => {
43
+ return reject(error);
44
+ });
45
+ })
46
+ .catch(reject);
47
+ }
48
+ catch (error) {
49
+ debug(error);
50
+ return reject(error);
51
+ }
52
+ });
53
+ };
54
+ exports.uploadAssetHelper = uploadAssetHelper;
55
+ // get assets object
56
+ const lookupAssets = function (data, mappedAssetUids, mappedAssetUrls, assetUidMapperPath, installedExtensions) {
57
+ if (!_.has(data, 'entry') ||
58
+ !_.has(data, 'content_type') ||
59
+ !_.isPlainObject(mappedAssetUids) ||
60
+ !_.isPlainObject(mappedAssetUrls) ||
61
+ typeof assetUidMapperPath !== 'string') {
62
+ throw new Error('Invalid inputs for lookupAssets!');
63
+ }
64
+ let parent = [];
65
+ let assetUids = [];
66
+ let assetUrls = [];
67
+ let unmatchedUids = [];
68
+ let unmatchedUrls = [];
69
+ let matchedUids = [];
70
+ let matchedUrls = [];
71
+ let find = function (schema, entryToFind) {
72
+ for (let i = 0, _i = schema.length; i < _i; i++) {
73
+ if (schema[i].data_type === 'text' &&
74
+ schema[i].field_metadata &&
75
+ (schema[i].field_metadata.markdown || schema[i].field_metadata.rich_text_type)) {
76
+ parent.push(schema[i].uid);
77
+ findFileUrls(schema[i], entryToFind, assetUrls);
78
+ parent.pop();
79
+ }
80
+ if (schema[i].data_type === 'group' || schema[i].data_type === 'global_field') {
81
+ parent.push(schema[i].uid);
82
+ find(schema[i].schema, entryToFind);
83
+ parent.pop();
84
+ }
85
+ if (schema[i].data_type === 'blocks') {
86
+ for (let j = 0, _j = schema[i].blocks.length; j < _j; j++) {
87
+ if (schema[i].blocks[j].schema) {
88
+ parent.push(schema[i].uid);
89
+ parent.push(schema[i].blocks[j].uid);
90
+ find(schema[i].blocks[j].schema, entryToFind);
91
+ parent.pop();
92
+ parent.pop();
93
+ }
94
+ }
95
+ }
96
+ // added rich_text_type field check because some marketplace extensions also
97
+ // have data_type has json
98
+ if (schema[i].data_type === 'json' && schema[i].field_metadata.rich_text_type) {
99
+ parent.push(schema[i].uid);
100
+ // findFileUrls(schema[i], entry, assetUrls)
101
+ findAssetIdsFromJsonRte(data.entry, data.content_type.schema);
102
+ // maybe only one of these checks would be enough
103
+ parent.pop();
104
+ }
105
+ else if (schema[i].data_type === 'json' &&
106
+ schema[i].field_metadata.extension &&
107
+ schema[i].field_metadata.is_asset) {
108
+ findAssetIdsFromJsonCustomFields(data.entry, data.content_type.schema);
109
+ }
110
+ else if (schema[i].data_type === 'json' && schema[i].field_metadata.extension) {
111
+ if (installedExtensions && installedExtensions[schema[i].extension_uid]) {
112
+ schema[i].extension_uid = installedExtensions[schema[i].extension_uid];
113
+ }
114
+ }
115
+ }
116
+ };
117
+ function findAssetIdsFromJsonCustomFields(entryObj, ctSchema) {
118
+ ctSchema.map((row) => {
119
+ if (row.data_type === 'json') {
120
+ if (entryObj[row.uid] && row.field_metadata.extension && row.field_metadata.is_asset) {
121
+ if (installedExtensions && installedExtensions[row.extension_uid]) {
122
+ row.extension_uid = installedExtensions[row.extension_uid];
123
+ }
124
+ if (entryObj[row.uid].metadata && entryObj[row.uid].metadata.extension_uid) {
125
+ if (installedExtensions && installedExtensions[entryObj[row.uid].metadata.extension_uid]) {
126
+ entryObj[row.uid].metadata.extension_uid = installedExtensions[entryObj[row.uid].metadata.extension_uid];
127
+ }
128
+ }
129
+ }
130
+ }
131
+ return row;
132
+ });
133
+ }
134
+ function findAssetIdsFromJsonRte(entryObj, ctSchema) {
135
+ for (const element of ctSchema) {
136
+ switch (element.data_type) {
137
+ case 'blocks': {
138
+ if (entryObj[element.uid]) {
139
+ if (element.multiple) {
140
+ entryObj[element.uid].forEach((e) => {
141
+ let key = Object.keys(e).pop();
142
+ let subBlock = element.blocks.filter((block) => block.uid === key).pop();
143
+ findAssetIdsFromJsonRte(e[key], subBlock.schema);
144
+ });
145
+ }
146
+ }
147
+ break;
148
+ }
149
+ case 'global_field':
150
+ case 'group': {
151
+ if (entryObj[element.uid]) {
152
+ if (element.multiple) {
153
+ entryObj[element.uid].forEach((e) => {
154
+ findAssetIdsFromJsonRte(e, element.schema);
155
+ });
156
+ }
157
+ else {
158
+ findAssetIdsFromJsonRte(entryObj[element.uid], element.schema);
159
+ }
160
+ }
161
+ break;
162
+ }
163
+ case 'json': {
164
+ if (entryObj[element.uid] && element.field_metadata.rich_text_type) {
165
+ if (element.multiple) {
166
+ entryObj[element.uid].forEach((jsonRteData) => {
167
+ gatherJsonRteAssetIds(jsonRteData);
168
+ });
169
+ }
170
+ else {
171
+ gatherJsonRteAssetIds(entryObj[element.uid]);
172
+ }
173
+ }
174
+ break;
175
+ }
176
+ }
177
+ }
178
+ }
179
+ function gatherJsonRteAssetIds(jsonRteData) {
180
+ jsonRteData.children.forEach((element) => {
181
+ if (element.type) {
182
+ switch (element.type) {
183
+ case 'a':
184
+ case 'p': {
185
+ if (element.children && element.children.length > 0) {
186
+ gatherJsonRteAssetIds(element);
187
+ }
188
+ break;
189
+ }
190
+ case 'reference': {
191
+ if (Object.keys(element.attrs).length > 0 && element.attrs.type === 'asset') {
192
+ if (assetUids.indexOf(element.attrs['asset-uid']) === -1) {
193
+ assetUids.push(element.attrs['asset-uid']);
194
+ }
195
+ // assets references inserted as link inside entry reference inserted as link did not have asset-link property
196
+ // instead it had an 'href' property. I haven't seen 'asset-link' and 'href' together yet
197
+ // writing this condition assuming that this never occurs, need to confirm
198
+ // (element.attrs['asset-link']) ? assetUrls.push(element.attrs['asset-link']) : assetUrls.push(element.attrs['asset-link'])
199
+ if (element.attrs['asset-link']) {
200
+ if (assetUrls.indexOf(element.attrs['asset-link']) === -1) {
201
+ assetUrls.push(element.attrs['asset-link']);
202
+ }
203
+ }
204
+ else if (element.attrs['href']) {
205
+ if (assetUrls.indexOf(element.attrs['href']) === -1) {
206
+ assetUrls.push(element.attrs['href']);
207
+ }
208
+ }
209
+ }
210
+ if (element.children && element.children.length > 0) {
211
+ gatherJsonRteAssetIds(element);
212
+ }
213
+ break;
214
+ }
215
+ }
216
+ }
217
+ });
218
+ }
219
+ find(data.content_type.schema, data.entry);
220
+ updateFileFields(data.entry, data, null, mappedAssetUids, matchedUids, unmatchedUids, mappedAssetUrls);
221
+ assetUids = _.uniq(assetUids);
222
+ assetUrls = _.uniq(assetUrls);
223
+ let entry = JSON.stringify(data.entry);
224
+ assetUrls.forEach(function (assetUrl) {
225
+ let mappedAssetUrl = mappedAssetUrls[assetUrl];
226
+ if (typeof mappedAssetUrl !== 'undefined') {
227
+ entry = entry.replace(new RegExp(assetUrl, 'img'), mappedAssetUrl);
228
+ matchedUrls.push(mappedAssetUrl);
229
+ }
230
+ else {
231
+ unmatchedUrls.push(assetUrl);
232
+ }
233
+ });
234
+ assetUids.forEach(function (assetUid) {
235
+ let uid = mappedAssetUids[assetUid];
236
+ if (typeof uid !== 'undefined') {
237
+ entry = entry.replace(new RegExp(assetUid, 'img'), uid);
238
+ matchedUids.push(assetUid);
239
+ }
240
+ else {
241
+ unmatchedUids.push(assetUid);
242
+ }
243
+ });
244
+ if (matchedUids.length) {
245
+ let matchedAssetUids = helper.readFileSync(path.join(assetUidMapperPath, 'matched-asset-uids.json'));
246
+ matchedAssetUids = matchedAssetUids || {};
247
+ if (matchedAssetUids.hasOwnProperty(data.content_type.uid)) {
248
+ matchedAssetUids[data.content_type.uid][data.entry.uid] = matchedUids;
249
+ }
250
+ else {
251
+ matchedAssetUids[data.content_type.uid] = {
252
+ [data.entry.uid]: matchedUids,
253
+ };
254
+ }
255
+ if (!helper.fileExistsSync(path.join(assetUidMapperPath, 'matched-asset-uids.json'))) {
256
+ helper.writeFile(path.join(assetUidMapperPath, 'matched-asset-uids.json'));
257
+ }
258
+ }
259
+ if (unmatchedUids.length) {
260
+ let unmatchedAssetUids = helper.readFileSync(path.join(assetUidMapperPath, 'unmatched-asset-uids.json'));
261
+ unmatchedAssetUids = unmatchedAssetUids || {};
262
+ if (unmatchedAssetUids.hasOwnProperty(data.content_type.uid)) {
263
+ unmatchedAssetUids[data.content_type.uid][data.entry.uid] = unmatchedUids;
264
+ }
265
+ else {
266
+ unmatchedAssetUids[data.content_type.uid] = {
267
+ [data.entry.uid]: unmatchedUids,
268
+ };
269
+ }
270
+ helper.writeFile(path.join(assetUidMapperPath, 'unmatched-asset-uids.json'));
271
+ }
272
+ if (unmatchedUrls.length) {
273
+ let unmatchedAssetUrls = helper.readFileSync(path.join(assetUidMapperPath, 'unmatched-asset-urls.json'));
274
+ unmatchedAssetUrls = unmatchedAssetUrls || {};
275
+ if (unmatchedAssetUrls.hasOwnProperty(data.content_type.uid)) {
276
+ unmatchedAssetUrls[data.content_type.uid][data.entry.uid] = unmatchedUrls;
277
+ }
278
+ else {
279
+ unmatchedAssetUrls[data.content_type.uid] = {
280
+ [data.entry.uid]: unmatchedUrls,
281
+ };
282
+ }
283
+ helper.writeFile(path.join(assetUidMapperPath, 'unmatched-asset-urls.json'));
284
+ }
285
+ if (matchedUrls.length) {
286
+ let matchedAssetUrls = helper.readFileSync(path.join(assetUidMapperPath, 'matched-asset-urls.json'));
287
+ matchedAssetUrls = matchedAssetUrls || {};
288
+ if (matchedAssetUrls.hasOwnProperty(data.content_type.uid)) {
289
+ matchedAssetUrls[data.content_type.uid][data.entry.uid] = matchedUrls;
290
+ }
291
+ else {
292
+ matchedAssetUrls[data.content_type.uid] = {
293
+ [data.entry.uid]: matchedUrls,
294
+ };
295
+ }
296
+ helper.writeFile(path.join(assetUidMapperPath, 'matched-asset-urls.json'));
297
+ }
298
+ return JSON.parse(entry);
299
+ };
300
+ exports.lookupAssets = lookupAssets;
301
+ function findFileUrls(schema, _entry, assetUrls) {
302
+ let markdownRegEx;
303
+ let markdownMatch;
304
+ // Regex to detect v2 asset uri patterns
305
+ let _matches, regex;
306
+ if (schema && schema.field_metadata && schema.field_metadata.markdown) {
307
+ regex = new RegExp(
308
+ // eslint-disable-next-line no-control-regex
309
+ 'https://(contentstack-|)api.(built|contentstack).io/(.*?)/download(.*?)uid=([a-z0-9]+[^?&s\n])((.*)[\ns]?)', 'g');
310
+ }
311
+ else {
312
+ regex = new RegExp('https://(contentstack-|)api.(built|contentstack).io/(.*?)/download(.*?)uid=([a-z0-9]+[^?&\'"])(.*?)', 'g');
313
+ }
314
+ while ((_matches = regex.exec(_entry)) !== null) {
315
+ if (_matches && _matches.length) {
316
+ if (_matches[0]) {
317
+ assetUrls.push(url.parse(_matches[0]).pathname.split('/').slice(1).join('/'));
318
+ }
319
+ }
320
+ }
321
+ let text;
322
+ // Regex to detect v3 asset uri patterns
323
+ if (schema && schema.field_metadata && schema.field_metadata.markdown) {
324
+ text = marked(JSON.stringify(_entry));
325
+ }
326
+ else {
327
+ text = JSON.stringify(_entry);
328
+ }
329
+ markdownRegEx = new RegExp('(https://(assets|(eu-|azure-na-|azure-eu-)?images).contentstack.(io|com)/v3/assets/(.*?)/(.*?)/(.*?)/(.*?)(?="))', 'g');
330
+ while ((markdownMatch = markdownRegEx.exec(text)) !== null) {
331
+ if (markdownMatch && typeof markdownMatch[0] === 'string') {
332
+ assetUrls.push(markdownMatch[0]);
333
+ }
334
+ }
335
+ }
336
+ function updateFileFields(objekt, parent, pos, mappedAssetUids, matchedUids, unmatchedUids, mappedAssetUrls) {
337
+ if (_.isPlainObject(objekt) && _.has(objekt, 'filename') && _.has(objekt, 'uid')) {
338
+ if (typeof pos !== 'undefined') {
339
+ if (typeof pos === 'number' || typeof pos === 'string') {
340
+ const replacer = () => {
341
+ if (mappedAssetUids.hasOwnProperty(objekt.uid)) {
342
+ parent[pos] = mappedAssetUids[objekt.uid];
343
+ matchedUids.push(objekt.uid);
344
+ }
345
+ else {
346
+ parent[pos] = '';
347
+ unmatchedUids.push(objekt.uid);
348
+ }
349
+ };
350
+ if (parent.uid && mappedAssetUids[parent.uid]) {
351
+ parent.uid = mappedAssetUids[parent.uid];
352
+ }
353
+ if (objekt &&
354
+ _.isObject(parent[pos]) &&
355
+ parent[pos].uid &&
356
+ parent[pos].url &&
357
+ _.has(parent, 'asset') &&
358
+ _.has(parent, '_content_type_uid') &&
359
+ parent._content_type_uid === 'sys_assets') {
360
+ if (_.has(parent, 'asset') &&
361
+ _.has(parent, '_content_type_uid') &&
362
+ parent._content_type_uid === 'sys_assets') {
363
+ parent = _.omit(parent, ['asset']);
364
+ }
365
+ if (objekt.uid && mappedAssetUids && mappedAssetUids[objekt.uid]) {
366
+ objekt.uid = mappedAssetUids[objekt.uid];
367
+ }
368
+ if (objekt.url && mappedAssetUrls && mappedAssetUrls[objekt.url]) {
369
+ objekt.url = mappedAssetUrls[objekt.url];
370
+ }
371
+ }
372
+ else {
373
+ replacer();
374
+ }
375
+ }
376
+ }
377
+ }
378
+ else if (_.isPlainObject(objekt)) {
379
+ for (let key in objekt)
380
+ updateFileFields(objekt[key], objekt, key, mappedAssetUids, matchedUids, unmatchedUids);
381
+ }
382
+ else if (_.isArray(objekt) && objekt.length) {
383
+ for (let i = 0; i <= objekt.length; i++)
384
+ updateFileFields(objekt[i], objekt, i, mappedAssetUids, matchedUids, unmatchedUids);
385
+ parent[pos] = _.compact(objekt);
386
+ }
387
+ }
@@ -0,0 +1,2 @@
1
+ import { ImportConfig } from '../types';
2
+ export default function setupBackupDir(importConfig: ImportConfig): Promise<string>;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const path = tslib_1.__importStar(require("path"));
5
+ const ncp_1 = tslib_1.__importDefault(require("ncp"));
6
+ function setupBackupDir(importConfig) {
7
+ return new Promise(async (resolve, reject) => {
8
+ if (importConfig.hasOwnProperty('useBackedupDir')) {
9
+ return resolve(importConfig.useBackedupDir);
10
+ }
11
+ const backupDirPath = path.join(process.cwd(), '_backup_' + Math.floor(Math.random() * 1000));
12
+ const limit = importConfig.backupConcurrency || 16;
13
+ if (path.isAbsolute(importConfig.contentDir)) {
14
+ return (0, ncp_1.default)(importConfig.contentDir, backupDirPath, { limit }, (error) => {
15
+ if (error) {
16
+ return reject(error);
17
+ }
18
+ return resolve(backupDirPath);
19
+ });
20
+ }
21
+ else {
22
+ (0, ncp_1.default)(importConfig.contentDir, backupDirPath, (error) => {
23
+ if (error) {
24
+ return reject(error);
25
+ }
26
+ return resolve(backupDirPath);
27
+ });
28
+ }
29
+ });
30
+ }
31
+ exports.default = setupBackupDir;
@@ -0,0 +1,20 @@
1
+ /*!
2
+ * Contentstack Import
3
+ * Copyright (c) 2019 Contentstack LLC
4
+ * MIT Licensed
5
+ */
6
+ import { ImportConfig } from '../types';
7
+ export declare const initialization: (configData: ImportConfig) => ImportConfig;
8
+ export declare const validateConfig: (importConfig: ImportConfig) => string;
9
+ export declare const buildAppConfig: (importConfig: ImportConfig) => ImportConfig;
10
+ export declare const sanitizeStack: (importConfig: ImportConfig) => Promise<void>;
11
+ export declare const masterLocalDetails: (stackAPIClient: any) => Promise<{
12
+ code: string;
13
+ }>;
14
+ export declare const field_rules_update: (importConfig: ImportConfig, ctPath: string) => Promise<unknown>;
15
+ export declare const getConfig: () => ImportConfig;
16
+ export declare const formatError: (error: any) => any;
17
+ export declare const executeTask: (tasks: unknown[], handler: (task: unknown) => Promise<unknown>, options: {
18
+ concurrency: number;
19
+ }) => Promise<unknown[]>;
20
+ export declare const validateBranch: (stackAPIClient: any, config: ImportConfig, branch: any) => Promise<unknown>;