From bdc53dd73da9bba7129614d7f0e399126e2ce794 Mon Sep 17 00:00:00 2001 From: Benjamin Dupont <4503241+Benjozork@users.noreply.github.com> Date: Sat, 5 Aug 2023 11:06:00 -0400 Subject: [PATCH] Fix JS module build scripts to know about all env vars --- fbw-a32nx/src/systems/atsu/common/build.js | 5 ++-- fbw-a32nx/src/systems/atsu/fmsclient/build.js | 27 +++---------------- fbw-a32nx/src/systems/extras-host/build.js | 26 +++--------------- fbw-a32nx/src/systems/fmgc/build.js | 27 +++---------------- fbw-a32nx/src/systems/sentry-client/build.js | 26 +++--------------- .../src/systems/simbridge-client/build.js | 27 +++---------------- fbw-a32nx/src/systems/systems-host/build.js | 26 +++--------------- fbw-a32nx/src/systems/tcas/build.js | 26 +++--------------- package.json | 3 +++ 9 files changed, 27 insertions(+), 166 deletions(-) diff --git a/fbw-a32nx/src/systems/atsu/common/build.js b/fbw-a32nx/src/systems/atsu/common/build.js index 9588b99fd60..8369e87d540 100644 --- a/fbw-a32nx/src/systems/atsu/common/build.js +++ b/fbw-a32nx/src/systems/atsu/common/build.js @@ -6,16 +6,17 @@ const esbuild = require('esbuild'); const path = require('path'); +const { esbuildModuleBuild, defineEnvVars } = require('#build-utils'); const rootDir = path.join(__dirname, '..', '..', '..', '..'); -const outFile = 'out/flybywire-aircraft-a320-neo/html_ui/JS/fbw-a32nx/atsu/common.js'; +const outFile = 'fbw-a32nx/out/flybywire-aircraft-a320-neo/html_ui/JS/fbw-a32nx/atsu/common.js'; const isProductionBuild = process.env.A32NX_PRODUCTION_BUILD === '1'; esbuild.build({ absWorkingDir: __dirname, - define: { DEBUG: 'false' }, + define: { DEBUG: 'false', ...defineEnvVars() }, entryPoints: [path.join(rootDir, '../fbw-common/src/systems/datalink/common/src/index.ts')], bundle: true, diff --git a/fbw-a32nx/src/systems/atsu/fmsclient/build.js b/fbw-a32nx/src/systems/atsu/fmsclient/build.js index a218145cfea..ea01837ce66 100644 --- a/fbw-a32nx/src/systems/atsu/fmsclient/build.js +++ b/fbw-a32nx/src/systems/atsu/fmsclient/build.js @@ -6,29 +6,8 @@ const esbuild = require('esbuild'); const path = require('path'); +const { esbuildModuleBuild } = require('#build-utils'); -const rootDir = path.join(__dirname, '..', '..', '..'); -const outFile = '../out/flybywire-aircraft-a320-neo/html_ui/JS/fbw-a32nx/atsu/fmsclient.js'; +const outFile = 'fbw-a32nx/out/flybywire-aircraft-a320-neo/html_ui/JS/fbw-a32nx/atsu/fmsclient.js'; -const isProductionBuild = process.env.A32NX_PRODUCTION_BUILD === '1'; - -esbuild.build({ - absWorkingDir: __dirname, - - define: { DEBUG: 'false' }, - - entryPoints: ['src/index.ts'], - bundle: true, - treeShaking: false, - minify: isProductionBuild, - - outfile: path.join(rootDir, outFile), - - format: 'iife', - globalName: 'AtsuFmsClient', - - sourcemap: isProductionBuild ? 'linked' : undefined, - - // Target approximate CoherentGT WebKit version - target: 'safari11', -}); +esbuild.build(esbuildModuleBuild('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 f2d44658b52..8125a2a13a7 100644 --- a/fbw-a32nx/src/systems/extras-host/build.js +++ b/fbw-a32nx/src/systems/extras-host/build.js @@ -6,28 +6,8 @@ const esbuild = require('esbuild'); const path = require('path'); +const { esbuildModuleBuild } = require('#build-utils'); -const rootDir = path.join(__dirname, '..', '..', '..'); -const outFile = 'out/flybywire-aircraft-a320-neo/html_ui/Pages/VCockpit/Instruments/A32NX/ExtrasHost'; +const outFile = 'fbw-a32nx/out/flybywire-aircraft-a320-neo/html_ui/Pages/VCockpit/Instruments/A32NX/ExtrasHost/index.js'; -const isProductionBuild = process.env.A32NX_PRODUCTION_BUILD === '1'; - -esbuild.build({ - absWorkingDir: __dirname, - - define: { 'DEBUG': 'false', 'process.env.CLIENT_ID': `'${process.env.CLIENT_ID}'`, 'process.env.CLIENT_SECRET': `'${process.env.CLIENT_SECRET}'` }, - - entryPoints: ['./index.ts'], - bundle: true, - treeShaking: false, - minify: isProductionBuild, - - outdir: path.join(rootDir, outFile), - - format: 'iife', - - sourcemap: isProductionBuild ? 'linked' : undefined, - - // Target approximate CoherentGT WebKit version - target: 'safari11', -}); +esbuild.build(esbuildModuleBuild(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 fa2d16c3000..225dec8cea3 100644 --- a/fbw-a32nx/src/systems/fmgc/build.js +++ b/fbw-a32nx/src/systems/fmgc/build.js @@ -6,29 +6,8 @@ const esbuild = require('esbuild'); const path = require('path'); +const { esbuildModuleBuild } = require('#build-utils'); -const rootDir = path.join(__dirname, '..', '..', '..'); -const outFile = 'out/flybywire-aircraft-a320-neo/html_ui/JS/fbw-a32nx/fmgc/fmgc.js'; +const outFile = 'fbw-a32nx/out/flybywire-aircraft-a320-neo/html_ui/JS/fbw-a32nx/fmgc/fmgc.js'; -const isProductionBuild = process.env.A32NX_PRODUCTION_BUILD === '1'; - -esbuild.build({ - absWorkingDir: __dirname, - - define: { DEBUG: 'false' }, - - entryPoints: ['src/index.ts'], - bundle: true, - treeShaking: false, - minify: isProductionBuild, - - outfile: path.join(rootDir, outFile), - - format: 'iife', - globalName: 'Fmgc', - - sourcemap: isProductionBuild ? 'linked' : undefined, - - // Target approximate CoherentGT WebKit version - target: 'safari11', -}); +esbuild.build(esbuildModuleBuild('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 f7f95eeb572..39634ea4fc4 100644 --- a/fbw-a32nx/src/systems/sentry-client/build.js +++ b/fbw-a32nx/src/systems/sentry-client/build.js @@ -6,30 +6,10 @@ const esbuild = require('esbuild'); const path = require('path'); +const { esbuildModuleBuild } = require('#build-utils'); require('dotenv').config(); -const rootDir = path.join(__dirname, '..', '..', '..'); -const outFile = 'out/flybywire-aircraft-a320-neo/html_ui/JS/fbw-a32nx/sentry-client/sentry-client.js'; +const outFile = 'fbw-a32nx/out/flybywire-aircraft-a320-neo/html_ui/JS/fbw-a32nx/sentry-client/sentry-client.js'; -const isProductionBuild = process.env.A32NX_PRODUCTION_BUILD === '1'; - -esbuild.build({ - absWorkingDir: __dirname, - - define: { 'DEBUG': 'false', 'process.env.SENTRY_DSN': `'${process.env.SENTRY_DSN}'` }, - - entryPoints: ['src/index.ts'], - bundle: true, - treeShaking: false, - minify: isProductionBuild, - - outfile: path.join(rootDir, outFile), - - format: 'iife', - - sourcemap: isProductionBuild ? 'linked' : undefined, - - // Target approximate CoherentGT WebKit version - target: 'safari11', -}); +esbuild.build(esbuildModuleBuild(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 461d8930cb2..628266f24fe 100644 --- a/fbw-a32nx/src/systems/simbridge-client/build.js +++ b/fbw-a32nx/src/systems/simbridge-client/build.js @@ -6,29 +6,8 @@ const esbuild = require('esbuild'); const path = require('path'); +const { esbuildModuleBuild } = require('#build-utils'); -const rootDir = path.join(__dirname, '..', '..', '..'); -const outFile = 'out/flybywire-aircraft-a320-neo/html_ui/JS/fbw-a32nx/simbridge-client/simbridge-client.js'; +const outFile = 'fbw-a32nx/out/flybywire-aircraft-a320-neo/html_ui/JS/fbw-a32nx/simbridge-client/simbridge-client.js'; -const isProductionBuild = process.env.A32NX_PRODUCTION_BUILD === '1'; - -esbuild.build({ - absWorkingDir: __dirname, - - define: { DEBUG: 'false' }, - - entryPoints: ['src/index.ts'], - bundle: true, - treeShaking: false, - minify: isProductionBuild, - - outfile: path.join(rootDir, outFile), - - format: 'iife', - globalName: 'SimBridgeClient', - - sourcemap: isProductionBuild ? 'linked' : undefined, - - // Target approximate CoherentGT WebKit version - target: 'safari11', -}); +esbuild.build(esbuildModuleBuild('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 ca44006c5d1..0d3600748ee 100644 --- a/fbw-a32nx/src/systems/systems-host/build.js +++ b/fbw-a32nx/src/systems/systems-host/build.js @@ -6,28 +6,8 @@ const esbuild = require('esbuild'); const path = require('path'); +const { esbuildModuleBuild } = require('#build-utils'); -const rootDir = path.join(__dirname, '..', '..', '..'); -const outFile = 'out/flybywire-aircraft-a320-neo/html_ui/Pages/VCockpit/Instruments/A32NX/SystemsHost'; +const outFile = 'fbw-a32nx/out/flybywire-aircraft-a320-neo/html_ui/Pages/VCockpit/Instruments/A32NX/SystemsHost/index.js'; -const isProductionBuild = process.env.A32NX_PRODUCTION_BUILD === '1'; - -esbuild.build({ - absWorkingDir: __dirname, - - define: { 'DEBUG': 'false', 'process.env.CLIENT_ID': `'${process.env.CLIENT_ID}'`, 'process.env.CLIENT_SECRET': `'${process.env.CLIENT_SECRET}'` }, - - entryPoints: ['./index.ts'], - bundle: true, - treeShaking: false, - minify: isProductionBuild, - - outdir: path.join(rootDir, outFile), - - format: 'iife', - - sourcemap: isProductionBuild ? 'linked' : undefined, - - // Target approximate CoherentGT WebKit version - target: 'safari11', -}); +esbuild.build(esbuildModuleBuild(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 9c8f630544d..99a4b6f7421 100644 --- a/fbw-a32nx/src/systems/tcas/build.js +++ b/fbw-a32nx/src/systems/tcas/build.js @@ -6,28 +6,8 @@ const esbuild = require('esbuild'); const path = require('path'); +const { esbuildModuleBuild } = require('#build-utils'); -const rootDir = path.join(__dirname, '..', '..', '..'); -const outFile = 'out/flybywire-aircraft-a320-neo/html_ui/JS/fbw-a32nx/tcas/tcas.js'; +const outFile = 'fbw-a32nx/out/flybywire-aircraft-a320-neo/html_ui/JS/fbw-a32nx/tcas/tcas.js'; -const isProductionBuild = process.env.A32NX_PRODUCTION_BUILD === '1'; - -esbuild.build({ - absWorkingDir: __dirname, - - define: { DEBUG: 'false' }, - - entryPoints: ['src/index.ts'], - bundle: true, - treeShaking: false, - minify: isProductionBuild, - - outfile: path.join(rootDir, outFile), - - format: 'iife', - - sourcemap: isProductionBuild ? 'linked' : undefined, - - // Target approximate CoherentGT WebKit version - target: 'safari11', -}); +esbuild.build(esbuildModuleBuild(undefined, path.join(__dirname, 'src/index.ts'), outFile)); diff --git a/package.json b/package.json index 9e23efa2798..f033a1a65e5 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,9 @@ "name": "a32nx", "version": "0.11.0", "edition": "development", + "imports": { + "#build-utils": "./build-utils.js" + }, "scripts": { "====== A320 =================": "==========================================",