diff --git a/packages/core/src/build/app.js b/packages/core/src/build/app.js index 6ee8271d..a2935c1a 100644 --- a/packages/core/src/build/app.js +++ b/packages/core/src/build/app.js @@ -12,7 +12,7 @@ export default async (root, config) => { postbuild: [], bindings: {}, roots: [], - targets: { web }, + targets: { web: { target: web } }, importmaps: {}, assets: [], path, diff --git a/packages/core/src/build/hook/build.js b/packages/core/src/build/hook/build.js index 745fa840..2fdfd5dd 100644 --- a/packages/core/src/build/hook/build.js +++ b/packages/core/src/build/hook/build.js @@ -14,11 +14,15 @@ import $router from "./router.js"; const html = /^.*.html$/u; const pre = async (app, mode, target) => { - if (app.targets[target] === undefined) { + let target$ = target; + if (app.targets[target$] === undefined) { throw new Error(`target ${dim(target)} does not exist`); } - app.build_target = target; - log.system(`starting ${dim(target)} build in ${dim(mode)} mode`); + if (app.targets[target$].forward) { + target$ = app.targets[target$].forward; + } + app.build_target = target$; + log.system(`starting ${dim(target$)} build in ${dim(mode)} mode`); app.build = new Build({ ...exclude(app.get("build"), ["includes", "index"]), @@ -147,7 +151,7 @@ const post = async (app, mode, target) => { await app.build.start(); // a target needs to create an `assets.js` that exports assets - await app.targets[target](app); + await app.targets[app.build_target].target(app); const build_number = crypto.randomUUID().slice(0, 8); const build_directory = app.path.build.join(build_number); diff --git a/packages/native/src/desktop.js b/packages/native/src/desktop.js index 77d0c824..46aa0134 100644 --- a/packages/native/src/desktop.js +++ b/packages/native/src/desktop.js @@ -81,7 +81,7 @@ export default async app => { return Webview; } }; - const target = "desktop"; + const target = "${app.build_target}"; export { assets, loader, target }; `; diff --git a/packages/native/src/index.js b/packages/native/src/index.js index 045b77ae..be37b226 100644 --- a/packages/native/src/index.js +++ b/packages/native/src/index.js @@ -1,9 +1,9 @@ import dim from "@rcompat/cli/color/dim"; import execute from "@rcompat/stdio/execute"; -import desktop from "./desktop.js"; import targets from "./targets.js"; import log from "@primate/core/log"; +const target_keys = Object.keys(targets); const command = "bun build build/serve.js --conditions=runtime --compile --minify"; export default ({ @@ -12,11 +12,11 @@ export default ({ return { name: "primate:native", init(app, next) { - Object.keys(targets).forEach(target => app.target(target, desktop)); + target_keys.forEach(target => app.target(target, targets[target])); return next(app); }, build(app, next) { - if (app.build_target === "linux-x64") { + if (target_keys.includes(app.build_target)) { app.done(async () => { const { flags, exe } = targets[app.build_target]; const executable_path = dim(`${app.path.build}/${exe}`); @@ -27,7 +27,7 @@ export default ({ return next(app); }, async serve(app, next) { - if (app.build_target === "desktop") { + if (target_keys.includes(app.build_target)) { const Webview = app.loader.webview(); const webview = new Webview(); const { host, port } = app.get("http"); diff --git a/packages/native/src/targets.js b/packages/native/src/targets.js index 57dc416b..9232c25a 100644 --- a/packages/native/src/targets.js +++ b/packages/native/src/targets.js @@ -1,25 +1,31 @@ +import target from "./desktop.js"; + const desktop = { - flags: "", + forward: `${process.platform}-${process.arch}`, }; const linux_x64 = { flags: "--target=bun-linux-x64", exe: "app", + target, }; const windows_x64 = { flags: "--target=bun-windows-x64", exe: "app.exe", + target, }; const darwin_x64 = { flags: "--target=bun-darwin-x64", exe: "app", + target, }; const darwin_arm64 = { flags: "--target=bun-darwin-arm64", exe: "app", + target, }; export default {