Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/development' into Hotfix/AxiosV1…
Browse files Browse the repository at this point in the history
….7.4-package-bump
  • Loading branch information
sunil-lakshman committed Aug 30, 2024
2 parents dcd84b9 + 3fda090 commit dc53f8c
Show file tree
Hide file tree
Showing 19 changed files with 394 additions and 90 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

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

28 changes: 15 additions & 13 deletions packages/contentstack-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $ npm install -g @contentstack/cli-audit
$ csdx COMMAND
running command...
$ csdx (--version|-v)
@contentstack/cli-audit/1.6.5 darwin-arm64 node-v22.2.0
@contentstack/cli-audit/1.7.0 darwin-arm64 node-v22.2.0
$ csdx --help [COMMAND]
USAGE
$ csdx COMMAND
Expand Down Expand Up @@ -52,12 +52,13 @@ Perform audits and find possible errors in the exported Contentstack data

```
USAGE
$ csdx audit [--report-path <value>] [--modules content-types|global-fields|entries|extensions|workflows]
[--columns <value> | ] [--sort <value>] [--filter <value>] [--csv | --no-truncate]
$ csdx audit [--report-path <value>] [--modules
content-types|global-fields|entries|extensions|workflows|custom-roles] [--columns <value> | ] [--sort <value>]
[--filter <value>] [--csv | --no-truncate]
FLAGS
--modules=<option>... Provide the list of modules to be audited
<options: content-types|global-fields|entries|extensions|workflows>
<options: content-types|global-fields|entries|extensions|workflows|custom-roles>
--report-path=<value> Path to store the audit reports
TABLE FLAGS
Expand Down Expand Up @@ -92,8 +93,8 @@ Perform audits and fix possible errors in the exported Contentstack data.

```
USAGE
$ csdx audit:fix [--report-path <value>] [--modules content-types|global-fields|entries|extensions|workflows]
[--copy-path <value> --copy-dir] [--fix-only
$ csdx audit:fix [--report-path <value>] [--modules
content-types|global-fields|entries|extensions|workflows|custom-roles] [--copy-path <value> --copy-dir] [--fix-only
reference|global_field|json:rte|json:extension|blocks|group|content_types] [--columns <value> | ] [--sort <value>]
[--filter <value>] [--csv | --no-truncate]
Expand All @@ -103,7 +104,7 @@ FLAGS
--fix-only=<option>... Provide the list of fix options
<options: reference|global_field|json:rte|json:extension|blocks|group|content_types>
--modules=<option>... Provide the list of modules to be audited
<options: content-types|global-fields|entries|extensions|workflows>
<options: content-types|global-fields|entries|extensions|workflows|custom-roles>
--report-path=<value> Path to store the audit reports
TABLE FLAGS
Expand Down Expand Up @@ -140,12 +141,13 @@ Perform audits and find possible errors in the exported Contentstack data

```
USAGE
$ csdx cm:stacks:audit [--report-path <value>] [--modules content-types|global-fields|entries|extensions|workflows]
[--columns <value> | ] [--sort <value>] [--filter <value>] [--csv | --no-truncate]
$ csdx cm:stacks:audit [--report-path <value>] [--modules
content-types|global-fields|entries|extensions|workflows|custom-roles] [--columns <value> | ] [--sort <value>]
[--filter <value>] [--csv | --no-truncate]
FLAGS
--modules=<option>... Provide the list of modules to be audited
<options: content-types|global-fields|entries|extensions|workflows>
<options: content-types|global-fields|entries|extensions|workflows|custom-roles>
--report-path=<value> Path to store the audit reports
TABLE FLAGS
Expand Down Expand Up @@ -182,8 +184,8 @@ Perform audits and fix possible errors in the exported Contentstack data.

```
USAGE
$ csdx cm:stacks:audit:fix [--report-path <value>] [--modules content-types|global-fields|entries|extensions|workflows]
[--copy-path <value> --copy-dir] [--fix-only
$ csdx cm:stacks:audit:fix [--report-path <value>] [--modules
content-types|global-fields|entries|extensions|workflows|custom-roles] [--copy-path <value> --copy-dir] [--fix-only
reference|global_field|json:rte|json:extension|blocks|group|content_types] [--columns <value> | ] [--sort <value>]
[--filter <value>] [--csv | --no-truncate]
Expand All @@ -193,7 +195,7 @@ FLAGS
--fix-only=<option>... Provide the list of fix options
<options: reference|global_field|json:rte|json:extension|blocks|group|content_types>
--modules=<option>... Provide the list of modules to be audited
<options: content-types|global-fields|entries|extensions|workflows>
<options: content-types|global-fields|entries|extensions|workflows|custom-roles>
--report-path=<value> Path to store the audit reports
TABLE FLAGS
Expand Down
2 changes: 1 addition & 1 deletion packages/contentstack-audit/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/cli-audit",
"version": "1.6.5",
"version": "1.7.0",
"description": "Contentstack audit plugin",
"author": "Contentstack CLI",
"homepage": "https://github.com/contentstack/cli",
Expand Down
30 changes: 26 additions & 4 deletions packages/contentstack-audit/src/audit-base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
RefErrorReturnType,
WorkflowExtensionsRefErrorReturnType,
} from './types';
import CustomRoles from './modules/custom-roles';

export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseCommand> {
private currentCommand!: CommandNames;
Expand Down Expand Up @@ -56,6 +57,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
missingCtRefsInWorkflow,
missingSelectFeild,
missingMandatoryFields,
missingTitleFields,
missingRefInCustomRoles
} = await this.scanAndFix();

this.showOutputOnScreen([
Expand All @@ -69,13 +72,19 @@ 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) ||
!isEmpty(missingGfRefs) ||
!isEmpty(missingEntryRefs) ||
!isEmpty(missingCtRefsInWorkflow) ||
!isEmpty(missingCtRefsInExtensions) ||
!isEmpty(missingSelectFeild)
!isEmpty(missingSelectFeild) ||
!isEmpty(missingTitleFields) ||
!isEmpty(missingRefInCustomRoles)
) {
if (this.currentCommand === 'cm:stacks:audit') {
this.log(this.$t(auditMsg.FINAL_REPORT_PATH, { path: this.sharedConfig.reportPath }), 'warn');
Expand All @@ -102,7 +111,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
!isEmpty(missingEntryRefs) ||
!isEmpty(missingCtRefsInWorkflow) ||
!isEmpty(missingCtRefsInExtensions) ||
!isEmpty(missingSelectFeild)
!isEmpty(missingSelectFeild) ||
!isEmpty(missingRefInCustomRoles)
);
}

Expand All @@ -121,7 +131,9 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
missingCtRefsInWorkflow,
missingSelectFeild,
missingEntry,
missingMandatoryFields;
missingMandatoryFields,
missingTitleFields,
missingRefInCustomRoles;

for (const module of this.sharedConfig.flags.modules || this.sharedConfig.modules) {
print([
Expand Down Expand Up @@ -154,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 All @@ -174,6 +190,10 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
missingCtRefsInExtensions = await new Extensions(cloneDeep(constructorParam)).run();
await this.prepareReport(module, missingCtRefsInExtensions);
break;
case 'custom-roles':
missingRefInCustomRoles = await new CustomRoles(cloneDeep(constructorParam)).run();
await this.prepareReport(module, missingRefInCustomRoles);
break;
}

print([
Expand All @@ -198,6 +218,8 @@ export abstract class AuditBaseCommand extends BaseCommand<typeof AuditBaseComma
missingCtRefsInWorkflow,
missingSelectFeild,
missingMandatoryFields,
missingTitleFields,
missingRefInCustomRoles,
};
}

Expand Down Expand Up @@ -416,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
9 changes: 8 additions & 1 deletion packages/contentstack-audit/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const config = {
showTerminalOutput: true,
skipRefs: ['sys_assets'],
skipFieldTypes: ['taxonomy', 'group'],
modules: ['content-types', 'global-fields', 'entries', 'extensions', 'workflows'],
modules: ['content-types', 'global-fields', 'entries', 'extensions', 'workflows', 'custom-roles'],
'fix-fields': ['reference', 'global_field', 'json:rte', 'json:extension', 'blocks', 'group', 'content_types'],
moduleConfig: {
'content-types': {
Expand Down Expand Up @@ -35,6 +35,11 @@ const config = {
dirName: 'extensions',
fileName: 'extensions.json',
},
'custom-roles': {
name: 'custom-roles',
dirName: 'custom-roles',
fileName: 'custom-roles.json',
},
},
entries: {
systemKeys: [
Expand Down Expand Up @@ -75,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;
2 changes: 2 additions & 0 deletions packages/contentstack-audit/src/messages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const commonMsg = {
EXTENSION_FIX_WARN: `The extension associated with UID {uid} and title '{title}' will be removed.`,
EXTENSION_FIX_CONFIRMATION: `Would you like to overwrite existing file?`,
WF_BRANCH_REMOVAL: `Removing the branch '{branch} from workflow with UID {uid} and name {name} will be removed.'`,
CR_BRANCH_REMOVAL: `Removing the branch '{branch} from custom role with UID {uid} and name {name} will be removed.'`,
};

const auditMsg = {
Expand All @@ -35,6 +36,7 @@ const auditMsg = {
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 completed the scanning of workflow with UID {uid} and name {name}.',
SCAN_CR_SUCCESS_MSG: 'Successfully completed the scanning of custom role with UID {uid} and name {name}.',
};

const auditFixMsg = {
Expand Down
Loading

0 comments on commit dc53f8c

Please sign in to comment.