Skip to content

Commit

Permalink
Fix build scripts dotenv config working dir
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjozork committed Aug 12, 2023
1 parent a5fe4d6 commit bb882d2
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 11 deletions.
13 changes: 9 additions & 4 deletions build-utils.js
Original file line number Diff line number Diff line change
@@ -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}"`;
Expand All @@ -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,

Expand Down
2 changes: 1 addition & 1 deletion fbw-a32nx/src/systems/atsu/fmsclient/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
2 changes: 1 addition & 1 deletion fbw-a32nx/src/systems/extras-host/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
2 changes: 1 addition & 1 deletion fbw-a32nx/src/systems/fmgc/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
2 changes: 1 addition & 1 deletion fbw-a32nx/src/systems/sentry-client/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
2 changes: 1 addition & 1 deletion fbw-a32nx/src/systems/simbridge-client/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
2 changes: 1 addition & 1 deletion fbw-a32nx/src/systems/systems-host/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
2 changes: 1 addition & 1 deletion fbw-a32nx/src/systems/tcas/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

0 comments on commit bb882d2

Please sign in to comment.