install.js 1.2 KB

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