@contentstack/cli-cm-import 1.5.11 → 1.7.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 (126) 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 +395 -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 +70 -0
  17. package/lib/import/modules/base-class.js +218 -0
  18. package/lib/import/modules/content-types.d.ts +56 -0
  19. package/lib/import/modules/content-types.js +186 -0
  20. package/lib/import/modules/custom-roles.d.ts +37 -0
  21. package/lib/import/modules/custom-roles.js +171 -0
  22. package/lib/import/modules/environments.d.ts +27 -0
  23. package/lib/import/modules/environments.js +106 -0
  24. package/lib/import/modules/extensions.d.ts +27 -0
  25. package/lib/import/modules/extensions.js +106 -0
  26. package/lib/import/modules/global-fields.d.ts +34 -0
  27. package/lib/import/modules/global-fields.js +99 -0
  28. package/lib/import/modules/index.d.ts +2 -0
  29. package/lib/import/modules/index.js +19 -0
  30. package/lib/import/modules/labels.d.ts +34 -0
  31. package/lib/import/modules/labels.js +171 -0
  32. package/lib/import/modules/locales.d.ts +31 -0
  33. package/lib/import/modules/locales.js +144 -0
  34. package/lib/import/modules/marketplace-apps.d.ts +51 -0
  35. package/lib/import/modules/marketplace-apps.js +297 -0
  36. package/lib/import/modules/webhooks.d.ts +27 -0
  37. package/lib/import/modules/webhooks.js +110 -0
  38. package/lib/import/modules-js/assets.d.ts +33 -0
  39. package/lib/import/modules-js/assets.js +415 -0
  40. package/lib/import/modules-js/content-types.d.ts +33 -0
  41. package/lib/import/modules-js/content-types.js +176 -0
  42. package/lib/import/modules-js/custom-roles.d.ts +15 -0
  43. package/lib/import/modules-js/custom-roles.js +143 -0
  44. package/lib/import/modules-js/entries.d.ts +54 -0
  45. package/lib/import/modules-js/entries.js +1260 -0
  46. package/lib/import/modules-js/environments.d.ts +13 -0
  47. package/lib/import/modules-js/environments.js +85 -0
  48. package/lib/import/modules-js/extensions.d.ts +18 -0
  49. package/lib/import/modules-js/extensions.js +86 -0
  50. package/lib/import/modules-js/global-fields.d.ts +13 -0
  51. package/lib/import/modules-js/global-fields.js +109 -0
  52. package/lib/import/modules-js/index.d.ts +1 -0
  53. package/lib/import/modules-js/index.js +33 -0
  54. package/lib/import/modules-js/labels.d.ts +20 -0
  55. package/lib/import/modules-js/labels.js +148 -0
  56. package/lib/import/modules-js/locales.d.ts +24 -0
  57. package/lib/import/modules-js/locales.js +196 -0
  58. package/lib/import/modules-js/marketplace-apps.d.ts +60 -0
  59. package/lib/import/modules-js/marketplace-apps.js +409 -0
  60. package/lib/import/modules-js/webhooks.d.ts +17 -0
  61. package/lib/import/modules-js/webhooks.js +85 -0
  62. package/lib/import/modules-js/workflows.d.ts +18 -0
  63. package/lib/import/modules-js/workflows.js +132 -0
  64. package/lib/types/default-config.d.ts +143 -0
  65. package/lib/types/default-config.js +2 -0
  66. package/lib/types/import-config.d.ts +52 -0
  67. package/lib/types/import-config.js +2 -0
  68. package/lib/types/index.d.ts +63 -0
  69. package/lib/types/index.js +4 -0
  70. package/lib/utils/asset-helper.d.ts +4 -0
  71. package/lib/utils/asset-helper.js +387 -0
  72. package/lib/utils/backup-handler.d.ts +2 -0
  73. package/lib/utils/backup-handler.js +31 -0
  74. package/lib/utils/common-helper.d.ts +20 -0
  75. package/lib/utils/common-helper.js +244 -0
  76. package/lib/utils/content-type-helper.d.ts +51 -0
  77. package/lib/utils/content-type-helper.js +145 -0
  78. package/lib/utils/entries-helper.d.ts +4 -0
  79. package/lib/utils/entries-helper.js +252 -0
  80. package/lib/utils/extension-helper.d.ts +5 -0
  81. package/lib/utils/extension-helper.js +84 -0
  82. package/lib/utils/file-helper.d.ts +14 -0
  83. package/lib/utils/file-helper.js +140 -0
  84. package/lib/utils/import-config-handler.d.ts +3 -0
  85. package/lib/utils/import-config-handler.js +73 -0
  86. package/lib/utils/index.d.ts +12 -0
  87. package/lib/utils/index.js +39 -0
  88. package/lib/utils/interactive.d.ts +7 -0
  89. package/lib/utils/interactive.js +88 -0
  90. package/lib/utils/logger.d.ts +8 -0
  91. package/lib/utils/logger.js +154 -0
  92. package/lib/utils/login-handler.d.ts +8 -0
  93. package/lib/utils/login-handler.js +53 -0
  94. package/lib/utils/marketplace-app-helper.d.ts +16 -0
  95. package/lib/utils/marketplace-app-helper.js +143 -0
  96. package/messages/index.json +1 -7
  97. package/oclif.manifest.json +2 -2
  98. package/package.json +46 -20
  99. package/src/app.js +0 -217
  100. package/src/commands/cm/stacks/import.js +0 -161
  101. package/src/config/default.js +0 -352
  102. package/src/lib/import/assets.js +0 -495
  103. package/src/lib/import/content-types.js +0 -201
  104. package/src/lib/import/custom-roles.js +0 -169
  105. package/src/lib/import/entries.js +0 -1495
  106. package/src/lib/import/environments.js +0 -106
  107. package/src/lib/import/extensions.js +0 -108
  108. package/src/lib/import/global-fields.js +0 -135
  109. package/src/lib/import/labels.js +0 -175
  110. package/src/lib/import/locales.js +0 -216
  111. package/src/lib/import/marketplace-apps.js +0 -542
  112. package/src/lib/import/webhooks.js +0 -113
  113. package/src/lib/import/workflows.js +0 -166
  114. package/src/lib/util/extensionsUidReplace.js +0 -67
  115. package/src/lib/util/fs.js +0 -124
  116. package/src/lib/util/import-flags.js +0 -187
  117. package/src/lib/util/index.js +0 -222
  118. package/src/lib/util/log.js +0 -144
  119. package/src/lib/util/login.js +0 -58
  120. package/src/lib/util/lookupReplaceAssets.js +0 -366
  121. package/src/lib/util/lookupReplaceEntries.js +0 -250
  122. package/src/lib/util/marketplace-app-helper.js +0 -31
  123. package/src/lib/util/removeReferenceFields.js +0 -59
  124. package/src/lib/util/schemaTemplate.js +0 -38
  125. package/src/lib/util/supress-mandatory-fields.js +0 -34
  126. package/src/lib/util/upload.js +0 -56
@@ -0,0 +1,252 @@
1
+ "use strict";
2
+ /**
3
+ * Entries lookup
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.lookupEntries = void 0;
7
+ const tslib_1 = require("tslib");
8
+ const path = tslib_1.__importStar(require("path"));
9
+ const _ = tslib_1.__importStar(require("lodash"));
10
+ const config_1 = tslib_1.__importDefault(require("../config"));
11
+ const fileHelper = tslib_1.__importStar(require("./file-helper"));
12
+ // update references in entry object
13
+ const lookupEntries = function (data, mappedUids, uidMapperPath) {
14
+ let parent = [];
15
+ let uids = [];
16
+ let unmapped = [];
17
+ let mapped = [];
18
+ let isNewRefFields = false;
19
+ let preserveStackVersion = config_1.default.preserveStackVersion;
20
+ function gatherJsonRteEntryIds(jsonRteData) {
21
+ jsonRteData.children.forEach((element) => {
22
+ if (element.type) {
23
+ switch (element.type) {
24
+ case 'a':
25
+ case 'p': {
26
+ if (element.children && element.children.length > 0) {
27
+ gatherJsonRteEntryIds(element);
28
+ }
29
+ break;
30
+ }
31
+ case 'reference': {
32
+ if (Object.keys(element.attrs).length > 0 && element.attrs.type === 'entry') {
33
+ if (uids.indexOf(element.attrs['entry-uid']) === -1) {
34
+ uids.push(element.attrs['entry-uid']);
35
+ }
36
+ }
37
+ if (element.children && element.children.length > 0) {
38
+ gatherJsonRteEntryIds(element);
39
+ }
40
+ break;
41
+ }
42
+ }
43
+ }
44
+ });
45
+ }
46
+ const update = function (_parent, form_id, updateEntry) {
47
+ let _entry = updateEntry;
48
+ let len = _parent.length;
49
+ for (let j = 0; j < len; j++) {
50
+ if (_entry && _parent[j]) {
51
+ if (j === len - 1 && _entry[_parent[j]]) {
52
+ if (form_id !== '_assets') {
53
+ if (_entry[_parent[j]].length) {
54
+ _entry[_parent[j]].forEach((item, idx) => {
55
+ if (typeof item.uid === 'string' && item._content_type_uid) {
56
+ uids.push(item.uid);
57
+ }
58
+ else if (typeof item === 'string' && preserveStackVersion === true) {
59
+ uids.push(item);
60
+ }
61
+ else {
62
+ uids.push(item);
63
+ _entry[_parent[j]][idx] = {
64
+ uid: item,
65
+ _content_type_uid: form_id,
66
+ };
67
+ }
68
+ });
69
+ }
70
+ }
71
+ else if (Array.isArray(_entry[_parent[j]])) {
72
+ for (const element of _entry[_parent[j]]) {
73
+ if (element.uid.length) {
74
+ uids.push(element.uid);
75
+ }
76
+ }
77
+ }
78
+ else if (_entry[_parent[j]].uid.length) {
79
+ uids.push(_entry[_parent[j]].uid);
80
+ }
81
+ }
82
+ else {
83
+ _entry = _entry[_parent[j]];
84
+ let _keys = _.clone(_parent).splice(j + 1, len);
85
+ if (Array.isArray(_entry)) {
86
+ for (let i = 0, _i = _entry.length; i < _i; i++) {
87
+ update(_keys, form_id, _entry[i]);
88
+ }
89
+ }
90
+ else if (!(_entry instanceof Object)) {
91
+ break;
92
+ }
93
+ }
94
+ }
95
+ }
96
+ };
97
+ const find = function (schema, _entry) {
98
+ for (let i = 0, _i = schema.length; i < _i; i++) {
99
+ switch (schema[i].data_type) {
100
+ case 'reference':
101
+ if (Array.isArray(schema[i].reference_to)) {
102
+ isNewRefFields = true;
103
+ schema[i].reference_to.forEach((reference) => {
104
+ parent.push(schema[i].uid);
105
+ update(parent, reference, _entry);
106
+ parent.pop();
107
+ });
108
+ }
109
+ else {
110
+ parent.push(schema[i].uid);
111
+ update(parent, schema[i].reference_to, _entry);
112
+ parent.pop();
113
+ }
114
+ break;
115
+ case 'global_field':
116
+ case 'group':
117
+ parent.push(schema[i].uid);
118
+ find(schema[i].schema, _entry);
119
+ parent.pop();
120
+ break;
121
+ case 'blocks':
122
+ for (let j = 0, _j = schema[i].blocks.length; j < _j; j++) {
123
+ parent.push(schema[i].uid);
124
+ parent.push(schema[i].blocks[j].uid);
125
+ find(schema[i].blocks[j].schema, _entry);
126
+ parent.pop();
127
+ parent.pop();
128
+ }
129
+ break;
130
+ case 'json':
131
+ if (schema[i].field_metadata.rich_text_type) {
132
+ findEntryIdsFromJsonRte(data.entry, data.content_type.schema);
133
+ }
134
+ break;
135
+ }
136
+ }
137
+ };
138
+ function findEntryIdsFromJsonRte(entry, ctSchema) {
139
+ for (const element of ctSchema) {
140
+ switch (element.data_type) {
141
+ case 'blocks': {
142
+ if (entry[element.uid]) {
143
+ if (element.multiple) {
144
+ entry[element.uid].forEach((e) => {
145
+ let key = Object.keys(e).pop();
146
+ let subBlock = element.blocks.filter((e) => e.uid === key).pop();
147
+ findEntryIdsFromJsonRte(e[key], subBlock.schema);
148
+ });
149
+ }
150
+ }
151
+ break;
152
+ }
153
+ case 'global_field':
154
+ case 'group': {
155
+ if (entry[element.uid]) {
156
+ if (element.multiple) {
157
+ entry[element.uid].forEach((e) => {
158
+ findEntryIdsFromJsonRte(e, element.schema);
159
+ });
160
+ }
161
+ else {
162
+ findEntryIdsFromJsonRte(entry[element.uid], element.schema);
163
+ }
164
+ }
165
+ break;
166
+ }
167
+ case 'json': {
168
+ if (entry[element.uid] && element.field_metadata.rich_text_type) {
169
+ if (element.multiple) {
170
+ entry[element.uid].forEach((jsonRteData) => {
171
+ gatherJsonRteEntryIds(jsonRteData);
172
+ });
173
+ }
174
+ else {
175
+ gatherJsonRteEntryIds(entry[element.uid]);
176
+ }
177
+ }
178
+ break;
179
+ }
180
+ }
181
+ }
182
+ }
183
+ find(data.content_type.schema, data.entry);
184
+ if (isNewRefFields) {
185
+ findUidsInNewRefFields(data.entry, uids);
186
+ }
187
+ uids = _.flattenDeep(uids);
188
+ // if no references are found, return
189
+ if (uids.length === 0) {
190
+ return data.entry;
191
+ }
192
+ uids = _.uniq(uids);
193
+ let entry = JSON.stringify(data.entry);
194
+ uids.forEach(function (uid) {
195
+ if (mappedUids.hasOwnProperty(uid)) {
196
+ entry = entry.replace(new RegExp(uid, 'img'), mappedUids[uid]);
197
+ mapped.push(uid);
198
+ }
199
+ else {
200
+ unmapped.push(uid);
201
+ }
202
+ });
203
+ if (unmapped.length > 0) {
204
+ let unmappedUids = fileHelper.readFileSync(path.join(uidMapperPath, 'unmapped-uids.json'));
205
+ unmappedUids = unmappedUids || {};
206
+ if (unmappedUids.hasOwnProperty(data.content_type.uid)) {
207
+ unmappedUids[data.content_type.uid][data.entry.uid] = unmapped;
208
+ }
209
+ else {
210
+ unmappedUids[data.content_type.uid] = {
211
+ [data.entry.uid]: unmapped,
212
+ };
213
+ }
214
+ // write the unmapped contents to ./mapper/language/unmapped-uids.json
215
+ fileHelper.writeFile(path.join(uidMapperPath, 'unmapped-uids.json'), unmappedUids);
216
+ }
217
+ if (mapped.length > 0) {
218
+ let _mappedUids = fileHelper.readFileSync(path.join(uidMapperPath, 'mapped-uids.json'));
219
+ _mappedUids = _mappedUids || {};
220
+ if (_mappedUids.hasOwnProperty(data.content_type.uid)) {
221
+ _mappedUids[data.content_type.uid][data.entry.uid] = mapped;
222
+ }
223
+ else {
224
+ _mappedUids[data.content_type.uid] = {
225
+ [data.entry.uid]: mapped,
226
+ };
227
+ }
228
+ // write the mapped contents to ./mapper/language/mapped-uids.json
229
+ fileHelper.writeFile(path.join(uidMapperPath, 'mapped-uids.json'), _mappedUids);
230
+ }
231
+ return JSON.parse(entry);
232
+ };
233
+ exports.lookupEntries = lookupEntries;
234
+ function findUidsInNewRefFields(entry, uids) {
235
+ if (entry && typeof entry === 'object') {
236
+ if (entry.uid && entry._content_type_uid) {
237
+ uids.push(entry.uid);
238
+ }
239
+ else if (Array.isArray(entry) && entry.length) {
240
+ entry.forEach(function (elem) {
241
+ findUidsInNewRefFields(elem, uids);
242
+ });
243
+ }
244
+ else if (Object.keys(entry).length) {
245
+ for (let key in entry) {
246
+ if (key) {
247
+ findUidsInNewRefFields(entry[key], uids);
248
+ }
249
+ }
250
+ }
251
+ }
252
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * extension lookup
3
+ */
4
+ import { ImportConfig } from '../types';
5
+ export declare const lookupExtension: (config: ImportConfig, schema: any, preserveStackVersion: any, installedExtensions: any) => void;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ /**
3
+ * extension lookup
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.lookupExtension = void 0;
7
+ /*!
8
+ * Contentstack Import
9
+ * Copyright (c) 2019 Contentstack LLC
10
+ * MIT Licensed
11
+ */
12
+ const node_path_1 = require("node:path");
13
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
14
+ // eslint-disable-next-line camelcase
15
+ const lookupExtension = function (config, schema, preserveStackVersion, installedExtensions) {
16
+ const fs = new cli_utilities_1.FsUtility({ basePath: config.backupDir });
17
+ const extensionPath = (0, node_path_1.join)(config.backupDir, 'mapper/extensions', 'uid-mapping.json');
18
+ const globalfieldsPath = (0, node_path_1.join)(config.backupDir, 'mapper/globalfields', 'uid-mapping.json');
19
+ for (let i in schema) {
20
+ if (schema[i].data_type === 'group') {
21
+ (0, exports.lookupExtension)(config, schema[i].schema, preserveStackVersion, installedExtensions);
22
+ }
23
+ else if (schema[i].data_type === 'blocks') {
24
+ for (let block in schema[i].blocks) {
25
+ if (schema[i].blocks[block].hasOwnProperty('reference_to')) {
26
+ delete schema[i].blocks[block].schema;
27
+ }
28
+ else {
29
+ (0, exports.lookupExtension)(config, schema[i].blocks[block].schema, preserveStackVersion, installedExtensions);
30
+ }
31
+ }
32
+ }
33
+ else if (schema[i].data_type === 'reference' &&
34
+ !schema[i].field_metadata.hasOwnProperty('ref_multiple_content_types')) {
35
+ if (preserveStackVersion) {
36
+ // do nothing
37
+ }
38
+ else {
39
+ schema[i].reference_to = [schema[i].reference_to];
40
+ schema[i].field_metadata.ref_multiple_content_types = true;
41
+ }
42
+ }
43
+ else if (schema[i].data_type === 'reference' &&
44
+ schema[i].field_metadata.hasOwnProperty('ref_multiple_content_types') &&
45
+ installedExtensions &&
46
+ installedExtensions[schema[i].extension_uid]) {
47
+ schema[i].extension_uid = installedExtensions[schema[i].extension_uid];
48
+ }
49
+ else if (schema[i].data_type === 'text' && installedExtensions && installedExtensions[schema[i].extension_uid]) {
50
+ schema[i].extension_uid = installedExtensions[schema[i].extension_uid];
51
+ }
52
+ else if (schema[i].data_type === 'global_field') {
53
+ const global_fields_key_value = schema[i].reference_to;
54
+ const global_fields_data = fs.readFile(globalfieldsPath);
55
+ if (global_fields_data && global_fields_data.hasOwnProperty(global_fields_key_value)) {
56
+ schema[i].reference_to = global_fields_data[global_fields_key_value];
57
+ }
58
+ }
59
+ else if (schema[i].hasOwnProperty('extension_uid')) {
60
+ const extension_key_value = schema[i].extension_uid;
61
+ const data = fs.readFile(extensionPath);
62
+ if (data && data.hasOwnProperty(extension_key_value)) {
63
+ // eslint-disable-next-line camelcase
64
+ schema[i].extension_uid = data[extension_key_value];
65
+ }
66
+ else if (schema[i].field_metadata && schema[i].field_metadata.extension) {
67
+ if (installedExtensions && installedExtensions[schema[i].extension_uid]) {
68
+ schema[i].extension_uid = installedExtensions[schema[i].extension_uid];
69
+ }
70
+ }
71
+ }
72
+ else if (schema[i].data_type === 'json' && schema[i].hasOwnProperty('plugins') && schema[i].plugins.length > 0) {
73
+ const newPluginUidsArray = [];
74
+ const data = fs.readFile(extensionPath);
75
+ schema[i].plugins.forEach((extension_key_value) => {
76
+ if (data && data.hasOwnProperty(extension_key_value)) {
77
+ newPluginUidsArray.push(data[extension_key_value]);
78
+ }
79
+ });
80
+ schema[i].plugins = newPluginUidsArray;
81
+ }
82
+ }
83
+ };
84
+ exports.lookupExtension = lookupExtension;
@@ -0,0 +1,14 @@
1
+ import { FsUtility } from '@contentstack/cli-utilities';
2
+ export declare const readFileSync: (filePath: string, parse?: boolean) => any;
3
+ export declare const readFile: (filePath: string, options?: {
4
+ type: string;
5
+ }) => Promise<any>;
6
+ export declare const readLargeFile: (filePath: string, opts?: any) => Promise<any>;
7
+ export declare const writeFileSync: (filePath: string, data: any) => void;
8
+ export declare const writeFile: (filePath: string, data: any) => Promise<any>;
9
+ export declare const writeLargeFile: (filePath: string, data: any) => Promise<any>;
10
+ export declare const makeDirectory: (dir: string) => void;
11
+ export declare const readdirSync: (dirPath: string) => any;
12
+ export declare const isFolderExist: (folderPath: string) => Promise<any>;
13
+ export declare const fileExistsSync: (path: string) => boolean;
14
+ export declare const fsUtil: FsUtility;
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fsUtil = exports.fileExistsSync = exports.isFolderExist = exports.readdirSync = exports.makeDirectory = exports.writeLargeFile = exports.writeFile = exports.writeFileSync = exports.readLargeFile = exports.readFile = exports.readFileSync = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const fs = tslib_1.__importStar(require("fs"));
6
+ const path = tslib_1.__importStar(require("path"));
7
+ const mkdirp_1 = tslib_1.__importDefault(require("mkdirp"));
8
+ const bigJSON = tslib_1.__importStar(require("big-json"));
9
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
10
+ const readFileSync = function (filePath, parse = true) {
11
+ let data;
12
+ filePath = path.resolve(filePath);
13
+ if (fs.existsSync(filePath)) {
14
+ try {
15
+ data = parse ? JSON.parse(fs.readFileSync(filePath, 'utf-8')) : data;
16
+ }
17
+ catch (error) {
18
+ return data;
19
+ }
20
+ }
21
+ return data;
22
+ };
23
+ exports.readFileSync = readFileSync;
24
+ // by default file type is json
25
+ const readFile = async (filePath, options = { type: 'json' }) => {
26
+ return new Promise((resolve, reject) => {
27
+ filePath = path.resolve(filePath);
28
+ fs.readFile(filePath, 'utf-8', (error, data) => {
29
+ if (error) {
30
+ if (error.code === 'ENOENT') {
31
+ return resolve('');
32
+ }
33
+ reject(error);
34
+ }
35
+ else {
36
+ if (options.type !== 'json') {
37
+ return resolve(data);
38
+ }
39
+ resolve(JSON.parse(data));
40
+ }
41
+ });
42
+ });
43
+ };
44
+ exports.readFile = readFile;
45
+ const readLargeFile = function (filePath, opts) {
46
+ if (typeof filePath !== 'string') {
47
+ return;
48
+ }
49
+ filePath = path.resolve(filePath);
50
+ if (fs.existsSync(filePath)) {
51
+ return new Promise((resolve, reject) => {
52
+ const readStream = fs.createReadStream(filePath, { encoding: 'utf-8' });
53
+ const parseStream = bigJSON.createParseStream();
54
+ parseStream.on('data', function (data) {
55
+ if ((opts === null || opts === void 0 ? void 0 : opts.type) === 'array') {
56
+ return resolve(Object.values(data));
57
+ }
58
+ resolve(data);
59
+ });
60
+ parseStream.on('error', function (error) {
61
+ console.log('error', error);
62
+ reject(error);
63
+ });
64
+ readStream.pipe(parseStream);
65
+ });
66
+ }
67
+ };
68
+ exports.readLargeFile = readLargeFile;
69
+ const writeFileSync = function (filePath, data) {
70
+ data = typeof data === 'object' ? JSON.stringify(data) : data || '{}';
71
+ fs.writeFileSync(filePath, data);
72
+ };
73
+ exports.writeFileSync = writeFileSync;
74
+ const writeFile = function (filePath, data) {
75
+ return new Promise((resolve, reject) => {
76
+ data = typeof data === 'object' ? JSON.stringify(data) : data || '{}';
77
+ fs.writeFile(filePath, data, (error) => {
78
+ if (error) {
79
+ return reject(error);
80
+ }
81
+ resolve('done');
82
+ });
83
+ });
84
+ };
85
+ exports.writeFile = writeFile;
86
+ const writeLargeFile = function (filePath, data) {
87
+ if (typeof filePath !== 'string' || typeof data !== 'object') {
88
+ return;
89
+ }
90
+ filePath = path.resolve(filePath);
91
+ return new Promise((resolve, reject) => {
92
+ const stringifyStream = bigJSON.createStringifyStream({
93
+ body: data,
94
+ });
95
+ var writeStream = fs.createWriteStream(filePath, 'utf-8');
96
+ stringifyStream.pipe(writeStream);
97
+ writeStream.on('finish', () => {
98
+ resolve('');
99
+ });
100
+ writeStream.on('error', (error) => {
101
+ reject(error);
102
+ });
103
+ });
104
+ };
105
+ exports.writeLargeFile = writeLargeFile;
106
+ const makeDirectory = function (dir) {
107
+ for (let key in arguments) {
108
+ const dirname = path.resolve(arguments[key]);
109
+ if (!fs.existsSync(dirname)) {
110
+ mkdirp_1.default.sync(dirname);
111
+ }
112
+ }
113
+ };
114
+ exports.makeDirectory = makeDirectory;
115
+ const readdirSync = function (dirPath) {
116
+ if (fs.existsSync(dirPath)) {
117
+ return fs.readdirSync(dirPath);
118
+ }
119
+ else {
120
+ return [];
121
+ }
122
+ };
123
+ exports.readdirSync = readdirSync;
124
+ const isFolderExist = async (folderPath) => {
125
+ return new Promise((resolve, reject) => {
126
+ folderPath = path.resolve(folderPath);
127
+ fs.access(folderPath, (error) => {
128
+ if (error) {
129
+ return resolve(false);
130
+ }
131
+ resolve(true);
132
+ });
133
+ });
134
+ };
135
+ exports.isFolderExist = isFolderExist;
136
+ const fileExistsSync = function (path) {
137
+ return fs.existsSync(path);
138
+ };
139
+ exports.fileExistsSync = fileExistsSync;
140
+ exports.fsUtil = new cli_utilities_1.FsUtility();
@@ -0,0 +1,3 @@
1
+ import { ImportConfig } from '../types';
2
+ declare const setupConfig: (importCmdFlags: any) => Promise<ImportConfig>;
3
+ export default setupConfig;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ const merge_1 = tslib_1.__importDefault(require("merge"));
5
+ const path = tslib_1.__importStar(require("path"));
6
+ const lodash_1 = require("lodash");
7
+ const cli_utilities_1 = require("@contentstack/cli-utilities");
8
+ const config_1 = tslib_1.__importDefault(require("../config"));
9
+ const file_helper_1 = require("./file-helper");
10
+ const interactive_1 = require("./interactive");
11
+ const login_handler_1 = tslib_1.__importDefault(require("./login-handler"));
12
+ const setupConfig = async (importCmdFlags) => {
13
+ let config = (0, merge_1.default)({}, config_1.default);
14
+ // setup the config
15
+ if (importCmdFlags['config']) {
16
+ let externalConfig = await (0, file_helper_1.readFile)(importCmdFlags['config']);
17
+ if ((0, lodash_1.isArray)(externalConfig['modules'])) {
18
+ config.modules.types = (0, lodash_1.filter)(config.modules.types, (module) => (0, lodash_1.includes)(externalConfig['modules'], module));
19
+ externalConfig = (0, lodash_1.omit)(externalConfig, ['modules']);
20
+ }
21
+ config = merge_1.default.recursive(config, externalConfig);
22
+ }
23
+ config.contentDir = importCmdFlags['data'] || importCmdFlags['data-dir'] || config.data || (await (0, interactive_1.askContentDir)());
24
+ config.contentDir = path.resolve(config.contentDir);
25
+ //Note to support the old key
26
+ config.data = config.contentDir;
27
+ const managementTokenAlias = importCmdFlags['management-token-alias'] || importCmdFlags['alias'];
28
+ if (managementTokenAlias) {
29
+ const { token, apiKey } = cli_utilities_1.configHandler.get(`tokens.${managementTokenAlias}`);
30
+ config.management_token = token;
31
+ config.apiKey = apiKey;
32
+ if (!config.management_token) {
33
+ throw new Error(`No management token found on given alias ${managementTokenAlias}`);
34
+ }
35
+ }
36
+ if (!config.management_token) {
37
+ if (!(0, cli_utilities_1.isAuthenticated)()) {
38
+ if (config.email && config.password) {
39
+ await (0, login_handler_1.default)(config);
40
+ }
41
+ else {
42
+ throw new Error('Please login or provide an alias for the management token');
43
+ }
44
+ }
45
+ else {
46
+ config.apiKey =
47
+ importCmdFlags['stack-uid'] || importCmdFlags['stack-api-key'] || config.target_stack || (await (0, interactive_1.askAPIKey)());
48
+ if (typeof config.apiKey !== 'string') {
49
+ throw new Error('Invalid API key received');
50
+ }
51
+ }
52
+ }
53
+ config.isAuthenticated = (0, cli_utilities_1.isAuthenticated)();
54
+ //Note to support the old key
55
+ config.source_stack = config.apiKey;
56
+ config.importWebhookStatus = importCmdFlags.importWebhookStatus;
57
+ config.forceStopMarketplaceAppsPrompt = importCmdFlags.yes;
58
+ if (importCmdFlags['branch']) {
59
+ config.branchName = importCmdFlags['branch'];
60
+ config.branchDir = path.join(config.contentDir, config.branchName);
61
+ }
62
+ if (importCmdFlags['module']) {
63
+ config.moduleName = importCmdFlags['module'];
64
+ config.singleModuleImport = true;
65
+ }
66
+ if (importCmdFlags['backup-dir']) {
67
+ config.useBackedupDir = importCmdFlags['backup-dir'];
68
+ }
69
+ // Note to support old modules
70
+ config.target_stack = config.apiKey;
71
+ return config;
72
+ };
73
+ exports.default = setupConfig;
@@ -0,0 +1,12 @@
1
+ export * as interactive from './interactive';
2
+ export { default as setupImportConfig } from './import-config-handler';
3
+ export * as fileHelper from './file-helper';
4
+ export { fsUtil } from './file-helper';
5
+ export { default as backupHandler } from './backup-handler';
6
+ export { log, unlinkFileLogger } from './logger';
7
+ export { uploadAssetHelper, lookupAssets } from './asset-helper';
8
+ export { getDeveloperHubUrl, getOrgUid, getConfirmationToCreateApps, createPrivateApp, handleNameConflict, installApp, makeRedirectUrlCall, confirmToCloseProcess, getAllStackSpecificApps, ifAppAlreadyExist, updateAppConfig } from './marketplace-app-helper';
9
+ export { schemaTemplate, suppressSchemaReference, removeReferenceFields } from './content-type-helper';
10
+ export { lookupExtension } from './extension-helper';
11
+ export { lookupEntries } from './entries-helper';
12
+ export * from './common-helper';
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lookupEntries = exports.lookupExtension = exports.removeReferenceFields = exports.suppressSchemaReference = exports.schemaTemplate = exports.updateAppConfig = exports.ifAppAlreadyExist = exports.getAllStackSpecificApps = exports.confirmToCloseProcess = exports.makeRedirectUrlCall = exports.installApp = exports.handleNameConflict = exports.createPrivateApp = exports.getConfirmationToCreateApps = exports.getOrgUid = exports.getDeveloperHubUrl = exports.lookupAssets = exports.uploadAssetHelper = exports.unlinkFileLogger = exports.log = exports.backupHandler = exports.fsUtil = exports.fileHelper = exports.setupImportConfig = exports.interactive = void 0;
4
+ const tslib_1 = require("tslib");
5
+ exports.interactive = tslib_1.__importStar(require("./interactive"));
6
+ var import_config_handler_1 = require("./import-config-handler");
7
+ Object.defineProperty(exports, "setupImportConfig", { enumerable: true, get: function () { return tslib_1.__importDefault(import_config_handler_1).default; } });
8
+ exports.fileHelper = tslib_1.__importStar(require("./file-helper"));
9
+ var file_helper_1 = require("./file-helper");
10
+ Object.defineProperty(exports, "fsUtil", { enumerable: true, get: function () { return file_helper_1.fsUtil; } });
11
+ var backup_handler_1 = require("./backup-handler");
12
+ Object.defineProperty(exports, "backupHandler", { enumerable: true, get: function () { return tslib_1.__importDefault(backup_handler_1).default; } });
13
+ var logger_1 = require("./logger");
14
+ Object.defineProperty(exports, "log", { enumerable: true, get: function () { return logger_1.log; } });
15
+ Object.defineProperty(exports, "unlinkFileLogger", { enumerable: true, get: function () { return logger_1.unlinkFileLogger; } });
16
+ var asset_helper_1 = require("./asset-helper");
17
+ Object.defineProperty(exports, "uploadAssetHelper", { enumerable: true, get: function () { return asset_helper_1.uploadAssetHelper; } });
18
+ Object.defineProperty(exports, "lookupAssets", { enumerable: true, get: function () { return asset_helper_1.lookupAssets; } });
19
+ var marketplace_app_helper_1 = require("./marketplace-app-helper");
20
+ Object.defineProperty(exports, "getDeveloperHubUrl", { enumerable: true, get: function () { return marketplace_app_helper_1.getDeveloperHubUrl; } });
21
+ Object.defineProperty(exports, "getOrgUid", { enumerable: true, get: function () { return marketplace_app_helper_1.getOrgUid; } });
22
+ Object.defineProperty(exports, "getConfirmationToCreateApps", { enumerable: true, get: function () { return marketplace_app_helper_1.getConfirmationToCreateApps; } });
23
+ Object.defineProperty(exports, "createPrivateApp", { enumerable: true, get: function () { return marketplace_app_helper_1.createPrivateApp; } });
24
+ Object.defineProperty(exports, "handleNameConflict", { enumerable: true, get: function () { return marketplace_app_helper_1.handleNameConflict; } });
25
+ Object.defineProperty(exports, "installApp", { enumerable: true, get: function () { return marketplace_app_helper_1.installApp; } });
26
+ Object.defineProperty(exports, "makeRedirectUrlCall", { enumerable: true, get: function () { return marketplace_app_helper_1.makeRedirectUrlCall; } });
27
+ Object.defineProperty(exports, "confirmToCloseProcess", { enumerable: true, get: function () { return marketplace_app_helper_1.confirmToCloseProcess; } });
28
+ Object.defineProperty(exports, "getAllStackSpecificApps", { enumerable: true, get: function () { return marketplace_app_helper_1.getAllStackSpecificApps; } });
29
+ Object.defineProperty(exports, "ifAppAlreadyExist", { enumerable: true, get: function () { return marketplace_app_helper_1.ifAppAlreadyExist; } });
30
+ Object.defineProperty(exports, "updateAppConfig", { enumerable: true, get: function () { return marketplace_app_helper_1.updateAppConfig; } });
31
+ var content_type_helper_1 = require("./content-type-helper");
32
+ Object.defineProperty(exports, "schemaTemplate", { enumerable: true, get: function () { return content_type_helper_1.schemaTemplate; } });
33
+ Object.defineProperty(exports, "suppressSchemaReference", { enumerable: true, get: function () { return content_type_helper_1.suppressSchemaReference; } });
34
+ Object.defineProperty(exports, "removeReferenceFields", { enumerable: true, get: function () { return content_type_helper_1.removeReferenceFields; } });
35
+ var extension_helper_1 = require("./extension-helper");
36
+ Object.defineProperty(exports, "lookupExtension", { enumerable: true, get: function () { return extension_helper_1.lookupExtension; } });
37
+ var entries_helper_1 = require("./entries-helper");
38
+ Object.defineProperty(exports, "lookupEntries", { enumerable: true, get: function () { return entries_helper_1.lookupEntries; } });
39
+ tslib_1.__exportStar(require("./common-helper"), exports);
@@ -0,0 +1,7 @@
1
+ export declare const askContentDir: () => Promise<string>;
2
+ export declare const askAPIKey: () => Promise<string>;
3
+ export declare const askDeveloperHubUrl: (regionName: string) => Promise<string>;
4
+ export declare const askEncryptionKey: (defaultValue: unknown) => Promise<string>;
5
+ export declare const askAppName: (app: any, appSuffix: number) => Promise<string>;
6
+ export declare const getAppName: (name: string, appSuffix?: number) => string;
7
+ export declare const selectConfiguration: () => Promise<string>;