2024-05-19 21:20:42 +08:00
|
|
|
import type { CAC } from 'cac';
|
|
|
|
|
|
|
|
import { $ } from '@vben/node-utils';
|
|
|
|
|
|
|
|
interface LintCommandOptions {
|
|
|
|
/**
|
|
|
|
* Format lint problem.
|
|
|
|
*/
|
|
|
|
format?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function runLint({ format }: LintCommandOptions) {
|
|
|
|
process.env.FORCE_COLOR = '3';
|
|
|
|
if (format) {
|
|
|
|
await $`stylelint "**/*.{vue,css,less.scss}" --cache --fix`;
|
|
|
|
await $`eslint . --cache --fix`;
|
2024-07-10 22:30:39 +08:00
|
|
|
await $`prettier . --write --cache --log-level warn`;
|
2024-05-19 21:20:42 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await Promise.all([
|
|
|
|
$`eslint . --cache`,
|
|
|
|
// $`ls-lint`,
|
|
|
|
$`prettier . --ignore-unknown --check --cache`,
|
|
|
|
$`stylelint "**/*.{vue,css,less.scss}" --cache`,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
function defineLintCommand(cac: CAC) {
|
|
|
|
cac
|
|
|
|
.command('lint')
|
|
|
|
.usage('Batch execute project lint check.')
|
|
|
|
.option('--format', 'Format lint problem.')
|
|
|
|
.action(runLint);
|
|
|
|
}
|
|
|
|
|
|
|
|
export { defineLintCommand };
|