architecture-check.mjs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env node
  2. import {
  3. checkArchitecture,
  4. changedFilesFromGit,
  5. formatMarkdownReport,
  6. formatReport,
  7. generateContext,
  8. updateBaseline,
  9. } from "./index.mjs";
  10. const args = process.argv.slice(2);
  11. const command = args[0] ?? "check";
  12. const cwd = process.cwd();
  13. if (command === "context") {
  14. const moduleId = args[1];
  15. if (!moduleId) throw new Error("用法: pnpm architecture:context <module-id>");
  16. console.log(await generateContext({ cwd, moduleId }));
  17. process.exit(0);
  18. }
  19. const changed = args.includes("--changed") ? await changedFilesFromGit(cwd) : null;
  20. const result = await checkArchitecture({ cwd, changedFiles: changed });
  21. if (command === "baseline:update") {
  22. await updateBaseline({ cwd, violations: result.violations });
  23. console.log(`baseline updated: ${result.violations.length} violations`);
  24. process.exit(0);
  25. }
  26. if (command === "report") {
  27. console.log(
  28. args.includes("--markdown") ? formatMarkdownReport(result) : JSON.stringify(result, null, 2),
  29. );
  30. process.exit(result.newViolations.length > 0 ? 1 : 0);
  31. }
  32. console.log(formatReport(result));
  33. process.exit(result.newViolations.length > 0 ? 1 : 0);