From eee14f5e7c20bde9a5112cfde15cdd91a9dc74bf Mon Sep 17 00:00:00 2001 From: Antony Date: Fri, 22 Dec 2023 16:59:02 +0530 Subject: [PATCH 1/8] Feat: Audit fix command integration with Import --- package-lock.json | 1 + .../src/audit-base-command.ts | 4 +- .../contentstack-audit/src/base-command.ts | 3 +- .../src/commands/cm/stacks/audit/fix.ts | 8 +- packages/contentstack-audit/src/index.ts | 5 +- .../src/modules/content-types.ts | 2 +- .../contentstack-audit/src/modules/entries.ts | 2 +- packages/contentstack-import/README.md | 8 +- packages/contentstack-import/package.json | 3 +- .../src/commands/cm/stacks/import.ts | 6 +- .../src/import/module-importer.ts | 88 ++++++++++++++++--- .../src/types/import-config.ts | 1 + .../src/utils/import-config-handler.ts | 3 +- pnpm-lock.yaml | 8 +- 14 files changed, 113 insertions(+), 29 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4b190fa3a1..919a407e36 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24923,6 +24923,7 @@ "version": "1.12.2", "license": "MIT", "dependencies": { + "@contentstack/cli-audit": "^1.3.2", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.10", "@contentstack/management": "~1.13.0", diff --git a/packages/contentstack-audit/src/audit-base-command.ts b/packages/contentstack-audit/src/audit-base-command.ts index 8f899224b7..aa6c15815c 100644 --- a/packages/contentstack-audit/src/audit-base-command.ts +++ b/packages/contentstack-audit/src/audit-base-command.ts @@ -36,7 +36,7 @@ export abstract class AuditBaseCommand extends BaseCommand { + async start(command: CommandNames): Promise { this.currentCommand = command; await this.promptQueue(); await this.createBackUp(); @@ -69,6 +69,8 @@ export abstract class AuditBaseCommand extends BaseCommand extends Command { this.sharedConfig = Object.assign(this.sharedConfig, { flags: this.flags }); - if (this.flags['external-config']?.config) { + if (!isEmpty(this.flags['external-config']?.config)) { this.sharedConfig = Object.assign(this.sharedConfig, this.flags['external-config']?.config); } diff --git a/packages/contentstack-audit/src/commands/cm/stacks/audit/fix.ts b/packages/contentstack-audit/src/commands/cm/stacks/audit/fix.ts index 31f22e05e5..0145b9a931 100644 --- a/packages/contentstack-audit/src/commands/cm/stacks/audit/fix.ts +++ b/packages/contentstack-audit/src/commands/cm/stacks/audit/fix.ts @@ -60,12 +60,12 @@ export default class AuditFix extends AuditBaseCommand { * The `run` function is an asynchronous function that performs an audit on different modules * (content-types, global-fields, entries) and generates a report. */ - async run(): Promise { + async run(): Promise { try { - await this.start('cm:stacks:audit:fix'); + const hasFix = await this.start('cm:stacks:audit:fix'); - if (this.flags['external-config']?.returnConfig) { - return this.sharedConfig; + if (this.flags['external-config']?.returnResponse) { + return { config: this.sharedConfig, hasFix }; } } catch (error) { this.log(error instanceof Error ? error.message : error, 'error'); diff --git a/packages/contentstack-audit/src/index.ts b/packages/contentstack-audit/src/index.ts index ff8b4c5632..b612d475f8 100644 --- a/packages/contentstack-audit/src/index.ts +++ b/packages/contentstack-audit/src/index.ts @@ -1 +1,4 @@ -export default {}; +import Audit from "./commands/cm/stacks/audit"; +import AuditFix from "./commands/cm/stacks/audit/fix"; + +export { Audit, AuditFix }; diff --git a/packages/contentstack-audit/src/modules/content-types.ts b/packages/contentstack-audit/src/modules/content-types.ts index 7f91346119..0b544992f5 100644 --- a/packages/contentstack-audit/src/modules/content-types.ts +++ b/packages/contentstack-audit/src/modules/content-types.ts @@ -102,7 +102,7 @@ export default class ContentType { let canWrite = true; if (!this.inMemoryFix && this.fix) { - if (!this.config.flags['copy-dir']) { + if (!this.config.flags['copy-dir'] && !this.config.flags['external-config']?.skipConfirm) { canWrite = this.config.flags.yes ?? (await ux.confirm(commonMsg.FIX_CONFIRMATION)); } diff --git a/packages/contentstack-audit/src/modules/entries.ts b/packages/contentstack-audit/src/modules/entries.ts index f68224cf42..586d4071b6 100644 --- a/packages/contentstack-audit/src/modules/entries.ts +++ b/packages/contentstack-audit/src/modules/entries.ts @@ -160,7 +160,7 @@ export default class Entries { let canWrite = true; if (this.fix) { - if (!this.config.flags['copy-dir']) { + if (!this.config.flags['copy-dir'] && !this.config.flags['external-config']?.skipConfirm) { canWrite = this.config.flags.yes || (await ux.confirm(commonMsg.FIX_CONFIRMATION)); } diff --git a/packages/contentstack-import/README.md b/packages/contentstack-import/README.md index 7e2ac01355..12b43d4a34 100644 --- a/packages/contentstack-import/README.md +++ b/packages/contentstack-import/README.md @@ -47,7 +47,7 @@ $ npm install -g @contentstack/cli-cm-import $ csdx COMMAND running command... $ csdx (--version) -@contentstack/cli-cm-import/1.12.2 darwin-arm64 node-v20.8.0 +@contentstack/cli-cm-import/1.12.2 darwin-arm64 node-v20.10.0 $ csdx --help [COMMAND] USAGE $ csdx COMMAND @@ -83,6 +83,7 @@ FLAGS --replace-existing Replaces the existing module in the target stack. --skip-app-recreation [optional] Skip private apps recreation if already exist + --skip-audit Skips the audit fix. --skip-existing Skips the module exists warning messages. DESCRIPTION @@ -106,7 +107,7 @@ EXAMPLES $ csdx cm:stacks:import --alias --config - $ csdx cm:stacks:import --branch --yes + $ csdx cm:stacks:import --branch --yes --skip-audit ``` ## `csdx cm:stacks:import [-c ] [-k ] [-d ] [-a ] [--module ] [--backup-dir ] [--branch ] [--import-webhook-status disable|current]` @@ -131,6 +132,7 @@ FLAGS --replace-existing Replaces the existing module in the target stack. --skip-app-recreation [optional] Skip private apps recreation if already exist + --skip-audit Skips the audit fix. --skip-existing Skips the module exists warning messages. DESCRIPTION @@ -154,7 +156,7 @@ EXAMPLES $ csdx cm:stacks:import --alias --config - $ csdx cm:stacks:import --branch --yes + $ csdx cm:stacks:import --branch --yes --skip-audit ``` _See code: [src/commands/cm/stacks/import.ts](https://github.com/contentstack/cli/blob/main/packages/contentstack-import/src/commands/cm/stacks/import.ts)_ diff --git a/packages/contentstack-import/package.json b/packages/contentstack-import/package.json index 6da5117134..f290a81c54 100644 --- a/packages/contentstack-import/package.json +++ b/packages/contentstack-import/package.json @@ -5,6 +5,7 @@ "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { + "@contentstack/cli-audit": "^1.3.2", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.10", "@contentstack/management": "~1.13.0", @@ -99,4 +100,4 @@ } }, "repository": "https://github.com/contentstack/cli" -} \ No newline at end of file +} diff --git a/packages/contentstack-import/src/commands/cm/stacks/import.ts b/packages/contentstack-import/src/commands/cm/stacks/import.ts index fbf94f43b6..01a0c1dd9c 100644 --- a/packages/contentstack-import/src/commands/cm/stacks/import.ts +++ b/packages/contentstack-import/src/commands/cm/stacks/import.ts @@ -9,7 +9,6 @@ import { ContentstackClient, } from '@contentstack/cli-utilities'; -import { trace } from '../../../utils/log'; import { ImportConfig } from '../../../types'; import { ModuleImporter } from '../../../import'; import { setupImportConfig, formatError, log } from '../../../utils'; @@ -25,7 +24,7 @@ export default class ImportCommand extends Command { `csdx cm:stacks:import --alias `, `csdx cm:stacks:import --alias --data-dir `, `csdx cm:stacks:import --alias --config `, - `csdx cm:stacks:import --branch --yes`, + `csdx cm:stacks:import --branch --yes --skip-audit`, ]; static flags: FlagInput = { @@ -106,6 +105,9 @@ export default class ImportCommand extends Command { default: false, description: 'Skips the module exists warning messages.', }), + 'skip-audit': flags.boolean({ + description: 'Skips the audit fix.', + }), }; static aliases: string[] = ['cm:import']; diff --git a/packages/contentstack-import/src/import/module-importer.ts b/packages/contentstack-import/src/import/module-importer.ts index f92999429b..46c780bf97 100755 --- a/packages/contentstack-import/src/import/module-importer.ts +++ b/packages/contentstack-import/src/import/module-importer.ts @@ -1,9 +1,11 @@ -import { addLocale, ContentstackClient } from '@contentstack/cli-utilities'; +import { resolve } from 'path'; +import { AuditFix } from '@contentstack/cli-audit'; +import { addLocale, cliux, ContentstackClient } from '@contentstack/cli-utilities'; import startModuleImport from './modules'; import startJSModuleImport from './modules-js'; import { ImportConfig, Modules } from '../types'; -import { backupHandler, log, validateBranch, masterLocalDetails, sanitizeStack, initLogger } from '../utils'; +import { backupHandler, log, validateBranch, masterLocalDetails, sanitizeStack, initLogger, trace } from '../utils'; class ModuleImporter { private managementAPIClient: ContentstackClient; @@ -24,18 +26,10 @@ class ModuleImporter { await validateBranch(this.stackAPIClient, this.importConfig, this.importConfig.branchName); } - // Temporarily adding this api call to verify management token has read and write permissions - // TODO: CS-40354 - CLI | import rewrite | Migrate HTTP call to SDK call once fix is ready from SDK side - if (this.importConfig.management_token) { await addLocale(this.importConfig.apiKey, this.importConfig.management_token, this.importConfig.host); } - if (!this.importConfig.master_locale) { - let masterLocalResponse = await masterLocalDetails(this.stackAPIClient); - this.importConfig['master_locale'] = { code: masterLocalResponse.code }; - this.importConfig.masterLocale = { code: masterLocalResponse.code }; - } const backupDir = await backupHandler(this.importConfig); if (backupDir) { this.importConfig.backupDir = backupDir; @@ -46,6 +40,23 @@ class ModuleImporter { // NOTE init log initLogger(this.importConfig); + // NOTE audit and fix the import content. + if ( + !this.importConfig.skipAudit && + (!this.importConfig.moduleName || + ['content-types', 'global-fields', 'entries'].includes(this.importConfig.moduleName)) + ) { + if (!(await this.auditImportData())) { + return; + } + } + + if (!this.importConfig.master_locale) { + let masterLocalResponse = await masterLocalDetails(this.stackAPIClient); + this.importConfig['master_locale'] = { code: masterLocalResponse.code }; + this.importConfig.masterLocale = { code: masterLocalResponse.code }; + } + await sanitizeStack(this.stackAPIClient); return this.import(); @@ -90,6 +101,63 @@ class ModuleImporter { await this.importByModuleByName(moduleName); } } + + /** + * The `auditImportData` function performs an audit process on imported data, using a specified + * configuration, and returns a boolean indicating whether a fix is needed. + * @returns The function `auditImportData()` returns a boolean value. It returns `true` if there is a + * fix available and the user confirms to proceed with the fix, otherwise it returns `false`. + */ + async auditImportData() { + const basePath = resolve(this.importConfig.backupDir, 'logs', 'audit'); + const auditConfig = { + noLog: false, // Skip logs printing on terminal + skipConfirm: true, // Skip confirmation if any + returnResponse: true, // On process completion should return config used in the command + noTerminalOutput: false, // Skip final audit table output on terminal + config: { basePath }, // To overwrite any build-in config. This config is equal to --config flag. + }; + try { + const args = [ + '--data-dir', + this.importConfig.backupDir, + '--external-config', + JSON.stringify(auditConfig), + '--report-path', + basePath, + ]; + + if (this.importConfig.moduleName) { + args.push('--modules', this.importConfig.moduleName); + } + + log(this.importConfig, 'Starting audit process', 'info'); + const result = await AuditFix.run(args); + log(this.importConfig, 'Starting audit process completed', 'info'); + + if (result) { + const { hasFix } = result; + + if (hasFix) { + if ( + this.importConfig.forceStopMarketplaceAppsPrompt || + (await cliux.inquire({ + type: 'confirm', + message: 'Can you check the fix on the given path and confirm if you would like to proceed with the fix?', + name: 'confirmation', + })) + ) { + return true; + } + + return false; + } + } + } catch (error) { + trace(error); + log(this.importConfig, `Audit failed with following error. ${error}`, 'error'); + } + } } export default ModuleImporter; diff --git a/packages/contentstack-import/src/types/import-config.ts b/packages/contentstack-import/src/types/import-config.ts index 036dccb0a5..bdf75c4727 100644 --- a/packages/contentstack-import/src/types/import-config.ts +++ b/packages/contentstack-import/src/types/import-config.ts @@ -47,6 +47,7 @@ export default interface ImportConfig extends DefaultConfig, ExternalConfig { contentVersion: number; replaceExisting?: boolean; skipExisting?: boolean; + skipAudit?: boolean; } type branch = { diff --git a/packages/contentstack-import/src/utils/import-config-handler.ts b/packages/contentstack-import/src/utils/import-config-handler.ts index b83fd00951..1421a3e5c6 100644 --- a/packages/contentstack-import/src/utils/import-config-handler.ts +++ b/packages/contentstack-import/src/utils/import-config-handler.ts @@ -64,8 +64,9 @@ const setupConfig = async (importCmdFlags: any): Promise => { //Note to support the old key config.source_stack = config.apiKey; - config.importWebhookStatus = importCmdFlags['import-webhook-status']; + config.skipAudit = importCmdFlags['skip-audit']; config.forceStopMarketplaceAppsPrompt = importCmdFlags.yes; + config.importWebhookStatus = importCmdFlags['import-webhook-status']; config.skipPrivateAppRecreationIfExist = importCmdFlags['skip-app-recreation']; if (importCmdFlags['branch']) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 79ceb6aafd..ebfe0dbea2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -724,6 +724,7 @@ importers: packages/contentstack-import: specifiers: + '@contentstack/cli-audit': ^1.3.2 '@contentstack/cli-command': ~1.2.16 '@contentstack/cli-utilities': ~1.5.10 '@contentstack/management': ~1.13.0 @@ -767,6 +768,7 @@ importers: uuid: ^9.0.0 winston: ^3.7.2 dependencies: + '@contentstack/cli-audit': link:../contentstack-audit '@contentstack/cli-command': link:../contentstack-command '@contentstack/cli-utilities': link:../contentstack-utilities '@contentstack/management': 1.13.0_debug@4.3.4 @@ -6534,7 +6536,7 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: - '@typescript-eslint/parser': 6.13.2_7hj7rehet5x3fvq7nqub5sammm + '@typescript-eslint/parser': 6.13.2_sjjl3gun7puonkp27uqtyjm5b4 debug: 3.2.7 eslint: 8.55.0 eslint-import-resolver-node: 0.3.9 @@ -6564,7 +6566,7 @@ packages: eslint-import-resolver-webpack: optional: true dependencies: - '@typescript-eslint/parser': 6.13.2_7hj7rehet5x3fvq7nqub5sammm + '@typescript-eslint/parser': 6.13.2_sjjl3gun7puonkp27uqtyjm5b4 debug: 3.2.7 eslint: 8.55.0 eslint-import-resolver-typescript: 3.6.1_hdscurta55xxypqxbdhu44qa6e @@ -6669,7 +6671,7 @@ packages: '@typescript-eslint/parser': optional: true dependencies: - '@typescript-eslint/parser': 6.13.2_7hj7rehet5x3fvq7nqub5sammm + '@typescript-eslint/parser': 6.13.2_sjjl3gun7puonkp27uqtyjm5b4 array-includes: 3.1.7 array.prototype.findlastindex: 1.2.3 array.prototype.flat: 1.3.2 From 7055073493ce09179a1912ffa61c38554decec29 Mon Sep 17 00:00:00 2001 From: Antony Date: Wed, 3 Jan 2024 10:59:37 +0530 Subject: [PATCH 2/8] Version bum --- package-lock.json | 8 ++++---- packages/contentstack-clone/package.json | 2 +- packages/contentstack-import/package.json | 2 +- packages/contentstack-seed/package.json | 2 +- packages/contentstack/package.json | 2 +- pnpm-lock.yaml | 6 +++--- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index 919a407e36..15a105889e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23501,7 +23501,7 @@ "@contentstack/cli-cm-clone": "~1.8.0", "@contentstack/cli-cm-export": "~1.10.2", "@contentstack/cli-cm-export-to-csv": "~1.6.2", - "@contentstack/cli-cm-import": "~1.12.2", + "@contentstack/cli-cm-import": "~1.12.3", "@contentstack/cli-cm-migrate-rte": "~1.4.15", "@contentstack/cli-cm-seed": "~1.7.0", "@contentstack/cli-command": "~1.2.16", @@ -24054,7 +24054,7 @@ "dependencies": { "@colors/colors": "^1.5.0", "@contentstack/cli-cm-export": "~1.10.2", - "@contentstack/cli-cm-import": "~1.12.2", + "@contentstack/cli-cm-import": "~1.12.3", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.10", "async": "^3.2.4", @@ -24920,7 +24920,7 @@ }, "packages/contentstack-import": { "name": "@contentstack/cli-cm-import", - "version": "1.12.2", + "version": "1.12.3", "license": "MIT", "dependencies": { "@contentstack/cli-audit": "^1.3.2", @@ -25382,7 +25382,7 @@ "version": "1.7.0", "license": "MIT", "dependencies": { - "@contentstack/cli-cm-import": "~1.12.2", + "@contentstack/cli-cm-import": "~1.12.3", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.10", "inquirer": "8.2.4", diff --git a/packages/contentstack-clone/package.json b/packages/contentstack-clone/package.json index e0d7614279..19b9284a46 100644 --- a/packages/contentstack-clone/package.json +++ b/packages/contentstack-clone/package.json @@ -6,7 +6,7 @@ "bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues", "dependencies": { "@contentstack/cli-cm-export": "~1.10.2", - "@contentstack/cli-cm-import": "~1.12.2", + "@contentstack/cli-cm-import": "~1.12.3", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.10", "@colors/colors": "^1.5.0", diff --git a/packages/contentstack-import/package.json b/packages/contentstack-import/package.json index f290a81c54..f3a37f7c7a 100644 --- a/packages/contentstack-import/package.json +++ b/packages/contentstack-import/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-cm-import", "description": "Contentstack CLI plugin to import content into stack", - "version": "1.12.2", + "version": "1.12.3", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { diff --git a/packages/contentstack-seed/package.json b/packages/contentstack-seed/package.json index 5ebadf20a8..fc7de910c1 100644 --- a/packages/contentstack-seed/package.json +++ b/packages/contentstack-seed/package.json @@ -5,7 +5,7 @@ "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { - "@contentstack/cli-cm-import": "~1.12.2", + "@contentstack/cli-cm-import": "~1.12.3", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.10", "inquirer": "8.2.4", diff --git a/packages/contentstack/package.json b/packages/contentstack/package.json index 0deadcc227..d10c89b9a9 100755 --- a/packages/contentstack/package.json +++ b/packages/contentstack/package.json @@ -30,7 +30,7 @@ "@contentstack/cli-cm-clone": "~1.8.0", "@contentstack/cli-cm-export": "~1.10.2", "@contentstack/cli-cm-export-to-csv": "~1.6.2", - "@contentstack/cli-cm-import": "~1.12.2", + "@contentstack/cli-cm-import": "~1.12.3", "@contentstack/cli-cm-migrate-rte": "~1.4.15", "@contentstack/cli-cm-seed": "~1.7.0", "@contentstack/cli-command": "~1.2.16", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ebfe0dbea2..d83be28568 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,7 +18,7 @@ importers: '@contentstack/cli-cm-clone': ~1.8.0 '@contentstack/cli-cm-export': ~1.10.2 '@contentstack/cli-cm-export-to-csv': ~1.6.2 - '@contentstack/cli-cm-import': ~1.12.2 + '@contentstack/cli-cm-import': ~1.12.3 '@contentstack/cli-cm-migrate-rte': ~1.4.15 '@contentstack/cli-cm-seed': ~1.7.0 '@contentstack/cli-command': ~1.2.16 @@ -422,7 +422,7 @@ importers: specifiers: '@colors/colors': ^1.5.0 '@contentstack/cli-cm-export': ~1.10.2 - '@contentstack/cli-cm-import': ~1.12.2 + '@contentstack/cli-cm-import': ~1.12.3 '@contentstack/cli-command': ~1.2.16 '@contentstack/cli-utilities': ~1.5.10 '@oclif/test': ^1.2.7 @@ -986,7 +986,7 @@ importers: packages/contentstack-seed: specifiers: - '@contentstack/cli-cm-import': ~1.12.2 + '@contentstack/cli-cm-import': ~1.12.3 '@contentstack/cli-command': ~1.2.16 '@contentstack/cli-utilities': ~1.5.10 '@oclif/plugin-help': ^5.1.19 From b4f00fab65bbd037c6385cd5ac50e6bca2c7ab28 Mon Sep 17 00:00:00 2001 From: Antony Date: Wed, 3 Jan 2024 11:17:06 +0530 Subject: [PATCH 3/8] Import minor version bump --- package-lock.json | 16 ++++++++-------- packages/contentstack-clone/package.json | 4 ++-- packages/contentstack-import/package.json | 2 +- packages/contentstack-seed/package.json | 4 ++-- packages/contentstack/package.json | 6 +++--- pnpm-lock.yaml | 10 +++++----- 6 files changed, 21 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index afcc36529a..5ddae70104 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23498,12 +23498,12 @@ "@contentstack/cli-cm-bootstrap": "~1.7.1", "@contentstack/cli-cm-branches": "~1.0.19", "@contentstack/cli-cm-bulk-publish": "~1.4.0", - "@contentstack/cli-cm-clone": "~1.8.0", + "@contentstack/cli-cm-clone": "~1.8.1", "@contentstack/cli-cm-export": "~1.10.2", "@contentstack/cli-cm-export-to-csv": "~1.6.2", - "@contentstack/cli-cm-import": "~1.12.3", + "@contentstack/cli-cm-import": "~1.13.0", "@contentstack/cli-cm-migrate-rte": "~1.4.15", - "@contentstack/cli-cm-seed": "~1.7.0", + "@contentstack/cli-cm-seed": "~1.7.1", "@contentstack/cli-command": "~1.2.17", "@contentstack/cli-config": "~1.5.1", "@contentstack/cli-launch": "~1.0.15", @@ -24049,12 +24049,12 @@ }, "packages/contentstack-clone": { "name": "@contentstack/cli-cm-clone", - "version": "1.8.0", + "version": "1.8.1", "license": "MIT", "dependencies": { "@colors/colors": "^1.5.0", "@contentstack/cli-cm-export": "~1.10.2", - "@contentstack/cli-cm-import": "~1.12.3", + "@contentstack/cli-cm-import": "~1.13.0", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.10", "async": "^3.2.4", @@ -24920,7 +24920,7 @@ }, "packages/contentstack-import": { "name": "@contentstack/cli-cm-import", - "version": "1.12.3", + "version": "1.13.0", "license": "MIT", "dependencies": { "@contentstack/cli-audit": "^1.3.2", @@ -25379,10 +25379,10 @@ }, "packages/contentstack-seed": { "name": "@contentstack/cli-cm-seed", - "version": "1.7.0", + "version": "1.7.1", "license": "MIT", "dependencies": { - "@contentstack/cli-cm-import": "~1.12.3", + "@contentstack/cli-cm-import": "~1.13.0", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.10", "inquirer": "8.2.4", diff --git a/packages/contentstack-clone/package.json b/packages/contentstack-clone/package.json index 19b9284a46..bedf5bd5c1 100644 --- a/packages/contentstack-clone/package.json +++ b/packages/contentstack-clone/package.json @@ -1,12 +1,12 @@ { "name": "@contentstack/cli-cm-clone", "description": "Contentstack stack clone plugin", - "version": "1.8.0", + "version": "1.8.1", "author": "Contentstack", "bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues", "dependencies": { "@contentstack/cli-cm-export": "~1.10.2", - "@contentstack/cli-cm-import": "~1.12.3", + "@contentstack/cli-cm-import": "~1.13.0", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.10", "@colors/colors": "^1.5.0", diff --git a/packages/contentstack-import/package.json b/packages/contentstack-import/package.json index 862537db7f..fd2fbf0caa 100644 --- a/packages/contentstack-import/package.json +++ b/packages/contentstack-import/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-cm-import", "description": "Contentstack CLI plugin to import content into stack", - "version": "1.12.3", + "version": "1.13.0", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { diff --git a/packages/contentstack-seed/package.json b/packages/contentstack-seed/package.json index d27988772b..d95322a6c8 100644 --- a/packages/contentstack-seed/package.json +++ b/packages/contentstack-seed/package.json @@ -1,11 +1,11 @@ { "name": "@contentstack/cli-cm-seed", "description": "create a Stack from existing content types, entries, assets, etc.", - "version": "1.7.0", + "version": "1.7.1", "author": "Contentstack", "bugs": "https://github.com/contentstack/cli/issues", "dependencies": { - "@contentstack/cli-cm-import": "~1.12.3", + "@contentstack/cli-cm-import": "~1.13.0", "@contentstack/cli-command": "~1.2.16", "@contentstack/cli-utilities": "~1.5.10", "inquirer": "8.2.4", diff --git a/packages/contentstack/package.json b/packages/contentstack/package.json index 39d8d92e3b..5f1be7e5a5 100755 --- a/packages/contentstack/package.json +++ b/packages/contentstack/package.json @@ -27,12 +27,12 @@ "@contentstack/cli-cm-bootstrap": "~1.7.1", "@contentstack/cli-cm-branches": "~1.0.19", "@contentstack/cli-cm-bulk-publish": "~1.4.0", - "@contentstack/cli-cm-clone": "~1.8.0", + "@contentstack/cli-cm-clone": "~1.8.1", "@contentstack/cli-cm-export": "~1.10.2", "@contentstack/cli-cm-export-to-csv": "~1.6.2", - "@contentstack/cli-cm-import": "~1.12.3", + "@contentstack/cli-cm-import": "~1.13.0", "@contentstack/cli-cm-migrate-rte": "~1.4.15", - "@contentstack/cli-cm-seed": "~1.7.0", + "@contentstack/cli-cm-seed": "~1.7.1", "@contentstack/cli-command": "~1.2.17", "@contentstack/cli-config": "~1.5.1", "@contentstack/cli-launch": "~1.0.15", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 93204029b3..04c8c78798 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,12 +15,12 @@ importers: '@contentstack/cli-cm-bootstrap': ~1.7.1 '@contentstack/cli-cm-branches': ~1.0.19 '@contentstack/cli-cm-bulk-publish': ~1.4.0 - '@contentstack/cli-cm-clone': ~1.8.0 + '@contentstack/cli-cm-clone': ~1.8.1 '@contentstack/cli-cm-export': ~1.10.2 '@contentstack/cli-cm-export-to-csv': ~1.6.2 - '@contentstack/cli-cm-import': ~1.12.3 + '@contentstack/cli-cm-import': ~1.13.0 '@contentstack/cli-cm-migrate-rte': ~1.4.15 - '@contentstack/cli-cm-seed': ~1.7.0 + '@contentstack/cli-cm-seed': ~1.7.1 '@contentstack/cli-command': ~1.2.17 '@contentstack/cli-config': ~1.5.1 '@contentstack/cli-launch': ~1.0.15 @@ -422,7 +422,7 @@ importers: specifiers: '@colors/colors': ^1.5.0 '@contentstack/cli-cm-export': ~1.10.2 - '@contentstack/cli-cm-import': ~1.12.3 + '@contentstack/cli-cm-import': ~1.13.0 '@contentstack/cli-command': ~1.2.16 '@contentstack/cli-utilities': ~1.5.10 '@oclif/test': ^1.2.7 @@ -986,7 +986,7 @@ importers: packages/contentstack-seed: specifiers: - '@contentstack/cli-cm-import': ~1.12.3 + '@contentstack/cli-cm-import': ~1.13.0 '@contentstack/cli-command': ~1.2.16 '@contentstack/cli-utilities': ~1.5.10 '@oclif/plugin-help': ^5.1.19 From c9c53eb75a1a66ff3b16553ee7cbbbaca3d2db7d Mon Sep 17 00:00:00 2001 From: Antony Date: Wed, 3 Jan 2024 12:28:36 +0530 Subject: [PATCH 4/8] Skip audit-fix on seed command --- packages/contentstack-seed/src/seed/importer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contentstack-seed/src/seed/importer.ts b/packages/contentstack-seed/src/seed/importer.ts index daf507a901..930c42090a 100644 --- a/packages/contentstack-seed/src/seed/importer.ts +++ b/packages/contentstack-seed/src/seed/importer.ts @@ -22,5 +22,5 @@ export async function run(options: ImporterOptions) { : ['-k', options.api_key, '-d', importPath]; process.chdir(options.tmpPath); - await ImportCommand.run(args); + await ImportCommand.run(args.concat('--skip-audit')); } From ce32a52f045b0de415c87aafef81c40bf3d38bb3 Mon Sep 17 00:00:00 2001 From: Antony Date: Wed, 3 Jan 2024 13:34:12 +0530 Subject: [PATCH 5/8] Feat: Audit fix command integration with Import --- package-lock.json | 4 ++-- packages/contentstack-clone/package.json | 2 +- packages/contentstack-clone/src/commands/cm/stacks/clone.js | 4 ++++ packages/contentstack-clone/src/lib/util/clone-handler.js | 2 ++ packages/contentstack/package.json | 2 +- pnpm-lock.yaml | 2 +- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index afcc36529a..03e1b54b44 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23498,7 +23498,7 @@ "@contentstack/cli-cm-bootstrap": "~1.7.1", "@contentstack/cli-cm-branches": "~1.0.19", "@contentstack/cli-cm-bulk-publish": "~1.4.0", - "@contentstack/cli-cm-clone": "~1.8.0", + "@contentstack/cli-cm-clone": "~1.9.0", "@contentstack/cli-cm-export": "~1.10.2", "@contentstack/cli-cm-export-to-csv": "~1.6.2", "@contentstack/cli-cm-import": "~1.12.3", @@ -24049,7 +24049,7 @@ }, "packages/contentstack-clone": { "name": "@contentstack/cli-cm-clone", - "version": "1.8.0", + "version": "1.9.0", "license": "MIT", "dependencies": { "@colors/colors": "^1.5.0", diff --git a/packages/contentstack-clone/package.json b/packages/contentstack-clone/package.json index 19b9284a46..c0c0a1a8aa 100644 --- a/packages/contentstack-clone/package.json +++ b/packages/contentstack-clone/package.json @@ -1,7 +1,7 @@ { "name": "@contentstack/cli-cm-clone", "description": "Contentstack stack clone plugin", - "version": "1.8.0", + "version": "1.9.0", "author": "Contentstack", "bugs": "https://github.com/rohitmishra209/cli-cm-clone/issues", "dependencies": { diff --git a/packages/contentstack-clone/src/commands/cm/stacks/clone.js b/packages/contentstack-clone/src/commands/cm/stacks/clone.js index 12542e2cf8..6f0e1d8766 100644 --- a/packages/contentstack-clone/src/commands/cm/stacks/clone.js +++ b/packages/contentstack-clone/src/commands/cm/stacks/clone.js @@ -29,6 +29,7 @@ class StackCloneCommand extends Command { const listOfTokens = configHandler.get('tokens'); config.forceStopMarketplaceAppsPrompt = yes; + config.skipAudit = cloneCommandFlags['skip-audit']; if (cloneType) { config.cloneType = cloneType; @@ -245,6 +246,9 @@ b) Structure with content (all modules including entries & assets) required: false, description: '[Optional] Override marketplace prompts', }), + 'skip-audit': flags.boolean({ + description: 'Skips the audit fix.', + }), }; StackCloneCommand.usage = diff --git a/packages/contentstack-clone/src/lib/util/clone-handler.js b/packages/contentstack-clone/src/lib/util/clone-handler.js index c594827c46..e471e29b26 100644 --- a/packages/contentstack-clone/src/lib/util/clone-handler.js +++ b/packages/contentstack-clone/src/lib/util/clone-handler.js @@ -655,6 +655,8 @@ class CloneHandler { cmd.push('--import-webhook-status', config.importWebhookStatus); } + if (config.skipAudit) cmd.push('--skip-audit'); + if (config.forceStopMarketplaceAppsPrompt) cmd.push('-y'); fs.writeFileSync(path.join(__dirname, 'dummyConfig.json'), JSON.stringify(config)); diff --git a/packages/contentstack/package.json b/packages/contentstack/package.json index 39d8d92e3b..483af2ccce 100755 --- a/packages/contentstack/package.json +++ b/packages/contentstack/package.json @@ -27,7 +27,7 @@ "@contentstack/cli-cm-bootstrap": "~1.7.1", "@contentstack/cli-cm-branches": "~1.0.19", "@contentstack/cli-cm-bulk-publish": "~1.4.0", - "@contentstack/cli-cm-clone": "~1.8.0", + "@contentstack/cli-cm-clone": "~1.9.0", "@contentstack/cli-cm-export": "~1.10.2", "@contentstack/cli-cm-export-to-csv": "~1.6.2", "@contentstack/cli-cm-import": "~1.12.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 93204029b3..bc78ccfcfc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,7 +15,7 @@ importers: '@contentstack/cli-cm-bootstrap': ~1.7.1 '@contentstack/cli-cm-branches': ~1.0.19 '@contentstack/cli-cm-bulk-publish': ~1.4.0 - '@contentstack/cli-cm-clone': ~1.8.0 + '@contentstack/cli-cm-clone': ~1.9.0 '@contentstack/cli-cm-export': ~1.10.2 '@contentstack/cli-cm-export-to-csv': ~1.6.2 '@contentstack/cli-cm-import': ~1.12.3 From 61176df34b5381e8b76facddafe6b8724778e48f Mon Sep 17 00:00:00 2001 From: Antony Date: Mon, 8 Jan 2024 12:19:32 +0530 Subject: [PATCH 6/8] Fix: Missing return statement added --- packages/contentstack-import/src/import/module-importer.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/contentstack-import/src/import/module-importer.ts b/packages/contentstack-import/src/import/module-importer.ts index 46c780bf97..68a803736d 100755 --- a/packages/contentstack-import/src/import/module-importer.ts +++ b/packages/contentstack-import/src/import/module-importer.ts @@ -143,8 +143,8 @@ class ModuleImporter { this.importConfig.forceStopMarketplaceAppsPrompt || (await cliux.inquire({ type: 'confirm', - message: 'Can you check the fix on the given path and confirm if you would like to proceed with the fix?', name: 'confirmation', + message: 'Can you check the fix on the given path and confirm if you would like to proceed with the fix?', })) ) { return true; @@ -153,6 +153,8 @@ class ModuleImporter { return false; } } + + return true; } catch (error) { trace(error); log(this.importConfig, `Audit failed with following error. ${error}`, 'error'); From 5223355f73340749413ff9a5df2d485eada3bef6 Mon Sep 17 00:00:00 2001 From: Antony Date: Mon, 8 Jan 2024 12:34:21 +0530 Subject: [PATCH 7/8] Log correction --- packages/contentstack-import/src/import/module-importer.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/contentstack-import/src/import/module-importer.ts b/packages/contentstack-import/src/import/module-importer.ts index 68a803736d..1b21fe45b0 100755 --- a/packages/contentstack-import/src/import/module-importer.ts +++ b/packages/contentstack-import/src/import/module-importer.ts @@ -133,7 +133,7 @@ class ModuleImporter { log(this.importConfig, 'Starting audit process', 'info'); const result = await AuditFix.run(args); - log(this.importConfig, 'Starting audit process completed', 'info'); + log(this.importConfig, 'Audit process completed', 'info'); if (result) { const { hasFix } = result; From 4ff4518e186c83920987b4c4cba476dd6b88ecf0 Mon Sep 17 00:00:00 2001 From: Antony Date: Mon, 8 Jan 2024 17:44:51 +0530 Subject: [PATCH 8/8] UI text corrections --- .../src/commands/cm/stacks/import.ts | 8 ++++++-- .../src/import/module-importer.ts | 15 +++++++++------ packages/contentstack-import/src/utils/log.ts | 2 ++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/contentstack-import/src/commands/cm/stacks/import.ts b/packages/contentstack-import/src/commands/cm/stacks/import.ts index 01a0c1dd9c..047a528453 100644 --- a/packages/contentstack-import/src/commands/cm/stacks/import.ts +++ b/packages/contentstack-import/src/commands/cm/stacks/import.ts @@ -129,8 +129,12 @@ export default class ImportCommand extends Command { const managementAPIClient: ContentstackClient = await managementSDKClient(importConfig); const moduleImporter = new ModuleImporter(managementAPIClient, importConfig); - await moduleImporter.start(); - log(importConfig, `The content has been imported to the stack ${importConfig.apiKey} successfully!`, 'success'); + const result = await moduleImporter.start(); + + if (!result?.noSuccessMsg) { + log(importConfig, `The content has been imported to the stack ${importConfig.apiKey} successfully!`, 'success'); + } + log( importConfig, `The log has been stored at '${path.join(importConfig.backupDir, 'logs', 'import')}'`, diff --git a/packages/contentstack-import/src/import/module-importer.ts b/packages/contentstack-import/src/import/module-importer.ts index 1b21fe45b0..1fd509978e 100755 --- a/packages/contentstack-import/src/import/module-importer.ts +++ b/packages/contentstack-import/src/import/module-importer.ts @@ -1,6 +1,7 @@ import { resolve } from 'path'; import { AuditFix } from '@contentstack/cli-audit'; -import { addLocale, cliux, ContentstackClient } from '@contentstack/cli-utilities'; +import messages, { $t } from '@contentstack/cli-audit/lib/messages'; +import { addLocale, cliux, ContentstackClient, Logger } from '@contentstack/cli-utilities'; import startModuleImport from './modules'; import startJSModuleImport from './modules-js'; @@ -38,7 +39,7 @@ class ModuleImporter { } // NOTE init log - initLogger(this.importConfig); + const logger = initLogger(this.importConfig); // NOTE audit and fix the import content. if ( @@ -46,8 +47,8 @@ class ModuleImporter { (!this.importConfig.moduleName || ['content-types', 'global-fields', 'entries'].includes(this.importConfig.moduleName)) ) { - if (!(await this.auditImportData())) { - return; + if (!(await this.auditImportData(logger))) { + return { noSuccessMsg: true }; } } @@ -108,7 +109,7 @@ class ModuleImporter { * @returns The function `auditImportData()` returns a boolean value. It returns `true` if there is a * fix available and the user confirms to proceed with the fix, otherwise it returns `false`. */ - async auditImportData() { + async auditImportData(logger: Logger) { const basePath = resolve(this.importConfig.backupDir, 'logs', 'audit'); const auditConfig = { noLog: false, // Skip logs printing on terminal @@ -136,9 +137,11 @@ class ModuleImporter { log(this.importConfig, 'Audit process completed', 'info'); if (result) { - const { hasFix } = result; + const { hasFix, config } = result; if (hasFix) { + logger.log($t(messages.FINAL_REPORT_PATH, { path: config.reportPath }), 'warn'); + if ( this.importConfig.forceStopMarketplaceAppsPrompt || (await cliux.inquire({ diff --git a/packages/contentstack-import/src/utils/log.ts b/packages/contentstack-import/src/utils/log.ts index 9b5e3775b7..ead46c0964 100644 --- a/packages/contentstack-import/src/utils/log.ts +++ b/packages/contentstack-import/src/utils/log.ts @@ -33,4 +33,6 @@ export function initLogger(config?: ImportConfig | undefined) { return logger; } +export { logger }; + export const trace = log;