From e9b1f34a431adde8ea4faebdc35de33e7be1c975 Mon Sep 17 00:00:00 2001 From: raj pandey Date: Wed, 13 Mar 2024 11:44:34 +0530 Subject: [PATCH] fixed the writing of content without --yes flag in audit --- .../contentstack-audit/src/messages/index.ts | 2 +- .../src/modules/extensions.ts | 4 +-- .../src/modules/workflows.ts | 34 ++++++++++--------- .../src/import/module-importer.ts | 2 +- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/packages/contentstack-audit/src/messages/index.ts b/packages/contentstack-audit/src/messages/index.ts index bed295e648..b6036a7ef2 100644 --- a/packages/contentstack-audit/src/messages/index.ts +++ b/packages/contentstack-audit/src/messages/index.ts @@ -34,7 +34,7 @@ const auditMsg = { SCAN_ENTRY_SUCCESS_MSG: "Successfully completed the scanning of {module} ({local}) '{title}'.", SCAN_EXT_SUCCESS_MSG: "Successfully completed scanning the {module} titled '{title}' with UID '{uid}'", AUDIT_CMD_DESCRIPTION: 'Perform audits and find possible errors in the exported Contentstack data', - SCAN_WF_SUCCESS_MSG: 'Successfully removed the workflow with UID {uid} and name {name}.', + SCAN_WF_SUCCESS_MSG: 'Successfully completed the scanning of workflow with UID {uid} and name {name}.', }; const auditFixMsg = { diff --git a/packages/contentstack-audit/src/modules/extensions.ts b/packages/contentstack-audit/src/modules/extensions.ts index 4b07481417..f28c4afc77 100644 --- a/packages/contentstack-audit/src/modules/extensions.ts +++ b/packages/contentstack-audit/src/modules/extensions.ts @@ -79,7 +79,7 @@ export default class Extensions { if (this.fix && this.missingCtInExtensions.length) { await this.fixExtensionsScope(cloneDeep(this.missingCtInExtensions)); this.missingCtInExtensions.forEach((ext) => (ext.fixStatus = 'Fixed')); - return this.missingCtInExtensions + return this.missingCtInExtensions; } return this.missingCtInExtensions; } @@ -106,7 +106,7 @@ export default class Extensions { async writeFixContent(fixedExtensions: Record) { if ( - this.fix || + this.fix && (this.config.flags['copy-dir'] || this.config.flags['external-config']?.skipConfirm || (await ux.confirm(commonMsg.FIX_CONFIRMATION))) diff --git a/packages/contentstack-audit/src/modules/workflows.ts b/packages/contentstack-audit/src/modules/workflows.ts index 15b5f5a838..4c463d2dee 100644 --- a/packages/contentstack-audit/src/modules/workflows.ts +++ b/packages/contentstack-audit/src/modules/workflows.ts @@ -54,12 +54,14 @@ export default class Workflows { this.log($t(auditMsg.NOT_VALID_PATH, { path: this.folderPath }), { color: 'yellow' }); return {}; } - + this.workflowPath = join(this.folderPath, this.fileName); - this.workflowSchema = existsSync(this.workflowPath) ? values(JSON.parse(readFileSync(this.workflowPath, 'utf8')) as Workflow[]) : []; - + this.workflowSchema = existsSync(this.workflowPath) + ? values(JSON.parse(readFileSync(this.workflowPath, 'utf8')) as Workflow[]) + : []; + this.ctSchema.forEach((ct) => this.ctUidSet.add(ct.uid)); - + for (const workflow of this.workflowSchema) { const ctNotPresent = workflow.content_types.filter((ct) => !this.ctUidSet.has(ct)); if (ctNotPresent.length) { @@ -68,53 +70,53 @@ export default class Workflows { ctNotPresent.forEach((ct) => this.missingCts.add(ct)); this.missingCtInWorkflows.push(tempwf); } - + this.log( $t(auditMsg.SCAN_WF_SUCCESS_MSG, { name: workflow.name, - module: this.config.moduleConfig[this.moduleName].name, + uid: workflow.uid, }), - 'info' + 'info', ); } - + if (this.fix && this.missingCtInWorkflows.length) { await this.fixWorkflowSchema(); this.missingCtInWorkflows.forEach((wf) => (wf.fixStatus = 'Fixed')); } - + return this.missingCtInWorkflows; } - async fixWorkflowSchema() { + async fixWorkflowSchema() { const newWorkflowSchema: Record = existsSync(this.workflowPath) ? JSON.parse(readFileSync(this.workflowPath, 'utf8')) : {}; - + if (Object.keys(newWorkflowSchema).length !== 0) { - for (const workflow of this.workflowSchema) { + for (const workflow of this.workflowSchema) { const fixedCts = workflow.content_types.filter((ct) => !this.missingCts.has(ct)); if (fixedCts.length) { newWorkflowSchema[workflow.uid].content_types = fixedCts; } else { const { name, uid } = workflow; const warningMessage = $t(commonMsg.WORKFLOW_FIX_WARN, { name, uid }); - + this.log(warningMessage, { color: 'yellow' }); - + if (this.config.flags.yes || (await ux.confirm(commonMsg.WORKFLOW_FIX_CONFIRMATION))) { delete newWorkflowSchema[workflow.uid]; } } } } - + await this.writeFixContent(newWorkflowSchema); } async writeFixContent(newWorkflowSchema: Record) { if ( - this.fix || + this.fix && !(this.config.flags['copy-dir'] || this.config.flags['external-config']?.skipConfirm) && (this.config.flags.yes || (await ux.confirm(commonMsg.FIX_CONFIRMATION))) ) { diff --git a/packages/contentstack-import/src/import/module-importer.ts b/packages/contentstack-import/src/import/module-importer.ts index bcdd538e48..675489e18e 100755 --- a/packages/contentstack-import/src/import/module-importer.ts +++ b/packages/contentstack-import/src/import/module-importer.ts @@ -49,7 +49,7 @@ class ModuleImporter { if ( !this.importConfig.skipAudit && (!this.importConfig.moduleName || - ['content-types', 'global-fields', 'entries'].includes(this.importConfig.moduleName)) + ['content-types', 'global-fields', 'entries', 'extensions', 'workflows'].includes(this.importConfig.moduleName)) ) { if (!(await this.auditImportData(logger))) { return { noSuccessMsg: true };