Fix issues with linux build

also add error logging to compile and install steps
This commit is contained in:
sdfasd 2020-08-29 01:29:25 -07:00 committed by hormelcookies
parent dcbfa98cd9
commit f5b594027d
2 changed files with 43 additions and 34 deletions

View File

@ -14,17 +14,29 @@ spawnSync("npm run build", join(__dirname, "LightcordApi"))
spawnSync("npm run build-prod", join(__dirname, "LightcordApi")) spawnSync("npm run build-prod", join(__dirname, "LightcordApi"))
spawnSync("tsc", join(__dirname, "LightcordApi")) spawnSync("tsc", join(__dirname, "LightcordApi"))
var exitedWithErrorProcessList = [];
function spawnSync(args, cwd){ function spawnSync(cmdString, cwd){
args = args.split(" ") let args = cmdString.split(" ")
let command = args.shift() let command = args.shift()
return spawn(command, args, { return spawn(command, args, {
cwd: cwd || process.cwd(), cwd: cwd || process.cwd(),
env: process.env, env: process.env,
stdio: "inherit" 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", () => { 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`) console.log(`Exiting compilation`)
}) })

View File

@ -4,6 +4,20 @@ const path = require("path")
const MODULES_DIRNAME = path.join(__dirname, "modules") 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}) fs.readdirSync(MODULES_DIRNAME, {withFileTypes: true})
.forEach(e => { .forEach(e => {
if(!e.isDirectory())return if(!e.isDirectory())return
@ -12,43 +26,26 @@ fs.readdirSync(MODULES_DIRNAME, {withFileTypes: true})
if(e.name === "discord_spellcheck")return if(e.name === "discord_spellcheck")return
console.log(`Installing modules in ${e.name}.`) console.log(`Installing modules in ${e.name}.`)
spawnNpmInstallProcess(MODULE_DIRNAME)
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)
})
}) })
const MODULE_DIRNAME = path.join(__dirname, "modules", "discord_desktop_core", "core") const MODULE_DIRNAME = path.join(__dirname, "modules", "discord_desktop_core", "core")
const BETTERDISCORD_DIRNAME = path.join(__dirname, "BetterDiscordApp") const BETTERDISCORD_DIRNAME = path.join(__dirname, "BetterDiscordApp")
const DISCORDJS_DIRNAME = path.join(__dirname, "DiscordJS") const DISCORDJS_DIRNAME = path.join(__dirname, "DiscordJS")
const LIGHTCORDAPI_DIRNAME = path.join(__dirname, "LightcordApi")
child_process.spawn((process.platform === "win32" ? "npm.cmd" : "npm"), ["i"], { spawnNpmInstallProcess(MODULE_DIRNAME)
cwd: MODULE_DIRNAME, spawnNpmInstallProcess(BETTERDISCORD_DIRNAME)
env: process.env, spawnNpmInstallProcess(LIGHTCORDAPI_DIRNAME)
stdio: "inherit" spawnNpmInstallProcess(DISCORDJS_DIRNAME)
}).on("error", (err) => {
console.error(err)
process.exit(1)
})
child_process.spawn((process.platform === "win32" ? "npm.cmd" : "npm"), ["i"], { process.on("beforeExit", () => {
cwd: BETTERDISCORD_DIRNAME, if (exitedWithErrorProcessList.length != 0){
env: process.env, console.error("Failed to run 'npm install' on:\n")
stdio: "inherit" exitedWithErrorProcessList.forEach((val)=>{
}).on("error", (err) => { console.error(val)
console.error(err) });
process.exit(1) }
}) console.error();
child_process.spawn((process.platform === "win32" ? "npm.cmd" : "npm"), ["i"], {
cwd: DISCORDJS_DIRNAME,
env: process.env,
stdio: "inherit"
}) })