|
1 | 1 | import { $ } from "bun"; |
2 | | -import { existsSync, mkdirSync, readFileSync, rmdirSync } from "node:fs"; |
| 2 | +import { constants, copyFile, existsSync, mkdirSync, readFileSync, rmdirSync } from "node:fs"; |
3 | 3 | import { dirname, join, normalize, resolve } from "node:path"; |
4 | | -import { parseArgs } from "util"; |
5 | 4 |
|
6 | 5 | /// The type returned from the `cargo-msfs info -f` command |
7 | 6 | interface InstalledSdkVersions { |
8 | | - versions: { sim: "Msfs2020" | "Msfs2024"; up_to_date: boolean; installed?: string; latest: string }[]; |
| 7 | + versions: { sim: "Msfs2020"; up_to_date: boolean; installed?: string; latest: string }[]; |
9 | 8 | } |
10 | 9 |
|
11 | 10 | /// The docker image name |
@@ -37,23 +36,6 @@ function findWorkspaceRoot() { |
37 | 36 | return null; |
38 | 37 | } |
39 | 38 |
|
40 | | -// Determine which version(s) to build based on command line argument --version |
41 | | -const allowedVersions = ["2020", "2024"]; |
42 | | - |
43 | | -const { values } = parseArgs({ |
44 | | - args: Bun.argv, |
45 | | - options: { version: { type: "string" } }, |
46 | | - strict: true, |
47 | | - allowPositionals: true, |
48 | | -}); |
49 | | - |
50 | | -if (values.version && !allowedVersions.includes(values.version)) { |
51 | | - console.error(`Invalid version argument: ${values.version}. Allowed values are ${allowedVersions.join(", ")}`); |
52 | | - process.exit(1); |
53 | | -} |
54 | | - |
55 | | -const versionsToBuild = values.version ? [values.version] : allowedVersions; |
56 | | - |
57 | 39 | // Get workspace root for docker commands |
58 | 40 | const workspaceRoot = findWorkspaceRoot(); |
59 | 41 | if (!workspaceRoot) { |
@@ -85,36 +67,51 @@ if (installedSdks.versions.some(v => !v.up_to_date)) { |
85 | 67 |
|
86 | 68 | // Clear out dir |
87 | 69 | const outDir = resolve(workspaceRoot, "dist/wasm"); |
| 70 | +const panelDir = resolve( |
| 71 | + workspaceRoot, |
| 72 | + "example/aircraft/PackageSources/SimObjects/Airplanes/Navigraph_Navigation_Data_Interface_Aircraft/panel", |
| 73 | +); |
| 74 | + |
88 | 75 | if (existsSync(outDir)) rmdirSync(outDir, { recursive: true }); |
89 | 76 |
|
90 | 77 | // The work directory, relative to workspace root |
91 | 78 | const relativeWorkdDir = process.cwd().replace(workspaceRoot, "").replaceAll("\\", "/"); |
92 | 79 |
|
93 | | -// Build the selected versions |
94 | | -await Promise.all( |
95 | | - versionsToBuild.map(async simVersion => { |
96 | | - console.info(`[*] Building for ${simVersion}`); |
97 | | - |
98 | | - // Create the subfolder |
99 | | - const simDir = join(outDir, simVersion); |
100 | | - const relativeSimDir = simDir.replace(workspaceRoot, "").replaceAll("\\", "/"); |
101 | | - mkdirSync(simDir, { recursive: true }); |
102 | | - |
103 | | - const color = simVersion === "2020" ? "\x1b[34m" : "\x1b[32m"; |
104 | | - |
105 | | - // Run cargo-msfs |
106 | | - await $`docker run \ |
107 | | - --rm -t \ |
108 | | - --name msfs-${simVersion}-wasm-builder \ |
109 | | - -v ${workspaceRoot}:/workspace \ |
110 | | - -w /workspace${relativeWorkdDir} \ |
111 | | - -e CARGO_TARGET_DIR=/workspace/targets/${simVersion} \ |
112 | | - ${IMAGE_NAME} \ |
113 | | - bash -c "cargo-msfs build msfs${simVersion} -i ./src/wasm -o ./${relativeSimDir}/msfs_navigation_data_interface.wasm \ |
114 | | - 1> >(sed \"s/^/[${color}${simVersion}\\x1b[0m]/\") \ |
115 | | - 2> >(sed \"s/^/[${color}${simVersion}\\x1b[0m]/\" >&2)"`.catch((err: { exitCode?: number; stderr?: Buffer }) => { |
116 | | - console.error(`[-] Error building for ${simVersion}: ${err.exitCode} ${err.stderr?.toString()}`); |
| 80 | +// Build the 2020 version |
| 81 | +const simVersion = "2020"; |
| 82 | + |
| 83 | +console.info(`[*] Building for ${simVersion}`); |
| 84 | + |
| 85 | +// Create the subfolder |
| 86 | +const simDir = join(outDir, simVersion); |
| 87 | +const relativeSimDir = simDir.replace(workspaceRoot, "").replaceAll("\\", "/"); |
| 88 | +mkdirSync(simDir, { recursive: true }); |
| 89 | + |
| 90 | +// Run cargo-msfs |
| 91 | +await $`docker run \ |
| 92 | + --rm -t \ |
| 93 | + --name msfs-${simVersion}-wasm-builder \ |
| 94 | + -v ${workspaceRoot}:/workspace \ |
| 95 | + -w /workspace${relativeWorkdDir} \ |
| 96 | + -e CARGO_TARGET_DIR=/workspace/targets/${simVersion} \ |
| 97 | + ${IMAGE_NAME} \ |
| 98 | + bash -c "cargo-msfs build msfs${simVersion} -i ./src/wasm -o ./${relativeSimDir}/msfs_navigation_data_interface.wasm \ |
| 99 | +1> >(sed \"s/^/[\x1b[34m${simVersion}\\x1b[0m]/\") \ |
| 100 | +2> >(sed \"s/^/[\x1b[34m${simVersion}\\x1b[0m]/\" >&2)"`.catch((err: { exitCode?: number; stderr?: Buffer }) => { |
| 101 | + console.error(`[-] Error building for ${simVersion}: ${err.exitCode} ${err.stderr?.toString()}`); |
| 102 | + process.exit(1); |
| 103 | +}); |
| 104 | + |
| 105 | +copyFile( |
| 106 | + `${join(simDir, "msfs_navigation_data_interface.wasm")}`, |
| 107 | + `${join(panelDir, "msfs_navigation_data_interface.wasm")}`, |
| 108 | + constants.COPYFILE_FICLONE, |
| 109 | + err => { |
| 110 | + if (err) { |
| 111 | + console.error("[-] Wasm module copy failed "); |
117 | 112 | process.exit(1); |
118 | | - }); |
119 | | - }), |
| 113 | + } |
| 114 | + |
| 115 | + console.info(`[*] Copying WASM module to aircraft panel folder`); |
| 116 | + }, |
120 | 117 | ); |
0 commit comments