Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/contentstack-audit/src/audit-base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
missingCtRefsInWorkflow,
missingSelectFeild,
missingMandatoryFields,
missingTitleFields,
missingRefInCustomRoles
} = await this.scanAndFix();

Expand All @@ -71,6 +72,9 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
this.showOutputOnScreenWorkflowsAndExtension([
{ module: 'Entries Mandatory Field', missingRefs: missingMandatoryFields },
]);
this.showOutputOnScreenWorkflowsAndExtension([
{ module: 'Entries Title Field', missingRefs: missingTitleFields },
]);
this.showOutputOnScreenWorkflowsAndExtension([{ module: 'Custom Roles', missingRefs: missingRefInCustomRoles }]);
if (
!isEmpty(missingCtRefs) ||
Expand All @@ -79,6 +83,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
!isEmpty(missingCtRefsInWorkflow) ||
!isEmpty(missingCtRefsInExtensions) ||
!isEmpty(missingSelectFeild) ||
!isEmpty(missingTitleFields) ||
!isEmpty(missingRefInCustomRoles)
) {
if (this.currentCommand === 'cm:stacks:audit') {
Expand Down Expand Up @@ -127,6 +132,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
missingSelectFeild,
missingEntry,
missingMandatoryFields,
missingTitleFields,
missingRefInCustomRoles;

for (const module of this.sharedConfig.flags.modules || this.sharedConfig.modules) {
Expand Down Expand Up @@ -160,11 +166,15 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
missingEntryRefs = missingEntry.missingEntryRefs ?? {};
missingSelectFeild = missingEntry.missingSelectFeild ?? {};
missingMandatoryFields = missingEntry.missingMandatoryFields ?? {};
missingTitleFields = missingEntry.missingTitleFields ?? {};
await this.prepareReport(module, missingEntryRefs);

await this.prepareReport(`Entries_Select_feild`, missingSelectFeild);

await this.prepareReport('Entries_Mandatory_feild', missingMandatoryFields);

await this.prepareReport('Entries_Title_feild', missingTitleFields);

break;
case 'workflows':
missingCtRefsInWorkflow = await new Workflows({
Expand Down Expand Up @@ -208,6 +218,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
missingCtRefsInWorkflow,
missingSelectFeild,
missingMandatoryFields,
missingTitleFields,
missingRefInCustomRoles,
};
}
Expand Down Expand Up @@ -427,7 +438,7 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
moduleName: keyof typeof config.moduleConfig | keyof typeof config.ReportTitleForEntries,
listOfMissingRefs: Record<string, any>,
): Promise<void> {
if (Object.keys(config.moduleConfig).includes(moduleName)) {
if (Object.keys(config.moduleConfig).includes(moduleName) || config.feild_level_modules.includes(moduleName)) {
const csvPath = join(sanitizePath(this.sharedConfig.reportPath), `${sanitizePath(moduleName)}.csv`);
return new Promise<void>((resolve, reject) => {
// file deepcode ignore MissingClose: Will auto close once csv stream end
Expand Down
2 changes: 2 additions & 0 deletions packages/contentstack-audit/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ const config = {
ReportTitleForEntries: {
Entries_Select_feild: 'Entries_Select_feild',
Entries_Mandatory_feild: 'Entries_Mandatory_feild',
Entries_Title_feild: 'Entries_Title_feild'
},
'feild_level_modules' : ['Entries_Title_feild']
};

export default config;
79 changes: 43 additions & 36 deletions packages/contentstack-audit/src/modules/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export default class Entries {
protected missingRefs: Record<string, any> = {};
protected missingSelectFeild: Record<string, any> = {};
protected missingMandatoryFields: Record<string, any> = {};
protected missingTitleFields: Record<string, any> = {};
public entryMetaData: Record<string, any>[] = [];
public moduleName: keyof typeof auditConfig.moduleConfig = 'entries';

Expand All @@ -71,11 +72,14 @@ export default class Entries {
this.folderPath = resolve(sanitizePath(config.basePath), sanitizePath(config.moduleConfig.entries.dirName));
}

validateModules(moduleName: keyof typeof auditConfig.moduleConfig, moduleConfig: Record<string, unknown>): keyof typeof auditConfig.moduleConfig {
validateModules(
moduleName: keyof typeof auditConfig.moduleConfig,
moduleConfig: Record<string, unknown>,
): keyof typeof auditConfig.moduleConfig {
if (Object.keys(moduleConfig).includes(moduleName)) {
return moduleName;
}
return 'entries'
return 'entries';
}

/**
Expand Down Expand Up @@ -168,6 +172,7 @@ export default class Entries {
missingEntryRefs: this.missingRefs,
missingSelectFeild: this.missingSelectFeild,
missingMandatoryFields: this.missingMandatoryFields,
missingTitleFields: this.missingTitleFields,
};
}

Expand Down Expand Up @@ -199,15 +204,15 @@ export default class Entries {
async fixPrerequisiteData() {
this.ctSchema = (await new ContentType({
fix: true,
log: () => { },
log: () => {},
config: this.config,
moduleName: 'content-types',
ctSchema: this.ctSchema,
gfSchema: this.gfSchema,
}).run(true)) as ContentTypeStruct[];
this.gfSchema = (await new GlobalField({
fix: true,
log: () => { },
log: () => {},
config: this.config,
moduleName: 'global-fields',
ctSchema: this.ctSchema,
Expand All @@ -220,7 +225,7 @@ export default class Entries {
if (existsSync(extensionPath)) {
try {
this.extensions = Object.keys(JSON.parse(readFileSync(extensionPath, 'utf8')));
} catch (error) { }
} catch (error) {}
}

if (existsSync(marketplacePath)) {
Expand All @@ -233,7 +238,7 @@ export default class Entries {
) as string[];
this.extensions.push(...metaData);
}
} catch (error) { }
} catch (error) {}
}
}

Expand Down Expand Up @@ -415,19 +420,19 @@ export default class Entries {

return missingRefs.length
? [
{
tree,
data_type,
missingRefs,
display_name,
ct_uid: this.currentUid,
name: this.currentTitle,
treeStr: tree
.map(({ name }) => name)
.filter((val) => val)
.join(' ➜ '),
},
]
{
tree,
data_type,
missingRefs,
display_name,
ct_uid: this.currentUid,
name: this.currentTitle,
treeStr: tree
.map(({ name }) => name)
.filter((val) => val)
.join(' ➜ '),
},
]
: [];
}

Expand Down Expand Up @@ -587,19 +592,19 @@ export default class Entries {

return missingRefs.length
? [
{
tree,
data_type,
missingRefs,
display_name,
uid: this.currentUid,
name: this.currentTitle,
treeStr: tree
.map(({ name }) => name)
.filter((val) => val)
.join(' ➜ '),
},
]
{
tree,
data_type,
missingRefs,
display_name,
uid: this.currentUid,
name: this.currentTitle,
treeStr: tree
.map(({ name }) => name)
.filter((val) => val)
.join(' ➜ '),
},
]
: [];
}

Expand Down Expand Up @@ -858,10 +863,7 @@ export default class Entries {
};

if (mandatory) {
if (
(data_type === 'json' && field_metadata.allow_json_rte && isJsonRteEmpty()) ||
(!(data_type === 'json') && isEntryEmpty())
) {
if ((data_type === 'json' && field_metadata.allow_json_rte && isJsonRteEmpty()) || (!(data_type === 'json') && isEntryEmpty())) {
return [
{
uid: this.currentUid,
Expand Down Expand Up @@ -1261,6 +1263,11 @@ export default class Entries {
let { title } = entries[entryUid];

if (entries[entryUid].hasOwnProperty('title') && !title) {
this.missingTitleFields[entryUid] = {
'Entry UID': entryUid,
'Content Type UID': uid,
"Locale": code,
};
this.log(
`The 'title' field in Entry with UID '${entryUid}' of Content Type '${uid}' in Locale '${code}' is empty.`,
`error`,
Expand Down
5 changes: 4 additions & 1 deletion packages/contentstack-audit/src/types/content-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ enum OutputColumn {
'MissingValues' = 'missingCTSelectFieldValues',
'Minimum Required Instaces' = 'min_instance',
'missingFieldUid' = 'missingFieldUid',
'isPublished' = 'isPublished'
'isPublished' = 'isPublished',
'Entry UID' ="Entry UID",
'Content Type UID'= 'Content Type UID',
"Locale"="Locale",
}

export {
Expand Down