check-playground-samples-js.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import { spawn } from "child_process";
  2. import { globSync } from "glob";
  3. import { exit } from "process";
  4. (async () => {
  5. let someFileError = false;
  6. const files = globSync("src/website/data/playground-samples/*/*/*.js");
  7. type Result = { file: string; status: number; stdout: string };
  8. const promises: Promise<Result>[] = [];
  9. for (const file of files) {
  10. promises.push(
  11. new Promise<Result>((resolve) => {
  12. const process = spawn(
  13. "yarn",
  14. [
  15. "tsc",
  16. "--noEmit",
  17. "--allowJs",
  18. "--checkJs",
  19. "--skipLibCheck",
  20. "../out/monaco-editor/monaco.d.ts",
  21. file,
  22. ],
  23. { shell: true }
  24. );
  25. let buffer = "";
  26. process.on("exit", () => {
  27. resolve({
  28. file: file,
  29. status: process.exitCode ?? 1,
  30. stdout: buffer,
  31. });
  32. });
  33. process.stdout.on("data", (data) => {
  34. buffer += data.toString();
  35. });
  36. process.stderr.on("data", (data) => {
  37. buffer += data.toString();
  38. });
  39. })
  40. );
  41. }
  42. for (const promise of promises) {
  43. const result = await promise;
  44. console.log(result.file);
  45. if (result.status != 0) {
  46. console.log(result.stdout.toString());
  47. someFileError = true;
  48. }
  49. }
  50. if (someFileError) {
  51. console.error("Some files had type errors.");
  52. exit(1);
  53. }
  54. })();