| 1 | /** |
| 2 | * @file Install node modules for the VS Code extension and gui. This is also intended to run as a child process. |
| 3 | */ |
| 4 | |
| 5 | const { fork } = require("child_process"); |
| 6 | const path = require("path"); |
| 7 | |
| 8 | const { execCmdSync } = require("../../../scripts/util"); |
| 9 | |
| 10 | const { continueDir } = require("./utils"); |
| 11 | |
| 12 | async function installNodeModulesInGui() { |
| 13 | process.chdir(path.join(continueDir, "gui")); |
| 14 | execCmdSync("npm install"); |
| 15 | console.log("[info] npm install in gui completed"); |
| 16 | } |
| 17 | |
| 18 | async function installNodeModulesInVscode() { |
| 19 | process.chdir(path.join(continueDir, "extensions", "vscode")); |
| 20 | execCmdSync("npm install"); |
| 21 | console.log("[info] npm install in extensions/vscode completed"); |
| 22 | } |
| 23 | |
| 24 | process.on("message", (msg) => { |
| 25 | const { targetDir } = msg.payload; |
| 26 | if (targetDir === "gui") { |
| 27 | installNodeModulesInGui() |
| 28 | .then(() => process.send({ done: true })) |
| 29 | .catch((error) => { |
| 30 | console.error(error); // show the error in the parent process |
| 31 | process.send({ error: true }); |
| 32 | }); |
| 33 | } else if (targetDir === "vscode") { |
| 34 | installNodeModulesInVscode() |
| 35 | .then(() => process.send({ done: true })) |
| 36 | .catch((error) => { |
| 37 | console.error(error); // show the error in the parent process |
| 38 | process.send({ error: true }); |
| 39 | }); |
| 40 | } |
| 41 | }); |
| 42 | |
| 43 | async function npmInstall() { |
| 44 | const installVscodeChild = fork(__filename, { |
| 45 | stdio: "inherit", |
| 46 | }); |
| 47 | installVscodeChild.send({ payload: { targetDir: "vscode" } }); |
| 48 | |
| 49 | const installGuiChild = fork(__filename, { |
| 50 | stdio: "inherit", |
| 51 | }); |
| 52 | installGuiChild.send({ payload: { targetDir: "gui" } }); |
| 53 | |
| 54 | await Promise.all([ |
| 55 | new Promise((resolve, reject) => { |
| 56 | installVscodeChild.on("message", (msg) => { |
| 57 | if (msg.error) { |
| 58 | reject(); |
| 59 | } |
| 60 | resolve(); |
| 61 | }); |
| 62 | }), |
| 63 | new Promise((resolve, reject) => { |
| 64 | installGuiChild.on("message", (msg) => { |
| 65 | if (msg.error) { |
| 66 | reject(); |
| 67 | } |
| 68 | resolve(); |
| 69 | }); |
| 70 | }), |
| 71 | ]).catch((error) => { |
| 72 | console.error(error); |
| 73 | process.exit(1); |
| 74 | }); |
| 75 | } |
| 76 | |
| 77 | module.exports = { |
| 78 | npmInstall, |
| 79 | }; |