index.ts 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import type { CAC } from 'cac';
  2. import { execaCommand } from '@vben/node-utils';
  3. interface LintCommandOptions {
  4. /**
  5. * Format lint problem.
  6. */
  7. format?: boolean;
  8. }
  9. async function runLint({ format }: LintCommandOptions) {
  10. // process.env.FORCE_COLOR = '3';
  11. if (format) {
  12. await execaCommand(`stylelint "**/*.{vue,css,less.scss}" --cache --fix`, {
  13. stdio: 'inherit',
  14. });
  15. await execaCommand(`eslint . --cache --fix`, {
  16. stdio: 'inherit',
  17. });
  18. await execaCommand(`prettier . --write --cache --log-level warn`, {
  19. stdio: 'inherit',
  20. });
  21. return;
  22. }
  23. await Promise.all([
  24. execaCommand(`eslint . --cache`, {
  25. stdio: 'inherit',
  26. }),
  27. // $`ls-lint`,
  28. execaCommand(`prettier . --ignore-unknown --check --cache`, {
  29. stdio: 'inherit',
  30. }),
  31. execaCommand(`stylelint "**/*.{vue,css,less.scss}" --cache`, {
  32. stdio: 'inherit',
  33. }),
  34. ]);
  35. }
  36. function defineLintCommand(cac: CAC) {
  37. cac
  38. .command('lint')
  39. .usage('Batch execute project lint check.')
  40. .option('--format', 'Format lint problem.')
  41. .action(runLint);
  42. }
  43. export { defineLintCommand };