testRelease.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. try {
  62. await spawnPromise(
  63. "npx",
  64. ["rimraf", "node_modules"],
  65. "Deleting node_modules",
  66. );
  67. } catch (e) {
  68. console.error(e);
  69. }
  70. await spawnPromise(
  71. "yarn",
  72. ["workspaces", "focus", "--all", "--production"],
  73. "Installing production dependencies",
  74. );
  75. await spawnPromise("npm", ["run", "build"], "Production build");
  76. await spawnStart("Production start");
  77. await spawnPromise(
  78. "yarn",
  79. ["install"],
  80. "Testing successful! Reverting to development install",
  81. );
  82. } catch (e) {
  83. console.error(e);
  84. } finally {
  85. process.exit(0);
  86. }
  87. };
  88. main();