Skip to content

Commit

Permalink
feat: integrate import setup with import plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
aman19K committed Oct 25, 2024
1 parent 574bb3d commit 21714d4
Show file tree
Hide file tree
Showing 16 changed files with 102 additions and 22 deletions.
9 changes: 5 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/contentstack-clone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"dependencies": {
"@colors/colors": "^1.5.0",
"@contentstack/cli-cm-export": "~1.14.1",
"@contentstack/cli-cm-import": "~1.19.1",
"@contentstack/cli-cm-import": "~1.20.0",
"@contentstack/cli-command": "~1.3.2",
"@contentstack/cli-utilities": "~1.8.0",
"async": "^3.2.4",
Expand Down
2 changes: 2 additions & 0 deletions packages/contentstack-import-setup/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ FLAGS
-a, --alias=<value> alias of the management token
-d, --data-dir=<value> path and location where data is stored
-k, --stack-api-key=<value> API key of the target stack
--backup-dir=<value> [optional] backup directory name when using specific module
--modules=<option> [optional] specific module name
<options: content-types|entries|both>
Expand All @@ -98,6 +99,7 @@ FLAGS
-a, --alias=<value> alias of the management token
-d, --data-dir=<value> path and location where data is stored
-k, --stack-api-key=<value> API key of the target stack
--backup-dir=<value> [optional] backup directory name when using specific module
--modules=<option> [optional] specific module name
<options: content-types|entries|both>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export default class ImportSetupCommand extends Command {
options: ['content-types', 'entries', 'both'], // only allow the value to be from a discrete set
description: '[optional] specific module name',
}),
'backup-dir': flags.string({
description: '[optional] backup directory name when using specific module',
}),
};

static aliases: string[] = ['cm:import'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default class ExtensionImportSetup {
for (const extension of Object.values(extensions) as any) {
const targetExtension: any = await this.getExtension(extension);
if (!targetExtension) {
log(this.config, `Extension with title '${extension.title}' not found in the stack!`, 'error');
log(this.config, `Extension with title '${extension.title}' not found in the stack!`, 'info');
continue;
}
this.extensionMapper[extension.uid] = targetExtension.uid;
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import
$ csdx COMMAND
running command...
$ csdx (--version)
@contentstack/cli-cm-import/1.19.1 darwin-arm64 node-v22.2.0
@contentstack/cli-cm-import/1.20.0 darwin-arm64 node-v22.2.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down
5 changes: 3 additions & 2 deletions packages/contentstack-import/package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
{
"name": "@contentstack/cli-cm-import",
"description": "Contentstack CLI plugin to import content into stack",
"version": "1.19.1",
"version": "1.20.0",
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-audit": "~1.7.2",
"@contentstack/cli-cm-import-setup": "~1.0.0-beta.0",
"@contentstack/cli-command": "~1.3.2",
"@contentstack/cli-utilities": "~1.8.0",
"@contentstack/management": "~1.17.0",
"@contentstack/cli-variants": "~1.1.1",
"@contentstack/management": "~1.17.0",
"@oclif/core": "^3.26.5",
"big-json": "^3.2.0",
"bluebird": "^3.7.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

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

export default class ContentTypesImport extends BaseClass {
private cTsMapperPath: string;
Expand Down Expand Up @@ -108,6 +108,11 @@ export default class ContentTypesImport extends BaseClass {
return;
}
await fsUtil.makeDirectory(this.cTsMapperPath);

// check and create mapper file
log(this.importConfig, 'Checking and generating CT import dependant mapper file...', 'info');
await checkAndCreateMapperFile(this.importConfig);

this.installedExtensions = (
((await fsUtil.readFile(this.marketplaceAppMapperPath)) as any) || { extension_uid: {} }
).extension_uid;
Expand Down
12 changes: 9 additions & 3 deletions packages/contentstack-import/src/import/modules/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
lookupAssets,
fileHelper,
lookUpTerms,
checkAndCreateMapperFile,
} from '../../utils';
import { ModuleClassParams } from '../../types';
import BaseClass, { ApiOptions } from './base-class';
Expand Down Expand Up @@ -112,6 +113,11 @@ export default class EntriesImport extends BaseClass {
log(this.importConfig, 'No content type found', 'info');
return;
}

// check and create mapper file
log(this.importConfig, 'Checking and generating entries import dependant mapper file...', 'info');
await checkAndCreateMapperFile(this.importConfig);

this.installedExtensions = (
((await fsUtil.readFile(this.marketplaceAppMapperPath)) as any) || { extension_uid: {} }
).extension_uid;
Expand Down Expand Up @@ -954,8 +960,8 @@ export default class EntriesImport extends BaseClass {
...content,
locale: publish.locale,
publish_details: [publish],
}))
);
})),
);
apiContent = apiContentDuplicate;
await this.makeConcurrentCall({
apiContent,
Expand Down Expand Up @@ -1010,7 +1016,7 @@ export default class EntriesImport extends BaseClass {
apiOptions.apiData = null;
return apiOptions;
}
if(requestObject.environments.length === 0 || requestObject.locales.length === 0 ){
if (requestObject.environments.length === 0 || requestObject.locales.length === 0) {
apiOptions.apiData = null;
return apiOptions;
}
Expand Down
1 change: 1 addition & 0 deletions packages/contentstack-import/src/types/import-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default interface ImportConfig extends DefaultConfig, ExternalConfig {
region: Region;
personalizeProjectName?: string;
'exclude-global-modules': false;
alias?: string;
}

type branch = {
Expand Down
13 changes: 13 additions & 0 deletions packages/contentstack-import/src/utils/generate-mapper-file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import ImportSetupCommand from '@contentstack/cli-cm-import-setup';
import { ImportConfig } from '../types';

export const checkAndCreateMapperFile = async (config: ImportConfig) => {
try {
const args = ['--data-dir', config.data, '--modules', config.moduleName, '--backup-dir', config.backupDir];
if (config.alias) args.push('--alias', config.alias);
else args.push('--stack-api-key', config.apiKey);
await ImportSetupCommand.run(args);
} catch (error) {
throw new Error(`Error while creating the mapper file: ${error?.message}`);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const setupConfig = async (importCmdFlags: any): Promise<ImportConfig> => {
const managementTokenAlias = importCmdFlags['management-token-alias'] || importCmdFlags['alias'];

if (managementTokenAlias) {
config.alias = managementTokenAlias;
const { token, apiKey } = configHandler.get(`tokens.${managementTokenAlias}`) ?? {};
config.management_token = token;
config.apiKey = apiKey;
Expand Down
1 change: 1 addition & 0 deletions packages/contentstack-import/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ export {
export * from './common-helper';
export * from './log';
export { lookUpTaxonomy, lookUpTerms } from './taxonomies-helper';
export { checkAndCreateMapperFile } from './generate-mapper-file';
2 changes: 1 addition & 1 deletion packages/contentstack-seed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Contentstack",
"bugs": "https://github.com/contentstack/cli/issues",
"dependencies": {
"@contentstack/cli-cm-import": "~1.19.1",
"@contentstack/cli-cm-import": "~1.20.0",
"@contentstack/cli-command": "~1.3.2",
"@contentstack/cli-utilities": "~1.8.0",
"inquirer": "8.2.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"@contentstack/cli-cm-export": "~1.14.1",
"@contentstack/cli-cm-clone": "~1.13.0",
"@contentstack/cli-cm-export-to-csv": "~1.7.3",
"@contentstack/cli-cm-import": "~1.19.1",
"@contentstack/cli-cm-import": "~1.20.0",
"@contentstack/cli-cm-migrate-rte": "~1.4.20",
"@contentstack/cli-cm-seed": "~1.10.0",
"@contentstack/cli-command": "~1.3.2",
Expand Down
58 changes: 52 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 21714d4

Please sign in to comment.