index.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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(`oxfmt .`, {
  16. stdio: 'inherit',
  17. });
  18. await execaCommand(`oxlint . --fix`, {
  19. stdio: 'inherit',
  20. });
  21. await execaCommand(`eslint . --cache --fix`, {
  22. stdio: 'inherit',
  23. });
  24. return;
  25. }
  26. await Promise.all([
  27. execaCommand(`oxfmt .`, {
  28. stdio: 'inherit',
  29. }),
  30. execaCommand(`oxlint . --fix`, {
  31. stdio: 'inherit',
  32. }),
  33. execaCommand(`eslint . --cache`, {
  34. stdio: 'inherit',
  35. }),
  36. execaCommand(`stylelint "**/*.{vue,css,less,scss}" --cache`, {
  37. stdio: 'inherit',
  38. }),
  39. ]);
  40. }
  41. function defineLintCommand(cac: CAC) {
  42. cac
  43. .command('lint')
  44. .usage('Batch execute project lint check.')
  45. .option('--format', 'Format lint problem.')
  46. .action(runLint);
  47. }
  48. export { defineLintCommand };