@contentstack/cli-cm-import 1.12.2 → 1.13.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 +5 -3
- package/lib/commands/cm/stacks/import.js +8 -3
- package/lib/import/module-importer.d.ts +8 -1
- package/lib/import/module-importer.js +75 -8
- package/lib/types/import-config.d.ts +1 -0
- package/lib/utils/content-type-helper.js +9 -0
- package/lib/utils/import-config-handler.js +2 -1
- package/lib/utils/log.d.ts +2 -0
- package/lib/utils/log.js +4 -3
- package/oclif.manifest.json +8 -2
- package/package.json +4 -4
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
|
|
|
47
47
|
$ csdx COMMAND
|
|
48
48
|
running command...
|
|
49
49
|
$ csdx (--version)
|
|
50
|
-
@contentstack/cli-cm-import/1.
|
|
50
|
+
@contentstack/cli-cm-import/1.13.1 linux-x64 node-v18.19.0
|
|
51
51
|
$ csdx --help [COMMAND]
|
|
52
52
|
USAGE
|
|
53
53
|
$ csdx COMMAND
|
|
@@ -83,6 +83,7 @@ FLAGS
|
|
|
83
83
|
<options: disable|current>
|
|
84
84
|
--replace-existing Replaces the existing module in the target stack.
|
|
85
85
|
--skip-app-recreation [optional] Skip private apps recreation if already exist
|
|
86
|
+
--skip-audit Skips the audit fix.
|
|
86
87
|
--skip-existing Skips the module exists warning messages.
|
|
87
88
|
|
|
88
89
|
DESCRIPTION
|
|
@@ -106,7 +107,7 @@ EXAMPLES
|
|
|
106
107
|
|
|
107
108
|
$ csdx cm:stacks:import --alias <management_token_alias> --config <path/of/config/file>
|
|
108
109
|
|
|
109
|
-
$ csdx cm:stacks:import --branch <branch name> --yes
|
|
110
|
+
$ csdx cm:stacks:import --branch <branch name> --yes --skip-audit
|
|
110
111
|
```
|
|
111
112
|
|
|
112
113
|
## `csdx cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>] [--branch <value>] [--import-webhook-status disable|current]`
|
|
@@ -131,6 +132,7 @@ FLAGS
|
|
|
131
132
|
<options: disable|current>
|
|
132
133
|
--replace-existing Replaces the existing module in the target stack.
|
|
133
134
|
--skip-app-recreation [optional] Skip private apps recreation if already exist
|
|
135
|
+
--skip-audit Skips the audit fix.
|
|
134
136
|
--skip-existing Skips the module exists warning messages.
|
|
135
137
|
|
|
136
138
|
DESCRIPTION
|
|
@@ -154,7 +156,7 @@ EXAMPLES
|
|
|
154
156
|
|
|
155
157
|
$ csdx cm:stacks:import --alias <management_token_alias> --config <path/of/config/file>
|
|
156
158
|
|
|
157
|
-
$ csdx cm:stacks:import --branch <branch name> --yes
|
|
159
|
+
$ csdx cm:stacks:import --branch <branch name> --yes --skip-audit
|
|
158
160
|
```
|
|
159
161
|
|
|
160
162
|
_See code: [src/commands/cm/stacks/import.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-import/src/commands/cm/stacks/import.ts)_
|
|
@@ -20,8 +20,10 @@ class ImportCommand extends cli_command_1.Command {
|
|
|
20
20
|
backupDir = importConfig.backupDir;
|
|
21
21
|
const managementAPIClient = await (0, cli_utilities_1.managementSDKClient)(importConfig);
|
|
22
22
|
const moduleImporter = new import_1.ModuleImporter(managementAPIClient, importConfig);
|
|
23
|
-
await moduleImporter.start();
|
|
24
|
-
|
|
23
|
+
const result = await moduleImporter.start();
|
|
24
|
+
if (!(result === null || result === void 0 ? void 0 : result.noSuccessMsg)) {
|
|
25
|
+
(0, utils_1.log)(importConfig, `The content has been imported to the stack ${importConfig.apiKey} successfully!`, 'success');
|
|
26
|
+
}
|
|
25
27
|
(0, utils_1.log)(importConfig, `The log has been stored at '${node_path_1.default.join(importConfig.backupDir, 'logs', 'import')}'`, 'success');
|
|
26
28
|
}
|
|
27
29
|
catch (error) {
|
|
@@ -40,7 +42,7 @@ ImportCommand.examples = [
|
|
|
40
42
|
`csdx cm:stacks:import --alias <management_token_alias>`,
|
|
41
43
|
`csdx cm:stacks:import --alias <management_token_alias> --data-dir <path/of/export/destination/dir>`,
|
|
42
44
|
`csdx cm:stacks:import --alias <management_token_alias> --config <path/of/config/file>`,
|
|
43
|
-
`csdx cm:stacks:import --branch <branch name> --yes`,
|
|
45
|
+
`csdx cm:stacks:import --branch <branch name> --yes --skip-audit`,
|
|
44
46
|
];
|
|
45
47
|
ImportCommand.flags = {
|
|
46
48
|
config: cli_utilities_1.flags.string({
|
|
@@ -120,6 +122,9 @@ ImportCommand.flags = {
|
|
|
120
122
|
default: false,
|
|
121
123
|
description: 'Skips the module exists warning messages.',
|
|
122
124
|
}),
|
|
125
|
+
'skip-audit': cli_utilities_1.flags.boolean({
|
|
126
|
+
description: 'Skips the audit fix.',
|
|
127
|
+
}),
|
|
123
128
|
};
|
|
124
129
|
ImportCommand.aliases = ['cm:import'];
|
|
125
130
|
ImportCommand.usage = 'cm:stacks:import [-c <value>] [-k <value>] [-d <value>] [-a <value>] [--module <value>] [--backup-dir <value>] [--branch <value>] [--import-webhook-status disable|current]';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContentstackClient } from '@contentstack/cli-utilities';
|
|
1
|
+
import { ContentstackClient, Logger } from '@contentstack/cli-utilities';
|
|
2
2
|
import { ImportConfig, Modules } from '../types';
|
|
3
3
|
declare class ModuleImporter {
|
|
4
4
|
private managementAPIClient;
|
|
@@ -9,5 +9,12 @@ declare class ModuleImporter {
|
|
|
9
9
|
import(): Promise<any>;
|
|
10
10
|
importByModuleByName(moduleName: Modules): Promise<any>;
|
|
11
11
|
importAllModules(): Promise<any>;
|
|
12
|
+
/**
|
|
13
|
+
* The `auditImportData` function performs an audit process on imported data, using a specified
|
|
14
|
+
* configuration, and returns a boolean indicating whether a fix is needed.
|
|
15
|
+
* @returns The function `auditImportData()` returns a boolean value. It returns `true` if there is a
|
|
16
|
+
* fix available and the user confirms to proceed with the fix, otherwise it returns `false`.
|
|
17
|
+
*/
|
|
18
|
+
auditImportData(logger: Logger): Promise<boolean>;
|
|
12
19
|
}
|
|
13
20
|
export default ModuleImporter;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
const path_1 = require("path");
|
|
5
|
+
const cli_audit_1 = require("@contentstack/cli-audit");
|
|
6
|
+
const messages_1 = tslib_1.__importStar(require("@contentstack/cli-audit/lib/messages"));
|
|
4
7
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
5
8
|
const modules_1 = tslib_1.__importDefault(require("./modules"));
|
|
6
9
|
const modules_js_1 = tslib_1.__importDefault(require("./modules-js"));
|
|
@@ -18,16 +21,9 @@ class ModuleImporter {
|
|
|
18
21
|
if (this.importConfig.branchName) {
|
|
19
22
|
await (0, utils_1.validateBranch)(this.stackAPIClient, this.importConfig, this.importConfig.branchName);
|
|
20
23
|
}
|
|
21
|
-
// Temporarily adding this api call to verify management token has read and write permissions
|
|
22
|
-
// TODO: CS-40354 - CLI | import rewrite | Migrate HTTP call to SDK call once fix is ready from SDK side
|
|
23
24
|
if (this.importConfig.management_token) {
|
|
24
25
|
await (0, cli_utilities_1.addLocale)(this.importConfig.apiKey, this.importConfig.management_token, this.importConfig.host);
|
|
25
26
|
}
|
|
26
|
-
if (!this.importConfig.master_locale) {
|
|
27
|
-
let masterLocalResponse = await (0, utils_1.masterLocalDetails)(this.stackAPIClient);
|
|
28
|
-
this.importConfig['master_locale'] = { code: masterLocalResponse.code };
|
|
29
|
-
this.importConfig.masterLocale = { code: masterLocalResponse.code };
|
|
30
|
-
}
|
|
31
27
|
const backupDir = await (0, utils_1.backupHandler)(this.importConfig);
|
|
32
28
|
if (backupDir) {
|
|
33
29
|
this.importConfig.backupDir = backupDir;
|
|
@@ -35,7 +31,20 @@ class ModuleImporter {
|
|
|
35
31
|
this.importConfig.data = backupDir;
|
|
36
32
|
}
|
|
37
33
|
// NOTE init log
|
|
38
|
-
(0, utils_1.initLogger)(this.importConfig);
|
|
34
|
+
const logger = (0, utils_1.initLogger)(this.importConfig);
|
|
35
|
+
// NOTE audit and fix the import content.
|
|
36
|
+
if (!this.importConfig.skipAudit &&
|
|
37
|
+
(!this.importConfig.moduleName ||
|
|
38
|
+
['content-types', 'global-fields', 'entries'].includes(this.importConfig.moduleName))) {
|
|
39
|
+
if (!(await this.auditImportData(logger))) {
|
|
40
|
+
return { noSuccessMsg: true };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (!this.importConfig.master_locale) {
|
|
44
|
+
let masterLocalResponse = await (0, utils_1.masterLocalDetails)(this.stackAPIClient);
|
|
45
|
+
this.importConfig['master_locale'] = { code: masterLocalResponse.code };
|
|
46
|
+
this.importConfig.masterLocale = { code: masterLocalResponse.code };
|
|
47
|
+
}
|
|
39
48
|
await (0, utils_1.sanitizeStack)(this.stackAPIClient);
|
|
40
49
|
return this.import();
|
|
41
50
|
}
|
|
@@ -76,5 +85,63 @@ class ModuleImporter {
|
|
|
76
85
|
await this.importByModuleByName(moduleName);
|
|
77
86
|
}
|
|
78
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* The `auditImportData` function performs an audit process on imported data, using a specified
|
|
90
|
+
* configuration, and returns a boolean indicating whether a fix is needed.
|
|
91
|
+
* @returns The function `auditImportData()` returns a boolean value. It returns `true` if there is a
|
|
92
|
+
* fix available and the user confirms to proceed with the fix, otherwise it returns `false`.
|
|
93
|
+
*/
|
|
94
|
+
async auditImportData(logger) {
|
|
95
|
+
const basePath = (0, path_1.resolve)(this.importConfig.backupDir, 'logs', 'audit');
|
|
96
|
+
const auditConfig = {
|
|
97
|
+
noLog: false,
|
|
98
|
+
skipConfirm: true,
|
|
99
|
+
returnResponse: true,
|
|
100
|
+
noTerminalOutput: false,
|
|
101
|
+
config: { basePath }, // To overwrite any build-in config. This config is equal to --config flag.
|
|
102
|
+
};
|
|
103
|
+
try {
|
|
104
|
+
const args = [
|
|
105
|
+
'--data-dir',
|
|
106
|
+
this.importConfig.backupDir,
|
|
107
|
+
'--external-config',
|
|
108
|
+
JSON.stringify(auditConfig),
|
|
109
|
+
'--report-path',
|
|
110
|
+
basePath,
|
|
111
|
+
];
|
|
112
|
+
if (this.importConfig.moduleName) {
|
|
113
|
+
args.push('--modules', this.importConfig.moduleName);
|
|
114
|
+
}
|
|
115
|
+
else if (this.importConfig.modules.types.length) {
|
|
116
|
+
this.importConfig.modules.types
|
|
117
|
+
.filter((val) => ['content-types', 'global-fields', 'entries'].includes(val))
|
|
118
|
+
.forEach((val) => {
|
|
119
|
+
args.push('--modules', val);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
(0, utils_1.log)(this.importConfig, 'Starting audit process', 'info');
|
|
123
|
+
const result = await cli_audit_1.AuditFix.run(args);
|
|
124
|
+
(0, utils_1.log)(this.importConfig, 'Audit process completed', 'info');
|
|
125
|
+
if (result) {
|
|
126
|
+
const { hasFix, config } = result;
|
|
127
|
+
if (hasFix) {
|
|
128
|
+
logger.log((0, messages_1.$t)(messages_1.default.FINAL_REPORT_PATH, { path: config.reportPath }), 'warn');
|
|
129
|
+
if (this.importConfig.forceStopMarketplaceAppsPrompt ||
|
|
130
|
+
(await cli_utilities_1.cliux.inquire({
|
|
131
|
+
type: 'confirm',
|
|
132
|
+
name: 'confirmation',
|
|
133
|
+
message: 'Can you check the fix on the given path and confirm if you would like to proceed with the fix?',
|
|
134
|
+
}))) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
catch (error) {
|
|
143
|
+
(0, utils_1.log)(this.importConfig, `Audit failed with following error. ${error}`, 'error');
|
|
144
|
+
}
|
|
145
|
+
}
|
|
79
146
|
}
|
|
80
147
|
exports.default = ModuleImporter;
|
|
@@ -147,6 +147,15 @@ const removeReferenceFields = async function (schema, flag = { supressed: false
|
|
|
147
147
|
flag.supressed = true;
|
|
148
148
|
schema[i].reference_to = ['sys_assets'];
|
|
149
149
|
}
|
|
150
|
+
else if (
|
|
151
|
+
// handling entry references in rte
|
|
152
|
+
schema[i].data_type === 'text' &&
|
|
153
|
+
schema[i].field_metadata.rich_text_type &&
|
|
154
|
+
schema[i].field_metadata.embed_entry &&
|
|
155
|
+
schema[i].reference_to.length >= 1) {
|
|
156
|
+
flag.supressed = true;
|
|
157
|
+
schema[i].reference_to = ['sys_assets'];
|
|
158
|
+
}
|
|
150
159
|
}
|
|
151
160
|
};
|
|
152
161
|
exports.removeReferenceFields = removeReferenceFields;
|
|
@@ -60,8 +60,9 @@ const setupConfig = async (importCmdFlags) => {
|
|
|
60
60
|
config.isAuthenticated = (0, cli_utilities_1.isAuthenticated)();
|
|
61
61
|
//Note to support the old key
|
|
62
62
|
config.source_stack = config.apiKey;
|
|
63
|
-
config.
|
|
63
|
+
config.skipAudit = importCmdFlags['skip-audit'];
|
|
64
64
|
config.forceStopMarketplaceAppsPrompt = importCmdFlags.yes;
|
|
65
|
+
config.importWebhookStatus = importCmdFlags['import-webhook-status'];
|
|
65
66
|
config.skipPrivateAppRecreationIfExist = importCmdFlags['skip-app-recreation'];
|
|
66
67
|
if (importCmdFlags['branch']) {
|
|
67
68
|
config.branchName = importCmdFlags['branch'];
|
package/lib/utils/log.d.ts
CHANGED
|
@@ -2,9 +2,11 @@ import { LogEntry } from 'winston/index';
|
|
|
2
2
|
import { Logger } from '@contentstack/cli-utilities';
|
|
3
3
|
import { LogsType, MessageType } from '@contentstack/cli-utilities/lib/logger';
|
|
4
4
|
import { ImportConfig } from '../types';
|
|
5
|
+
declare let logger: Logger;
|
|
5
6
|
export declare function isImportConfig(config: ImportConfig | MessageType): config is ImportConfig;
|
|
6
7
|
export declare function log(entry: LogEntry): void;
|
|
7
8
|
export declare function log(error: MessageType, logType: LogsType): void;
|
|
8
9
|
export declare function log(error: MessageType, logType: 'error', hidden: boolean): void;
|
|
9
10
|
export declare function initLogger(config?: ImportConfig | undefined): Logger;
|
|
11
|
+
export { logger };
|
|
10
12
|
export declare const trace: typeof log;
|
package/lib/utils/log.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.trace = exports.initLogger = exports.log = exports.isImportConfig = void 0;
|
|
3
|
+
exports.trace = exports.logger = exports.initLogger = exports.log = exports.isImportConfig = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
5
|
const cli_utilities_1 = require("@contentstack/cli-utilities");
|
|
6
6
|
let logger;
|
|
7
|
+
exports.logger = logger;
|
|
7
8
|
function isImportConfig(config) {
|
|
8
9
|
return config.data !== undefined && (config === null || config === void 0 ? void 0 : config.contentVersion) !== undefined;
|
|
9
10
|
}
|
|
10
11
|
exports.isImportConfig = isImportConfig;
|
|
11
12
|
function log(entryOrMessage, logType, hidden) {
|
|
12
|
-
logger = initLogger();
|
|
13
|
+
exports.logger = logger = initLogger();
|
|
13
14
|
if (logType === 'error') {
|
|
14
15
|
logger.log(entryOrMessage, logType, hidden);
|
|
15
16
|
}
|
|
@@ -22,7 +23,7 @@ function initLogger(config) {
|
|
|
22
23
|
var _a;
|
|
23
24
|
if (!logger) {
|
|
24
25
|
const basePath = (0, path_1.join)((_a = config === null || config === void 0 ? void 0 : config.data) !== null && _a !== void 0 ? _a : process.cwd(), 'logs', 'import');
|
|
25
|
-
logger = new cli_utilities_1.Logger(Object.assign(config !== null && config !== void 0 ? config : {}, { basePath }));
|
|
26
|
+
exports.logger = logger = new cli_utilities_1.Logger(Object.assign(config !== null && config !== void 0 ? config : {}, { basePath }));
|
|
26
27
|
}
|
|
27
28
|
return logger;
|
|
28
29
|
}
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.13.1",
|
|
3
3
|
"commands": {
|
|
4
4
|
"cm:stacks:import": {
|
|
5
5
|
"id": "cm:stacks:import",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"csdx cm:stacks:import --alias <management_token_alias>",
|
|
21
21
|
"csdx cm:stacks:import --alias <management_token_alias> --data-dir <path/of/export/destination/dir>",
|
|
22
22
|
"csdx cm:stacks:import --alias <management_token_alias> --config <path/of/config/file>",
|
|
23
|
-
"csdx cm:stacks:import --branch <branch name> --yes"
|
|
23
|
+
"csdx cm:stacks:import --branch <branch name> --yes --skip-audit"
|
|
24
24
|
],
|
|
25
25
|
"flags": {
|
|
26
26
|
"config": {
|
|
@@ -142,6 +142,12 @@
|
|
|
142
142
|
"description": "Skips the module exists warning messages.",
|
|
143
143
|
"required": false,
|
|
144
144
|
"allowNo": false
|
|
145
|
+
},
|
|
146
|
+
"skip-audit": {
|
|
147
|
+
"name": "skip-audit",
|
|
148
|
+
"type": "boolean",
|
|
149
|
+
"description": "Skips the audit fix.",
|
|
150
|
+
"allowNo": false
|
|
145
151
|
}
|
|
146
152
|
},
|
|
147
153
|
"args": {}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentstack/cli-cm-import",
|
|
3
3
|
"description": "Contentstack CLI plugin to import content into stack",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.13.1",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
+
"@contentstack/cli-audit": "^1.3.2",
|
|
8
9
|
"@contentstack/cli-command": "~1.2.16",
|
|
9
|
-
"@contentstack/cli-utilities": "~1.5.
|
|
10
|
+
"@contentstack/cli-utilities": "~1.5.10",
|
|
10
11
|
"@contentstack/management": "~1.13.0",
|
|
11
12
|
"@oclif/core": "^2.9.3",
|
|
12
|
-
"axios": "^1.6.0",
|
|
13
13
|
"big-json": "^3.2.0",
|
|
14
14
|
"bluebird": "^3.7.2",
|
|
15
15
|
"chalk": "^4.1.2",
|
|
@@ -99,4 +99,4 @@
|
|
|
99
99
|
}
|
|
100
100
|
},
|
|
101
101
|
"repository": "https://github.com/contentstack/cli"
|
|
102
|
-
}
|
|
102
|
+
}
|