@contentstack/cli-cm-import 1.19.5 → 1.20.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/README.md +5 -1
- package/lib/commands/cm/stacks/import.js +24 -0
- package/lib/config/index.js +3 -2
- package/lib/import/modules/assets.d.ts +0 -1
- package/lib/import/modules/assets.js +1 -1
- package/lib/import/modules/entries.js +1 -1
- package/lib/types/default-config.d.ts +2 -2
- package/lib/types/import-config.d.ts +2 -0
- package/lib/utils/asset-helper.js +1 -1
- package/lib/utils/import-config-handler.js +8 -2
- package/lib/utils/logger.js +5 -2
- package/oclif.manifest.json +13 -1
- package/package.json +4 -4
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.20.2 linux-x64 node-v22.14.0
|
|
51
51
|
$ csdx --help [COMMAND]
|
|
52
52
|
USAGE
|
|
53
53
|
$ csdx COMMAND
|
|
@@ -96,7 +96,9 @@ FLAGS
|
|
|
96
96
|
--personalize-project-name=<value> (optional) Provide a unique name for the Personalize project.
|
|
97
97
|
--replace-existing Replaces the existing module in the target stack.
|
|
98
98
|
--skip-app-recreation (optional) Skips the recreation of private apps if they already exist.
|
|
99
|
+
--skip-assets-publish Skips asset publishing during the import process.
|
|
99
100
|
--skip-audit Skips the audit fix that occurs during an import operation.
|
|
101
|
+
--skip-entries-publish Skips entry publishing during the import process
|
|
100
102
|
--skip-existing Skips the module exists warning messages.
|
|
101
103
|
|
|
102
104
|
DESCRIPTION
|
|
@@ -158,7 +160,9 @@ FLAGS
|
|
|
158
160
|
--personalize-project-name=<value> (optional) Provide a unique name for the Personalize project.
|
|
159
161
|
--replace-existing Replaces the existing module in the target stack.
|
|
160
162
|
--skip-app-recreation (optional) Skips the recreation of private apps if they already exist.
|
|
163
|
+
--skip-assets-publish Skips asset publishing during the import process.
|
|
161
164
|
--skip-audit Skips the audit fix that occurs during an import operation.
|
|
165
|
+
--skip-entries-publish Skips entry publishing during the import process
|
|
162
166
|
--skip-existing Skips the module exists warning messages.
|
|
163
167
|
|
|
164
168
|
DESCRIPTION
|
|
@@ -23,6 +23,22 @@ class ImportCommand extends cli_command_1.Command {
|
|
|
23
23
|
importConfig.modules.personalize.baseURL[importConfig.region.name] = this.personalizeUrl;
|
|
24
24
|
backupDir = importConfig.cliLogsPath || importConfig.backupDir;
|
|
25
25
|
const managementAPIClient = await (0, cli_utilities_1.managementSDKClient)(importConfig);
|
|
26
|
+
if (!flags.branch) {
|
|
27
|
+
try {
|
|
28
|
+
const branches = await managementAPIClient
|
|
29
|
+
.stack({ api_key: importConfig.apiKey })
|
|
30
|
+
.branch()
|
|
31
|
+
.query()
|
|
32
|
+
.find()
|
|
33
|
+
.then(({ items }) => items);
|
|
34
|
+
if (branches.length) {
|
|
35
|
+
flags.branch = 'main';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
// Branch not enabled, just the let flow continue
|
|
40
|
+
}
|
|
41
|
+
}
|
|
26
42
|
const moduleImporter = new import_1.ModuleImporter(managementAPIClient, importConfig);
|
|
27
43
|
const result = await moduleImporter.start();
|
|
28
44
|
if (!(result === null || result === void 0 ? void 0 : result.noSuccessMsg)) {
|
|
@@ -141,6 +157,14 @@ ImportCommand.flags = {
|
|
|
141
157
|
description: 'Excludes the branch-independent module from the import operation.',
|
|
142
158
|
default: false,
|
|
143
159
|
}),
|
|
160
|
+
'skip-assets-publish': cli_utilities_1.flags.boolean({
|
|
161
|
+
description: 'Skips asset publishing during the import process.',
|
|
162
|
+
default: false,
|
|
163
|
+
}),
|
|
164
|
+
'skip-entries-publish': cli_utilities_1.flags.boolean({
|
|
165
|
+
description: 'Skips entry publishing during the import process',
|
|
166
|
+
default: false,
|
|
167
|
+
}),
|
|
144
168
|
};
|
|
145
169
|
ImportCommand.aliases = ['cm:import'];
|
|
146
170
|
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]';
|
package/lib/config/index.js
CHANGED
|
@@ -10,6 +10,8 @@ const config = {
|
|
|
10
10
|
// host:'https://azure-eu-api.contentstack.com/v3',
|
|
11
11
|
// use below hosts for gcp-na region
|
|
12
12
|
// host:'https://gcp-na-api.contentstack.com',
|
|
13
|
+
// use below hosts for gcp-eu region
|
|
14
|
+
// host:'https://gcp-eu-api.contentstack.com',
|
|
13
15
|
// pass locale, only to migrate entries from that locale
|
|
14
16
|
// not passing `locale` will migrate all the locales present
|
|
15
17
|
// locales: ['fr-fr'],
|
|
@@ -21,6 +23,7 @@ const config = {
|
|
|
21
23
|
'https://azure-na-api.contentstack.com': 'https://azure-na-developerhub-api.contentstack.com',
|
|
22
24
|
'https://azure-eu-api.contentstack.com': 'https://azure-eu-developerhub-api.contentstack.com',
|
|
23
25
|
'https://gcp-na-api.contentstack.com': 'https://gcp-na-developerhub-api.contentstack.com',
|
|
26
|
+
'https://gcp-eu-api.contentstack.com': 'https://gcp-eu-developerhub-api.contentstack.com',
|
|
24
27
|
},
|
|
25
28
|
modules: {
|
|
26
29
|
apiConcurrency: 5,
|
|
@@ -86,7 +89,6 @@ const config = {
|
|
|
86
89
|
assets: {
|
|
87
90
|
dirName: 'assets',
|
|
88
91
|
assetBatchLimit: 1,
|
|
89
|
-
publishAssets: true,
|
|
90
92
|
fileName: 'assets.json',
|
|
91
93
|
importSameStructure: true,
|
|
92
94
|
uploadAssetsConcurrency: 2,
|
|
@@ -418,7 +420,6 @@ const config = {
|
|
|
418
420
|
overwriteSupportedModules: ['extensions', 'global-fields', 'content-types'],
|
|
419
421
|
rateLimit: 5,
|
|
420
422
|
preserveStackVersion: false,
|
|
421
|
-
entriesPublish: true,
|
|
422
423
|
concurrency: 1,
|
|
423
424
|
importConcurrency: 5,
|
|
424
425
|
fetchConcurrency: 5,
|
|
@@ -50,7 +50,7 @@ class ImportAssets extends base_class_1.default {
|
|
|
50
50
|
// NOTE Step 3: Import Assets and create it mapping files (uid, url)
|
|
51
51
|
await this.importAssets();
|
|
52
52
|
// NOTE Step 4: Publish assets
|
|
53
|
-
if (this.
|
|
53
|
+
if (!this.importConfig.skipAssetsPublish)
|
|
54
54
|
await this.publish();
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
@@ -99,7 +99,7 @@ class EntriesImport extends base_class_1.default {
|
|
|
99
99
|
});
|
|
100
100
|
(0, utils_1.log)(this.importConfig, 'Entries imported successfully', 'success');
|
|
101
101
|
// Publishing entries
|
|
102
|
-
if (this.importConfig.
|
|
102
|
+
if (!this.importConfig.skipEntriesPublish) {
|
|
103
103
|
(0, utils_1.log)(this.importConfig, 'Publishing entries', 'info');
|
|
104
104
|
this.envs = utils_1.fileHelper.readFileSync(this.envPath);
|
|
105
105
|
for (let entryRequestOption of entryRequestOptions) {
|
|
@@ -50,7 +50,6 @@ export default interface DefaultConfig {
|
|
|
50
50
|
assets: {
|
|
51
51
|
dirName: string;
|
|
52
52
|
assetBatchLimit: number;
|
|
53
|
-
publishAssets: boolean;
|
|
54
53
|
fileName: string;
|
|
55
54
|
importSameStructure: boolean;
|
|
56
55
|
uploadAssetsConcurrency: number;
|
|
@@ -175,7 +174,6 @@ export default interface DefaultConfig {
|
|
|
175
174
|
};
|
|
176
175
|
rateLimit: number;
|
|
177
176
|
preserveStackVersion: boolean;
|
|
178
|
-
entriesPublish: boolean;
|
|
179
177
|
concurrency: number;
|
|
180
178
|
importConcurrency: number;
|
|
181
179
|
fetchConcurrency: number;
|
|
@@ -197,4 +195,6 @@ export default interface DefaultConfig {
|
|
|
197
195
|
} & Record<string, any>;
|
|
198
196
|
};
|
|
199
197
|
globalModules: string[];
|
|
198
|
+
skipAssetsPublish?: boolean;
|
|
199
|
+
skipEntriesPublish?: boolean;
|
|
200
200
|
}
|
|
@@ -9,6 +9,8 @@ export interface ExternalConfig {
|
|
|
9
9
|
password?: string;
|
|
10
10
|
}
|
|
11
11
|
export default interface ImportConfig extends DefaultConfig, ExternalConfig {
|
|
12
|
+
skipAssetsPublish?: boolean;
|
|
13
|
+
skipEntriesPublish?: boolean;
|
|
12
14
|
cliLogsPath: string;
|
|
13
15
|
canCreatePrivateApp: boolean;
|
|
14
16
|
contentDir: string;
|
|
@@ -340,7 +340,7 @@ function findFileUrls(schema, _entry, assetUrls) {
|
|
|
340
340
|
else {
|
|
341
341
|
text = JSON.stringify(_entry);
|
|
342
342
|
}
|
|
343
|
-
markdownRegEx = new RegExp('(https://(assets|(eu-|azure-na-|azure-eu-|gcp-na-)?images).contentstack.(io|com)/v3/assets/(.*?)/(.*?)/(.*?)/(.*?)(?="))', 'g');
|
|
343
|
+
markdownRegEx = new RegExp('(https://(assets|(eu-|azure-na-|azure-eu-|gcp-na-|gcp-eu-)?images).contentstack.(io|com)/v3/assets/(.*?)/(.*?)/(.*?)/(.*?)(?="))', 'g');
|
|
344
344
|
while ((markdownMatch = markdownRegEx.exec(text)) !== null) {
|
|
345
345
|
if (markdownMatch && typeof markdownMatch[0] === 'string') {
|
|
346
346
|
let assetUrl = markdownMatch[0].replace(/\\/g, '');
|
|
@@ -21,13 +21,13 @@ const setupConfig = async (importCmdFlags) => {
|
|
|
21
21
|
}
|
|
22
22
|
config = merge_1.default.recursive(config, externalConfig);
|
|
23
23
|
}
|
|
24
|
-
config.contentDir = importCmdFlags['data'] || importCmdFlags['data-dir'] || config.data || (await (0, interactive_1.askContentDir)());
|
|
24
|
+
config.contentDir = (0, cli_utilities_1.sanitizePath)(importCmdFlags['data'] || importCmdFlags['data-dir'] || config.data || (await (0, interactive_1.askContentDir)()));
|
|
25
25
|
const pattern = /[*$%#<>{}!&?]/g;
|
|
26
26
|
if (pattern.test(config.contentDir)) {
|
|
27
27
|
cli_utilities_1.cliux.print(`\nPlease add a directory path without any of the special characters: (*,&,{,},[,],$,%,<,>,?,!)`, {
|
|
28
28
|
color: 'yellow',
|
|
29
29
|
});
|
|
30
|
-
config.contentDir = await (0, interactive_1.askContentDir)();
|
|
30
|
+
config.contentDir = (0, cli_utilities_1.sanitizePath)(await (0, interactive_1.askContentDir)());
|
|
31
31
|
}
|
|
32
32
|
config.contentDir = config.contentDir.replace(/['"]/g, '');
|
|
33
33
|
config.contentDir = path.resolve(config.contentDir);
|
|
@@ -85,6 +85,12 @@ const setupConfig = async (importCmdFlags) => {
|
|
|
85
85
|
if (importCmdFlags['backup-dir']) {
|
|
86
86
|
config.useBackedupDir = importCmdFlags['backup-dir'];
|
|
87
87
|
}
|
|
88
|
+
if (importCmdFlags['skip-assets-publish']) {
|
|
89
|
+
config.skipAssetsPublish = importCmdFlags['skip-assets-publish'];
|
|
90
|
+
}
|
|
91
|
+
if (importCmdFlags['skip-entries-publish']) {
|
|
92
|
+
config.skipEntriesPublish = importCmdFlags['skip-entries-publish'];
|
|
93
|
+
}
|
|
88
94
|
// Note to support old modules
|
|
89
95
|
config.target_stack = config.apiKey;
|
|
90
96
|
config.replaceExisting = importCmdFlags['replace-existing'];
|
package/lib/utils/logger.js
CHANGED
|
@@ -22,7 +22,10 @@ function returnString(args) {
|
|
|
22
22
|
.map(function (item) {
|
|
23
23
|
if (item && typeof item === 'object') {
|
|
24
24
|
try {
|
|
25
|
-
|
|
25
|
+
const redactedObject = (0, cli_utilities_1.redactObject)(item);
|
|
26
|
+
if (redactedObject && typeof redactedObject === 'object') {
|
|
27
|
+
return JSON.stringify(redactedObject);
|
|
28
|
+
}
|
|
26
29
|
}
|
|
27
30
|
catch (error) { }
|
|
28
31
|
return item;
|
|
@@ -122,7 +125,7 @@ function init(_logPath) {
|
|
|
122
125
|
};
|
|
123
126
|
}
|
|
124
127
|
const log = async (config, message, type) => {
|
|
125
|
-
config.cliLogsPath = config.cliLogsPath || config.data || path.join(__dirname, 'logs');
|
|
128
|
+
config.cliLogsPath = (0, cli_utilities_1.sanitizePath)(config.cliLogsPath || config.data || path.join(__dirname, 'logs'));
|
|
126
129
|
// ignoring the type argument, as we are not using it to create a logfile anymore
|
|
127
130
|
if (type !== 'error') {
|
|
128
131
|
// removed type argument from init method
|
package/oclif.manifest.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.20.2",
|
|
3
3
|
"commands": {
|
|
4
4
|
"cm:stacks:import": {
|
|
5
5
|
"id": "cm:stacks:import",
|
|
@@ -162,6 +162,18 @@
|
|
|
162
162
|
"type": "boolean",
|
|
163
163
|
"description": "Excludes the branch-independent module from the import operation.",
|
|
164
164
|
"allowNo": false
|
|
165
|
+
},
|
|
166
|
+
"skip-assets-publish": {
|
|
167
|
+
"name": "skip-assets-publish",
|
|
168
|
+
"type": "boolean",
|
|
169
|
+
"description": "Skips asset publishing during the import process.",
|
|
170
|
+
"allowNo": false
|
|
171
|
+
},
|
|
172
|
+
"skip-entries-publish": {
|
|
173
|
+
"name": "skip-entries-publish",
|
|
174
|
+
"type": "boolean",
|
|
175
|
+
"description": "Skips entry publishing during the import process",
|
|
176
|
+
"allowNo": false
|
|
165
177
|
}
|
|
166
178
|
},
|
|
167
179
|
"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.20.2",
|
|
5
5
|
"author": "Contentstack",
|
|
6
6
|
"bugs": "https://github.com/contentstack/cli/issues",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@contentstack/cli-audit": "~1.
|
|
8
|
+
"@contentstack/cli-audit": "~1.10.0",
|
|
9
9
|
"@contentstack/cli-command": "~1.3.3",
|
|
10
|
-
"@contentstack/cli-utilities": "~1.
|
|
10
|
+
"@contentstack/cli-utilities": "~1.9.0",
|
|
11
11
|
"@contentstack/management": "~1.18.4",
|
|
12
|
-
"@contentstack/cli-variants": "~1.1.
|
|
12
|
+
"@contentstack/cli-variants": "~1.1.6",
|
|
13
13
|
"@oclif/core": "^3.27.0",
|
|
14
14
|
"big-json": "^3.2.0",
|
|
15
15
|
"bluebird": "^3.7.2",
|