@contentstack/cli-cm-import-setup 1.7.2 → 2.0.0-beta.2
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 +1 -1
- package/README.md +4 -49
- package/lib/commands/cm/stacks/import-setup.d.ts +1 -0
- package/lib/commands/cm/stacks/import-setup.js +28 -11
- package/lib/import/import-setup.d.ts +19 -5
- package/lib/import/import-setup.js +27 -16
- package/lib/import/modules/assets.js +48 -16
- package/lib/import/modules/base-setup.d.ts +20 -7
- package/lib/import/modules/base-setup.js +48 -15
- package/lib/import/modules/content-types.js +27 -5
- package/lib/import/modules/entries.js +11 -4
- package/lib/import/modules/extensions.d.ts +3 -6
- package/lib/import/modules/extensions.js +39 -23
- package/lib/import/modules/global-fields.js +27 -5
- package/lib/import/modules/marketplace-apps.d.ts +3 -5
- package/lib/import/modules/marketplace-apps.js +40 -18
- package/lib/import/modules/taxonomies.d.ts +5 -7
- package/lib/import/modules/taxonomies.js +103 -61
- package/lib/types/import-config.d.ts +1 -1
- package/lib/types/index.d.ts +8 -1
- package/lib/utils/common-helper.d.ts +8 -1
- package/lib/utils/common-helper.js +6 -4
- package/lib/utils/constants.d.ts +39 -0
- package/lib/utils/constants.js +114 -0
- package/lib/utils/file-helper.d.ts +1 -1
- package/lib/utils/file-helper.js +4 -4
- package/lib/utils/import-config-handler.js +3 -8
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +6 -1
- package/lib/utils/log.js +1 -1
- package/lib/utils/logger.d.ts +1 -1
- package/lib/utils/logger.js +11 -16
- package/lib/utils/login-handler.d.ts +11 -2
- package/lib/utils/login-handler.js +12 -8
- package/oclif.manifest.json +3 -8
- package/package.json +5 -3
|
@@ -6,17 +6,16 @@ const omit_1 = tslib_1.__importDefault(require("lodash/omit"));
|
|
|
6
6
|
const isEmpty_1 = tslib_1.__importDefault(require("lodash/isEmpty"));
|
|
7
7
|
const utils_1 = require("../../utils");
|
|
8
8
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const base_setup_1 = tslib_1.__importDefault(require("./base-setup"));
|
|
10
|
+
const utils_2 = require("../../utils");
|
|
11
|
+
class TaxonomiesImportSetup extends base_setup_1.default {
|
|
12
|
+
constructor({ config, stackAPIClient }) {
|
|
11
13
|
var _a, _b, _c;
|
|
14
|
+
super({ config, stackAPIClient, dependencies: [] });
|
|
12
15
|
this.isLocaleBasedStructure = false;
|
|
13
16
|
this.taxonomiesMapper = {};
|
|
14
17
|
this.termsMapper = {};
|
|
15
|
-
this.
|
|
16
|
-
if (this.config.context) {
|
|
17
|
-
this.config.context.module = 'taxonomies';
|
|
18
|
-
}
|
|
19
|
-
this.stackAPIClient = stackAPIClient;
|
|
18
|
+
this.currentModuleName = utils_2.MODULE_NAMES[utils_2.MODULE_CONTEXTS.TAXONOMIES];
|
|
20
19
|
this.taxonomiesFolderPath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'taxonomies');
|
|
21
20
|
this.taxonomiesFilePath = (0, path_1.join)(this.taxonomiesFolderPath, 'taxonomies.json');
|
|
22
21
|
this.taxonomiesConfig = config.modules.taxonomies;
|
|
@@ -35,58 +34,90 @@ class TaxonomiesImportSetup {
|
|
|
35
34
|
* @returns {Promise<void>}
|
|
36
35
|
*/
|
|
37
36
|
async start() {
|
|
37
|
+
var _a;
|
|
38
38
|
try {
|
|
39
|
-
const taxonomies =
|
|
39
|
+
const taxonomies = await this.withLoadingSpinner('TAXONOMIES: Analyzing import data...', async () => {
|
|
40
|
+
return utils_1.fsUtil.readFile(this.taxonomiesFilePath);
|
|
41
|
+
});
|
|
40
42
|
if (!(0, isEmpty_1.default)(taxonomies)) {
|
|
41
|
-
|
|
43
|
+
const taxonomiesArray = Object.values(taxonomies);
|
|
44
|
+
const progress = this.createNestedProgress(this.currentModuleName);
|
|
45
|
+
// Detect locale-based structure
|
|
42
46
|
this.isLocaleBasedStructure = this.detectLocaleBasedStructure();
|
|
43
|
-
//
|
|
47
|
+
// Add processes
|
|
48
|
+
progress.addProcess(utils_2.PROCESS_NAMES.TAXONOMIES_MAPPER_GENERATION, 1);
|
|
49
|
+
progress.addProcess(utils_2.PROCESS_NAMES.TAXONOMIES_FETCH, taxonomiesArray.length);
|
|
50
|
+
progress.addProcess(utils_2.PROCESS_NAMES.TAXONOMIES_TERMS_FETCH, taxonomiesArray.length);
|
|
51
|
+
// Create mapper directory
|
|
52
|
+
progress
|
|
53
|
+
.startProcess(utils_2.PROCESS_NAMES.TAXONOMIES_MAPPER_GENERATION)
|
|
54
|
+
.updateStatus(utils_2.PROCESS_STATUS.TAXONOMIES_MAPPER_GENERATION.GENERATING, utils_2.PROCESS_NAMES.TAXONOMIES_MAPPER_GENERATION);
|
|
44
55
|
utils_1.fsUtil.makeDirectory(this.taxonomiesMapperDirPath);
|
|
45
56
|
utils_1.fsUtil.makeDirectory(this.termsMapperDirPath);
|
|
57
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, 'mapper directories created', null, utils_2.PROCESS_NAMES.TAXONOMIES_MAPPER_GENERATION);
|
|
58
|
+
progress.completeProcess(utils_2.PROCESS_NAMES.TAXONOMIES_MAPPER_GENERATION, true);
|
|
59
|
+
// Fetch taxonomies
|
|
60
|
+
progress
|
|
61
|
+
.startProcess(utils_2.PROCESS_NAMES.TAXONOMIES_FETCH)
|
|
62
|
+
.updateStatus(utils_2.PROCESS_STATUS.TAXONOMIES_FETCH.FETCHING, utils_2.PROCESS_NAMES.TAXONOMIES_FETCH);
|
|
46
63
|
if (this.isLocaleBasedStructure) {
|
|
47
|
-
|
|
48
|
-
await this.setupTaxonomiesByLocale(taxonomies);
|
|
64
|
+
(0, utils_1.log)(this.config, 'Detected locale-based folder structure for taxonomies', 'info');
|
|
65
|
+
await this.setupTaxonomiesByLocale(taxonomies, progress);
|
|
49
66
|
}
|
|
50
67
|
else {
|
|
51
|
-
|
|
52
|
-
await this.setupTaxonomiesLegacy(taxonomies);
|
|
68
|
+
(0, utils_1.log)(this.config, 'Using legacy folder structure for taxonomies', 'info');
|
|
69
|
+
await this.setupTaxonomiesLegacy(taxonomies, progress);
|
|
53
70
|
}
|
|
71
|
+
progress.completeProcess(utils_2.PROCESS_NAMES.TAXONOMIES_FETCH, true);
|
|
72
|
+
progress.completeProcess(utils_2.PROCESS_NAMES.TAXONOMIES_TERMS_FETCH, true);
|
|
54
73
|
if (this.taxonomiesMapper !== undefined && !(0, isEmpty_1.default)(this.taxonomiesMapper)) {
|
|
55
74
|
utils_1.fsUtil.writeFile(this.taxSuccessPath, this.taxonomiesMapper);
|
|
56
75
|
}
|
|
57
76
|
if (this.termsMapper !== undefined && !(0, isEmpty_1.default)(this.termsMapper)) {
|
|
58
77
|
utils_1.fsUtil.writeFile(this.termsSuccessPath, this.termsMapper);
|
|
59
78
|
}
|
|
60
|
-
|
|
79
|
+
this.completeProgress(true);
|
|
80
|
+
(0, utils_1.log)(this.config, `The required setup files for taxonomies have been generated successfully.`, 'success');
|
|
61
81
|
}
|
|
62
82
|
else {
|
|
63
|
-
|
|
83
|
+
(0, utils_1.log)(this.config, 'No taxonomies found in the content folder.', 'info');
|
|
64
84
|
}
|
|
65
85
|
}
|
|
66
86
|
catch (error) {
|
|
67
|
-
(
|
|
87
|
+
this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Taxonomies mapper generation failed');
|
|
88
|
+
(0, utils_1.log)(this.config, `Error generating taxonomies mapper: ${error.message}`, 'error');
|
|
68
89
|
}
|
|
69
90
|
}
|
|
70
91
|
/**
|
|
71
92
|
* Setup taxonomies using legacy format (root-level taxonomy files)
|
|
72
93
|
*/
|
|
73
|
-
async setupTaxonomiesLegacy(taxonomies) {
|
|
94
|
+
async setupTaxonomiesLegacy(taxonomies, progress) {
|
|
95
|
+
var _a, _b, _c, _d, _e;
|
|
74
96
|
for (const taxonomy of Object.values(taxonomies)) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
97
|
+
try {
|
|
98
|
+
let targetTaxonomy = await this.getTaxonomies(taxonomy);
|
|
99
|
+
if (!targetTaxonomy) {
|
|
100
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(false, `taxonomy: ${taxonomy.uid}`, 'Not found in stack', utils_2.PROCESS_NAMES.TAXONOMIES_FETCH);
|
|
101
|
+
(0, utils_1.log)(this.config, `Taxonomies with uid '${taxonomy.uid}' not found in the stack!`, 'info');
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
targetTaxonomy = this.sanitizeTaxonomyAttribs(targetTaxonomy);
|
|
105
|
+
this.taxonomiesMapper[taxonomy.uid] = targetTaxonomy;
|
|
106
|
+
(_b = this.progressManager) === null || _b === void 0 ? void 0 : _b.tick(true, `taxonomy: ${taxonomy.uid}`, null, utils_2.PROCESS_NAMES.TAXONOMIES_FETCH);
|
|
107
|
+
const terms = await this.getAllTermsOfTaxonomy(targetTaxonomy);
|
|
108
|
+
if (Array.isArray(terms) && terms.length > 0) {
|
|
109
|
+
(0, utils_1.log)(this.config, `Terms found for taxonomy '${taxonomy.uid}', processing...`, 'info');
|
|
110
|
+
const sanitizedTerms = this.sanitizeTermsAttribs(terms);
|
|
111
|
+
this.termsMapper[taxonomy.uid] = sanitizedTerms;
|
|
112
|
+
(_c = this.progressManager) === null || _c === void 0 ? void 0 : _c.tick(true, `terms: ${taxonomy.uid} (${terms.length})`, null, utils_2.PROCESS_NAMES.TAXONOMIES_TERMS_FETCH);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
(0, utils_1.log)(this.config, `No terms found for taxonomy '${taxonomy.uid}', skipping...`, 'info');
|
|
116
|
+
(_d = this.progressManager) === null || _d === void 0 ? void 0 : _d.tick(true, `terms: ${taxonomy.uid} (none)`, null, utils_2.PROCESS_NAMES.TAXONOMIES_TERMS_FETCH);
|
|
117
|
+
}
|
|
87
118
|
}
|
|
88
|
-
|
|
89
|
-
|
|
119
|
+
catch (error) {
|
|
120
|
+
(_e = this.progressManager) === null || _e === void 0 ? void 0 : _e.tick(false, `taxonomy: ${taxonomy.uid}`, (error === null || error === void 0 ? void 0 : error.message) || 'Failed to fetch', utils_2.PROCESS_NAMES.TAXONOMIES_FETCH);
|
|
90
121
|
}
|
|
91
122
|
}
|
|
92
123
|
}
|
|
@@ -94,29 +125,39 @@ class TaxonomiesImportSetup {
|
|
|
94
125
|
* Setup taxonomies using locale-based format (taxonomies organized by locale)
|
|
95
126
|
* For locale-based structure, we query the target stack for each taxonomy+locale combination
|
|
96
127
|
*/
|
|
97
|
-
async setupTaxonomiesByLocale(taxonomies) {
|
|
128
|
+
async setupTaxonomiesByLocale(taxonomies, progress) {
|
|
129
|
+
var _a, _b, _c, _d, _e;
|
|
98
130
|
const locales = this.loadAvailableLocales();
|
|
99
131
|
for (const localeCode of Object.keys(locales)) {
|
|
100
|
-
|
|
132
|
+
(0, utils_1.log)(this.config, `Processing taxonomies for locale: ${localeCode}`, 'info');
|
|
101
133
|
for (const taxonomy of Object.values(taxonomies)) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
134
|
+
try {
|
|
135
|
+
// Query target stack for this taxonomy in this locale
|
|
136
|
+
let targetTaxonomy = await this.getTaxonomies(taxonomy, localeCode);
|
|
137
|
+
if (!targetTaxonomy) {
|
|
138
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(false, `taxonomy: ${taxonomy.uid} (${localeCode})`, 'Not found in stack', utils_2.PROCESS_NAMES.TAXONOMIES_FETCH);
|
|
139
|
+
(0, utils_1.log)(this.config, `Taxonomy '${taxonomy.uid}' not found in target stack for locale: ${localeCode}`, 'info');
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
targetTaxonomy = this.sanitizeTaxonomyAttribs(targetTaxonomy);
|
|
143
|
+
// Store with composite key: taxonomyUID_locale
|
|
144
|
+
// const mapperKey = `${taxonomy.uid}_${localeCode}`; // TODO: Unsure about this required or not
|
|
145
|
+
this.taxonomiesMapper[taxonomy.uid] = targetTaxonomy;
|
|
146
|
+
(_b = this.progressManager) === null || _b === void 0 ? void 0 : _b.tick(true, `taxonomy: ${taxonomy.uid} (${localeCode})`, null, utils_2.PROCESS_NAMES.TAXONOMIES_FETCH);
|
|
147
|
+
const terms = await this.getAllTermsOfTaxonomy(targetTaxonomy, localeCode);
|
|
148
|
+
if (Array.isArray(terms) && terms.length > 0) {
|
|
149
|
+
(0, utils_1.log)(this.config, `Terms found for taxonomy '${taxonomy.uid} for locale: ${localeCode}', processing...`, 'info');
|
|
150
|
+
const sanitizedTerms = this.sanitizeTermsAttribs(terms);
|
|
151
|
+
this.termsMapper[taxonomy.uid] = sanitizedTerms;
|
|
152
|
+
(_c = this.progressManager) === null || _c === void 0 ? void 0 : _c.tick(true, `terms: ${taxonomy.uid} (${localeCode}, ${terms.length})`, null, utils_2.PROCESS_NAMES.TAXONOMIES_TERMS_FETCH);
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
(0, utils_1.log)(this.config, `No terms found for taxonomy '${taxonomy.uid} for locale: ${localeCode}', skipping...`, 'info');
|
|
156
|
+
(_d = this.progressManager) === null || _d === void 0 ? void 0 : _d.tick(true, `terms: ${taxonomy.uid} (${localeCode}, none)`, null, utils_2.PROCESS_NAMES.TAXONOMIES_TERMS_FETCH);
|
|
157
|
+
}
|
|
107
158
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
// const mapperKey = `${taxonomy.uid}_${localeCode}`; // TODO: Unsure about this required or not
|
|
111
|
-
this.taxonomiesMapper[taxonomy.uid] = targetTaxonomy;
|
|
112
|
-
const terms = await this.getAllTermsOfTaxonomy(targetTaxonomy, localeCode);
|
|
113
|
-
if (Array.isArray(terms) && terms.length > 0) {
|
|
114
|
-
cli_utilities_1.log.info(`Terms found for taxonomy '${taxonomy.uid} for locale: ${localeCode}', processing...`);
|
|
115
|
-
const sanitizedTerms = this.sanitizeTermsAttribs(terms);
|
|
116
|
-
this.termsMapper[taxonomy.uid] = sanitizedTerms;
|
|
117
|
-
}
|
|
118
|
-
else {
|
|
119
|
-
cli_utilities_1.log.info(`No terms found for taxonomy '${taxonomy.uid} for locale: ${localeCode}', skipping...`);
|
|
159
|
+
catch (error) {
|
|
160
|
+
(_e = this.progressManager) === null || _e === void 0 ? void 0 : _e.tick(false, `taxonomy: ${taxonomy.uid} (${localeCode})`, (error === null || error === void 0 ? void 0 : error.message) || 'Failed to fetch', utils_2.PROCESS_NAMES.TAXONOMIES_FETCH);
|
|
120
161
|
}
|
|
121
162
|
}
|
|
122
163
|
}
|
|
@@ -130,10 +171,10 @@ class TaxonomiesImportSetup {
|
|
|
130
171
|
const masterLocaleFolder = (0, path_1.join)(this.taxonomiesFolderPath, masterLocaleCode);
|
|
131
172
|
// Check if master locale folder exists (indicates new locale-based structure)
|
|
132
173
|
if (!utils_1.fileHelper.fileExistsSync(masterLocaleFolder)) {
|
|
133
|
-
|
|
174
|
+
(0, utils_1.log)(this.config, 'No locale-based folder structure detected', 'info');
|
|
134
175
|
return false;
|
|
135
176
|
}
|
|
136
|
-
|
|
177
|
+
(0, utils_1.log)(this.config, 'Locale-based folder structure detected', 'info');
|
|
137
178
|
return true;
|
|
138
179
|
}
|
|
139
180
|
/**
|
|
@@ -150,17 +191,17 @@ class TaxonomiesImportSetup {
|
|
|
150
191
|
// The file contains an object with UID as key, extract the code
|
|
151
192
|
const firstLocale = Object.values(masterLocaleData)[0];
|
|
152
193
|
if (firstLocale === null || firstLocale === void 0 ? void 0 : firstLocale.code) {
|
|
153
|
-
|
|
194
|
+
(0, utils_1.log)(this.config, `Master locale loaded from file: ${firstLocale.code}`, 'info');
|
|
154
195
|
return firstLocale.code;
|
|
155
196
|
}
|
|
156
197
|
}
|
|
157
198
|
catch (error) {
|
|
158
|
-
|
|
199
|
+
(0, utils_1.log)(this.config, 'Error reading master-locale.json, using fallback', 'warn');
|
|
159
200
|
}
|
|
160
201
|
}
|
|
161
202
|
// Fallback to config or default
|
|
162
203
|
const fallbackCode = ((_a = this.config.master_locale) === null || _a === void 0 ? void 0 : _a.code) || 'en-us';
|
|
163
|
-
|
|
204
|
+
(0, utils_1.log)(this.config, `Using fallback master locale: ${fallbackCode}`, 'info');
|
|
164
205
|
return fallbackCode;
|
|
165
206
|
}
|
|
166
207
|
/**
|
|
@@ -174,7 +215,7 @@ class TaxonomiesImportSetup {
|
|
|
174
215
|
locales[masterLocaleCode] = masterLocaleCode;
|
|
175
216
|
// Then load additional locales from locales.json if it exists
|
|
176
217
|
if (!utils_1.fileHelper.fileExistsSync(this.localesFilePath)) {
|
|
177
|
-
|
|
218
|
+
(0, utils_1.log)(this.config, 'No locales file found, using only master locale', 'info');
|
|
178
219
|
return locales;
|
|
179
220
|
}
|
|
180
221
|
try {
|
|
@@ -184,11 +225,11 @@ class TaxonomiesImportSetup {
|
|
|
184
225
|
locales[locale.code] = locale.code;
|
|
185
226
|
}
|
|
186
227
|
}
|
|
187
|
-
|
|
228
|
+
(0, utils_1.log)(this.config, `Loaded ${Object.keys(locales).length} locales (1 master + ${Object.keys(locales).length - 1} additional)`, 'info');
|
|
188
229
|
return locales;
|
|
189
230
|
}
|
|
190
231
|
catch (error) {
|
|
191
|
-
|
|
232
|
+
(0, utils_1.log)(this.config, 'Error loading locales file, using only master locale', 'error');
|
|
192
233
|
return locales;
|
|
193
234
|
}
|
|
194
235
|
}
|
|
@@ -270,10 +311,11 @@ class TaxonomiesImportSetup {
|
|
|
270
311
|
const taxInfo = taxonomyUid ? ` (${taxonomyUid}${context})` : '';
|
|
271
312
|
if ((err === null || err === void 0 ? void 0 : err.errorMessage) || (err === null || err === void 0 ? void 0 : err.message)) {
|
|
272
313
|
const errorMsg = (err === null || err === void 0 ? void 0 : err.errorMessage) || ((_a = err === null || err === void 0 ? void 0 : err.errors) === null || _a === void 0 ? void 0 : _a.taxonomy) || ((_b = err === null || err === void 0 ? void 0 : err.errors) === null || _b === void 0 ? void 0 : _b.term) || (err === null || err === void 0 ? void 0 : err.message);
|
|
273
|
-
|
|
314
|
+
(0, utils_1.log)(this.config, `${errorMsg}${taxInfo}`, 'error');
|
|
274
315
|
}
|
|
275
316
|
else {
|
|
276
|
-
|
|
317
|
+
(0, utils_1.log)(this.config, `Error fetching taxonomy data${taxInfo}!`, 'error');
|
|
318
|
+
(0, utils_1.log)(this.config, err, 'error');
|
|
277
319
|
}
|
|
278
320
|
}
|
|
279
321
|
}
|
|
@@ -38,7 +38,6 @@ export default interface ImportConfig extends DefaultConfig, ExternalConfig {
|
|
|
38
38
|
authtoken?: string;
|
|
39
39
|
destinationStackName?: string;
|
|
40
40
|
org_uid?: string;
|
|
41
|
-
contentVersion: number;
|
|
42
41
|
stackName?: string;
|
|
43
42
|
branchName: string;
|
|
44
43
|
selectedModules: Modules[];
|
|
@@ -46,6 +45,7 @@ export default interface ImportConfig extends DefaultConfig, ExternalConfig {
|
|
|
46
45
|
backupDir: string;
|
|
47
46
|
createBackupDir?: string;
|
|
48
47
|
region: any;
|
|
48
|
+
authenticationMethod?: string;
|
|
49
49
|
}
|
|
50
50
|
type branch = {
|
|
51
51
|
uid: string;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -51,7 +51,7 @@ export interface InquirePayload {
|
|
|
51
51
|
name: string;
|
|
52
52
|
message: string;
|
|
53
53
|
choices?: Array<any>;
|
|
54
|
-
transformer?:
|
|
54
|
+
transformer?: (...args: any[]) => any;
|
|
55
55
|
}
|
|
56
56
|
export interface User {
|
|
57
57
|
email: string;
|
|
@@ -115,5 +115,12 @@ export type TaxonomyQueryParams = {
|
|
|
115
115
|
locale?: string;
|
|
116
116
|
};
|
|
117
117
|
export interface Context {
|
|
118
|
+
command: string;
|
|
118
119
|
module: string;
|
|
120
|
+
userId: string | undefined;
|
|
121
|
+
email: string | undefined;
|
|
122
|
+
sessionId: string | undefined;
|
|
123
|
+
apiKey: string;
|
|
124
|
+
orgId: string;
|
|
125
|
+
authenticationMethod?: string;
|
|
119
126
|
}
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
import { log as defaultLog } from '@contentstack/cli-utilities';
|
|
1
2
|
import { ImportConfig } from 'src/types';
|
|
2
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Dependencies for validateBranch - can be injected for testing
|
|
5
|
+
*/
|
|
6
|
+
export interface ValidateBranchDeps {
|
|
7
|
+
log?: typeof defaultLog;
|
|
8
|
+
}
|
|
9
|
+
export declare const validateBranch: (stackAPIClient: any, config: ImportConfig, branch: any, deps?: ValidateBranchDeps) => Promise<unknown>;
|
|
@@ -4,14 +4,16 @@ exports.validateBranch = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
|
6
6
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
7
|
-
const validateBranch = async (stackAPIClient, config, branch) => {
|
|
7
|
+
const validateBranch = async (stackAPIClient, config, branch, deps = {}) => {
|
|
8
|
+
var _a;
|
|
9
|
+
const log = (_a = deps.log) !== null && _a !== void 0 ? _a : cli_utilities_1.log;
|
|
8
10
|
return new Promise(async (resolve, reject) => {
|
|
9
11
|
try {
|
|
10
12
|
const data = await stackAPIClient.branch(branch).fetch();
|
|
11
13
|
if (data && typeof data === 'object') {
|
|
12
14
|
if (data.error_message) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
log.error(chalk_1.default.red(data.error_message), { error: data.error_message });
|
|
16
|
+
log.error(chalk_1.default.red('No branch found with the name ' + branch), { branch });
|
|
15
17
|
reject({ message: 'No branch found with the name ' + branch, error: data.error_message });
|
|
16
18
|
}
|
|
17
19
|
else {
|
|
@@ -23,7 +25,7 @@ const validateBranch = async (stackAPIClient, config, branch) => {
|
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
catch (error) {
|
|
26
|
-
|
|
28
|
+
log.error(chalk_1.default.red('No branch found with the name ' + branch), { error, branch });
|
|
27
29
|
reject({ message: 'No branch found with the name ' + branch, error });
|
|
28
30
|
}
|
|
29
31
|
});
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const PROCESS_NAMES: {
|
|
2
|
+
readonly ENTRIES_MAPPER_GENERATION: "Mapper Generation";
|
|
3
|
+
readonly CONTENT_TYPES_MAPPER_GENERATION: "Mapper Generation";
|
|
4
|
+
readonly CONTENT_TYPES_DEPENDENCY_SETUP: "Dependency Setup";
|
|
5
|
+
readonly GLOBAL_FIELDS_MAPPER_GENERATION: "Mapper Generation";
|
|
6
|
+
readonly GLOBAL_FIELDS_DEPENDENCY_SETUP: "Dependency Setup";
|
|
7
|
+
readonly EXTENSIONS_MAPPER_GENERATION: "Mapper Generation";
|
|
8
|
+
readonly ASSETS_MAPPER_GENERATION: "Mapper Generation";
|
|
9
|
+
readonly ASSETS_FETCH_AND_MAP: "Fetch and Map";
|
|
10
|
+
readonly CUSTOM_ROLES_MAPPER_GENERATION: "Mapper Generation";
|
|
11
|
+
readonly MARKETPLACE_APPS_MAPPER_GENERATION: "Mapper Generation";
|
|
12
|
+
readonly MARKETPLACE_APPS_FETCH: "Fetch Apps";
|
|
13
|
+
readonly TAXONOMIES_MAPPER_GENERATION: "Mapper Generation";
|
|
14
|
+
readonly TAXONOMIES_FETCH: "Fetch Taxonomies";
|
|
15
|
+
readonly TAXONOMIES_TERMS_FETCH: "Fetch Terms";
|
|
16
|
+
};
|
|
17
|
+
export declare const MODULE_CONTEXTS: {
|
|
18
|
+
readonly ENTRIES: "entries";
|
|
19
|
+
readonly CONTENT_TYPES: "content-types";
|
|
20
|
+
readonly GLOBAL_FIELDS: "global-fields";
|
|
21
|
+
readonly EXTENSIONS: "extensions";
|
|
22
|
+
readonly ASSETS: "assets";
|
|
23
|
+
readonly CUSTOM_ROLES: "custom-roles";
|
|
24
|
+
readonly MARKETPLACE_APPS: "marketplace-apps";
|
|
25
|
+
readonly TAXONOMIES: "taxonomies";
|
|
26
|
+
};
|
|
27
|
+
export declare const MODULE_NAMES: {
|
|
28
|
+
readonly entries: "Entries";
|
|
29
|
+
readonly "content-types": "Content Types";
|
|
30
|
+
readonly "global-fields": "Global Fields";
|
|
31
|
+
readonly extensions: "Extensions";
|
|
32
|
+
readonly assets: "Assets";
|
|
33
|
+
readonly "custom-roles": "Custom Roles";
|
|
34
|
+
readonly "marketplace-apps": "Marketplace Apps";
|
|
35
|
+
readonly taxonomies: "Taxonomies";
|
|
36
|
+
};
|
|
37
|
+
export declare const PROCESS_STATUS: Record<keyof typeof PROCESS_NAMES, Record<string, string>>;
|
|
38
|
+
export type ImportSetupProcessName = (typeof PROCESS_NAMES)[keyof typeof PROCESS_NAMES];
|
|
39
|
+
export type ImportSetupModuleContext = (typeof MODULE_CONTEXTS)[keyof typeof MODULE_CONTEXTS];
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PROCESS_STATUS = exports.MODULE_NAMES = exports.MODULE_CONTEXTS = exports.PROCESS_NAMES = void 0;
|
|
4
|
+
exports.PROCESS_NAMES = {
|
|
5
|
+
// Entries module
|
|
6
|
+
ENTRIES_MAPPER_GENERATION: 'Mapper Generation',
|
|
7
|
+
// Content Types module
|
|
8
|
+
CONTENT_TYPES_MAPPER_GENERATION: 'Mapper Generation',
|
|
9
|
+
CONTENT_TYPES_DEPENDENCY_SETUP: 'Dependency Setup',
|
|
10
|
+
// Global Fields module
|
|
11
|
+
GLOBAL_FIELDS_MAPPER_GENERATION: 'Mapper Generation',
|
|
12
|
+
GLOBAL_FIELDS_DEPENDENCY_SETUP: 'Dependency Setup',
|
|
13
|
+
// Extensions module
|
|
14
|
+
EXTENSIONS_MAPPER_GENERATION: 'Mapper Generation',
|
|
15
|
+
// Assets module
|
|
16
|
+
ASSETS_MAPPER_GENERATION: 'Mapper Generation',
|
|
17
|
+
ASSETS_FETCH_AND_MAP: 'Fetch and Map',
|
|
18
|
+
// Custom Roles module
|
|
19
|
+
CUSTOM_ROLES_MAPPER_GENERATION: 'Mapper Generation',
|
|
20
|
+
// Marketplace Apps module
|
|
21
|
+
MARKETPLACE_APPS_MAPPER_GENERATION: 'Mapper Generation',
|
|
22
|
+
MARKETPLACE_APPS_FETCH: 'Fetch Apps',
|
|
23
|
+
// Taxonomies module
|
|
24
|
+
TAXONOMIES_MAPPER_GENERATION: 'Mapper Generation',
|
|
25
|
+
TAXONOMIES_FETCH: 'Fetch Taxonomies',
|
|
26
|
+
TAXONOMIES_TERMS_FETCH: 'Fetch Terms',
|
|
27
|
+
};
|
|
28
|
+
exports.MODULE_CONTEXTS = {
|
|
29
|
+
ENTRIES: 'entries',
|
|
30
|
+
CONTENT_TYPES: 'content-types',
|
|
31
|
+
GLOBAL_FIELDS: 'global-fields',
|
|
32
|
+
EXTENSIONS: 'extensions',
|
|
33
|
+
ASSETS: 'assets',
|
|
34
|
+
CUSTOM_ROLES: 'custom-roles',
|
|
35
|
+
MARKETPLACE_APPS: 'marketplace-apps',
|
|
36
|
+
TAXONOMIES: 'taxonomies',
|
|
37
|
+
};
|
|
38
|
+
// Display names for modules to avoid scattering user-facing strings
|
|
39
|
+
exports.MODULE_NAMES = {
|
|
40
|
+
[exports.MODULE_CONTEXTS.ENTRIES]: 'Entries',
|
|
41
|
+
[exports.MODULE_CONTEXTS.CONTENT_TYPES]: 'Content Types',
|
|
42
|
+
[exports.MODULE_CONTEXTS.GLOBAL_FIELDS]: 'Global Fields',
|
|
43
|
+
[exports.MODULE_CONTEXTS.EXTENSIONS]: 'Extensions',
|
|
44
|
+
[exports.MODULE_CONTEXTS.ASSETS]: 'Assets',
|
|
45
|
+
[exports.MODULE_CONTEXTS.CUSTOM_ROLES]: 'Custom Roles',
|
|
46
|
+
[exports.MODULE_CONTEXTS.MARKETPLACE_APPS]: 'Marketplace Apps',
|
|
47
|
+
[exports.MODULE_CONTEXTS.TAXONOMIES]: 'Taxonomies',
|
|
48
|
+
};
|
|
49
|
+
exports.PROCESS_STATUS = {
|
|
50
|
+
// Entries
|
|
51
|
+
ENTRIES_MAPPER_GENERATION: {
|
|
52
|
+
GENERATING: 'Generating mapper files...',
|
|
53
|
+
FAILED: 'Failed to generate mapper files.',
|
|
54
|
+
},
|
|
55
|
+
// Content Types
|
|
56
|
+
CONTENT_TYPES_MAPPER_GENERATION: {
|
|
57
|
+
GENERATING: 'Generating mapper files...',
|
|
58
|
+
FAILED: 'Failed to generate mapper files.',
|
|
59
|
+
},
|
|
60
|
+
CONTENT_TYPES_DEPENDENCY_SETUP: {
|
|
61
|
+
SETTING_UP: 'Setting up dependencies...',
|
|
62
|
+
FAILED: 'Failed to setup dependencies.',
|
|
63
|
+
},
|
|
64
|
+
// Global Fields
|
|
65
|
+
GLOBAL_FIELDS_MAPPER_GENERATION: {
|
|
66
|
+
GENERATING: 'Generating mapper files...',
|
|
67
|
+
FAILED: 'Failed to generate mapper files.',
|
|
68
|
+
},
|
|
69
|
+
GLOBAL_FIELDS_DEPENDENCY_SETUP: {
|
|
70
|
+
SETTING_UP: 'Setting up dependencies...',
|
|
71
|
+
FAILED: 'Failed to setup dependencies.',
|
|
72
|
+
},
|
|
73
|
+
// Extensions
|
|
74
|
+
EXTENSIONS_MAPPER_GENERATION: {
|
|
75
|
+
GENERATING: 'Generating mapper files...',
|
|
76
|
+
FAILED: 'Failed to generate mapper files.',
|
|
77
|
+
},
|
|
78
|
+
// Assets
|
|
79
|
+
ASSETS_MAPPER_GENERATION: {
|
|
80
|
+
GENERATING: 'Generating mapper files...',
|
|
81
|
+
FAILED: 'Failed to generate mapper files.',
|
|
82
|
+
},
|
|
83
|
+
ASSETS_FETCH_AND_MAP: {
|
|
84
|
+
FETCHING: 'Fetching and mapping assets...',
|
|
85
|
+
FAILED: 'Failed to fetch and map assets.',
|
|
86
|
+
},
|
|
87
|
+
// Custom Roles
|
|
88
|
+
CUSTOM_ROLES_MAPPER_GENERATION: {
|
|
89
|
+
GENERATING: 'Generating mapper files...',
|
|
90
|
+
FAILED: 'Failed to generate mapper files.',
|
|
91
|
+
},
|
|
92
|
+
// Marketplace Apps
|
|
93
|
+
MARKETPLACE_APPS_MAPPER_GENERATION: {
|
|
94
|
+
GENERATING: 'Generating mapper files...',
|
|
95
|
+
FAILED: 'Failed to generate mapper files.',
|
|
96
|
+
},
|
|
97
|
+
MARKETPLACE_APPS_FETCH: {
|
|
98
|
+
FETCHING: 'Fetching marketplace apps...',
|
|
99
|
+
FAILED: 'Failed to fetch marketplace apps.',
|
|
100
|
+
},
|
|
101
|
+
// Taxonomies
|
|
102
|
+
TAXONOMIES_MAPPER_GENERATION: {
|
|
103
|
+
GENERATING: 'Generating mapper files...',
|
|
104
|
+
FAILED: 'Failed to generate mapper files.',
|
|
105
|
+
},
|
|
106
|
+
TAXONOMIES_FETCH: {
|
|
107
|
+
FETCHING: 'Fetching taxonomies...',
|
|
108
|
+
FAILED: 'Failed to fetch taxonomies.',
|
|
109
|
+
},
|
|
110
|
+
TAXONOMIES_TERMS_FETCH: {
|
|
111
|
+
FETCHING: 'Fetching terms...',
|
|
112
|
+
FAILED: 'Failed to fetch terms.',
|
|
113
|
+
},
|
|
114
|
+
};
|
|
@@ -7,7 +7,7 @@ export declare const readLargeFile: (filePath: string, opts?: any) => Promise<an
|
|
|
7
7
|
export declare const writeFileSync: (filePath: string, data: any) => void;
|
|
8
8
|
export declare const writeFile: (filePath: string, data: any) => Promise<any>;
|
|
9
9
|
export declare const writeLargeFile: (filePath: string, data: any) => Promise<any>;
|
|
10
|
-
export declare const makeDirectory: (
|
|
10
|
+
export declare const makeDirectory: (...dirs: string[]) => void;
|
|
11
11
|
export declare const readdirSync: (dirPath: string) => any;
|
|
12
12
|
export declare const isFolderExist: (folderPath: string) => Promise<any>;
|
|
13
13
|
export declare const fileExistsSync: (path: string) => boolean;
|
package/lib/utils/file-helper.js
CHANGED
|
@@ -92,7 +92,7 @@ const writeLargeFile = function (filePath, data) {
|
|
|
92
92
|
const stringifyStream = bigJSON.createStringifyStream({
|
|
93
93
|
body: data,
|
|
94
94
|
});
|
|
95
|
-
|
|
95
|
+
const writeStream = fs.createWriteStream(filePath, 'utf-8');
|
|
96
96
|
stringifyStream.pipe(writeStream);
|
|
97
97
|
writeStream.on('finish', () => {
|
|
98
98
|
resolve('');
|
|
@@ -103,9 +103,9 @@ const writeLargeFile = function (filePath, data) {
|
|
|
103
103
|
});
|
|
104
104
|
};
|
|
105
105
|
exports.writeLargeFile = writeLargeFile;
|
|
106
|
-
const makeDirectory = function (
|
|
107
|
-
for (
|
|
108
|
-
const dirname = path.resolve(
|
|
106
|
+
const makeDirectory = function (...dirs) {
|
|
107
|
+
for (const dir of dirs) {
|
|
108
|
+
const dirname = path.resolve(dir);
|
|
109
109
|
if (!fs.existsSync(dirname)) {
|
|
110
110
|
mkdirp_1.default.sync(dirname);
|
|
111
111
|
}
|
|
@@ -5,11 +5,13 @@ const merge_1 = tslib_1.__importDefault(require("merge"));
|
|
|
5
5
|
const path = tslib_1.__importStar(require("path"));
|
|
6
6
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
7
7
|
const config_1 = tslib_1.__importDefault(require("../config"));
|
|
8
|
-
const file_helper_1 = require("./file-helper");
|
|
9
8
|
const interactive_1 = require("./interactive");
|
|
10
9
|
const login_handler_1 = tslib_1.__importDefault(require("./login-handler"));
|
|
11
10
|
const setupConfig = async (importCmdFlags) => {
|
|
12
11
|
var _a;
|
|
12
|
+
// Set progress supported module FIRST, before any log calls
|
|
13
|
+
// This ensures the logger respects the showConsoleLogs setting correctly
|
|
14
|
+
cli_utilities_1.configHandler.set('log.progressSupportedModule', 'import-setup');
|
|
13
15
|
let config = (0, merge_1.default)({}, config_1.default);
|
|
14
16
|
// setup the config
|
|
15
17
|
// if (importCmdFlags['config']) {
|
|
@@ -32,13 +34,6 @@ const setupConfig = async (importCmdFlags) => {
|
|
|
32
34
|
config.contentDir = path.resolve(config.contentDir);
|
|
33
35
|
//Note to support the old key
|
|
34
36
|
config.data = config.contentDir;
|
|
35
|
-
if ((0, file_helper_1.fileExistsSync)(path.join(config.contentDir, 'export-info.json'))) {
|
|
36
|
-
config.contentVersion =
|
|
37
|
-
((await (0, file_helper_1.readFile)(path.join(config.contentDir, 'export-info.json'))) || {}).contentVersion || 2;
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
config.contentVersion = 1;
|
|
41
|
-
}
|
|
42
37
|
const managementTokenAlias = importCmdFlags['management-token-alias'] || importCmdFlags['alias'];
|
|
43
38
|
if (managementTokenAlias) {
|
|
44
39
|
const { token, apiKey } = (_a = cli_utilities_1.configHandler.get(`tokens.${managementTokenAlias}`)) !== null && _a !== void 0 ? _a : {};
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setupBranchConfig = exports.unlinkFileLogger = exports.log = exports.backupHandler = exports.fsUtil = exports.fileHelper = exports.setupImportConfig = exports.interactive = void 0;
|
|
3
|
+
exports.PROCESS_STATUS = exports.PROCESS_NAMES = exports.MODULE_NAMES = exports.MODULE_CONTEXTS = exports.setupBranchConfig = exports.unlinkFileLogger = exports.log = exports.backupHandler = exports.fsUtil = exports.fileHelper = exports.setupImportConfig = exports.interactive = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
exports.interactive = tslib_1.__importStar(require("./interactive"));
|
|
6
6
|
var import_config_handler_1 = require("./import-config-handler");
|
|
@@ -17,3 +17,8 @@ tslib_1.__exportStar(require("./log"), exports);
|
|
|
17
17
|
tslib_1.__exportStar(require("./common-helper"), exports);
|
|
18
18
|
var setup_branch_1 = require("./setup-branch");
|
|
19
19
|
Object.defineProperty(exports, "setupBranchConfig", { enumerable: true, get: function () { return setup_branch_1.setupBranchConfig; } });
|
|
20
|
+
var constants_1 = require("./constants");
|
|
21
|
+
Object.defineProperty(exports, "MODULE_CONTEXTS", { enumerable: true, get: function () { return constants_1.MODULE_CONTEXTS; } });
|
|
22
|
+
Object.defineProperty(exports, "MODULE_NAMES", { enumerable: true, get: function () { return constants_1.MODULE_NAMES; } });
|
|
23
|
+
Object.defineProperty(exports, "PROCESS_NAMES", { enumerable: true, get: function () { return constants_1.PROCESS_NAMES; } });
|
|
24
|
+
Object.defineProperty(exports, "PROCESS_STATUS", { enumerable: true, get: function () { return constants_1.PROCESS_STATUS; } });
|
package/lib/utils/log.js
CHANGED
|
@@ -6,7 +6,7 @@ const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
|
6
6
|
let logger;
|
|
7
7
|
exports.logger = logger;
|
|
8
8
|
function isImportConfig(config) {
|
|
9
|
-
return config.data !== undefined
|
|
9
|
+
return config.data !== undefined;
|
|
10
10
|
}
|
|
11
11
|
exports.isImportConfig = isImportConfig;
|
|
12
12
|
function log(entryOrMessage, logType, hidden) {
|