install.js 1.5 KB

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