install.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. require("dotenv").config();
  2. const { exec, execSync } = require("child_process");
  3. const { existsSync, writeFileSync, appendFileSync } = require("fs");
  4. const { sep } = require("path");
  5. const getGuiEnv = () =>
  6. execSync(
  7. process.platform === "win32"
  8. ? 'pipenv run pip show taipy-gui | findStr "Location:"'
  9. : "pipenv run pip show taipy-gui | grep Location:"
  10. )
  11. .toString()
  12. .trim()
  13. .substring(9)
  14. .trim();
  15. let TAIPY_GUI_DIR = process.env.TAIPY_GUI_DIR;
  16. if (!TAIPY_GUI_DIR) {
  17. TAIPY_GUI_DIR = getGuiEnv();
  18. if (existsSync(".env")) {
  19. appendFileSync(".env", `\nTAIPY_GUI_DIR=${TAIPY_GUI_DIR}`);
  20. } else {
  21. writeFileSync(".env", `TAIPY_GUI_DIR=${TAIPY_GUI_DIR}`);
  22. }
  23. }
  24. const taipy_webapp_dir = `${TAIPY_GUI_DIR}${sep}taipy${sep}gui${sep}webapp`;
  25. if (!existsSync(taipy_webapp_dir)) {
  26. console.error(
  27. `Cannot find the Taipy GUI (${taipy_webapp_dir}) webapp directory.\nMake sure TAIPY_GUI_DIR is set properly as (${getGuiEnv()}).`
  28. );
  29. process.exit(1);
  30. }
  31. const spinner = "|/-\\";
  32. let i = 0;
  33. let spinnerTimer;
  34. exec(`npm i ${taipy_webapp_dir}`)
  35. .on("spawn", () => {
  36. spinnerTimer = setInterval(() => {
  37. process.stdout.write("Installing the Taipy GUI library... \r" + spinner[i++]);
  38. i = i % spinner.length;
  39. }, 150);
  40. })
  41. .on("exit", (code, signal) => {
  42. clearInterval(spinnerTimer);
  43. if (code === 0) {
  44. console.log("\nInstallation finished");
  45. } else {
  46. console.log(`\nInstallation failed (code ${code}, signal ${signal})`);
  47. }
  48. });