From f5b594027d2bff126f0786203490306714f58391 Mon Sep 17 00:00:00 2001 From: sdfasd Date: Sat, 29 Aug 2020 01:29:25 -0700 Subject: [PATCH] Fix issues with linux build also add error logging to compile and install steps --- compile.js | 18 +++++++++++--- installSubModules.js | 59 +++++++++++++++++++++----------------------- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/compile.js b/compile.js index fbcecda..751a2e0 100644 --- a/compile.js +++ b/compile.js @@ -14,17 +14,29 @@ spawnSync("npm run build", join(__dirname, "LightcordApi")) spawnSync("npm run build-prod", join(__dirname, "LightcordApi")) spawnSync("tsc", join(__dirname, "LightcordApi")) +var exitedWithErrorProcessList = []; -function spawnSync(args, cwd){ - args = args.split(" ") +function spawnSync(cmdString, cwd){ + let args = cmdString.split(" ") let command = args.shift() return spawn(command, args, { cwd: cwd || process.cwd(), env: process.env, stdio: "inherit" - }) + }).on("error", (err) => { + const DIRSTRING = cwd != undefined ? cwd : process.env.PWD + console.log("Error while running " + cmdString + " in target directory " + DIRSTRING) + console.error(err) + exitedWithErrorProcessList.push({cmd: cmdString, cwd: DIRSTRING}) + }) } process.on("beforeExit", () => { + if (exitedWithErrorProcessList.length != 0){ + console.error("Commands exited with errors:\n") + exitedWithErrorProcessList.forEach((val)=>{ + console.error("\tcommand:\t\t" + val.cmd + "\n\ttarget directory:\t" + val.cwd + "\n") + }); + } console.log(`Exiting compilation`) }) \ No newline at end of file diff --git a/installSubModules.js b/installSubModules.js index 46d4879..e2db263 100644 --- a/installSubModules.js +++ b/installSubModules.js @@ -4,6 +4,20 @@ const path = require("path") const MODULES_DIRNAME = path.join(__dirname, "modules") +var exitedWithErrorProcessList = []; + +function spawnNpmInstallProcess (targetDir) { + child_process.spawn((process.platform === "win32" ? "npm.cmd" : "npm"), ["i"], { + cwd: targetDir, + env: process.env, + stdio: "inherit" + }).on("error", (err) => { + console.log("Error while running 'npm i' in target directory " + targetDir) + console.error(err) + exitedWithErrorProcessList.push(targetDir) + }) +} + fs.readdirSync(MODULES_DIRNAME, {withFileTypes: true}) .forEach(e => { if(!e.isDirectory())return @@ -12,43 +26,26 @@ fs.readdirSync(MODULES_DIRNAME, {withFileTypes: true}) if(e.name === "discord_spellcheck")return console.log(`Installing modules in ${e.name}.`) - - child_process.spawn((process.platform === "win32" ? "npm.cmd" : "npm"), ["i"], { - cwd: MODULE_DIRNAME, - env: process.env, - stdio: "inherit" - }).on("error", (err) => { - console.error(err) - process.exit(1) - }) + spawnNpmInstallProcess(MODULE_DIRNAME) }) const MODULE_DIRNAME = path.join(__dirname, "modules", "discord_desktop_core", "core") const BETTERDISCORD_DIRNAME = path.join(__dirname, "BetterDiscordApp") const DISCORDJS_DIRNAME = path.join(__dirname, "DiscordJS") +const LIGHTCORDAPI_DIRNAME = path.join(__dirname, "LightcordApi") -child_process.spawn((process.platform === "win32" ? "npm.cmd" : "npm"), ["i"], { - cwd: MODULE_DIRNAME, - env: process.env, - stdio: "inherit" -}).on("error", (err) => { - console.error(err) - process.exit(1) -}) +spawnNpmInstallProcess(MODULE_DIRNAME) +spawnNpmInstallProcess(BETTERDISCORD_DIRNAME) +spawnNpmInstallProcess(LIGHTCORDAPI_DIRNAME) +spawnNpmInstallProcess(DISCORDJS_DIRNAME) -child_process.spawn((process.platform === "win32" ? "npm.cmd" : "npm"), ["i"], { - cwd: BETTERDISCORD_DIRNAME, - env: process.env, - stdio: "inherit" -}).on("error", (err) => { - console.error(err) - process.exit(1) -}) - - -child_process.spawn((process.platform === "win32" ? "npm.cmd" : "npm"), ["i"], { - cwd: DISCORDJS_DIRNAME, - env: process.env, - stdio: "inherit" +process.on("beforeExit", () => { + if (exitedWithErrorProcessList.length != 0){ + console.error("Failed to run 'npm install' on:\n") + exitedWithErrorProcessList.forEach((val)=>{ + console.error(val) + }); + } + console.error(); }) \ No newline at end of file