Skip to content

Commit ef478f6

Browse files
committed
feat: integrate import setup with import plugin
1 parent 1101b4a commit ef478f6

File tree

16 files changed

+102
-22
lines changed

16 files changed

+102
-22
lines changed

package-lock.json

+5-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/contentstack-clone/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"dependencies": {
88
"@colors/colors": "^1.5.0",
99
"@contentstack/cli-cm-export": "~1.14.1",
10-
"@contentstack/cli-cm-import": "~1.19.1",
10+
"@contentstack/cli-cm-import": "~1.20.0",
1111
"@contentstack/cli-command": "~1.3.2",
1212
"@contentstack/cli-utilities": "~1.8.0",
1313
"async": "^3.2.4",

packages/contentstack-import-setup/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ FLAGS
7373
-a, --alias=<value> alias of the management token
7474
-d, --data-dir=<value> path and location where data is stored
7575
-k, --stack-api-key=<value> API key of the target stack
76+
--backup-dir=<value> [optional] backup directory name when using specific module
7677
--modules=<option> [optional] specific module name
7778
<options: content-types|entries|both>
7879
@@ -98,6 +99,7 @@ FLAGS
9899
-a, --alias=<value> alias of the management token
99100
-d, --data-dir=<value> path and location where data is stored
100101
-k, --stack-api-key=<value> API key of the target stack
102+
--backup-dir=<value> [optional] backup directory name when using specific module
101103
--modules=<option> [optional] specific module name
102104
<options: content-types|entries|both>
103105

packages/contentstack-import-setup/src/commands/cm/stacks/import-setup.ts

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ export default class ImportSetupCommand extends Command {
3838
options: ['content-types', 'entries', 'both'], // only allow the value to be from a discrete set
3939
description: '[optional] specific module name',
4040
}),
41+
'backup-dir': flags.string({
42+
description: '[optional] backup directory name when using specific module',
43+
}),
4144
};
4245

4346
static aliases: string[] = ['cm:import'];

packages/contentstack-import-setup/src/import/modules/extensions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default class ExtensionImportSetup {
4040
for (const extension of Object.values(extensions) as any) {
4141
const targetExtension: any = await this.getExtension(extension);
4242
if (!targetExtension) {
43-
log(this.config, `Extension with title '${extension.title}' not found in the stack!`, 'error');
43+
log(this.config, `Extension with title '${extension.title}' not found in the stack!`, 'info');
4444
continue;
4545
}
4646
this.extensionMapper[extension.uid] = targetExtension.uid;

packages/contentstack-import/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
4747
$ csdx COMMAND
4848
running command...
4949
$ csdx (--version)
50-
@contentstack/cli-cm-import/1.19.1 darwin-arm64 node-v22.2.0
50+
@contentstack/cli-cm-import/1.20.0 darwin-arm64 node-v22.2.0
5151
$ csdx --help [COMMAND]
5252
USAGE
5353
$ csdx COMMAND

packages/contentstack-import/package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"name": "@contentstack/cli-cm-import",
33
"description": "Contentstack CLI plugin to import content into stack",
4-
"version": "1.19.1",
4+
"version": "1.20.0",
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {
88
"@contentstack/cli-audit": "~1.7.2",
9+
"@contentstack/cli-cm-import-setup": "~1.0.0-beta.0",
910
"@contentstack/cli-command": "~1.3.2",
1011
"@contentstack/cli-utilities": "~1.8.0",
11-
"@contentstack/management": "~1.17.0",
1212
"@contentstack/cli-variants": "~1.1.1",
13+
"@contentstack/management": "~1.17.0",
1314
"@oclif/core": "^3.26.5",
1415
"big-json": "^3.2.0",
1516
"bluebird": "^3.7.2",

packages/contentstack-import/src/import/modules/content-types.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
import * as path from 'path';
99
import { isEmpty, find, cloneDeep, map } from 'lodash';
10-
import { fsUtil, log, formatError, schemaTemplate, lookupExtension, lookUpTaxonomy } from '../../utils';
10+
import { sanitizePath } from '@contentstack/cli-utilities';
11+
import { fsUtil, log, formatError, schemaTemplate, lookupExtension, lookUpTaxonomy, checkAndCreateMapperFile } from '../../utils';
1112
import { ImportConfig, ModuleClassParams } from '../../types';
1213
import BaseClass, { ApiOptions } from './base-class';
1314
import { updateFieldRules } from '../../utils/content-type-helper';
14-
import { sanitizePath } from '@contentstack/cli-utilities';
1515

1616
export default class ContentTypesImport extends BaseClass {
1717
private cTsMapperPath: string;
@@ -108,6 +108,11 @@ export default class ContentTypesImport extends BaseClass {
108108
return;
109109
}
110110
await fsUtil.makeDirectory(this.cTsMapperPath);
111+
112+
// check and create mapper file
113+
log(this.importConfig, 'Checking and generating CT import dependant mapper file...', 'info');
114+
await checkAndCreateMapperFile(this.importConfig);
115+
111116
this.installedExtensions = (
112117
((await fsUtil.readFile(this.marketplaceAppMapperPath)) as any) || { extension_uid: {} }
113118
).extension_uid;

packages/contentstack-import/src/import/modules/entries.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
lookupAssets,
2222
fileHelper,
2323
lookUpTerms,
24+
checkAndCreateMapperFile,
2425
} from '../../utils';
2526
import { ModuleClassParams } from '../../types';
2627
import BaseClass, { ApiOptions } from './base-class';
@@ -112,6 +113,11 @@ export default class EntriesImport extends BaseClass {
112113
log(this.importConfig, 'No content type found', 'info');
113114
return;
114115
}
116+
117+
// check and create mapper file
118+
log(this.importConfig, 'Checking and generating entries import dependant mapper file...', 'info');
119+
await checkAndCreateMapperFile(this.importConfig);
120+
115121
this.installedExtensions = (
116122
((await fsUtil.readFile(this.marketplaceAppMapperPath)) as any) || { extension_uid: {} }
117123
).extension_uid;
@@ -954,8 +960,8 @@ export default class EntriesImport extends BaseClass {
954960
...content,
955961
locale: publish.locale,
956962
publish_details: [publish],
957-
}))
958-
);
963+
})),
964+
);
959965
apiContent = apiContentDuplicate;
960966
await this.makeConcurrentCall({
961967
apiContent,
@@ -1010,7 +1016,7 @@ export default class EntriesImport extends BaseClass {
10101016
apiOptions.apiData = null;
10111017
return apiOptions;
10121018
}
1013-
if(requestObject.environments.length === 0 || requestObject.locales.length === 0 ){
1019+
if (requestObject.environments.length === 0 || requestObject.locales.length === 0) {
10141020
apiOptions.apiData = null;
10151021
return apiOptions;
10161022
}

packages/contentstack-import/src/types/import-config.ts

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export default interface ImportConfig extends DefaultConfig, ExternalConfig {
5454
region: Region;
5555
personalizeProjectName?: string;
5656
'exclude-global-modules': false;
57+
alias?: string;
5758
}
5859

5960
type branch = {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import ImportSetupCommand from '@contentstack/cli-cm-import-setup';
2+
import { ImportConfig } from '../types';
3+
4+
export const checkAndCreateMapperFile = async (config: ImportConfig) => {
5+
try {
6+
const args = ['--data-dir', config.data, '--modules', config.moduleName, '--backup-dir', config.backupDir];
7+
if (config.alias) args.push('--alias', config.alias);
8+
else args.push('--stack-api-key', config.apiKey);
9+
await ImportSetupCommand.run(args);
10+
} catch (error) {
11+
throw new Error(`Error while creating the mapper file: ${error?.message}`);
12+
}
13+
};

packages/contentstack-import/src/utils/import-config-handler.ts

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const setupConfig = async (importCmdFlags: any): Promise<ImportConfig> => {
4242
const managementTokenAlias = importCmdFlags['management-token-alias'] || importCmdFlags['alias'];
4343

4444
if (managementTokenAlias) {
45+
config.alias = managementTokenAlias;
4546
const { token, apiKey } = configHandler.get(`tokens.${managementTokenAlias}`) ?? {};
4647
config.management_token = token;
4748
config.apiKey = apiKey;

packages/contentstack-import/src/utils/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ export {
2626
export * from './common-helper';
2727
export * from './log';
2828
export { lookUpTaxonomy, lookUpTerms } from './taxonomies-helper';
29+
export { checkAndCreateMapperFile } from './generate-mapper-file';

packages/contentstack-seed/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"author": "Contentstack",
66
"bugs": "https://github.com/contentstack/cli/issues",
77
"dependencies": {
8-
"@contentstack/cli-cm-import": "~1.19.1",
8+
"@contentstack/cli-cm-import": "~1.20.0",
99
"@contentstack/cli-command": "~1.3.2",
1010
"@contentstack/cli-utilities": "~1.8.0",
1111
"inquirer": "8.2.4",

packages/contentstack/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"@contentstack/cli-cm-export": "~1.14.1",
3131
"@contentstack/cli-cm-clone": "~1.13.0",
3232
"@contentstack/cli-cm-export-to-csv": "~1.7.3",
33-
"@contentstack/cli-cm-import": "~1.19.1",
33+
"@contentstack/cli-cm-import": "~1.20.0",
3434
"@contentstack/cli-cm-migrate-rte": "~1.4.20",
3535
"@contentstack/cli-cm-seed": "~1.10.0",
3636
"@contentstack/cli-command": "~1.3.2",

pnpm-lock.yaml

+52-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)