@contentstack/cli-cm-import-setup 1.7.2 → 2.0.0-beta.1
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 +1 -1
- package/lib/commands/cm/stacks/import-setup.d.ts +1 -0
- package/lib/commands/cm/stacks/import-setup.js +24 -3
- package/lib/import/modules/assets.js +47 -15
- 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 +7 -0
- package/lib/utils/constants.d.ts +39 -0
- package/lib/utils/constants.js +114 -0
- package/lib/utils/import-config-handler.js +0 -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 +1 -1
- package/lib/utils/login-handler.d.ts +1 -1
- package/lib/utils/login-handler.js +1 -1
- package/oclif.manifest.json +1 -1
- package/package.json +3 -3
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import-setup
|
|
|
47
47
|
$ csdx COMMAND
|
|
48
48
|
running command...
|
|
49
49
|
$ csdx (--version)
|
|
50
|
-
@contentstack/cli-cm-import-setup/
|
|
50
|
+
@contentstack/cli-cm-import-setup/2.0.0-beta.1 linux-x64 node-v22.21.1
|
|
51
51
|
$ csdx --help [COMMAND]
|
|
52
52
|
USAGE
|
|
53
53
|
$ csdx COMMAND
|
|
@@ -8,27 +8,48 @@ const utils_1 = require("../../../utils");
|
|
|
8
8
|
const import_1 = require("../../../import");
|
|
9
9
|
class ImportSetupCommand extends cli_command_1.Command {
|
|
10
10
|
async run() {
|
|
11
|
-
var _a, _b;
|
|
12
11
|
try {
|
|
13
12
|
const { flags } = await this.parse(ImportSetupCommand);
|
|
14
13
|
let importSetupConfig = await (0, utils_1.setupImportConfig)(flags);
|
|
15
14
|
// Prepare the context object
|
|
16
|
-
|
|
17
|
-
importSetupConfig.context = {
|
|
15
|
+
const context = this.createImportSetupContext(importSetupConfig.apiKey, importSetupConfig.authenticationMethod);
|
|
16
|
+
importSetupConfig.context = Object.assign({}, context);
|
|
18
17
|
// Note setting host to create cma client
|
|
19
18
|
importSetupConfig.host = this.cmaHost;
|
|
20
19
|
importSetupConfig.region = this.region;
|
|
21
20
|
importSetupConfig.developerHubBaseUrl = this.developerHubUrl;
|
|
21
|
+
if (flags.branch) {
|
|
22
|
+
cli_utilities_1.CLIProgressManager.initializeGlobalSummary(`IMPORT-SETUP-${flags.branch}`, flags.branch, `Setting up import for "${flags.branch}" branch...`);
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
cli_utilities_1.CLIProgressManager.initializeGlobalSummary(`IMPORT-SETUP`, flags.branch, 'Setting up import...');
|
|
26
|
+
}
|
|
22
27
|
const managementAPIClient = await (0, cli_utilities_1.managementSDKClient)(importSetupConfig);
|
|
23
28
|
const importSetup = new import_1.ImportSetup(importSetupConfig, managementAPIClient);
|
|
24
29
|
await importSetup.start();
|
|
30
|
+
cli_utilities_1.CLIProgressManager.printGlobalSummary();
|
|
25
31
|
cli_utilities_1.log.success(`Backup folder and mapper files have been successfully created for the stack using the API key ${importSetupConfig.apiKey}.`, importSetupConfig.context);
|
|
26
32
|
cli_utilities_1.log.success(`The backup folder has been created at '${(0, cli_utilities_1.pathValidator)(node_path_1.default.join(importSetupConfig.backupDir))}'.`, importSetupConfig.context);
|
|
27
33
|
}
|
|
28
34
|
catch (error) {
|
|
35
|
+
cli_utilities_1.CLIProgressManager.printGlobalSummary();
|
|
29
36
|
(0, cli_utilities_1.handleAndLogError)(error);
|
|
30
37
|
}
|
|
31
38
|
}
|
|
39
|
+
// Create import setup context object
|
|
40
|
+
createImportSetupContext(apiKey, authenticationMethod, module) {
|
|
41
|
+
var _a, _b, _c;
|
|
42
|
+
return {
|
|
43
|
+
command: ((_b = (_a = this.context) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.command) || 'cm:stacks:import-setup',
|
|
44
|
+
module: module || '',
|
|
45
|
+
userId: cli_utilities_1.configHandler.get('userUid') || undefined,
|
|
46
|
+
email: cli_utilities_1.configHandler.get('email') || undefined,
|
|
47
|
+
sessionId: (_c = this.context) === null || _c === void 0 ? void 0 : _c.sessionId,
|
|
48
|
+
apiKey: apiKey || '',
|
|
49
|
+
orgId: cli_utilities_1.configHandler.get('oauthOrgUid') || '',
|
|
50
|
+
authenticationMethod: authenticationMethod || 'Basic Auth',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
32
53
|
}
|
|
33
54
|
exports.default = ImportSetupCommand;
|
|
34
55
|
ImportSetupCommand.description = cli_utilities_1.messageHandler.parse('Helps to generate mappers and backup folder for importing (overwriting) specific modules');
|
|
@@ -6,10 +6,11 @@ const path_1 = require("path");
|
|
|
6
6
|
const lodash_1 = require("lodash");
|
|
7
7
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
8
8
|
const base_setup_1 = tslib_1.__importDefault(require("./base-setup"));
|
|
9
|
+
const utils_2 = require("../../utils");
|
|
9
10
|
class AssetImportSetup extends base_setup_1.default {
|
|
10
11
|
constructor({ config, stackAPIClient, dependencies }) {
|
|
11
12
|
super({ config, stackAPIClient, dependencies });
|
|
12
|
-
this.
|
|
13
|
+
this.currentModuleName = utils_2.MODULE_NAMES[utils_2.MODULE_CONTEXTS.ASSETS];
|
|
13
14
|
this.assetsFolderPath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'assets');
|
|
14
15
|
this.assetsFilePath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'assets', 'assets.json');
|
|
15
16
|
this.assetsConfig = config.modules.assets;
|
|
@@ -27,18 +28,43 @@ class AssetImportSetup extends base_setup_1.default {
|
|
|
27
28
|
* @returns {Promise<void>}
|
|
28
29
|
*/
|
|
29
30
|
async start() {
|
|
31
|
+
var _a;
|
|
30
32
|
try {
|
|
33
|
+
const progress = this.createNestedProgress(this.currentModuleName);
|
|
34
|
+
// Analyze to get chunk count
|
|
35
|
+
const indexerCount = await this.withLoadingSpinner('ASSETS: Analyzing import data...', async () => {
|
|
36
|
+
const basePath = this.assetsFolderPath;
|
|
37
|
+
const fs = new cli_utilities_1.FsUtility({ basePath, indexFileName: 'assets.json' });
|
|
38
|
+
const indexer = fs.indexFileContent;
|
|
39
|
+
return (0, lodash_1.values)(indexer).length;
|
|
40
|
+
});
|
|
41
|
+
if (indexerCount === 0) {
|
|
42
|
+
(0, utils_1.log)(this.config, 'No assets found in the content folder.', 'info');
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
// Add processes - use a large number for total assets since we don't know exact count
|
|
46
|
+
// The progress will update as we process each asset
|
|
47
|
+
progress.addProcess(utils_2.PROCESS_NAMES.ASSETS_MAPPER_GENERATION, 1);
|
|
48
|
+
progress.addProcess(utils_2.PROCESS_NAMES.ASSETS_FETCH_AND_MAP, indexerCount * 10); // Estimate: ~10 assets per chunk
|
|
49
|
+
// Create mapper directory
|
|
50
|
+
progress
|
|
51
|
+
.startProcess(utils_2.PROCESS_NAMES.ASSETS_MAPPER_GENERATION)
|
|
52
|
+
.updateStatus(utils_2.PROCESS_STATUS.ASSETS_MAPPER_GENERATION.GENERATING, utils_2.PROCESS_NAMES.ASSETS_MAPPER_GENERATION);
|
|
31
53
|
utils_1.fsUtil.makeDirectory(this.mapperDirPath);
|
|
32
|
-
|
|
54
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, 'mapper directory created', null, utils_2.PROCESS_NAMES.ASSETS_MAPPER_GENERATION);
|
|
55
|
+
progress.completeProcess(utils_2.PROCESS_NAMES.ASSETS_MAPPER_GENERATION, true);
|
|
56
|
+
// Fetch and map assets
|
|
57
|
+
progress
|
|
58
|
+
.startProcess(utils_2.PROCESS_NAMES.ASSETS_FETCH_AND_MAP)
|
|
59
|
+
.updateStatus(utils_2.PROCESS_STATUS.ASSETS_FETCH_AND_MAP.FETCHING, utils_2.PROCESS_NAMES.ASSETS_FETCH_AND_MAP);
|
|
33
60
|
await this.fetchAndMapAssets();
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
});
|
|
38
|
-
cli_utilities_1.log.success(`The required setup files for the asset have been generated successfully.`);
|
|
61
|
+
progress.completeProcess(utils_2.PROCESS_NAMES.ASSETS_FETCH_AND_MAP, true);
|
|
62
|
+
this.completeProgress(true);
|
|
63
|
+
(0, utils_1.log)(this.config, `The required setup files for the asset have been generated successfully.`, 'success');
|
|
39
64
|
}
|
|
40
65
|
catch (error) {
|
|
41
|
-
(
|
|
66
|
+
this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Assets mapper generation failed');
|
|
67
|
+
(0, utils_1.log)(this.config, `Error occurred while generating the asset mapper: ${(0, cli_utilities_1.formatError)(error)}.`, 'error');
|
|
42
68
|
}
|
|
43
69
|
}
|
|
44
70
|
/**
|
|
@@ -47,7 +73,6 @@ class AssetImportSetup extends base_setup_1.default {
|
|
|
47
73
|
* @returns {Promise<void>} Promise<void>
|
|
48
74
|
*/
|
|
49
75
|
async fetchAndMapAssets() {
|
|
50
|
-
cli_utilities_1.log.debug('Starting asset fetch and mapping', { assetsFolderPath: this.assetsFolderPath });
|
|
51
76
|
const processName = 'mapping assets';
|
|
52
77
|
const indexFileName = 'assets.json';
|
|
53
78
|
const basePath = this.assetsFolderPath;
|
|
@@ -55,28 +80,35 @@ class AssetImportSetup extends base_setup_1.default {
|
|
|
55
80
|
const indexer = fs.indexFileContent;
|
|
56
81
|
const indexerCount = (0, lodash_1.values)(indexer).length;
|
|
57
82
|
const onSuccess = ({ response: { items = [] } = {}, apiData: { uid, url, title } = undefined, }) => {
|
|
83
|
+
var _a, _b, _c;
|
|
58
84
|
if (items.length === 1) {
|
|
59
85
|
this.assetUidMapper[uid] = items[0].uid;
|
|
60
86
|
this.assetUrlMapper[url] = items[0].url;
|
|
61
|
-
|
|
87
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, `asset: ${title}`, null, utils_2.PROCESS_NAMES.ASSETS_FETCH_AND_MAP);
|
|
88
|
+
(0, utils_1.log)(this.config, `Mapped asset successfully: '${title}'`, 'info');
|
|
62
89
|
}
|
|
63
90
|
else if (items.length > 1) {
|
|
64
91
|
this.duplicateAssets[uid] = items.map((asset) => {
|
|
65
92
|
return { uid: asset.uid, title: asset.title, url: asset.url };
|
|
66
93
|
});
|
|
67
|
-
|
|
94
|
+
(_b = this.progressManager) === null || _b === void 0 ? void 0 : _b.tick(true, `asset: ${title} (duplicate)`, null, utils_2.PROCESS_NAMES.ASSETS_FETCH_AND_MAP);
|
|
95
|
+
(0, utils_1.log)(this.config, `Multiple assets found with the title '${title}'.`, 'info');
|
|
68
96
|
}
|
|
69
97
|
else {
|
|
70
|
-
|
|
98
|
+
(_c = this.progressManager) === null || _c === void 0 ? void 0 : _c.tick(false, `asset: ${title}`, 'Not found in stack', utils_2.PROCESS_NAMES.ASSETS_FETCH_AND_MAP);
|
|
99
|
+
(0, utils_1.log)(this.config, `Asset with title '${title}' not found in the stack!`, 'info');
|
|
71
100
|
}
|
|
72
101
|
};
|
|
73
102
|
const onReject = ({ error, apiData: { title } = undefined }) => {
|
|
74
|
-
|
|
103
|
+
var _a;
|
|
104
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(false, `asset: ${title}`, (0, cli_utilities_1.formatError)(error), utils_2.PROCESS_NAMES.ASSETS_FETCH_AND_MAP);
|
|
105
|
+
(0, utils_1.log)(this.config, `Failed to map the asset '${title}'.`, 'error');
|
|
106
|
+
(0, utils_1.log)(this.config, (0, cli_utilities_1.formatError)(error), 'error');
|
|
75
107
|
};
|
|
76
108
|
/* eslint-disable @typescript-eslint/no-unused-vars, guard-for-in */
|
|
77
109
|
for (const index in indexer) {
|
|
78
110
|
const chunk = await fs.readChunkFiles.next().catch((error) => {
|
|
79
|
-
|
|
111
|
+
(0, utils_1.log)(this.config, error, 'error');
|
|
80
112
|
});
|
|
81
113
|
if (chunk) {
|
|
82
114
|
let apiContent = (0, lodash_1.orderBy)((0, lodash_1.values)(chunk), '_version');
|
|
@@ -101,7 +133,7 @@ class AssetImportSetup extends base_setup_1.default {
|
|
|
101
133
|
}
|
|
102
134
|
if (!(0, lodash_1.isEmpty)(this.duplicateAssets)) {
|
|
103
135
|
utils_1.fsUtil.writeFile(this.duplicateAssetPath, this.duplicateAssets);
|
|
104
|
-
|
|
136
|
+
(0, utils_1.log)(this.config, `Duplicate asset files are stored at: ${this.duplicateAssetPath}.`, 'info');
|
|
105
137
|
}
|
|
106
138
|
}
|
|
107
139
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import { ApiOptions, CustomPromiseHandler, EnvType, ImportConfig, ModuleClassParams
|
|
1
|
+
import { ApiOptions, CustomPromiseHandler, EnvType, ImportConfig, ModuleClassParams } from '../../types';
|
|
2
|
+
import { CLIProgressManager } from '@contentstack/cli-utilities';
|
|
2
3
|
export default class BaseImportSetup {
|
|
3
4
|
config: ImportConfig;
|
|
4
5
|
stackAPIClient: ModuleClassParams['stackAPIClient'];
|
|
5
6
|
dependencies: ModuleClassParams['dependencies'];
|
|
7
|
+
protected progressManager: CLIProgressManager | null;
|
|
8
|
+
protected currentModuleName: string;
|
|
6
9
|
constructor({ config, stackAPIClient, dependencies }: ModuleClassParams);
|
|
7
|
-
/**
|
|
8
|
-
* Set the module name in context directly
|
|
9
|
-
* @param module - Module name to set
|
|
10
|
-
* @returns {void}
|
|
11
|
-
*/
|
|
12
|
-
protected initializeContext(module?: Modules): void;
|
|
13
10
|
setupDependencies(): Promise<void>;
|
|
14
11
|
/**
|
|
15
12
|
* @method delay
|
|
@@ -40,4 +37,20 @@ export default class BaseImportSetup {
|
|
|
40
37
|
* @return {Promise} Promise<void>
|
|
41
38
|
*/
|
|
42
39
|
makeAPICall(apiOptions: ApiOptions, isLastRequest?: boolean): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Create simple progress manager
|
|
42
|
+
*/
|
|
43
|
+
protected createSimpleProgress(moduleName: string, total?: number): CLIProgressManager;
|
|
44
|
+
/**
|
|
45
|
+
* Create nested progress manager
|
|
46
|
+
*/
|
|
47
|
+
protected createNestedProgress(moduleName: string): CLIProgressManager;
|
|
48
|
+
/**
|
|
49
|
+
* Complete progress manager
|
|
50
|
+
*/
|
|
51
|
+
protected completeProgress(success?: boolean, error?: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* Show a loading spinner before initializing progress
|
|
54
|
+
*/
|
|
55
|
+
protected withLoadingSpinner<T>(message: string, action: () => Promise<T>): Promise<T>;
|
|
43
56
|
}
|
|
@@ -23,30 +23,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const utils_1 = require("../../utils");
|
|
26
27
|
const lodash_1 = require("lodash");
|
|
27
28
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
28
29
|
class BaseImportSetup {
|
|
29
30
|
constructor({ config, stackAPIClient, dependencies }) {
|
|
31
|
+
this.progressManager = null;
|
|
32
|
+
this.currentModuleName = '';
|
|
30
33
|
this.config = config;
|
|
31
34
|
this.stackAPIClient = stackAPIClient;
|
|
32
35
|
this.dependencies = dependencies;
|
|
33
36
|
}
|
|
34
|
-
/**
|
|
35
|
-
* Set the module name in context directly
|
|
36
|
-
* @param module - Module name to set
|
|
37
|
-
* @returns {void}
|
|
38
|
-
*/
|
|
39
|
-
initializeContext(module) {
|
|
40
|
-
if (this.config.context && module) {
|
|
41
|
-
this.config.context.module = module;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
37
|
async setupDependencies() {
|
|
45
38
|
var _a;
|
|
46
|
-
cli_utilities_1.log.debug('Setting up dependencies', { dependencies: this.dependencies });
|
|
47
39
|
for (const moduleName of this.dependencies) {
|
|
48
40
|
try {
|
|
49
|
-
cli_utilities_1.log.debug(`Importing dependency module: ${moduleName}`);
|
|
50
41
|
const modulePath = `./${moduleName}`;
|
|
51
42
|
const { default: ModuleClass } = await (_a = modulePath, Promise.resolve().then(() => __importStar(require(_a))));
|
|
52
43
|
const modulePayload = {
|
|
@@ -55,10 +46,9 @@ class BaseImportSetup {
|
|
|
55
46
|
};
|
|
56
47
|
const moduleInstance = new ModuleClass(modulePayload);
|
|
57
48
|
await moduleInstance.start();
|
|
58
|
-
cli_utilities_1.log.debug(`Dependency module ${moduleName} imported successfully`);
|
|
59
49
|
}
|
|
60
50
|
catch (error) {
|
|
61
|
-
(0,
|
|
51
|
+
(0, utils_1.log)(this.config, `Error importing '${moduleName}': ${error.message}`, 'error');
|
|
62
52
|
}
|
|
63
53
|
}
|
|
64
54
|
}
|
|
@@ -134,7 +124,7 @@ class BaseImportSetup {
|
|
|
134
124
|
// info: Batch No. 20 of import assets is complete
|
|
135
125
|
if (currentIndexer)
|
|
136
126
|
batchMsg += `Current chunk processing is (${currentIndexer}/${indexerCount})`;
|
|
137
|
-
|
|
127
|
+
(0, utils_1.log)(this.config, `Batch No. (${batchNo}/${totelBatches}) of ${processName} is complete`, 'success');
|
|
138
128
|
}
|
|
139
129
|
// if (this.config.modules.assets.displayExecutionTime) {
|
|
140
130
|
// console.log(
|
|
@@ -192,5 +182,48 @@ class BaseImportSetup {
|
|
|
192
182
|
return Promise.resolve();
|
|
193
183
|
}
|
|
194
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Create simple progress manager
|
|
187
|
+
*/
|
|
188
|
+
createSimpleProgress(moduleName, total) {
|
|
189
|
+
var _a;
|
|
190
|
+
this.currentModuleName = moduleName;
|
|
191
|
+
const logConfig = cli_utilities_1.configHandler.get('log') || {};
|
|
192
|
+
const showConsoleLogs = (_a = logConfig.showConsoleLogs) !== null && _a !== void 0 ? _a : false;
|
|
193
|
+
this.progressManager = cli_utilities_1.CLIProgressManager.createSimple(moduleName, total, showConsoleLogs);
|
|
194
|
+
return this.progressManager;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Create nested progress manager
|
|
198
|
+
*/
|
|
199
|
+
createNestedProgress(moduleName) {
|
|
200
|
+
var _a;
|
|
201
|
+
this.currentModuleName = moduleName;
|
|
202
|
+
const logConfig = cli_utilities_1.configHandler.get('log') || {};
|
|
203
|
+
const showConsoleLogs = (_a = logConfig.showConsoleLogs) !== null && _a !== void 0 ? _a : false;
|
|
204
|
+
this.progressManager = cli_utilities_1.CLIProgressManager.createNested(moduleName, showConsoleLogs);
|
|
205
|
+
return this.progressManager;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Complete progress manager
|
|
209
|
+
*/
|
|
210
|
+
completeProgress(success = true, error) {
|
|
211
|
+
var _a;
|
|
212
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.complete(success, error);
|
|
213
|
+
this.progressManager = null;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Show a loading spinner before initializing progress
|
|
217
|
+
*/
|
|
218
|
+
async withLoadingSpinner(message, action) {
|
|
219
|
+
var _a;
|
|
220
|
+
const logConfig = cli_utilities_1.configHandler.get('log') || {};
|
|
221
|
+
const showConsoleLogs = (_a = logConfig.showConsoleLogs) !== null && _a !== void 0 ? _a : false;
|
|
222
|
+
if (showConsoleLogs) {
|
|
223
|
+
// If console logs are enabled, don't show spinner, just execute the action
|
|
224
|
+
return await action();
|
|
225
|
+
}
|
|
226
|
+
return await cli_utilities_1.CLIProgressManager.withLoadingSpinner(message, action);
|
|
227
|
+
}
|
|
195
228
|
}
|
|
196
229
|
exports.default = BaseImportSetup;
|
|
@@ -1,20 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
4
5
|
const base_setup_1 = tslib_1.__importDefault(require("./base-setup"));
|
|
5
|
-
const
|
|
6
|
+
const utils_2 = require("../../utils");
|
|
6
7
|
class ContentTypesImportSetup extends base_setup_1.default {
|
|
7
8
|
constructor(options) {
|
|
8
9
|
super(options);
|
|
9
|
-
this.
|
|
10
|
+
this.currentModuleName = utils_2.MODULE_NAMES[utils_2.MODULE_CONTEXTS.CONTENT_TYPES];
|
|
10
11
|
}
|
|
11
12
|
async start() {
|
|
13
|
+
var _a, _b, _c;
|
|
12
14
|
try {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
const progress = this.createNestedProgress(this.currentModuleName);
|
|
16
|
+
// Add processes
|
|
17
|
+
progress.addProcess(utils_2.PROCESS_NAMES.CONTENT_TYPES_DEPENDENCY_SETUP, ((_a = this.dependencies) === null || _a === void 0 ? void 0 : _a.length) || 0);
|
|
18
|
+
progress.addProcess(utils_2.PROCESS_NAMES.CONTENT_TYPES_MAPPER_GENERATION, 1);
|
|
19
|
+
// Setup dependencies
|
|
20
|
+
if (this.dependencies && this.dependencies.length > 0) {
|
|
21
|
+
progress
|
|
22
|
+
.startProcess(utils_2.PROCESS_NAMES.CONTENT_TYPES_DEPENDENCY_SETUP)
|
|
23
|
+
.updateStatus(utils_2.PROCESS_STATUS.CONTENT_TYPES_DEPENDENCY_SETUP.SETTING_UP, utils_2.PROCESS_NAMES.CONTENT_TYPES_DEPENDENCY_SETUP);
|
|
24
|
+
await this.setupDependencies();
|
|
25
|
+
(_b = this.progressManager) === null || _b === void 0 ? void 0 : _b.tick(true, 'dependencies setup', null, utils_2.PROCESS_NAMES.CONTENT_TYPES_DEPENDENCY_SETUP);
|
|
26
|
+
progress.completeProcess(utils_2.PROCESS_NAMES.CONTENT_TYPES_DEPENDENCY_SETUP, true);
|
|
27
|
+
}
|
|
28
|
+
// Mapper generation
|
|
29
|
+
progress
|
|
30
|
+
.startProcess(utils_2.PROCESS_NAMES.CONTENT_TYPES_MAPPER_GENERATION)
|
|
31
|
+
.updateStatus(utils_2.PROCESS_STATUS.CONTENT_TYPES_MAPPER_GENERATION.GENERATING, utils_2.PROCESS_NAMES.CONTENT_TYPES_MAPPER_GENERATION);
|
|
32
|
+
(_c = this.progressManager) === null || _c === void 0 ? void 0 : _c.tick(true, 'mapper generation', null, utils_2.PROCESS_NAMES.CONTENT_TYPES_MAPPER_GENERATION);
|
|
33
|
+
progress.completeProcess(utils_2.PROCESS_NAMES.CONTENT_TYPES_MAPPER_GENERATION, true);
|
|
34
|
+
this.completeProgress(true);
|
|
35
|
+
(0, utils_1.log)(this.config, `The required setup files for content types have been generated successfully.`, 'success');
|
|
15
36
|
}
|
|
16
37
|
catch (error) {
|
|
17
|
-
(
|
|
38
|
+
this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Content types mapper generation failed');
|
|
39
|
+
(0, utils_1.log)(this.config, `Error occurred while generating the content type mapper: ${error.message}.`, 'error');
|
|
18
40
|
}
|
|
19
41
|
}
|
|
20
42
|
}
|
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
4
5
|
const base_setup_1 = tslib_1.__importDefault(require("./base-setup"));
|
|
5
|
-
const
|
|
6
|
+
const utils_2 = require("../../utils");
|
|
6
7
|
class EntriesImportSetup extends base_setup_1.default {
|
|
7
8
|
constructor(options) {
|
|
8
9
|
super(options);
|
|
9
|
-
this.
|
|
10
|
+
this.currentModuleName = utils_2.MODULE_NAMES[utils_2.MODULE_CONTEXTS.ENTRIES];
|
|
10
11
|
}
|
|
11
12
|
async start() {
|
|
13
|
+
var _a;
|
|
12
14
|
try {
|
|
15
|
+
const progress = this.createSimpleProgress(this.currentModuleName, 1);
|
|
16
|
+
progress.updateStatus('Setting up dependencies...');
|
|
13
17
|
await this.setupDependencies();
|
|
14
|
-
|
|
18
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(true, 'entries mapper setup', null);
|
|
19
|
+
this.completeProgress(true);
|
|
20
|
+
(0, utils_1.log)(this.config, `The required setup files for entries have been generated successfully.`, 'success');
|
|
15
21
|
}
|
|
16
22
|
catch (error) {
|
|
17
|
-
(
|
|
23
|
+
this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Entries mapper generation failed');
|
|
24
|
+
(0, utils_1.log)(this.config, `Error occurred while generating the entry mapper: ${error.message}.`, 'error');
|
|
18
25
|
}
|
|
19
26
|
}
|
|
20
27
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { ModuleClassParams } from '../../types';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import BaseImportSetup from './base-setup';
|
|
3
|
+
export default class ExtensionImportSetup extends BaseImportSetup {
|
|
4
4
|
private extensionsFilePath;
|
|
5
5
|
private extensionMapper;
|
|
6
|
-
private stackAPIClient;
|
|
7
|
-
private dependencies;
|
|
8
6
|
private extensionsConfig;
|
|
9
|
-
private mapperDirPath;
|
|
10
7
|
private extensionsFolderPath;
|
|
11
8
|
private extUidMapperPath;
|
|
12
|
-
constructor({ config, stackAPIClient
|
|
9
|
+
constructor({ config, stackAPIClient }: ModuleClassParams);
|
|
13
10
|
/**
|
|
14
11
|
* Start the extension import setup
|
|
15
12
|
* This method reads the extensions from the content folder and generates a mapper file
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
3
4
|
const utils_1 = require("../../utils");
|
|
4
5
|
const path_1 = require("path");
|
|
5
6
|
const lodash_1 = require("lodash");
|
|
6
7
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
this.stackAPIClient = stackAPIClient;
|
|
8
|
+
const base_setup_1 = tslib_1.__importDefault(require("./base-setup"));
|
|
9
|
+
const utils_2 = require("../../utils");
|
|
10
|
+
class ExtensionImportSetup extends base_setup_1.default {
|
|
11
|
+
constructor({ config, stackAPIClient }) {
|
|
12
|
+
super({ config, stackAPIClient, dependencies: [] });
|
|
13
|
+
this.currentModuleName = utils_2.MODULE_NAMES[utils_2.MODULE_CONTEXTS.EXTENSIONS];
|
|
14
14
|
this.extensionsFilePath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.config.contentDir), 'extensions', 'extensions.json');
|
|
15
15
|
this.extensionsConfig = config.modules.extensions;
|
|
16
16
|
this.extUidMapperPath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'mapper', 'extensions', 'uid-mapping.json');
|
|
@@ -22,33 +22,49 @@ class ExtensionImportSetup {
|
|
|
22
22
|
* @returns {Promise<void>}
|
|
23
23
|
*/
|
|
24
24
|
async start() {
|
|
25
|
+
var _a, _b, _c;
|
|
25
26
|
try {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
const extensions = await utils_1.fsUtil.readFile(this.extensionsFilePath);
|
|
27
|
+
const extensions = await this.withLoadingSpinner('EXTENSIONS: Analyzing import data...', async () => {
|
|
28
|
+
return await utils_1.fsUtil.readFile(this.extensionsFilePath);
|
|
29
|
+
});
|
|
31
30
|
if (!(0, lodash_1.isEmpty)(extensions)) {
|
|
32
|
-
|
|
31
|
+
const extensionsArray = Object.values(extensions);
|
|
32
|
+
const progress = this.createNestedProgress(this.currentModuleName);
|
|
33
|
+
// Add process
|
|
34
|
+
progress.addProcess(utils_2.PROCESS_NAMES.EXTENSIONS_MAPPER_GENERATION, extensionsArray.length);
|
|
35
|
+
// Create mapper directory
|
|
33
36
|
const mapperFilePath = (0, path_1.join)((0, cli_utilities_1.sanitizePath)(this.config.backupDir), 'mapper', 'extensions');
|
|
34
|
-
utils_1.fsUtil.makeDirectory(mapperFilePath);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
utils_1.fsUtil.makeDirectory(mapperFilePath);
|
|
38
|
+
progress
|
|
39
|
+
.startProcess(utils_2.PROCESS_NAMES.EXTENSIONS_MAPPER_GENERATION)
|
|
40
|
+
.updateStatus(utils_2.PROCESS_STATUS.EXTENSIONS_MAPPER_GENERATION.GENERATING, utils_2.PROCESS_NAMES.EXTENSIONS_MAPPER_GENERATION);
|
|
41
|
+
for (const extension of extensionsArray) {
|
|
42
|
+
try {
|
|
43
|
+
const targetExtension = await this.getExtension(extension);
|
|
44
|
+
if (!targetExtension) {
|
|
45
|
+
(0, utils_1.log)(this.config, `Extension with the title '${extension.title}' not found in the stack.`, 'info');
|
|
46
|
+
(_a = this.progressManager) === null || _a === void 0 ? void 0 : _a.tick(false, `extension: ${extension.title}`, 'Not found in stack', utils_2.PROCESS_NAMES.EXTENSIONS_MAPPER_GENERATION);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
this.extensionMapper[extension.uid] = targetExtension.uid;
|
|
50
|
+
(_b = this.progressManager) === null || _b === void 0 ? void 0 : _b.tick(true, `extension: ${extension.title}`, null, utils_2.PROCESS_NAMES.EXTENSIONS_MAPPER_GENERATION);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
(_c = this.progressManager) === null || _c === void 0 ? void 0 : _c.tick(false, `extension: ${extension.title}`, (0, cli_utilities_1.formatError)(error), utils_2.PROCESS_NAMES.EXTENSIONS_MAPPER_GENERATION);
|
|
40
54
|
}
|
|
41
|
-
this.extensionMapper[extension.uid] = targetExtension.uid;
|
|
42
55
|
}
|
|
43
56
|
await utils_1.fsUtil.writeFile(this.extUidMapperPath, this.extensionMapper);
|
|
44
|
-
|
|
57
|
+
progress.completeProcess(utils_2.PROCESS_NAMES.EXTENSIONS_MAPPER_GENERATION, true);
|
|
58
|
+
this.completeProgress(true);
|
|
59
|
+
(0, utils_1.log)(this.config, `The required setup files for extensions have been generated successfully.`, 'success');
|
|
45
60
|
}
|
|
46
61
|
else {
|
|
47
|
-
|
|
62
|
+
(0, utils_1.log)(this.config, 'No extensions found in the content folder.', 'info');
|
|
48
63
|
}
|
|
49
64
|
}
|
|
50
65
|
catch (error) {
|
|
51
|
-
(
|
|
66
|
+
this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Extensions mapper generation failed');
|
|
67
|
+
(0, utils_1.log)(this.config, `Error occurred while generating the extension mapper: ${(0, cli_utilities_1.formatError)(error)}.`, 'error');
|
|
52
68
|
}
|
|
53
69
|
}
|
|
54
70
|
async getExtension(extension) {
|
|
@@ -1,20 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
const utils_1 = require("../../utils");
|
|
4
5
|
const base_setup_1 = tslib_1.__importDefault(require("./base-setup"));
|
|
5
|
-
const
|
|
6
|
+
const utils_2 = require("../../utils");
|
|
6
7
|
class GlobalFieldsImportSetup extends base_setup_1.default {
|
|
7
8
|
constructor(options) {
|
|
8
9
|
super(options);
|
|
9
|
-
this.
|
|
10
|
+
this.currentModuleName = utils_2.MODULE_NAMES[utils_2.MODULE_CONTEXTS.GLOBAL_FIELDS];
|
|
10
11
|
}
|
|
11
12
|
async start() {
|
|
13
|
+
var _a, _b, _c;
|
|
12
14
|
try {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
const progress = this.createNestedProgress(this.currentModuleName);
|
|
16
|
+
// Add processes
|
|
17
|
+
progress.addProcess(utils_2.PROCESS_NAMES.GLOBAL_FIELDS_DEPENDENCY_SETUP, ((_a = this.dependencies) === null || _a === void 0 ? void 0 : _a.length) || 0);
|
|
18
|
+
progress.addProcess(utils_2.PROCESS_NAMES.GLOBAL_FIELDS_MAPPER_GENERATION, 1);
|
|
19
|
+
// Setup dependencies
|
|
20
|
+
if (this.dependencies && this.dependencies.length > 0) {
|
|
21
|
+
progress
|
|
22
|
+
.startProcess(utils_2.PROCESS_NAMES.GLOBAL_FIELDS_DEPENDENCY_SETUP)
|
|
23
|
+
.updateStatus(utils_2.PROCESS_STATUS.GLOBAL_FIELDS_DEPENDENCY_SETUP.SETTING_UP, utils_2.PROCESS_NAMES.GLOBAL_FIELDS_DEPENDENCY_SETUP);
|
|
24
|
+
await this.setupDependencies();
|
|
25
|
+
(_b = this.progressManager) === null || _b === void 0 ? void 0 : _b.tick(true, 'dependencies setup', null, utils_2.PROCESS_NAMES.GLOBAL_FIELDS_DEPENDENCY_SETUP);
|
|
26
|
+
progress.completeProcess(utils_2.PROCESS_NAMES.GLOBAL_FIELDS_DEPENDENCY_SETUP, true);
|
|
27
|
+
}
|
|
28
|
+
// Mapper generation
|
|
29
|
+
progress
|
|
30
|
+
.startProcess(utils_2.PROCESS_NAMES.GLOBAL_FIELDS_MAPPER_GENERATION)
|
|
31
|
+
.updateStatus(utils_2.PROCESS_STATUS.GLOBAL_FIELDS_MAPPER_GENERATION.GENERATING, utils_2.PROCESS_NAMES.GLOBAL_FIELDS_MAPPER_GENERATION);
|
|
32
|
+
(_c = this.progressManager) === null || _c === void 0 ? void 0 : _c.tick(true, 'mapper generation', null, utils_2.PROCESS_NAMES.GLOBAL_FIELDS_MAPPER_GENERATION);
|
|
33
|
+
progress.completeProcess(utils_2.PROCESS_NAMES.GLOBAL_FIELDS_MAPPER_GENERATION, true);
|
|
34
|
+
this.completeProgress(true);
|
|
35
|
+
(0, utils_1.log)(this.config, `The required setup files for global fields have been generated successfully.`, 'success');
|
|
15
36
|
}
|
|
16
37
|
catch (error) {
|
|
17
|
-
(
|
|
38
|
+
this.completeProgress(false, (error === null || error === void 0 ? void 0 : error.message) || 'Global fields mapper generation failed');
|
|
39
|
+
(0, utils_1.log)(this.config, `Error occurred while generating the global field mapper: ${error.message}.`, 'error');
|
|
18
40
|
}
|
|
19
41
|
}
|
|
20
42
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { ModuleClassParams } from '../../types';
|
|
2
2
|
import { ContentstackMarketplaceClient, NodeCrypto } from '@contentstack/cli-utilities';
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import BaseImportSetup from './base-setup';
|
|
4
|
+
export default class marketplaceAppImportSetup extends BaseImportSetup {
|
|
5
5
|
private marketplaceAppsFilePath;
|
|
6
6
|
private marketplaceAppMapper;
|
|
7
|
-
private stackAPIClient;
|
|
8
|
-
private dependencies;
|
|
9
7
|
private marketplaceAppsConfig;
|
|
10
8
|
private mapperDirPath;
|
|
11
9
|
private marketplaceAppsFolderPath;
|
|
@@ -14,7 +12,7 @@ export default class marketplaceAppImportSetup {
|
|
|
14
12
|
marketplaceAppPath: string;
|
|
15
13
|
nodeCrypto: NodeCrypto;
|
|
16
14
|
appSdk: ContentstackMarketplaceClient;
|
|
17
|
-
constructor({ config, stackAPIClient
|
|
15
|
+
constructor({ config, stackAPIClient }: ModuleClassParams);
|
|
18
16
|
/**
|
|
19
17
|
* Start the marketplaceApp import setup
|
|
20
18
|
* This method reads the marketplaceApps from the content folder and generates a mapper file
|