Skip to content

Commit

Permalink
test case fixed, code optimisation
Browse files Browse the repository at this point in the history
  • Loading branch information
cs-raj committed Mar 2, 2024
1 parent cfa546c commit 37959b7
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 192 deletions.
10 changes: 8 additions & 2 deletions packages/contentstack-audit/src/audit-base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,19 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma

const tableKeys = Object.keys(missingRefs[0]);
const arrayOfObjects = tableKeys.map((key) => {
if (['title', 'name', 'uid', 'content_types'].includes(key)) {
if (['title', 'name', 'uid', 'content_types', 'fixStatus'].includes(key)) {
return {
[key]: {
minWidth: 7,
header: key,
get: (row: Record<string, unknown>) => {
return chalk.red(typeof row[key] === 'object' ? JSON.stringify(row[key]) : row[key]);
if(key==='fixStatus') {
return chalk.green(typeof row[key] === 'object' ? JSON.stringify(row[key]) : row[key]);
} else if(key==='content_types') {
return chalk.red(typeof row[key] === 'object' ? JSON.stringify(row[key]) : row[key]);
} else {
return chalk.white(typeof row[key] === 'object' ? JSON.stringify(row[key]) : row[key]);
}
},
},
};
Expand Down
14 changes: 3 additions & 11 deletions packages/contentstack-audit/src/modules/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export default class Extensions {
const ctNotPresent = scope?.content_types.filter((ct) => !this.ctUidSet.has(ct));

if (ctNotPresent?.length && ext.scope) {
ext.scope.content_types = ctNotPresent;
ext.content_types = ctNotPresent;
ctNotPresent.forEach((ct) => this.missingCts.add(ct));
this.missingCtInExtensions.push(cloneDeep(ext));
Expand All @@ -79,26 +78,19 @@ export default class Extensions {

if (this.fix && this.missingCtInExtensions.length) {
await this.fixExtensionsScope(cloneDeep(this.missingCtInExtensions));
return {};
this.missingCtInExtensions.forEach((ext) => (ext.fixStatus = 'Fixed'));
return this.missingCtInExtensions
}
return this.missingCtInExtensions;
}

async fixExtensionsScope(missingCtInExtensions: Extension[]) {
for (const ext of missingCtInExtensions) {
if (ext.scope) {
ext.scope.content_types = ext.scope.content_types.filter((ct) => !this.missingCts.has(ct));
}
}

let newExtensionSchema: Record<string, Extension> = existsSync(this.extensionsPath)
? JSON.parse(readFileSync(this.extensionsPath, 'utf8'))
: {};

for (const ext of missingCtInExtensions) {
const { uid, title } = ext;
const fixedCts = ext?.scope?.content_types.filter((ct) => !this.missingCts.has(ct));

if (fixedCts?.length) {
newExtensionSchema[uid].scope.content_types = fixedCts;
} else {
Expand All @@ -115,7 +107,7 @@ export default class Extensions {

async writeFixContent(fixedExtensions: Record<string, Extension>) {
if (
this.fix &&
this.fix ||
(this.config.flags['copy-dir'] ||
this.config.flags['external-config']?.skipConfirm ||
(await ux.confirm(commonMsg.FIX_CONFIRMATION)))
Expand Down
1 change: 1 addition & 0 deletions packages/contentstack-audit/src/types/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export interface Extension {
content_types: string[];
};
content_types?: string[];
fixStatus?: string;
}
Loading

0 comments on commit 37959b7

Please sign in to comment.