index.ts 1.3 KB

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