-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1038 from contentstack/feat/CS-41075
Feat: [CS-41075] cm:stacks:audit command for Content type
- Loading branch information
Showing
14 changed files
with
583 additions
and
16 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 98 additions & 3 deletions
101
packages/contentstack-audit/src/commands/cm/stacks/audit/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,108 @@ | ||
import { resolve } from 'path'; | ||
import chalk from 'chalk'; | ||
import { FlagInput, Flags, cliux, ux } from '@contentstack/cli-utilities'; | ||
|
||
import config from '../../../../config'; | ||
import { auditMsg } from '../../../../messages'; | ||
import { BaseCommand } from '../../../../base-command'; | ||
import ContentType from '../../../../modules/content-types'; | ||
|
||
export default class Audit extends BaseCommand<typeof Audit> { | ||
static aliases: string[] = ['cm:stacks:audit']; | ||
|
||
static description = 'Audit and find possible errors in the exported data'; | ||
|
||
static examples = ['$ <%= config.bin %> <%= command.id %>']; | ||
static examples = [ | ||
'$ <%= config.bin %> <%= command.id %>', | ||
'$ <%= config.bin %> <%= command.id %> --report-path=<path>', | ||
'$ <%= config.bin %> <%= command.id %> --report-path=<path> --csv', | ||
'$ <%= config.bin %> <%= command.id %> --report-path=<path> --filter="name=<filter-value>"', | ||
'$ <%= config.bin %> <%= command.id %> --report-path=<path> --modules=content-types --filter="name="<filter-value>"', | ||
]; | ||
|
||
static flags: FlagInput = { | ||
'report-path': Flags.string({ | ||
description: auditMsg.REPORT_PATH, | ||
}), | ||
'reference-only': Flags.boolean({ | ||
description: auditMsg.REFERENCE_ONLY, | ||
}), | ||
modules: Flags.string({ | ||
multiple: true, | ||
options: config.modules, | ||
description: auditMsg.MODULES, | ||
}), | ||
...ux.table.flags({ | ||
only: ['columns', 'sort', 'filter', 'csv', 'no-truncate'], | ||
}), | ||
}; | ||
|
||
async run(): Promise<void> { | ||
try { | ||
const { flags } = await this.parse(Audit); | ||
|
||
await this.promptQueue(); | ||
const reportPath = this.flags['report-path'] || process.cwd(); | ||
this.sharedConfig.reportPath = resolve(reportPath, 'audit-report'); | ||
|
||
static flags = {}; | ||
for (const module of this.sharedConfig.flags.modules || this.sharedConfig.modules) { | ||
switch (module) { | ||
case 'content-types': | ||
const ctErrors = await new ContentType({ config: this.sharedConfig, log: this.log }).run(); | ||
ux.table( | ||
Object.values(ctErrors).flat(), | ||
{ | ||
name: { | ||
minWidth: 7, | ||
header: 'Content Type name', | ||
}, | ||
display_name: { | ||
minWidth: 7, | ||
header: 'Field name', | ||
}, | ||
data_type: { | ||
minWidth: 7, | ||
header: 'Field type', | ||
}, | ||
missingRefs: { | ||
minWidth: 7, | ||
header: 'Missing references', | ||
get: (row) => { | ||
return chalk.red(row.missingRefs); | ||
}, | ||
}, | ||
treeStr: { | ||
minWidth: 7, | ||
header: 'Path', | ||
}, | ||
}, | ||
{ | ||
...flags, | ||
}, | ||
); | ||
this.log(''); // NOTE add new line in terminal | ||
this.log(''); // NOTE add new line in terminal | ||
break; | ||
case 'entries': | ||
break; | ||
case 'global-fields': | ||
break; | ||
} | ||
} | ||
} catch (error) { | ||
this.log(error instanceof Error ? error.message : error, 'error'); | ||
this.exit(1); | ||
} | ||
} | ||
|
||
async run(): Promise<void> {} | ||
async promptQueue() { | ||
// NOTE get content path if data-dir flag is missing | ||
this.sharedConfig.basePath = | ||
this.flags['data-dir'] || | ||
(await cliux.inquire<string>({ | ||
type: 'input', | ||
name: 'data-dir', | ||
message: this.messages.DATA_DIR, | ||
})); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
const config = { | ||
modues: [] | ||
modules: ['content-types', 'entries', 'global-fields'], | ||
skipRefs: ['sys_assets'], | ||
moduleConfig: { | ||
'content-types': { | ||
dirName: 'content_types', | ||
fileName: 'content_types.json', | ||
}, | ||
}, | ||
}; | ||
|
||
export default config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.