index.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. execaCommand(`prettier . --ignore-unknown --check --cache`, {
  28. stdio: 'inherit',
  29. }),
  30. execaCommand(`stylelint "**/*.{vue,css,less.scss}" --cache`, {
  31. stdio: 'inherit',
  32. }),
  33. ]);
  34. }
  35. function defineLintCommand(cac: CAC) {
  36. cac
  37. .command('lint')
  38. .usage('Batch execute project lint check.')
  39. .option('--format', 'Format lint problem.')
  40. .action(runLint);
  41. }
  42. export { defineLintCommand };