testRelease.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // eslint-disable-next-line @typescript-eslint/no-var-requires
  2. const spawn = require("cross-spawn");
  3. const TOTAL_SPAWN_STEPS = 10;
  4. const main = async () => {
  5. let currentSpawnStep = 0;
  6. const logProgress = message => {
  7. currentSpawnStep += 1;
  8. console.log(
  9. `\n\x1b[36m${currentSpawnStep}/${TOTAL_SPAWN_STEPS} ${message}...\x1b[0m\n`
  10. );
  11. };
  12. const spawnPromise = (command, args, message) =>
  13. new Promise((resolve, reject) => {
  14. logProgress(message);
  15. const childProcess = spawn(command, args, { stdio: "inherit" });
  16. childProcess.on("close", code => {
  17. if (code === 0) {
  18. resolve();
  19. } else {
  20. reject(
  21. new Error(`${command} ${args.join(" ")} exited with code ${code}`)
  22. );
  23. }
  24. });
  25. });
  26. const spawnStart = async message =>
  27. new Promise((resolve, reject) => {
  28. logProgress(message);
  29. process.env.FORCE_COLOR = true;
  30. const childProcess = spawn("npm", ["run", "start"], { env: process.env });
  31. childProcess.stdout.on("data", data => {
  32. process.stdout.write(data);
  33. if (data.toString().includes("server is up")) {
  34. console.log("\nContinue to next step? (Y/n)...");
  35. }
  36. });
  37. childProcess.stderr.on("data", data => {
  38. process.stderr.write(data);
  39. });
  40. process.stdin.setRawMode(true);
  41. process.stdin.once("data", data => {
  42. childProcess.kill();
  43. process.stdin.setRawMode(false);
  44. if (data.toString() === "n") {
  45. reject(new Error("Aborted"));
  46. } else {
  47. resolve();
  48. }
  49. });
  50. });
  51. try {
  52. await spawnPromise(
  53. "yarn",
  54. ["install"],
  55. "Installing development dependencies"
  56. );
  57. await spawnPromise("npm", ["run", "tsc"], "Typescript checks");
  58. await spawnPromise("npm", ["run", "eslint"], "ESLint checks");
  59. await spawnPromise("npm", ["run", "format"], "Run prettier");
  60. await spawnPromise("npm", ["run", "test"], "Run unit tests");
  61. await spawnPromise(
  62. "npx",
  63. ["rimraf", "node_modules"],
  64. "Deleting node_modules"
  65. );
  66. await spawnPromise(
  67. "yarn",
  68. ["workspaces", "focus", "--all", "--production"],
  69. "Installing production dependencies"
  70. );
  71. await spawnPromise("npm", ["run", "build"], "Production build");
  72. await spawnStart("Production start");
  73. await spawnPromise(
  74. "yarn",
  75. ["install"],
  76. "Testing successful! Reverting to development install"
  77. );
  78. } catch (e) {
  79. console.error(e);
  80. } finally {
  81. process.exit(0);
  82. }
  83. };
  84. main();