1
0

check-playground-samples-js.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. "--target",
  17. "es6",
  18. "--noEmit",
  19. "--allowJs",
  20. "--checkJs",
  21. "--skipLibCheck",
  22. "../out/monaco-editor/monaco.d.ts",
  23. file,
  24. ],
  25. { shell: true }
  26. );
  27. let buffer = "";
  28. process.on("exit", () => {
  29. resolve({
  30. file: file,
  31. status: process.exitCode ?? 1,
  32. stdout: buffer,
  33. });
  34. });
  35. process.stdout.on("data", (data) => {
  36. buffer += data.toString();
  37. });
  38. process.stderr.on("data", (data) => {
  39. buffer += data.toString();
  40. });
  41. })
  42. );
  43. }
  44. for (const promise of promises) {
  45. const result = await promise;
  46. console.log(result.file);
  47. if (result.status != 0) {
  48. console.log(result.stdout.toString());
  49. someFileError = true;
  50. }
  51. }
  52. if (someFileError) {
  53. console.error("Some files had type errors.");
  54. exit(1);
  55. }
  56. })();