diff --git a/build-utils.js b/build-utils.js index c67244960b7..0ccc11d5016 100644 --- a/build-utils.js +++ b/build-utils.js @@ -1,16 +1,18 @@ const dotenv = require('dotenv'); const path = require("path"); -dotenv.config(); - function defineEnvVars() { + dotenv.config(); + const defines = {}; for (const envVar of Object.keys(process.env)) { const value = process.env[envVar].trim(); let replacement; - if (value.trim() === 'true' || value.trim() === 'false' || !Number.isNaN(parseFloat(value))) { + if (value.trim() === 'true' || value.trim() === 'false') { + replacement = value; + } else if (!Number.isNaN(parseFloat(value))) { replacement = parseFloat(value).toString(); } else { replacement = `"${value}"`; @@ -25,13 +27,16 @@ function defineEnvVars() { module.exports.defineEnvVars = defineEnvVars; /** + * @param projectRoot {string} the project root folder, as a path relative to the root of the repository * @param globalName {string|undefined} the name of the global to define in the output IIFE * @param entryPoint {string} the entrypoint path, as an absolute path * @param outFile {string} the output file path, as a path relative to the root of the repository */ -function esbuildModuleBuild(globalName, entryPoint, outFile) { +function esbuildModuleBuild(projectRoot, globalName, entryPoint, outFile) { const isProductionBuild = process.env.A32NX_PRODUCTION_BUILD === '1'; + process.chdir(projectRoot); + return { absWorkingDir: __dirname, diff --git a/fbw-a32nx/src/systems/atsu/fmsclient/build.js b/fbw-a32nx/src/systems/atsu/fmsclient/build.js index ea01837ce66..cc368667c28 100644 --- a/fbw-a32nx/src/systems/atsu/fmsclient/build.js +++ b/fbw-a32nx/src/systems/atsu/fmsclient/build.js @@ -10,4 +10,4 @@ const { esbuildModuleBuild } = require('#build-utils'); const outFile = 'fbw-a32nx/out/flybywire-aircraft-a320-neo/html_ui/JS/fbw-a32nx/atsu/fmsclient.js'; -esbuild.build(esbuildModuleBuild('AtsuFmsClient', path.join(__dirname, 'src/index.ts'), outFile)); +esbuild.build(esbuildModuleBuild('fbw-a32nx', 'AtsuFmsClient', path.join(__dirname, 'src/index.ts'), outFile)); diff --git a/fbw-a32nx/src/systems/extras-host/build.js b/fbw-a32nx/src/systems/extras-host/build.js index 8125a2a13a7..66ab9cabdfa 100644 --- a/fbw-a32nx/src/systems/extras-host/build.js +++ b/fbw-a32nx/src/systems/extras-host/build.js @@ -10,4 +10,4 @@ const { esbuildModuleBuild } = require('#build-utils'); const outFile = 'fbw-a32nx/out/flybywire-aircraft-a320-neo/html_ui/Pages/VCockpit/Instruments/A32NX/ExtrasHost/index.js'; -esbuild.build(esbuildModuleBuild(undefined, path.join(__dirname, './index.ts'), outFile)); +esbuild.build(esbuildModuleBuild('fbw-a32nx', undefined, path.join(__dirname, './index.ts'), outFile)); diff --git a/fbw-a32nx/src/systems/fmgc/build.js b/fbw-a32nx/src/systems/fmgc/build.js index 225dec8cea3..908c260da21 100644 --- a/fbw-a32nx/src/systems/fmgc/build.js +++ b/fbw-a32nx/src/systems/fmgc/build.js @@ -10,4 +10,4 @@ const { esbuildModuleBuild } = require('#build-utils'); const outFile = 'fbw-a32nx/out/flybywire-aircraft-a320-neo/html_ui/JS/fbw-a32nx/fmgc/fmgc.js'; -esbuild.build(esbuildModuleBuild('Fmgc', path.join(__dirname, 'src/index.ts'), outFile)); +esbuild.build(esbuildModuleBuild('fbw-a32nx', 'Fmgc', path.join(__dirname, 'src/index.ts'), outFile)); diff --git a/fbw-a32nx/src/systems/sentry-client/build.js b/fbw-a32nx/src/systems/sentry-client/build.js index 39634ea4fc4..6c229da1b4f 100644 --- a/fbw-a32nx/src/systems/sentry-client/build.js +++ b/fbw-a32nx/src/systems/sentry-client/build.js @@ -12,4 +12,4 @@ require('dotenv').config(); const outFile = 'fbw-a32nx/out/flybywire-aircraft-a320-neo/html_ui/JS/fbw-a32nx/sentry-client/sentry-client.js'; -esbuild.build(esbuildModuleBuild(undefined, path.join(__dirname, 'src/index.ts'), outFile)); +esbuild.build(esbuildModuleBuild('fbw-a32nx', undefined, path.join(__dirname, 'src/index.ts'), outFile)); diff --git a/fbw-a32nx/src/systems/simbridge-client/build.js b/fbw-a32nx/src/systems/simbridge-client/build.js index 628266f24fe..be7c3239616 100644 --- a/fbw-a32nx/src/systems/simbridge-client/build.js +++ b/fbw-a32nx/src/systems/simbridge-client/build.js @@ -10,4 +10,4 @@ const { esbuildModuleBuild } = require('#build-utils'); const outFile = 'fbw-a32nx/out/flybywire-aircraft-a320-neo/html_ui/JS/fbw-a32nx/simbridge-client/simbridge-client.js'; -esbuild.build(esbuildModuleBuild('SimBridgeClient', path.join(__dirname, 'src/index.ts'), outFile)); +esbuild.build(esbuildModuleBuild('fbw-a32nx', 'SimBridgeClient', path.join(__dirname, 'src/index.ts'), outFile)); diff --git a/fbw-a32nx/src/systems/systems-host/build.js b/fbw-a32nx/src/systems/systems-host/build.js index 0d3600748ee..ae97258c5cf 100644 --- a/fbw-a32nx/src/systems/systems-host/build.js +++ b/fbw-a32nx/src/systems/systems-host/build.js @@ -10,4 +10,4 @@ const { esbuildModuleBuild } = require('#build-utils'); const outFile = 'fbw-a32nx/out/flybywire-aircraft-a320-neo/html_ui/Pages/VCockpit/Instruments/A32NX/SystemsHost/index.js'; -esbuild.build(esbuildModuleBuild(undefined, path.join(__dirname, './index.ts'), outFile)); +esbuild.build(esbuildModuleBuild('fbw-a32nx', undefined, path.join(__dirname, './index.ts'), outFile)); diff --git a/fbw-a32nx/src/systems/tcas/build.js b/fbw-a32nx/src/systems/tcas/build.js index 99a4b6f7421..3516951e521 100644 --- a/fbw-a32nx/src/systems/tcas/build.js +++ b/fbw-a32nx/src/systems/tcas/build.js @@ -10,4 +10,4 @@ const { esbuildModuleBuild } = require('#build-utils'); const outFile = 'fbw-a32nx/out/flybywire-aircraft-a320-neo/html_ui/JS/fbw-a32nx/tcas/tcas.js'; -esbuild.build(esbuildModuleBuild(undefined, path.join(__dirname, 'src/index.ts'), outFile)); +esbuild.build(esbuildModuleBuild('fbw-a32nx', undefined, path.join(__dirname, 'src/index.ts'), outFile));