@bake-native/core 0.0.0 → 0.1.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/THIRD_PARTY_NOTICES.txt +548 -0
- package/bake-prelude.js +189 -0
- package/batch-contract.json +21 -0
- package/batch-wire.js +674 -0
- package/compat.json +64 -0
- package/controls.css +108 -0
- package/determinism.js +175 -0
- package/devtools.d.ts +13 -0
- package/devtools.js +73 -0
- package/dialogs.js +59 -0
- package/direct-style.js +105 -0
- package/direct-table.js +261 -0
- package/dist/bake.mjs +2211 -0
- package/dist/build-CMsvCcZ0.mjs +1 -0
- package/dist/build-CkLSZw06.mjs +5514 -0
- package/dist/build-tools-Dxyl6XAf.mjs +80 -0
- package/dist/client-Cm7o6dQd.mjs +17544 -0
- package/dist/compiler.mjs +4 -0
- package/dist/config-B1W8gfZY.mjs +12 -0
- package/dist/dev-Cskd8Hl4.mjs +986 -0
- package/dist/direct-report-Bdda-k_Y.mjs +153 -0
- package/dist/direct-report-Du44nNWl.mjs +1 -0
- package/dist/index.d.mts +176 -0
- package/dist/index.mjs +1 -0
- package/dist/intl-ROnAp2qO.mjs +75 -0
- package/dist/jiti-stub-CKcaShwE.mjs +5 -0
- package/dist/native-views-BuzB9x5H.mjs +7849 -0
- package/dist/octane/package.json +5 -0
- package/dist/package-KkUSMoji.mjs +2784 -0
- package/dist/react/package.json +13 -0
- package/dist/rolldown-runtime-D3KUYPsf.mjs +12 -0
- package/dist/run-D2aPm54a.mjs +6632 -0
- package/dist/scope-8W2aIuQ9.mjs +262 -0
- package/dist/screens/BakeNativeScreen.native.ts +9 -0
- package/dist/screens/package.json +5 -0
- package/dom-exception.js +31 -0
- package/element-api.js +158 -0
- package/first-screen.js +30 -0
- package/fonts/Geist-Italic-Variable.ttf +0 -0
- package/fonts/Geist-Variable.ttf +0 -0
- package/fonts/GeistMono-Italic-Variable.ttf +0 -0
- package/fonts/GeistMono-Variable.ttf +0 -0
- package/fonts/OFL.txt +93 -0
- package/fonts/README.md +27 -0
- package/fonts/geist-italic.css +8 -0
- package/fonts/geist-mono-italic.css +8 -0
- package/fonts/geist-mono.css +8 -0
- package/fonts/geist.css +8 -0
- package/header-icons.json +53 -0
- package/host-runtime.js +508 -0
- package/image-props.js +17 -0
- package/index.d.ts +8 -0
- package/index.js +7 -0
- package/licenses/Apache-2.0.txt +73 -0
- package/locale-entry.d.ts +1 -0
- package/locale-entry.js +1 -0
- package/locale.d.ts +28 -0
- package/locale.js +124 -0
- package/markup-support.js +87 -0
- package/media-element.js +115 -0
- package/native-args-entry.js +2 -0
- package/native-args.d.ts +7 -0
- package/native-args.js +155 -0
- package/native-entry.js +1 -0
- package/native-globals.d.ts +156 -0
- package/native-scenarios.d.ts +17 -0
- package/native-scenarios.js +46 -0
- package/native-support.json +349 -0
- package/native.d.ts +52 -0
- package/native.js +237 -0
- package/package.json +142 -4
- package/page-elements.js +123 -0
- package/runtime-provides.json +412 -0
- package/safe-area.d.ts +1 -0
- package/safe-area.js +44 -0
- package/swift-ui/modifiers.js +164 -0
- package/tab-icons.js +62 -0
- package/templates/create/tabs/AGENTS.md +22 -0
- package/templates/create/tabs/README.md +43 -0
- package/templates/create/tabs/_gitignore +13 -0
- package/templates/create/tabs/android/app/build.gradle.kts +79 -0
- package/templates/create/tabs/android/app/src/main/AndroidManifest.xml +39 -0
- package/templates/create/tabs/android/app/src/main/kotlin/MainActivity.kt +35 -0
- package/templates/create/tabs/android/app/src/main/res/values/themes.xml +8 -0
- package/templates/create/tabs/android/build.gradle.kts +5 -0
- package/templates/create/tabs/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/templates/create/tabs/android/gradle/wrapper/gradle-wrapper.properties +9 -0
- package/templates/create/tabs/android/gradle.properties +3 -0
- package/templates/create/tabs/android/gradlew +248 -0
- package/templates/create/tabs/android/settings.gradle.kts +47 -0
- package/templates/create/tabs/bake.config.ts +10 -0
- package/templates/create/tabs/ios/App/App.swift +30 -0
- package/templates/create/tabs/ios/build.sh +23 -0
- package/templates/create/tabs/ios/project.yml +57 -0
- package/templates/create/tabs/macos/Package.swift +24 -0
- package/templates/create/tabs/macos/Sources/__SWIFT_NAME__/App.swift +146 -0
- package/templates/create/tabs/macos/build.sh +4 -0
- package/templates/create/tabs/package.json +23 -0
- package/templates/create/tabs/pnpm-workspace.yaml +6 -0
- package/templates/create/tabs/src/App.tsrx +92 -0
- package/templates/create/tabs/src/App.tsx +67 -0
- package/templates/create/tabs/src/styles.css +32 -0
- package/templates/create/tabs/tsconfig.json +5 -0
- package/templates/create/tabs/windows/Cargo.toml +29 -0
- package/templates/create/tabs/windows/build.rs +9 -0
- package/templates/create/tabs/windows/src/main.rs +52 -0
- package/templates/create/tabs/windows/src/shell.rs +316 -0
- package/templates/module/__NAME__.kt +20 -0
- package/templates/module/__NAME__.native.ts +24 -0
- package/templates/module/__NAME__.swift +25 -0
- package/templates/module/__NAME__.web.ts +13 -0
- package/templates/module/__NAME__Test.kt +26 -0
- package/templates/module/__NAME__Tests.swift +25 -0
- package/templates/module/__SNAKE__.rs +43 -0
- package/text.d.ts +20 -0
- package/text.js +100 -0
- package/transform-entry.js +1 -0
- package/transform.d.ts +15 -0
- package/transform.js +98 -0
- package/tsconfig.native.json +16 -0
- package/ui/scope.js +103 -0
- package/ui/swift.js +106 -0
- package/ui/ui.css +272 -0
- package/view-ref-writer.js +268 -0
- package/view-ref.d.ts +26 -0
- package/view-ref.js +85 -0
- package/views/Video.native.ts +68 -0
- package/views/generated/VideoViewAndroid.h +68 -0
- package/views/generated/VideoViewJSI.h +94 -0
- package/views/generated/VideoViewSpec.kt +113 -0
- package/views/generated/apple/VideoViewJSI/VideoViewJSIApple.cpp +40 -0
- package/views/generated/apple/VideoViewJSI/include/VideoViewJSIApple.h +28 -0
- package/views/generated/apple/VideoViewSpec/VideoViewInterop.swift +39 -0
- package/views/generated/apple/VideoViewSpec/VideoViewSpec.swift +186 -0
- package/views/generated/video_view_spec.rs +189 -0
- package/views.d.ts +24 -0
- package/views.js +45 -0
- package/virtual-window.js +35 -0
- package/visibility.js +75 -0
- package/web-crypto.js +84 -0
- package/web-fetch.js +1071 -0
- package/README.md +0 -3
package/dist/bake.mjs
ADDED
|
@@ -0,0 +1,2211 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { t as __exportAll } from "./rolldown-runtime-D3KUYPsf.mjs";
|
|
3
|
+
import { closeSync, copyFileSync, cpSync, existsSync, fstatSync, mkdirSync, mkdtempSync, openSync, readFileSync, readSync, readdirSync, realpathSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
4
|
+
import { basename, dirname, extname, join, relative, resolve, sep } from "node:path";
|
|
5
|
+
import { C as flag, D as integer, E as float, F as optional, I as withDefault, M as or, N as map, O as string, P as multiple, S as constant, T as choice, _ as inspectRequest, b as argument, g as inspectParser, j as object, l as inspectParsed, w as option, wt as message, x as command } from "./client-Cm7o6dQd.mjs";
|
|
6
|
+
import { c as TARGETS, d as targetList$1, f as writeMobileApp, l as loadBakeConfig, n as aarPackageManifest, r as checkAar, s as DEFAULT_CONFIG_TARGETS, t as run, u as resolveTargets } from "./run-D2aPm54a.mjs";
|
|
7
|
+
import { A as writeRegistration, C as bundleAppModules, D as registrationFiles, E as checkoutRelative, G as toolchainFor, I as repo, J as execToolBuffer, L as toolProcessEnv, N as defaultHermesc, P as nativeTool, R as COMPAT, S as appViewUnit, T as bundleViews, W as toolchainDir, Z as NOTICES_JSON, a as androidIdentity, b as FAMILY, d as thirdPartyDeclarations, et as mergeComponents, k as targetNativeDeps, n as packageConfig, nt as readNoticesJson, q as execTool, rt as writeOutputNotices, s as integrateThirdParty, tt as placedAt, w as bundleModules, x as appModuleSources } from "./package-KkUSMoji.mjs";
|
|
8
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
9
|
+
import { execFileSync } from "node:child_process";
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
import { A as moduleDir, C as MODULES_DIR, D as compareVersions, E as buildRegistry, F as registryLocation, I as satisfies, J as unpinnedPackages, L as sha256$1, M as openRegistry, N as parseRequest, O as filesFor, P as readLock, S as LOCK_FILE, T as appModules, Ut as packageRoot$1, X as merge3, Y as diffStat, Z as unifiedDiff, _ as specsSchema, at as releaseCheck, f as generateSpecs, j as normalize$1, k as lockEntry, o as viewFiles, r as viewCatalog, s as viewIssues, t as readViewSpec, u as appModuleSpecs, x as ALL_TARGETS, z as writeLock } from "./native-views-BuzB9x5H.mjs";
|
|
12
|
+
import { n as loadReactCompiler, r as selectRenderer } from "./build-tools-Dxyl6XAf.mjs";
|
|
13
|
+
// src/apple-runtime.ts
|
|
14
|
+
/** The runtime's files in the toolchain package's apple/ directory. */
|
|
15
|
+
const APPLE_RUNTIME_ARCHIVE = "BakeNative.xcframework.zip";
|
|
16
|
+
const APPLE_RUNTIME_STAMP = "runtime.json";
|
|
17
|
+
/** Where the runtime is unpacked in an app, relative to its root. */
|
|
18
|
+
const APPLE_RUNTIME_DIR = ".bake/native/bakenative";
|
|
19
|
+
/** The slices every runtime has: their Swift module is what a host app imports. */
|
|
20
|
+
const APPLE_RUNTIME_SLICES = {
|
|
21
|
+
"ios-arm64": "BakeNativeKit",
|
|
22
|
+
"ios-arm64-simulator": "BakeNativeKit",
|
|
23
|
+
"macos-arm64": "BakeNativeAppKit"
|
|
24
|
+
};
|
|
25
|
+
/** The reasons a runtime is not this table's; [] when it is. */
|
|
26
|
+
function appleRuntimeIssues(table, runtime) {
|
|
27
|
+
const v = table["@bake-native/core"];
|
|
28
|
+
const { stamp, package: pkg } = runtime;
|
|
29
|
+
const issues = [];
|
|
30
|
+
if (pkg && pkg.version !== v) issues.push(`it comes from ${pkg.name} ${pkg.version}, but @bake-native/core is ${v}: the two are released together. Install ${pkg.name}@${v}.`);
|
|
31
|
+
if (stamp["@bake-native/core"] !== v) issues.push(`it was built for @bake-native/core ${stamp["@bake-native/core"]}, not ${v}`);
|
|
32
|
+
if (stamp.runtime?.version !== table.runtime.version || stamp.runtime?.series !== table.runtime.series) issues.push(`it is runtime ${stamp.runtime?.version} (series ${stamp.runtime?.series}); @bake-native/core ${v} builds bundles for runtime ${table.runtime.version} (series ${table.runtime.series})`);
|
|
33
|
+
if (stamp.hostProtocol !== table.hostProtocol) issues.push(`it understands host protocol ${stamp.hostProtocol}; @bake-native/core ${v} writes ${table.hostProtocol}`);
|
|
34
|
+
if (stamp.hermes?.bytecode !== table.hermes.bytecode) issues.push(`its Hermes runs bytecode v${stamp.hermes?.bytecode}; @bake-native/core ${v} compiles app.hbc to v${table.hermes.bytecode}`);
|
|
35
|
+
if (stamp.schemaDigest !== table.schemaDigest) issues.push(`it has host schema ${stamp.schemaDigest}; @bake-native/core ${v} has ${table.schemaDigest}`);
|
|
36
|
+
if (stamp.batchDigest !== table.batchDigest) issues.push(`it reads renderer batch schema ${stamp.batchDigest}; @bake-native/core ${v} writes ${table.batchDigest}`);
|
|
37
|
+
for (const [slice, module] of Object.entries(APPLE_RUNTIME_SLICES)) if (stamp.slices?.[slice] !== module) issues.push(`it has no ${slice} slice with ${module}.framework`);
|
|
38
|
+
return issues;
|
|
39
|
+
}
|
|
40
|
+
const checkoutHint = "Or build against an BakeNative source checkout: bake native link --bakenative <checkout> (docs: installation#build-from-source).";
|
|
41
|
+
/** Why this host has no installed Apple runtime, and what to do instead. */
|
|
42
|
+
function missingReason() {
|
|
43
|
+
const v = COMPAT["@bake-native/core"];
|
|
44
|
+
const key = `${process.platform}-${process.arch}`;
|
|
45
|
+
const entry = toolchainFor();
|
|
46
|
+
const hosts = Object.entries(COMPAT.toolchain).filter(([, t]) => t.apple?.length).map(([k]) => k);
|
|
47
|
+
if (!entry?.apple?.length) return `@bake-native/core ${v} ships the prebuilt Apple runtime for ${hosts.join(", ") || "no host"} only, and this is ${key}. ${checkoutHint}`;
|
|
48
|
+
if (!toolchainDir()) return `${entry.package}@${v} is not installed: @bake-native/core brings it as an optional dependency, which --no-optional / --omit=optional or a lockfile made on another platform leaves out. Reinstall @bake-native/core with optional dependencies (npm install --include=optional). ${checkoutHint}`;
|
|
49
|
+
return `${entry.package} is installed without apple/${APPLE_RUNTIME_ARCHIVE} and apple/${APPLE_RUNTIME_STAMP} (a broken install, or a version before the Apple runtime shipped): reinstall @bake-native/core. ${checkoutHint}`;
|
|
50
|
+
}
|
|
51
|
+
/** The runtime in `dir` (a toolchain package's apple/ directory); throws when it is not one. */
|
|
52
|
+
function readAppleRuntime(dir) {
|
|
53
|
+
const file = join(dir, APPLE_RUNTIME_STAMP);
|
|
54
|
+
let stamp;
|
|
55
|
+
try {
|
|
56
|
+
stamp = JSON.parse(readFileSync(file, "utf8"));
|
|
57
|
+
} catch (e) {
|
|
58
|
+
throw new Error(`the Apple runtime's ${file} cannot be read (${e.message}): reinstall @bake-native/core`);
|
|
59
|
+
}
|
|
60
|
+
let pkg = null;
|
|
61
|
+
try {
|
|
62
|
+
const { name, version } = JSON.parse(readFileSync(join(dirname(dir), "package.json"), "utf8"));
|
|
63
|
+
if (typeof name === "string" && typeof version === "string") pkg = {
|
|
64
|
+
name,
|
|
65
|
+
version
|
|
66
|
+
};
|
|
67
|
+
} catch {}
|
|
68
|
+
return {
|
|
69
|
+
dir,
|
|
70
|
+
stamp,
|
|
71
|
+
package: pkg
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/** This host's installed Apple runtime (its toolchain package's apple/); throws with the reason
|
|
75
|
+
* and the fix when there is none. */
|
|
76
|
+
function installedAppleRuntime() {
|
|
77
|
+
const dir = toolchainDir();
|
|
78
|
+
const apple = dir && toolchainFor()?.apple?.length ? join(dir, "apple") : null;
|
|
79
|
+
if (!apple || !existsSync(join(apple, "BakeNative.xcframework.zip")) || !existsSync(join(apple, "runtime.json"))) throw new Error(`the prebuilt Apple runtime is not available: ${missingReason()}`);
|
|
80
|
+
return readAppleRuntime(apple);
|
|
81
|
+
}
|
|
82
|
+
/** Throws one error naming every mismatch between a runtime and the version table. */
|
|
83
|
+
function assertAppleRuntime(runtime, table = COMPAT) {
|
|
84
|
+
const issues = appleRuntimeIssues(table, runtime);
|
|
85
|
+
if (issues.length) throw new Error(`the Apple runtime in ${runtime.dir} does not match @bake-native/core ${table["@bake-native/core"]}'s version table (@bake-native/core/compat.json):\n ${issues.join("\n ")}\nReinstall @bake-native/core so both come from one release. ${checkoutHint}`);
|
|
86
|
+
}
|
|
87
|
+
/** Deployment targets: keep equal to the root Package.swift and xcframework.mjs (IOS_MIN, MACOS_MIN). */
|
|
88
|
+
const PLATFORMS = ".macOS(\"14.0\"), .iOS(\"16.0\")";
|
|
89
|
+
/** Package.swift of the unpacked runtime: the package the app and BakeNativeAppModules depend on by
|
|
90
|
+
* path, with the products an BakeNative checkout gives the same names. */
|
|
91
|
+
function appleRuntimePackageSwift(stamp) {
|
|
92
|
+
const products = [...new Set(Object.values(APPLE_RUNTIME_SLICES))];
|
|
93
|
+
return `// swift-tools-version: 5.9
|
|
94
|
+
// BakeNative ${stamp["@bake-native/core"]}: the prebuilt Apple runtime (BakeNative.xcframework: ${Object.entries(APPLE_RUNTIME_SLICES).map(([slice, module]) => `${module} for ${slice}`).join(", ")}).
|
|
95
|
+
// Unpacked by \`bake native link\` from the installed @bake-native/core toolchain package. Do not edit:
|
|
96
|
+
// the next build writes it again.
|
|
97
|
+
import PackageDescription
|
|
98
|
+
|
|
99
|
+
let package = Package(
|
|
100
|
+
name: "BakeNative",
|
|
101
|
+
platforms: [${PLATFORMS}],
|
|
102
|
+
products: [
|
|
103
|
+
${products.map((p) => ` .library(name: "${p}", targets: ["BakeNative"]),`).join("\n")}
|
|
104
|
+
],
|
|
105
|
+
targets: [
|
|
106
|
+
.binaryTarget(name: "BakeNative", path: "BakeNative.xcframework"),
|
|
107
|
+
]
|
|
108
|
+
)
|
|
109
|
+
`;
|
|
110
|
+
}
|
|
111
|
+
const sha256 = (file) => createHash("sha256").update(readFileSync(file)).digest("hex");
|
|
112
|
+
/**
|
|
113
|
+
* Unpacks `runtime` into <root>/.bake/native/bakenative as the local Swift package `BakeNative`, after
|
|
114
|
+
* checking it against the version table and its archive against runtime.json. An unpacked copy
|
|
115
|
+
* of the same archive is left untouched (no file changes, so Xcode and SwiftPM do not rebuild).
|
|
116
|
+
* Returns { dir, written }.
|
|
117
|
+
*/
|
|
118
|
+
function materializeAppleRuntime(root, runtime = installedAppleRuntime(), table = COMPAT) {
|
|
119
|
+
assertAppleRuntime(runtime, table);
|
|
120
|
+
const dir = join(root, APPLE_RUNTIME_DIR);
|
|
121
|
+
const marker = join(dir, APPLE_RUNTIME_STAMP);
|
|
122
|
+
const manifest = appleRuntimePackageSwift(runtime.stamp);
|
|
123
|
+
const want = JSON.stringify(runtime.stamp, null, 2) + "\n";
|
|
124
|
+
const same = (file, text) => existsSync(file) && readFileSync(file, "utf8") === text;
|
|
125
|
+
if (same(marker, want) && same(join(dir, "Package.swift"), manifest) && existsSync(join(dir, "BakeNative.xcframework/Info.plist"))) return {
|
|
126
|
+
dir,
|
|
127
|
+
written: false
|
|
128
|
+
};
|
|
129
|
+
if (process.platform !== "darwin") throw new Error("the Apple runtime is unpacked with ditto: build iOS and macOS hosts on macOS");
|
|
130
|
+
const archive = join(runtime.dir, APPLE_RUNTIME_ARCHIVE);
|
|
131
|
+
const digest = sha256(archive);
|
|
132
|
+
if (digest !== runtime.stamp.sha256) throw new Error(`${archive} is not the archive its ${APPLE_RUNTIME_STAMP} names (SHA-256 ${digest}, expected ${runtime.stamp.sha256}): a broken install. Reinstall @bake-native/core.`);
|
|
133
|
+
const tmp = `${dir}.${process.pid}.tmp`;
|
|
134
|
+
rmSync(tmp, {
|
|
135
|
+
recursive: true,
|
|
136
|
+
force: true
|
|
137
|
+
});
|
|
138
|
+
mkdirSync(tmp, { recursive: true });
|
|
139
|
+
try {
|
|
140
|
+
execFileSync("ditto", [
|
|
141
|
+
"-x",
|
|
142
|
+
"-k",
|
|
143
|
+
archive,
|
|
144
|
+
tmp
|
|
145
|
+
], { stdio: [
|
|
146
|
+
"ignore",
|
|
147
|
+
"pipe",
|
|
148
|
+
"pipe"
|
|
149
|
+
] });
|
|
150
|
+
if (!existsSync(join(tmp, "BakeNative.xcframework/Info.plist"))) throw new Error(`${archive} has no BakeNative.xcframework at its root`);
|
|
151
|
+
writeFileSync(join(tmp, "Package.swift"), manifest);
|
|
152
|
+
writeFileSync(join(tmp, APPLE_RUNTIME_STAMP), want);
|
|
153
|
+
rmSync(dir, {
|
|
154
|
+
recursive: true,
|
|
155
|
+
force: true
|
|
156
|
+
});
|
|
157
|
+
renameSync(tmp, dir);
|
|
158
|
+
} catch (e) {
|
|
159
|
+
rmSync(tmp, {
|
|
160
|
+
recursive: true,
|
|
161
|
+
force: true
|
|
162
|
+
});
|
|
163
|
+
throw e;
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
dir,
|
|
167
|
+
written: true
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
// src/bake-add.mjs
|
|
171
|
+
var bake_add_exports = /* @__PURE__ */ __exportAll({
|
|
172
|
+
ALL_TARGETS: () => ALL_TARGETS,
|
|
173
|
+
addModules: () => addModules$1,
|
|
174
|
+
diffModules: () => diffModules$1,
|
|
175
|
+
removeModule: () => removeModule$1,
|
|
176
|
+
upgradeModules: () => upgradeModules$1
|
|
177
|
+
});
|
|
178
|
+
const rel = (root, p) => relative(root, p).split(sep).join("/");
|
|
179
|
+
const read = (file) => existsSync(file) ? normalize$1(readFileSync(file, "utf8")) : null;
|
|
180
|
+
const stat = (before, after) => {
|
|
181
|
+
const { added, removed } = diffStat(before ?? "", after ?? "");
|
|
182
|
+
return `+${added} -${removed}`;
|
|
183
|
+
};
|
|
184
|
+
/**
|
|
185
|
+
* Opens registries by location once per command. `ctx`: { root, registries (bake.config.ts),
|
|
186
|
+
* repo (the checkout bake runs from, for the official registry), registry (--registry) }.
|
|
187
|
+
*/
|
|
188
|
+
function registries(ctx) {
|
|
189
|
+
const open = /* @__PURE__ */ new Map();
|
|
190
|
+
/** The registry of a lock entry or request: { reg, label } (label: what the lock records). */
|
|
191
|
+
return async function get(alias) {
|
|
192
|
+
const label = ctx.registry ?? alias ?? "bakenative";
|
|
193
|
+
const location = ctx.registry ?? registryLocation(alias ?? "bakenative", {
|
|
194
|
+
registries: ctx.registries,
|
|
195
|
+
repo: ctx.repo
|
|
196
|
+
});
|
|
197
|
+
const key = typeof location === "string" ? location : location.url;
|
|
198
|
+
if (!open.has(key)) open.set(key, openRegistry(location, {
|
|
199
|
+
cwd: ctx.root,
|
|
200
|
+
label
|
|
201
|
+
}));
|
|
202
|
+
return {
|
|
203
|
+
reg: await open.get(key),
|
|
204
|
+
label
|
|
205
|
+
};
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
/** The base item of a locked module: the registry's copy of the locked version, checked against the lock. */
|
|
209
|
+
async function lockedItem(reg, name, entry) {
|
|
210
|
+
const item = await reg.item(name, entry.version);
|
|
211
|
+
if (entry.sha256 && item.sha256 !== entry.sha256) throw new Error(`${name}@${entry.version} in registry ${reg.label} is not the one ${LOCK_FILE} recorded (sha256 ${item.sha256.slice(0, 12)}…, locked ${entry.sha256.slice(0, 12)}…): a published version changed in place. Do not trust it; ask the registry's owner, or pin another registry with --registry.`);
|
|
212
|
+
return item;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Copies modules into native/<name>/. `requests`: ['clipboard', 'acme/camera@1.2.0'].
|
|
216
|
+
* `ctx`: { root, targets, registries, repo, registry, overwrite, dryRun, bakeVersion, log }.
|
|
217
|
+
*/
|
|
218
|
+
async function addModules$1(requests, ctx) {
|
|
219
|
+
const { root, targets, log = () => {} } = ctx;
|
|
220
|
+
const get = registries(ctx);
|
|
221
|
+
const lock = readLock(root);
|
|
222
|
+
const queue = requests.map((r) => ({
|
|
223
|
+
...parseRequest(r),
|
|
224
|
+
requested: true
|
|
225
|
+
}));
|
|
226
|
+
const done = /* @__PURE__ */ new Set();
|
|
227
|
+
const results = [];
|
|
228
|
+
const warnings = [];
|
|
229
|
+
while (queue.length) {
|
|
230
|
+
const req = queue.shift();
|
|
231
|
+
if (done.has(req.name)) continue;
|
|
232
|
+
done.add(req.name);
|
|
233
|
+
const locked = lock.modules[req.name];
|
|
234
|
+
if (!req.requested && locked) continue;
|
|
235
|
+
const { reg, label } = await get(req.registry ?? (locked && !ctx.registry ? locked.registry : null));
|
|
236
|
+
const item = await reg.item(req.name, req.version ?? void 0);
|
|
237
|
+
if (ctx.bakeVersion && !satisfies(ctx.bakeVersion, item.bake)) throw new Error(`${item.name}@${item.version} needs bake ${item.bake}; this is @bake-native/core ${ctx.bakeVersion} (update @bake-native/core, or add an older version: bake add ${item.name}@<version>)`);
|
|
238
|
+
if (locked && locked.version !== item.version && !ctx.overwrite) throw new Error(`${item.name}@${locked.version} is already in ${MODULES_DIR}/${item.name}: bake upgrade ${item.name} merges ${item.version} into it (bake diff ${item.name} shows the changes first)`);
|
|
239
|
+
const unsupported = targets.filter((t) => !item.platforms.includes(t));
|
|
240
|
+
if (unsupported.length) warnings.push(`${item.name}@${item.version} has no ${unsupported.join(", ")} implementation (it implements ${item.platforms.join(", ") || "no target"}): a ${unsupported.join(" or ")} build that calls native.${item.module} fails until native/${item.name} has one`);
|
|
241
|
+
const dir = moduleDir(root, item.name);
|
|
242
|
+
const files = filesFor(item.files, targets);
|
|
243
|
+
const changes = [];
|
|
244
|
+
const blocked = [];
|
|
245
|
+
for (const f of files) {
|
|
246
|
+
const dest = join(dir, f.path);
|
|
247
|
+
const local = read(dest);
|
|
248
|
+
if (local === f.content) {
|
|
249
|
+
changes.push({
|
|
250
|
+
path: f.path,
|
|
251
|
+
op: "="
|
|
252
|
+
});
|
|
253
|
+
continue;
|
|
254
|
+
}
|
|
255
|
+
if (local !== null && !ctx.overwrite) {
|
|
256
|
+
if (locked?.version === item.version && f.path in locked.files) {
|
|
257
|
+
changes.push({
|
|
258
|
+
path: f.path,
|
|
259
|
+
op: "kept"
|
|
260
|
+
});
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
263
|
+
blocked.push(f.path);
|
|
264
|
+
continue;
|
|
265
|
+
}
|
|
266
|
+
changes.push({
|
|
267
|
+
path: f.path,
|
|
268
|
+
op: local === null ? "A" : "M",
|
|
269
|
+
stat: stat(local, f.content),
|
|
270
|
+
content: f.content,
|
|
271
|
+
before: local
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
if (blocked.length) throw new Error(`${MODULES_DIR}/${item.name}: ${blocked.join(", ")} ${blocked.length === 1 ? "differs" : "differ"} from ${item.name}@${item.version} and would be overwritten: bake diff ${item.name} shows the difference; pass --overwrite to replace ${blocked.length === 1 ? "it" : "them"} with the registry's copy`);
|
|
275
|
+
if (!ctx.dryRun) {
|
|
276
|
+
for (const c of changes.filter((c) => c.op === "A" || c.op === "M")) {
|
|
277
|
+
mkdirSync(dirname(join(dir, c.path)), { recursive: true });
|
|
278
|
+
writeFileSync(join(dir, c.path), c.content);
|
|
279
|
+
}
|
|
280
|
+
const keep = Object.keys(locked?.version === item.version ? locked.files : {}).filter((p) => existsSync(join(dir, p)));
|
|
281
|
+
lock.modules[item.name] = lockEntry(item, label, [.../* @__PURE__ */ new Set([...files.map((f) => f.path), ...keep])]);
|
|
282
|
+
writeLock(root, lock);
|
|
283
|
+
}
|
|
284
|
+
results.push({
|
|
285
|
+
name: item.name,
|
|
286
|
+
module: item.module,
|
|
287
|
+
version: item.version,
|
|
288
|
+
registry: label,
|
|
289
|
+
platforms: item.platforms,
|
|
290
|
+
unsupported,
|
|
291
|
+
files: changes.map(({ content, before, ...c }) => c)
|
|
292
|
+
});
|
|
293
|
+
for (const d of item.dependencies) if (!done.has(d)) queue.push({
|
|
294
|
+
registry: req.registry,
|
|
295
|
+
name: d,
|
|
296
|
+
version: null,
|
|
297
|
+
requested: false
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
for (const r of results) {
|
|
301
|
+
log(`${ctx.dryRun ? "would add" : "✓"} ${r.name}@${r.version} (${r.module}; ${r.registry}; implements ${r.platforms.join(", ")})`);
|
|
302
|
+
for (const f of r.files) log(` ${f.op} ${MODULES_DIR}/${r.name}/${f.path}${f.stat ? ` (${f.stat})` : f.op === "=" ? " (unchanged)" : ""}`);
|
|
303
|
+
}
|
|
304
|
+
for (const w of warnings) log(`warning: ${w}`);
|
|
305
|
+
if (results.length && !ctx.dryRun) {
|
|
306
|
+
log(` ${LOCK_FILE} records ${results.map((r) => `${r.name}@${r.version}`).join(", ")}`);
|
|
307
|
+
log(`next: call native.<Module> from src/ (the spec in ${MODULES_DIR}/<name>/<Module>.native.ts types it); the next bake build generates the glue and registers the module on every target in .bake/native/<target>`);
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
added: results,
|
|
311
|
+
warnings
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
/** The modules a command acts on: `name` (must be locked) or every locked module. */
|
|
315
|
+
function selected(lock, name) {
|
|
316
|
+
if (!name) return Object.keys(lock.modules).sort();
|
|
317
|
+
if (!lock.modules[name]) throw new Error(`${name} is not in ${LOCK_FILE} (bake add ${name} adds it)`);
|
|
318
|
+
return [name];
|
|
319
|
+
}
|
|
320
|
+
/** Files of the app's module folder that the lock does not list (the app's own additions). */
|
|
321
|
+
function untracked(dir, entry) {
|
|
322
|
+
if (!existsSync(dir)) return [];
|
|
323
|
+
const walk = (d) => readdirSync(d).flatMap((e) => statSync(join(d, e)).isDirectory() ? walk(join(d, e)) : [rel(dir, join(d, e))]);
|
|
324
|
+
return walk(dir).filter((p) => !(p in entry.files)).sort();
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Local edits against the locked version, and the registry's changes from the locked version
|
|
328
|
+
* to its latest (for the app's targets). `ctx`: { root, targets, registries, repo, registry,
|
|
329
|
+
* stat (no patches), log }.
|
|
330
|
+
*/
|
|
331
|
+
async function diffModules$1(name, ctx) {
|
|
332
|
+
const { root, targets, log = () => {} } = ctx;
|
|
333
|
+
const lock = readLock(root);
|
|
334
|
+
const get = registries(ctx);
|
|
335
|
+
const out = [];
|
|
336
|
+
for (const n of selected(lock, name)) {
|
|
337
|
+
const entry = lock.modules[n];
|
|
338
|
+
const { reg } = await get(ctx.registry ? null : entry.registry);
|
|
339
|
+
const base = await lockedItem(reg, n, entry);
|
|
340
|
+
const latestVersion = reg.entry(n).latest;
|
|
341
|
+
const latest = latestVersion === entry.version ? base : await reg.item(n, latestVersion);
|
|
342
|
+
const dir = moduleDir(root, n);
|
|
343
|
+
const local = [];
|
|
344
|
+
for (const f of base.files.filter((f) => f.path in entry.files)) {
|
|
345
|
+
const text = read(join(dir, f.path));
|
|
346
|
+
if (text === f.content) continue;
|
|
347
|
+
local.push({
|
|
348
|
+
path: f.path,
|
|
349
|
+
op: text === null ? "D" : "M",
|
|
350
|
+
stat: stat(f.content, text),
|
|
351
|
+
patch: unifiedDiff(f.content, text, {
|
|
352
|
+
from: `a/${f.path} (${n}@${entry.version})`,
|
|
353
|
+
to: `b/${f.path} (local)`
|
|
354
|
+
})
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
const upstream = [];
|
|
358
|
+
if (latest !== base) {
|
|
359
|
+
const want = filesFor(latest.files, targets);
|
|
360
|
+
const paths = [.../* @__PURE__ */ new Set([...want.map((f) => f.path), ...base.files.filter((f) => f.path in entry.files).map((f) => f.path)])].sort();
|
|
361
|
+
for (const p of paths) {
|
|
362
|
+
const a = base.files.find((f) => f.path === p)?.content ?? null;
|
|
363
|
+
const b = want.find((f) => f.path === p)?.content ?? null;
|
|
364
|
+
if (a === b) continue;
|
|
365
|
+
upstream.push({
|
|
366
|
+
path: p,
|
|
367
|
+
op: a === null ? "A" : b === null ? "D" : "M",
|
|
368
|
+
stat: stat(a, b),
|
|
369
|
+
patch: unifiedDiff(a, b, {
|
|
370
|
+
from: `a/${p} (${n}@${entry.version})`,
|
|
371
|
+
to: `b/${p} (${n}@${latestVersion})`
|
|
372
|
+
})
|
|
373
|
+
});
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
const missing = filesFor(base.files, targets).filter((f) => !(f.path in entry.files) && !existsSync(join(dir, f.path))).map((f) => f.path);
|
|
377
|
+
const own = untracked(dir, entry);
|
|
378
|
+
out.push({
|
|
379
|
+
name: n,
|
|
380
|
+
version: entry.version,
|
|
381
|
+
latest: latestVersion,
|
|
382
|
+
local,
|
|
383
|
+
upstream,
|
|
384
|
+
missing,
|
|
385
|
+
own
|
|
386
|
+
});
|
|
387
|
+
const state = [local.length ? `${local.length} local change${local.length === 1 ? "" : "s"}` : "no local changes", latestVersion === entry.version ? "up to date" : `${latestVersion} available`].join(", ");
|
|
388
|
+
log(`${n} ${entry.version}${latestVersion === entry.version ? "" : ` → ${latestVersion}`} (${state})`);
|
|
389
|
+
if (local.length) {
|
|
390
|
+
log(` local changes against ${n}@${entry.version}:`);
|
|
391
|
+
for (const c of local) log(` ${c.op} ${MODULES_DIR}/${n}/${c.path} (${c.stat})`);
|
|
392
|
+
}
|
|
393
|
+
if (upstream.length) {
|
|
394
|
+
log(` registry changes ${entry.version} → ${latestVersion}:`);
|
|
395
|
+
for (const c of upstream) log(` ${c.op} ${c.path} (${c.stat})`);
|
|
396
|
+
}
|
|
397
|
+
if (missing.length) log(` not copied (a target added since): ${missing.join(", ")}; bake add ${n} copies them`);
|
|
398
|
+
if (own.length) log(` the app's own files (not from the registry): ${own.join(", ")}`);
|
|
399
|
+
if (!ctx.stat) {
|
|
400
|
+
for (const c of [...local, ...upstream]) if (c.patch) log(c.patch.trimEnd());
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
if (!out.length) log(`no registry modules (${LOCK_FILE} lists none)`);
|
|
404
|
+
return { modules: out };
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Merges the registry's latest version (or `to`) into each selected module: three ways, with the
|
|
408
|
+
* locked version as the base. Conflicts are written with markers, the lock moves to the new
|
|
409
|
+
* version, and the result says so (the CLI exits 1; the build refuses the markers). `dryRun`
|
|
410
|
+
* writes nothing. `ctx`: { root, targets, registries, repo, registry, dryRun, to, bakeVersion, log }.
|
|
411
|
+
*/
|
|
412
|
+
async function upgradeModules$1(name, ctx) {
|
|
413
|
+
const { root, targets, log = () => {} } = ctx;
|
|
414
|
+
const lock = readLock(root);
|
|
415
|
+
const get = registries(ctx);
|
|
416
|
+
const out = [];
|
|
417
|
+
for (const n of selected(lock, name)) {
|
|
418
|
+
const entry = lock.modules[n];
|
|
419
|
+
const { reg, label } = await get(ctx.registry ? null : entry.registry);
|
|
420
|
+
const base = await lockedItem(reg, n, entry);
|
|
421
|
+
const target = ctx.to ?? reg.entry(n).latest;
|
|
422
|
+
if (compareVersions(target, entry.version) <= 0) {
|
|
423
|
+
if (target !== entry.version) throw new Error(`${n}: ${target} is older than the locked ${entry.version} (bake upgrade does not go back; bake add ${n}@${target} --overwrite replaces the module)`);
|
|
424
|
+
log(`${n}@${entry.version} up to date`);
|
|
425
|
+
out.push({
|
|
426
|
+
name: n,
|
|
427
|
+
from: entry.version,
|
|
428
|
+
to: entry.version,
|
|
429
|
+
files: [],
|
|
430
|
+
conflicts: 0
|
|
431
|
+
});
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
const next = await reg.item(n, target);
|
|
435
|
+
if (ctx.bakeVersion && !satisfies(ctx.bakeVersion, next.bake)) throw new Error(`${n}@${target} needs bake ${next.bake}; this is @bake-native/core ${ctx.bakeVersion}`);
|
|
436
|
+
const dir = moduleDir(root, n);
|
|
437
|
+
const want = filesFor(next.files, targets);
|
|
438
|
+
const deleted = Object.keys(entry.files).filter((p) => !existsSync(join(dir, p)));
|
|
439
|
+
if (deleted.length) throw new Error(`${MODULES_DIR}/${n}: ${deleted.join(", ")} ${deleted.length === 1 ? "was" : "were"} deleted; restore ${deleted.length === 1 ? "it" : "them"} (bake add ${n} --overwrite) or remove the module (bake remove ${n}) before upgrading`);
|
|
440
|
+
const labels = {
|
|
441
|
+
ours: `local (${MODULES_DIR}/${n})`,
|
|
442
|
+
base: `${n}@${entry.version}`,
|
|
443
|
+
theirs: `${n}@${target}`
|
|
444
|
+
};
|
|
445
|
+
const files = [];
|
|
446
|
+
const paths = [.../* @__PURE__ */ new Set([...Object.keys(entry.files), ...want.map((f) => f.path)])].sort();
|
|
447
|
+
for (const p of paths) {
|
|
448
|
+
const b = p in entry.files ? base.files.find((f) => f.path === p)?.content ?? null : null;
|
|
449
|
+
const theirs = want.find((f) => f.path === p)?.content ?? null;
|
|
450
|
+
const local = read(join(dir, p));
|
|
451
|
+
let result;
|
|
452
|
+
if (theirs === null) result = local === b ? {
|
|
453
|
+
op: "D",
|
|
454
|
+
text: null
|
|
455
|
+
} : {
|
|
456
|
+
op: "kept",
|
|
457
|
+
text: local,
|
|
458
|
+
note: `removed in ${n}@${target}; kept your edited copy (now the app's own file)`
|
|
459
|
+
};
|
|
460
|
+
else if (local === null) result = {
|
|
461
|
+
op: "A",
|
|
462
|
+
text: theirs
|
|
463
|
+
};
|
|
464
|
+
else if (local === theirs) result = {
|
|
465
|
+
op: "=",
|
|
466
|
+
text: local
|
|
467
|
+
};
|
|
468
|
+
else if (b === null) {
|
|
469
|
+
const m = merge3("", local, theirs, labels);
|
|
470
|
+
result = {
|
|
471
|
+
op: m.conflicts ? "C" : "M",
|
|
472
|
+
text: m.text,
|
|
473
|
+
conflicts: m.conflicts
|
|
474
|
+
};
|
|
475
|
+
} else if (local === b) result = {
|
|
476
|
+
op: "M",
|
|
477
|
+
text: theirs
|
|
478
|
+
};
|
|
479
|
+
else if (theirs === b) result = {
|
|
480
|
+
op: "kept",
|
|
481
|
+
text: local,
|
|
482
|
+
note: "your edit; the registry did not change it"
|
|
483
|
+
};
|
|
484
|
+
else {
|
|
485
|
+
const m = merge3(b, local, theirs, labels);
|
|
486
|
+
result = {
|
|
487
|
+
op: m.conflicts ? "C" : "merged",
|
|
488
|
+
text: m.text,
|
|
489
|
+
conflicts: m.conflicts
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
files.push({
|
|
493
|
+
path: p,
|
|
494
|
+
...result,
|
|
495
|
+
stat: stat(local, result.text)
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
const conflicts = files.reduce((k, f) => k + (f.conflicts ?? 0), 0);
|
|
499
|
+
if (!ctx.dryRun) {
|
|
500
|
+
for (const f of files) {
|
|
501
|
+
const dest = join(dir, f.path);
|
|
502
|
+
if (f.text === null) {
|
|
503
|
+
if (existsSync(dest)) rmSync(dest);
|
|
504
|
+
continue;
|
|
505
|
+
}
|
|
506
|
+
if (read(dest) === f.text) continue;
|
|
507
|
+
mkdirSync(dirname(dest), { recursive: true });
|
|
508
|
+
writeFileSync(dest, f.text);
|
|
509
|
+
}
|
|
510
|
+
lock.modules[n] = lockEntry(next, entry.registry ?? label, want.map((f) => f.path));
|
|
511
|
+
writeLock(root, lock);
|
|
512
|
+
}
|
|
513
|
+
out.push({
|
|
514
|
+
name: n,
|
|
515
|
+
from: entry.version,
|
|
516
|
+
to: target,
|
|
517
|
+
files: files.map(({ text, ...f }) => f),
|
|
518
|
+
conflicts
|
|
519
|
+
});
|
|
520
|
+
log(`${ctx.dryRun ? "would upgrade" : conflicts ? "✗" : "✓"} ${n} ${entry.version} → ${target}${conflicts ? ` (${conflicts} conflict${conflicts === 1 ? "" : "s"})` : ""}`);
|
|
521
|
+
for (const f of files.filter((f) => f.op !== "=")) log(` ${f.op.padEnd(6)} ${MODULES_DIR}/${n}/${f.path} (${f.stat})${f.note ? ` ${f.note}` : ""}${f.conflicts ? ` ${f.conflicts} conflict${f.conflicts === 1 ? "" : "s"}` : ""}`);
|
|
522
|
+
}
|
|
523
|
+
const conflicted = out.filter((m) => m.conflicts);
|
|
524
|
+
if (conflicted.length) log(`${ctx.dryRun ? "would leave" : "left"} conflict markers (<<<<<<< local … >>>>>>> registry) in ${conflicted.map((m) => `${MODULES_DIR}/${m.name}`).join(", ")}: resolve them, then build (bake build refuses a module file with markers)`);
|
|
525
|
+
return {
|
|
526
|
+
modules: out,
|
|
527
|
+
conflicts: conflicted.length
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
/** Removes a registry module: its folder (refusing edited files without `force`) and its lock entry. */
|
|
531
|
+
function removeModule$1(name, { root, force = false, dryRun = false, log = () => {} }) {
|
|
532
|
+
const lock = readLock(root);
|
|
533
|
+
const entry = lock.modules[name];
|
|
534
|
+
if (!entry) throw new Error(`${name} is not in ${LOCK_FILE}`);
|
|
535
|
+
const dir = moduleDir(root, name);
|
|
536
|
+
const edited = Object.entries(entry.files).filter(([p, h]) => existsSync(join(dir, p)) && sha256$1(readFileSync(join(dir, p), "utf8")) !== h).map(([p]) => p);
|
|
537
|
+
const own = untracked(dir, entry);
|
|
538
|
+
if ((edited.length || own.length) && !force) throw new Error(`${MODULES_DIR}/${name} has ${[edited.length ? `edited files (${edited.join(", ")})` : "", own.length ? `files of the app's own (${own.join(", ")})` : ""].filter(Boolean).join(" and ")}: pass --force to delete them too`);
|
|
539
|
+
if (!dryRun) {
|
|
540
|
+
rmSync(dir, {
|
|
541
|
+
recursive: true,
|
|
542
|
+
force: true
|
|
543
|
+
});
|
|
544
|
+
delete lock.modules[name];
|
|
545
|
+
writeLock(root, lock);
|
|
546
|
+
}
|
|
547
|
+
log(`${dryRun ? "would remove" : "✓ removed"} ${MODULES_DIR}/${name} (${name}@${entry.version})`);
|
|
548
|
+
return { removed: name };
|
|
549
|
+
}
|
|
550
|
+
// cli/create.ts
|
|
551
|
+
/** The registry modules a new app starts with (`bake add`, from the official registry). */
|
|
552
|
+
const DEFAULT_MODULES = [
|
|
553
|
+
"clipboard",
|
|
554
|
+
"linking",
|
|
555
|
+
"share",
|
|
556
|
+
"haptics"
|
|
557
|
+
];
|
|
558
|
+
const templates$1 = fileURLToPath(new URL("../templates/create/", import.meta.url));
|
|
559
|
+
const screensSpec = "BakeNativeScreen.native.ts";
|
|
560
|
+
const screensPackage = "@bake-native/screens";
|
|
561
|
+
const hasMobileHost = (targets) => targets.includes("ios") || targets.includes("android");
|
|
562
|
+
const TEMPLATES = ["tabs"];
|
|
563
|
+
const create = command("create", object({
|
|
564
|
+
command: constant("create"),
|
|
565
|
+
name: argument(string({
|
|
566
|
+
metavar: "NAME",
|
|
567
|
+
pattern: /^[a-z][a-z0-9-]*$/,
|
|
568
|
+
errors: { patternMismatch: message`Use a lowercase name of letters, digits and dashes that starts with a letter, such as my-app.` }
|
|
569
|
+
})),
|
|
570
|
+
targets: withDefault(option("--targets", targetList$1, { description: message`Comma-separated platforms the app ships on: web, ios, android, mac, windows. Only their host folders (ios/, macos/, android/, windows/) are created, and bake.config.ts lists them.` }), [...TARGETS]),
|
|
571
|
+
renderer: withDefault(option("--renderer", choice(["react", "octane"]), { description: message`Render the app with React (.tsx) or Octane (.tsrx).` }), "react"),
|
|
572
|
+
template: withDefault(option("--template", choice(TEMPLATES), { description: message`The app template.` }), "tabs"),
|
|
573
|
+
dir: optional(option("--dir", string({ metavar: "PATH" }), { description: message`Directory to create the app in (default: ./NAME). It must not exist or be empty.` })),
|
|
574
|
+
appId: optional(option("--app-id", string({
|
|
575
|
+
metavar: "ID",
|
|
576
|
+
pattern: /^[a-z][a-z0-9_]*(\.[a-z][a-z0-9_]*)+$/
|
|
577
|
+
}), { description: message`Native application identifier (default: com.example.NAME).` })),
|
|
578
|
+
registry: optional(option("--registry", string({ metavar: "URL" }), { description: message`The registry the default modules (${DEFAULT_MODULES.join(", ")}) come from (default: the official one).` })),
|
|
579
|
+
bakenative: optional(option("--bakenative", string({ metavar: "PATH" }), { description: message`The BakeNative checkout the native hosts build against: its libraries and first-party modules (default: the checkout this bake runs from; with bake installed from npm the iOS and macOS hosts link the prebuilt runtime that comes with it, and Android and Windows use ../bakenative next to the app).` }))
|
|
580
|
+
}), { brief: message`Create a new BakeNative app from a template.` });
|
|
581
|
+
/** A source checkout: @bake-native/core is packages/core of a repository with the Rust core. An npm
|
|
582
|
+
* install is not: the app then depends on this @bake-native/core version from the registry. */
|
|
583
|
+
const checkout = () => existsSync(join(repo, "native/rust/Cargo.toml"));
|
|
584
|
+
/**
|
|
585
|
+
* The BakeNative checkout the native hosts build against (absolute, forward slashes): `--bakenative`
|
|
586
|
+
* (it must have the root Package.swift), else the checkout this bake runs from, else `bakenative`
|
|
587
|
+
* next to the app. npm carries no Android libraries, so an npm-installed bake cannot point at
|
|
588
|
+
* one by itself (docs: installation#build-from-source); the iOS and macOS hosts do not need one
|
|
589
|
+
* then (prebuiltApple).
|
|
590
|
+
*/
|
|
591
|
+
function bakeNativePath(o, dest) {
|
|
592
|
+
if (o.bakenative) {
|
|
593
|
+
const dir = resolve(o.bakenative);
|
|
594
|
+
if (!existsSync(join(dir, "Package.swift"))) throw new Error(`--bakenative ${dir}: not a BakeNative checkout (no Package.swift)`);
|
|
595
|
+
return realpathSync(dir).replaceAll("\\", "/");
|
|
596
|
+
}
|
|
597
|
+
return (checkout() ? realpathSync(repo) : resolve(dest, "../bakenative")).replaceAll("\\", "/");
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* The iOS and macOS hosts link the prebuilt Apple runtime instead of a checkout: bake is installed
|
|
601
|
+
* from npm and no `--bakenative` names one. Their projects then name `.bake/native/bakenative`, the
|
|
602
|
+
* Swift package `bake native link` unpacks from the installed toolchain package
|
|
603
|
+
* (src/apple-runtime.ts), so the app has no absolute path and no clone.
|
|
604
|
+
*/
|
|
605
|
+
const prebuiltApple = (o) => !o.bakenative && !checkout();
|
|
606
|
+
/** The host folder of each target that has one. */
|
|
607
|
+
const HOST_DIRS = {
|
|
608
|
+
ios: "ios",
|
|
609
|
+
mac: "macos",
|
|
610
|
+
android: "android",
|
|
611
|
+
windows: "windows"
|
|
612
|
+
};
|
|
613
|
+
/** Per target: its name in prose, its README build row, its layout line and its package.json script. */
|
|
614
|
+
const TARGET_TEXT = {
|
|
615
|
+
web: {
|
|
616
|
+
name: "the web",
|
|
617
|
+
row: "| Web | `pnpm build:web` | serve `dist/web` (open `dist/web/index.html`) |",
|
|
618
|
+
script: ["build:web", "bake build --target web"]
|
|
619
|
+
},
|
|
620
|
+
ios: {
|
|
621
|
+
name: "iOS",
|
|
622
|
+
row: "| iOS | `pnpm build:ios` (macOS, Apple silicon) | `sh __BAKENATIVE__/tools/build-rust-apple.sh` once, then `cd ios && xcodegen generate`, open `__SWIFT_NAME__.xcodeproj` |",
|
|
623
|
+
prebuiltRow: "| iOS | `pnpm build:ios` (macOS, Apple silicon) | `cd ios && xcodegen generate`, open `__SWIFT_NAME__.xcodeproj` |",
|
|
624
|
+
layout: "ios/ XcodeGen project (BakeNativeKit) that shows the bundle full screen",
|
|
625
|
+
script: ["build:ios", "sh ios/build.sh"]
|
|
626
|
+
},
|
|
627
|
+
android: {
|
|
628
|
+
name: "Android",
|
|
629
|
+
row: "| Android | `pnpm build:android` | `sh __BAKENATIVE__/native/android/bakenative/build-rust.sh`, then `cd android && ./gradlew :app:installDebug` |",
|
|
630
|
+
layout: "android/ Gradle app (one Activity with a BakeNativeView)",
|
|
631
|
+
script: ["build:android", "bake build --target android --bake"]
|
|
632
|
+
},
|
|
633
|
+
mac: {
|
|
634
|
+
name: "macOS",
|
|
635
|
+
row: "| macOS | Build the [native runtime](https://bake-native.com/docs/installation#build-from-source), then `pnpm build:mac` | open `dist/standalone/__SWIFT_NAME__.app` |",
|
|
636
|
+
prebuiltRow: "| macOS | `pnpm build:mac` (macOS, Apple silicon) | open `dist/standalone/__SWIFT_NAME__.app` |",
|
|
637
|
+
layout: "macos/ SwiftPM app (BakeNativeAppKit), one window",
|
|
638
|
+
script: ["build:mac", "sh macos/build.sh"]
|
|
639
|
+
},
|
|
640
|
+
windows: {
|
|
641
|
+
name: "Windows",
|
|
642
|
+
row: "| Windows | `pnpm build:windows` (Windows x64) | run `dist/standalone/windows/__SWIFT_NAME__.exe` |",
|
|
643
|
+
layout: "windows/ Cargo app (Win32 with one BakeNativeWindow)",
|
|
644
|
+
script: ["build:windows", "bake package --standalone --target windows --viewport 640x480 --bakenative \"__BAKENATIVE__\""]
|
|
645
|
+
}
|
|
646
|
+
};
|
|
647
|
+
/** "a", "a and b", "a, b and c" */
|
|
648
|
+
const prose = (words) => words.length < 2 ? words.join("") : `${words.slice(0, -1).join(", ")} and ${words.at(-1)}`;
|
|
649
|
+
/** The README line on where the native libraries come from. */
|
|
650
|
+
function bakeNativeNote(targets, prebuilt) {
|
|
651
|
+
if (!prebuilt) return "It uses the BakeNative checkout at `__BAKENATIVE__` (Hermes and the native libraries).";
|
|
652
|
+
const apple = targets.filter((t) => t === "ios" || t === "mac");
|
|
653
|
+
const lines = [];
|
|
654
|
+
if (apple.length) lines.push(`The ${prose(apple.map((t) => TARGET_TEXT[t].name))} ${apple.length === 1 ? "host links" : "hosts link"} the prebuilt BakeNative runtime that \`@bake-native/core\` installs on a Mac with\nApple silicon (\`@bake-native/toolchain-darwin-arm64\`). ${prose(apple.map((t) => `\`pnpm build:${t}\``))} ${apple.length === 1 ? "unpacks" : "unpack"} it to \`.bake/native/bakenative\`, the\nSwift package ${prose(apple.map((t) => `\`${t === "ios" ? "ios/project.yml" : "macos/Package.swift"}\``))} ${apple.length === 1 ? "depends" : "depend"} on: no BakeNative checkout, Rust or Hermes build.`);
|
|
655
|
+
const source = targets.filter((t) => t === "android" || t === "windows");
|
|
656
|
+
if (source.length) lines.push(`The ${prose(source.map((t) => TARGET_TEXT[t].name))} ${source.length === 1 ? "host builds" : "hosts build"} against a BakeNative checkout at \`__BAKENATIVE__\`. Clone BakeNative there, or create the app with \`--bakenative <checkout>\`.`);
|
|
657
|
+
return lines.join("\n\n");
|
|
658
|
+
}
|
|
659
|
+
/** The placeholders that depend on the chosen targets (in TARGETS order). `prebuilt`: the iOS and
|
|
660
|
+
* macOS hosts link the prebuilt Apple runtime (prebuiltApple). */
|
|
661
|
+
function targetValues(targets, prebuilt = false) {
|
|
662
|
+
const hosts = targets.filter((t) => HOST_DIRS[t]);
|
|
663
|
+
const dirs = hosts.map((t) => `\`${HOST_DIRS[t]}/\``);
|
|
664
|
+
const builds = hosts.map((t) => `\`pnpm build:${t}\``);
|
|
665
|
+
const projectPaths = {
|
|
666
|
+
ios: "ios/project.yml",
|
|
667
|
+
mac: "macos/Package.swift",
|
|
668
|
+
android: "android/settings.gradle.kts",
|
|
669
|
+
windows: "windows/Cargo.toml"
|
|
670
|
+
};
|
|
671
|
+
const projects = hosts.map((t) => `\`${projectPaths[t]}\``);
|
|
672
|
+
return {
|
|
673
|
+
TARGETS: `[${targets.map((t) => `'${t}'`).join(", ")}]`,
|
|
674
|
+
TARGET_LIST: targets.map((t) => `\`${t}\``).join(", "),
|
|
675
|
+
TARGET_NAMES: prose(targets.map((t) => TARGET_TEXT[t].name)),
|
|
676
|
+
TARGET_ROWS: targets.map((t) => prebuilt && TARGET_TEXT[t].prebuiltRow || TARGET_TEXT[t].row).join("\n"),
|
|
677
|
+
BAKENATIVE_NOTE: bakeNativeNote(targets, prebuilt),
|
|
678
|
+
HOST_LAYOUT: targets.flatMap((t) => TARGET_TEXT[t].layout ?? []).join("\n"),
|
|
679
|
+
HOSTS_NOTE: hosts.length ? `The native hosts link the modules in \`native/\` the app calls (\`bake add\` put clipboard, linking,\nshare and haptics there). Each host build (${prose(builds)}) copies them and writes their\nregistration to \`.bake/native/<target>\`, which ${prose(projects)} ${hosts.length === 1 ? "includes" : "include"}. Run\nthe build once before opening a host project.` : "",
|
|
680
|
+
SCREENS_NOTE: hasMobileHost(targets) ? "For native screen transitions, import `pushScreen` and `popScreen` from `@bake-native/screens`. The app owns its routes. Implement the generated `BakeNativeScreenSpec` in the host and pass it to the generated `BakeNativeBundleModules.root` before opening the bundle. See the [screens package guide](https://github.com/gronxb/bake-native/tree/main/packages/screens)." : "",
|
|
681
|
+
HOSTS_BULLET: hosts.length ? `- The native ${hosts.length === 1 ? "project" : "projects"} (${dirs.join(", ")}) load the bundle that \`bake build\` writes to\n \`dist/<target>\`; their build scripts copy it in.` : ""
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
/** The values a template's `__KEY__` placeholders take. */
|
|
685
|
+
function templateValues(o, dest = resolve(o.name)) {
|
|
686
|
+
const words = o.name.split("-").filter(Boolean);
|
|
687
|
+
const appId = o.appId ?? `com.example.${words.join("")}`;
|
|
688
|
+
const product = words.map((w) => w[0].toUpperCase() + w.slice(1)).join("");
|
|
689
|
+
const inCheckout = checkout();
|
|
690
|
+
const prebuilt = prebuiltApple(o);
|
|
691
|
+
const renderer = o.renderer ?? "react";
|
|
692
|
+
const adapter = JSON.parse(readFileSync(join(packageRoot$1, "dist", renderer, "package.json"), "utf8"));
|
|
693
|
+
const bakenative = bakeNativePath({ bakenative: o.bakenative }, dest);
|
|
694
|
+
const pkg = JSON.parse(readFileSync(join(packageRoot$1, "package.json"), "utf8"));
|
|
695
|
+
const compat = JSON.parse(readFileSync(join(packageRoot$1, "compat.json"), "utf8"));
|
|
696
|
+
return {
|
|
697
|
+
NAME: o.name,
|
|
698
|
+
RENDERER: renderer,
|
|
699
|
+
RENDERER_NAME: renderer === "react" ? "React" : "Octane",
|
|
700
|
+
RENDERER_PACKAGE: String(adapter.name),
|
|
701
|
+
RENDERER_VERSION: inCheckout ? `link:${join(repo, "packages", renderer).replaceAll("\\", "/")}` : String(adapter.version),
|
|
702
|
+
FRAMEWORK_VERSION: renderer === "react" ? String(adapter.peerDependencies.react) : String(compat.octane),
|
|
703
|
+
REACT_DOM: String(adapter.peerDependencies["react-dom"]),
|
|
704
|
+
REACT_TYPES: String(adapter.devDependencies?.["@types/react"]),
|
|
705
|
+
TYPESCRIPT: String(pkg.devDependencies.typescript),
|
|
706
|
+
APP_ENTRY: renderer === "react" ? "src/App.tsx" : "src/App.tsrx",
|
|
707
|
+
COMPILER: renderer === "octane" ? " compiler: { strong: true }," : "",
|
|
708
|
+
TITLE: words.map((w) => w[0].toUpperCase() + w.slice(1)).join(" "),
|
|
709
|
+
SWIFT_NAME: product,
|
|
710
|
+
MAC_RESOURCE_BUNDLE: `${product}_${product}`,
|
|
711
|
+
APP_ID: appId,
|
|
712
|
+
APP_CONFIG: (o.targets ?? TARGETS).some((target) => target !== "web") ? ` app: { appId: '${appId}' },` : "",
|
|
713
|
+
BAKENATIVE: bakenative,
|
|
714
|
+
BAKENATIVE_SWIFT: prebuilt ? `../${APPLE_RUNTIME_DIR}` : bakenative,
|
|
715
|
+
BAKENATIVE_SWIFT_FROM: prebuilt ? `@bake-native/core's prebuilt runtime, unpacked to ${APPLE_RUNTIME_DIR} by the host build` : "your BakeNative checkout",
|
|
716
|
+
LINK_BAKENATIVE: prebuilt ? "" : ` --bakenative "${bakenative}"`,
|
|
717
|
+
BAKENATIVE_JS: inCheckout ? `link:${packageRoot$1.replaceAll("\\", "/")}` : String(pkg.version),
|
|
718
|
+
VITE: String(pkg.devDependencies.vite),
|
|
719
|
+
OXC: String(pkg.dependencies["@tsrx/oxc"]),
|
|
720
|
+
...targetValues(TARGETS.filter((t) => (o.targets ?? TARGETS).includes(t)), prebuilt)
|
|
721
|
+
};
|
|
722
|
+
}
|
|
723
|
+
const BINARY = /\.(jar|png|jpg|ico)$/;
|
|
724
|
+
function fill(text, values) {
|
|
725
|
+
const once = (t) => t.replace(/^__([A-Z_]+?)__\r?\n/gm, (m, key) => values[key] === "" ? "" : m).replace(/__([A-Z_]+?)__/g, (m, key) => values[key] ?? m);
|
|
726
|
+
return once(once(text));
|
|
727
|
+
}
|
|
728
|
+
/** The template's package.json for `targets`: build:<target> scripts of those targets only. */
|
|
729
|
+
function packageJson(text, targets, values, screensVersion) {
|
|
730
|
+
const pkg = JSON.parse(text);
|
|
731
|
+
const scripts = { build: targets.includes("web") ? "bake build --target web" : "bake build" };
|
|
732
|
+
for (const t of TARGETS) {
|
|
733
|
+
const script = TARGET_TEXT[t].script;
|
|
734
|
+
if (targets.includes(t) && script) scripts[script[0]] = fill(script[1], values);
|
|
735
|
+
}
|
|
736
|
+
pkg.scripts = scripts;
|
|
737
|
+
if (values.RENDERER === "react") {
|
|
738
|
+
if (targets.includes("web")) pkg.dependencies["react-dom"] = values.REACT_DOM;
|
|
739
|
+
pkg.devDependencies["@types/react"] = values.REACT_TYPES;
|
|
740
|
+
pkg.devDependencies.typescript = values.TYPESCRIPT;
|
|
741
|
+
}
|
|
742
|
+
if (values.RENDERER === "octane") pkg.devDependencies["@tsrx/oxc"] = values.OXC;
|
|
743
|
+
if (screensVersion) pkg.dependencies[screensPackage] = screensVersion;
|
|
744
|
+
return JSON.stringify(pkg, null, 2) + "\n";
|
|
745
|
+
}
|
|
746
|
+
/** .gitignore without the lines of host folders the app does not have. */
|
|
747
|
+
function gitignore(text, skipped) {
|
|
748
|
+
return text.split("\n").filter((line) => !skipped.some((dir) => line.startsWith(`${dir}/`))).join("\n");
|
|
749
|
+
}
|
|
750
|
+
function createApp(o) {
|
|
751
|
+
const dest = resolve(o.dir ?? o.name);
|
|
752
|
+
if (existsSync(dest) && readdirSync(dest).length > 0) throw new Error(`${dest} exists and is not empty`);
|
|
753
|
+
const values = templateValues(o, dest);
|
|
754
|
+
const source = join(templates$1, o.template);
|
|
755
|
+
const targets = TARGETS.filter((t) => o.targets.includes(t));
|
|
756
|
+
const screensDir = join(packageRoot$1, "dist/screens");
|
|
757
|
+
const screensVersion = hasMobileHost(targets) ? checkout() ? `link:${join(repo, "packages/screens").replaceAll("\\", "/")}` : String(JSON.parse(readFileSync(join(screensDir, "package.json"), "utf8")).version) : void 0;
|
|
758
|
+
const skipped = TARGETS.filter((t) => !targets.includes(t)).flatMap((t) => HOST_DIRS[t] ?? []);
|
|
759
|
+
const written = [];
|
|
760
|
+
const walk = (dir) => {
|
|
761
|
+
for (const entry of readdirSync(dir)) {
|
|
762
|
+
const from = join(dir, entry);
|
|
763
|
+
if (dir === join(source, "src") && entry.startsWith("App.") && from !== join(source, values.APP_ENTRY)) continue;
|
|
764
|
+
if (dir === source && (skipped.includes(entry) || entry === "tsconfig.json" && o.renderer !== "react")) continue;
|
|
765
|
+
if (statSync(from).isDirectory()) {
|
|
766
|
+
walk(from);
|
|
767
|
+
continue;
|
|
768
|
+
}
|
|
769
|
+
const rel = fill(relative(source, from), values).replace(/(^|[\\/])_gitignore$/, "$1.gitignore");
|
|
770
|
+
const to = join(dest, rel);
|
|
771
|
+
mkdirSync(dirname(to), { recursive: true });
|
|
772
|
+
if (BINARY.test(entry)) copyFileSync(from, to);
|
|
773
|
+
else {
|
|
774
|
+
let text = fill(readFileSync(from, "utf8"), values);
|
|
775
|
+
if (rel === "package.json") text = packageJson(text, targets, values, screensVersion);
|
|
776
|
+
if (rel === "tsconfig.json" && targets.every((target) => target === "web")) {
|
|
777
|
+
const config = JSON.parse(text);
|
|
778
|
+
config.compilerOptions.lib = [
|
|
779
|
+
"ES2022",
|
|
780
|
+
"DOM",
|
|
781
|
+
"DOM.Iterable"
|
|
782
|
+
];
|
|
783
|
+
config.compilerOptions.types = ["react"];
|
|
784
|
+
text = JSON.stringify(config, null, 2) + "\n";
|
|
785
|
+
}
|
|
786
|
+
if (rel === ".gitignore") text = gitignore(text, skipped);
|
|
787
|
+
writeFileSync(to, text, { mode: statSync(from).mode });
|
|
788
|
+
}
|
|
789
|
+
written.push(rel);
|
|
790
|
+
}
|
|
791
|
+
};
|
|
792
|
+
walk(source);
|
|
793
|
+
if (screensVersion) {
|
|
794
|
+
const dir = join(dest, "native/bake-native-screen");
|
|
795
|
+
mkdirSync(dir, { recursive: true });
|
|
796
|
+
copyFileSync(join(screensDir, screensSpec), join(dir, screensSpec));
|
|
797
|
+
written.push(`native/bake-native-screen/${screensSpec}`);
|
|
798
|
+
}
|
|
799
|
+
return {
|
|
800
|
+
dest,
|
|
801
|
+
files: written.map((f) => f.replaceAll("\\", "/")).sort()
|
|
802
|
+
};
|
|
803
|
+
}
|
|
804
|
+
/**
|
|
805
|
+
* The default modules, copied with `bake add` into the new app (native/<name>, bake-modules.json).
|
|
806
|
+
* Returns the summary lines: the modules, and one line for targets a module does not implement.
|
|
807
|
+
*/
|
|
808
|
+
async function addDefaultModules(dest, o) {
|
|
809
|
+
const targets = TARGETS.filter((t) => o.targets.includes(t));
|
|
810
|
+
const pkg = JSON.parse(readFileSync(join(packageRoot$1, "package.json"), "utf8"));
|
|
811
|
+
const registry = o.registry && !/^(https?|file):/.test(o.registry) ? resolve(o.registry) : o.registry;
|
|
812
|
+
const { added } = await addModules$1(DEFAULT_MODULES, {
|
|
813
|
+
root: dest,
|
|
814
|
+
targets,
|
|
815
|
+
registries: {},
|
|
816
|
+
repo,
|
|
817
|
+
registry,
|
|
818
|
+
bakeVersion: String(pkg.version)
|
|
819
|
+
});
|
|
820
|
+
const gaps = added.filter((m) => m.unsupported.length).map((m) => `${m.name} (no ${m.unsupported.join(", ")})`);
|
|
821
|
+
return [` modules ${added.map((m) => `${m.name}@${m.version}`).join(", ")} (native/, bake-modules.json; bake diff / bake upgrade)`, ...gaps.length ? [` note not every target has an implementation yet: ${gaps.join(", ")}; a build that calls one there fails`] : []];
|
|
822
|
+
}
|
|
823
|
+
async function createCommand(o) {
|
|
824
|
+
const { dest } = createApp(o);
|
|
825
|
+
const where = relative(process.cwd(), dest) || ".";
|
|
826
|
+
console.log(`✓ ${where} ${o.renderer} ${o.template} app (targets: ${TARGETS.filter((t) => o.targets.includes(t)).join(", ")})`);
|
|
827
|
+
for (const line of await addDefaultModules(dest, o)) console.log(line);
|
|
828
|
+
const bakenative = bakeNativePath(o, dest);
|
|
829
|
+
const hosts = TARGETS.filter((t) => o.targets.includes(t) && HOST_DIRS[t] && !(prebuiltApple(o) && (t === "ios" || t === "mac")));
|
|
830
|
+
if (hosts.length && !existsSync(join(bakenative, "Package.swift"))) {
|
|
831
|
+
const names = hosts.map((t) => TARGET_TEXT[t].name);
|
|
832
|
+
console.log(`note: the ${prose(names)} ${names.length === 1 ? "host builds" : "hosts build"} against the BakeNative checkout at ${bakenative}, which does not exist yet: clone it there, or create the app again with --bakenative <checkout>`);
|
|
833
|
+
}
|
|
834
|
+
console.log(`next:\n cd ${where}\n pnpm install`);
|
|
835
|
+
if (o.targets.includes("web")) console.log(" pnpm build:web");
|
|
836
|
+
if (o.targets.some((t) => t !== "web")) console.log("For native builds, see https://bake-native.com/docs/installation.");
|
|
837
|
+
}
|
|
838
|
+
// cli/modules.ts
|
|
839
|
+
const { addModules, diffModules, removeModule, upgradeModules } = bake_add_exports;
|
|
840
|
+
const path$3 = string({ metavar: "PATH" });
|
|
841
|
+
const moduleSpec = string({ metavar: "MODULE" });
|
|
842
|
+
const root = withDefault(option("--root", path$3, { description: message`The app's directory (its bake.config.ts).` }), ".");
|
|
843
|
+
const registry = optional(option("--registry", string({ metavar: "URL" }), { description: message`Use this registry (a URL or a directory with index.json) instead of the one the lock or bake.config.ts names.` }));
|
|
844
|
+
const json$1 = withDefault(flag("--json", { description: message`Print the result as JSON.` }), false);
|
|
845
|
+
const dryRun = withDefault(flag("--dry-run", { description: message`Show what would change; write nothing.` }), false);
|
|
846
|
+
const add = command("add", object({
|
|
847
|
+
command: constant("add"),
|
|
848
|
+
modules: multiple(argument(moduleSpec), { min: 1 }),
|
|
849
|
+
root,
|
|
850
|
+
registry,
|
|
851
|
+
overwrite: withDefault(flag("--overwrite", { description: message`Replace files that differ from the registry's copy (restores deleted ones too).` }), false),
|
|
852
|
+
dryRun,
|
|
853
|
+
json: json$1
|
|
854
|
+
}), {
|
|
855
|
+
brief: message`Copy native modules from a registry into native/<name>/.`,
|
|
856
|
+
description: message`Copies each module's spec and the implementations of the targets in bake.config.ts into native/<name>/ and records the version and file hashes in bake-modules.json. MODULE is name, name@1.2.3, or registry/name with a registry from bake.config.ts registries. The app owns the files; the next bake build generates their glue and registration. A file that differs from the registry's copy is never overwritten without --overwrite.`
|
|
857
|
+
});
|
|
858
|
+
const diff = command("diff", object({
|
|
859
|
+
command: constant("diff"),
|
|
860
|
+
name: optional(argument(moduleSpec)),
|
|
861
|
+
root,
|
|
862
|
+
registry,
|
|
863
|
+
stat: withDefault(flag("--stat", { description: message`File summary only, no patches.` }), false),
|
|
864
|
+
json: json$1
|
|
865
|
+
}), {
|
|
866
|
+
brief: message`Show local edits and registry changes of the app's modules.`,
|
|
867
|
+
description: message`For each module in bake-modules.json (or NAME): the app's edits against the version it took, and the registry's changes from that version to its latest, as unified diffs.`
|
|
868
|
+
});
|
|
869
|
+
const upgrade = command("upgrade", object({
|
|
870
|
+
command: constant("upgrade"),
|
|
871
|
+
name: optional(argument(moduleSpec)),
|
|
872
|
+
root,
|
|
873
|
+
registry,
|
|
874
|
+
to: optional(option("--to", string({
|
|
875
|
+
metavar: "VERSION",
|
|
876
|
+
pattern: /^\d+\.\d+\.\d+$/
|
|
877
|
+
}), { description: message`Upgrade to this version instead of the latest.` })),
|
|
878
|
+
dryRun,
|
|
879
|
+
json: json$1
|
|
880
|
+
}), {
|
|
881
|
+
brief: message`Merge the registry's latest version into the app's modules.`,
|
|
882
|
+
description: message`A three-way merge per file: the locked version is the base, the app's file one side, the registry's new version the other. A region both changed differently is left with conflict markers, the command exits 1 and bake build refuses the file until it is resolved. Nothing is overwritten silently.`
|
|
883
|
+
});
|
|
884
|
+
const remove = command("remove", object({
|
|
885
|
+
command: constant("remove"),
|
|
886
|
+
name: argument(moduleSpec),
|
|
887
|
+
root,
|
|
888
|
+
force: withDefault(flag("--force", { description: message`Also delete edited files and the app's own files in the folder.` }), false),
|
|
889
|
+
dryRun
|
|
890
|
+
}), { brief: message`Remove a registry module from native/ and bake-modules.json.` });
|
|
891
|
+
const registryCommand = command("registry", command("build", object({
|
|
892
|
+
command: constant("registry build"),
|
|
893
|
+
dir: withDefault(option("--dir", path$3, { description: message`The registry directory (with modules/<name>/).` }), "registry"),
|
|
894
|
+
check: withDefault(flag("--check", { description: message`Fail when index.json or an item is out of date; write nothing.` }), false)
|
|
895
|
+
}), {
|
|
896
|
+
brief: message`Build a registry's index.json and version items from modules/<name>/.`,
|
|
897
|
+
description: message`Writes index.json and r/<name>/<version>.json. A published version never changes: a module whose files changed needs a new version in module.json.`
|
|
898
|
+
}), { brief: message`Build a native module registry.` });
|
|
899
|
+
const modulesParser = or(add, diff, upgrade, remove, registryCommand);
|
|
900
|
+
const bakeVersion = () => String(JSON.parse(readFileSync(join(packageRoot$1, "package.json"), "utf8")).version);
|
|
901
|
+
async function context(o) {
|
|
902
|
+
const dir = resolve(o.root);
|
|
903
|
+
const config = await loadBakeConfig(dir);
|
|
904
|
+
return {
|
|
905
|
+
root: dir,
|
|
906
|
+
targets: config?.targets ?? [...DEFAULT_CONFIG_TARGETS],
|
|
907
|
+
registries: config?.registries ?? {},
|
|
908
|
+
repo,
|
|
909
|
+
registry: o.registry,
|
|
910
|
+
bakeVersion: bakeVersion()
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
async function modulesCommand(o) {
|
|
914
|
+
const quiet = "json" in o && o.json;
|
|
915
|
+
const log = quiet ? () => {} : (line) => console.log(line);
|
|
916
|
+
let result;
|
|
917
|
+
switch (o.command) {
|
|
918
|
+
case "add":
|
|
919
|
+
result = await addModules(o.modules, {
|
|
920
|
+
...await context(o),
|
|
921
|
+
overwrite: o.overwrite,
|
|
922
|
+
dryRun: o.dryRun,
|
|
923
|
+
log
|
|
924
|
+
});
|
|
925
|
+
break;
|
|
926
|
+
case "diff":
|
|
927
|
+
result = await diffModules(o.name, {
|
|
928
|
+
...await context(o),
|
|
929
|
+
stat: o.stat,
|
|
930
|
+
log
|
|
931
|
+
});
|
|
932
|
+
break;
|
|
933
|
+
case "upgrade": {
|
|
934
|
+
const r = await upgradeModules(o.name, {
|
|
935
|
+
...await context(o),
|
|
936
|
+
dryRun: o.dryRun,
|
|
937
|
+
to: o.to,
|
|
938
|
+
log
|
|
939
|
+
});
|
|
940
|
+
if (r.conflicts) process.exitCode = 1;
|
|
941
|
+
result = r;
|
|
942
|
+
break;
|
|
943
|
+
}
|
|
944
|
+
case "remove":
|
|
945
|
+
result = removeModule(o.name, {
|
|
946
|
+
root: resolve(o.root),
|
|
947
|
+
force: o.force,
|
|
948
|
+
dryRun: o.dryRun,
|
|
949
|
+
log
|
|
950
|
+
});
|
|
951
|
+
break;
|
|
952
|
+
case "registry build": {
|
|
953
|
+
const r = buildRegistry(resolve(o.dir), { check: o.check });
|
|
954
|
+
if (o.check && r.stale.length) throw new Error(`the registry is out of date (run bake registry build): ${r.stale.join(", ")}`);
|
|
955
|
+
console.log(`✓ ${o.dir} ${r.modules.length} modules${o.check ? " (up to date)" : r.written.length ? ` (${r.written.length} written)` : " (unchanged)"}`);
|
|
956
|
+
return;
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
if (quiet) console.log(JSON.stringify(result, null, 2));
|
|
960
|
+
}
|
|
961
|
+
// src/native-declarations.ts
|
|
962
|
+
function nativeDeclarations(schema, source = "native-modules.json") {
|
|
963
|
+
const lines = [
|
|
964
|
+
`// Generated by \`bake native types\` from ${source}. Do not edit; regenerate after changing a module.`,
|
|
965
|
+
`import '@bake-native/core';`,
|
|
966
|
+
"",
|
|
967
|
+
...viewLines(schema.views),
|
|
968
|
+
`declare module '@bake-native/core' {`,
|
|
969
|
+
" interface NativeModules {"
|
|
970
|
+
];
|
|
971
|
+
const ident = (n) => /^[A-Za-z_$][\w$]*$/.test(n) ? n : JSON.stringify(n);
|
|
972
|
+
for (const mod of schema.modules ?? []) {
|
|
973
|
+
lines.push(` ${ident(mod.name)}: {`);
|
|
974
|
+
for (const m of mod.members ?? []) {
|
|
975
|
+
if (m.only?.length) lines.push(` /** Only in ${m.only.join(", ")}. */`);
|
|
976
|
+
if (m.kind === "constant") {
|
|
977
|
+
lines.push(` readonly ${ident(m.name)}: ${m.returns};`);
|
|
978
|
+
continue;
|
|
979
|
+
}
|
|
980
|
+
if (m.kind === "event") {
|
|
981
|
+
lines.push(` ${ident(m.name)}(listener: (${m.returns === "void" ? "" : `value: ${m.returns}`}) => void): () => void;`);
|
|
982
|
+
continue;
|
|
983
|
+
}
|
|
984
|
+
const params = m.parameters ?? [];
|
|
985
|
+
let lastRequired = -1;
|
|
986
|
+
params.forEach((p, i) => {
|
|
987
|
+
if (!p.optional) lastRequired = i;
|
|
988
|
+
});
|
|
989
|
+
const name = (p, i) => p.name && /^[A-Za-z_$][\w$]*$/.test(p.name) ? p.name : `arg${i}`;
|
|
990
|
+
const orNull = (t) => /\|\s*null$/.test(t) ? t : `${t} | null`;
|
|
991
|
+
const list = params.map((p, i) => p.optional ? i > lastRequired ? `${name(p, i)}?: ${orNull(p.type)}` : `${name(p, i)}: ${orNull(p.type)} | undefined` : `${name(p, i)}: ${p.type}`).join(", ");
|
|
992
|
+
const ret = m.kind === "asyncFunction" ? `Promise<${m.returns}>` : m.returns;
|
|
993
|
+
lines.push(` ${ident(m.name)}(${list}): ${ret};`);
|
|
994
|
+
}
|
|
995
|
+
lines.push(" };");
|
|
996
|
+
}
|
|
997
|
+
lines.push(" }", "}", "");
|
|
998
|
+
return lines.join("\n");
|
|
999
|
+
}
|
|
1000
|
+
/** The host's native views as a comment: their JS types are the components `bake native view gen`
|
|
1001
|
+
* writes from each spec (`@bake-native/octane/<view>` or the app's native/views/generated), which
|
|
1002
|
+
* `bake native types` checked against these signatures. */
|
|
1003
|
+
function viewLines(views) {
|
|
1004
|
+
if (!views?.length) return [];
|
|
1005
|
+
return [
|
|
1006
|
+
"// Native views of the host (their types: the components generated from each spec):",
|
|
1007
|
+
...views.map((v) => `// ${v.name} ${v.signature}${v.only?.length ? ` (only in ${v.only.join(", ")})` : ""}`),
|
|
1008
|
+
""
|
|
1009
|
+
];
|
|
1010
|
+
}
|
|
1011
|
+
/** `<kind>(<type>[?],...)-><returns>`: what makes two schemas' members the same member (the
|
|
1012
|
+
* signature OTA compatibility hashes; parameter names are not part of it). */
|
|
1013
|
+
const signature = (m) => `${m.kind}(${(m.parameters ?? []).map((p) => p.type + (p.optional ? "?" : "")).join(",")})->${m.returns}`;
|
|
1014
|
+
/**
|
|
1015
|
+
* The union of several hosts' schemas (e.g. the iOS and the Android app's native-modules.json):
|
|
1016
|
+
* every module and member of any of them. A member in more than one must have the same
|
|
1017
|
+
* signature everywhere (one JS type); a member missing from some is marked `only`.
|
|
1018
|
+
*/
|
|
1019
|
+
function mergeNativeSchemas(schemas) {
|
|
1020
|
+
if (schemas.length === 1) return schemas[0].schema;
|
|
1021
|
+
const views = /* @__PURE__ */ new Map();
|
|
1022
|
+
for (const { label, schema } of schemas) for (const v of schema.views ?? []) {
|
|
1023
|
+
const seen = views.get(v.name);
|
|
1024
|
+
if (seen && seen.view.signature !== v.signature) throw new Error(`native view ${v.name} differs between ${seen.from[0]} (signature ${seen.view.signature}) and ${label} (${v.signature}): every host implements the same spec`);
|
|
1025
|
+
views.set(v.name, {
|
|
1026
|
+
view: v,
|
|
1027
|
+
from: [...seen?.from ?? [], label]
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1030
|
+
const modules = /* @__PURE__ */ new Map();
|
|
1031
|
+
for (const { label, schema } of schemas) for (const mod of schema.modules ?? []) {
|
|
1032
|
+
const members = modules.get(mod.name) ?? /* @__PURE__ */ new Map();
|
|
1033
|
+
modules.set(mod.name, members);
|
|
1034
|
+
for (const m of mod.members ?? []) {
|
|
1035
|
+
const seen = members.get(m.name);
|
|
1036
|
+
if (!seen) {
|
|
1037
|
+
members.set(m.name, {
|
|
1038
|
+
member: m,
|
|
1039
|
+
from: [label]
|
|
1040
|
+
});
|
|
1041
|
+
continue;
|
|
1042
|
+
}
|
|
1043
|
+
if (signature(seen.member) !== signature(m)) throw new Error(`native.${mod.name}.${m.name} differs between ${seen.from[0]} (${signature(seen.member)}) and ${label} (${signature(m)}): one JS type needs the same parameters and result on every host`);
|
|
1044
|
+
const named = (seen.member.parameters ?? []).some((p) => p.name) ? seen.member : m;
|
|
1045
|
+
members.set(m.name, {
|
|
1046
|
+
member: named,
|
|
1047
|
+
from: [...seen.from, label]
|
|
1048
|
+
});
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
const all = schemas.length;
|
|
1052
|
+
const merged = [...views.values()].sort((a, b) => a.view.name < b.view.name ? -1 : a.view.name > b.view.name ? 1 : 0).map(({ view, from }) => from.length === all ? {
|
|
1053
|
+
name: view.name,
|
|
1054
|
+
signature: view.signature
|
|
1055
|
+
} : {
|
|
1056
|
+
name: view.name,
|
|
1057
|
+
signature: view.signature,
|
|
1058
|
+
only: from
|
|
1059
|
+
});
|
|
1060
|
+
return {
|
|
1061
|
+
version: merged.length ? 2 : 1,
|
|
1062
|
+
...merged.length ? { views: merged } : {},
|
|
1063
|
+
modules: [...modules.entries()].sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([name, members]) => ({
|
|
1064
|
+
name,
|
|
1065
|
+
members: [...members.values()].map(({ member, from }) => from.length === all ? member : {
|
|
1066
|
+
...member,
|
|
1067
|
+
only: from
|
|
1068
|
+
})
|
|
1069
|
+
}))
|
|
1070
|
+
};
|
|
1071
|
+
}
|
|
1072
|
+
// cli/native.ts
|
|
1073
|
+
const templates = fileURLToPath(new URL("../templates/", import.meta.url));
|
|
1074
|
+
const packageRoot = fileURLToPath(new URL("..", import.meta.url));
|
|
1075
|
+
const path$2 = string({ metavar: "PATH" });
|
|
1076
|
+
const kotlinPackage = string({
|
|
1077
|
+
metavar: "PACKAGE",
|
|
1078
|
+
pattern: /^[a-z_][A-Za-z0-9_]*(\.[a-z_][A-Za-z0-9_]*)*$/,
|
|
1079
|
+
errors: { patternMismatch: message`Use a Kotlin package name, such as com.example.app.` }
|
|
1080
|
+
});
|
|
1081
|
+
const native = command("native", or(command("types", object({
|
|
1082
|
+
command: constant("native types"),
|
|
1083
|
+
root: withDefault(option("--root", path$2), "."),
|
|
1084
|
+
schema: multiple(option("--schema", path$2)),
|
|
1085
|
+
out: withDefault(option("--out", path$2), "src/native.d.ts")
|
|
1086
|
+
}), {
|
|
1087
|
+
brief: message`Generate TypeScript declarations from the app's native module specs.`,
|
|
1088
|
+
description: message`Reads native/<name>/<Name>.native.ts under --root and writes the types of native.<Name> to --out. --schema adds the modules of a native-modules.json a host wrote (modules without a spec); a module both declare must have the same signature in each.`
|
|
1089
|
+
}), command("link", object({
|
|
1090
|
+
command: constant("native link"),
|
|
1091
|
+
root: withDefault(option("--root", path$2), "."),
|
|
1092
|
+
target: option("--target", choice([
|
|
1093
|
+
"ios",
|
|
1094
|
+
"mac",
|
|
1095
|
+
"android",
|
|
1096
|
+
"windows"
|
|
1097
|
+
])),
|
|
1098
|
+
bundle: multiple(option("--bundle", path$2, { description: message`Bundle directory, relative to --root (repeatable).` })),
|
|
1099
|
+
out: optional(option("--out", path$2, { description: message`Output directory, relative to --root (default: .bake/native/<target>).` })),
|
|
1100
|
+
bakenative: optional(option("--bakenative", path$2))
|
|
1101
|
+
}), {
|
|
1102
|
+
brief: message`Generate the registration of the first-party modules an app uses.`,
|
|
1103
|
+
description: message`Reads requires.modules of each bundle's manifest.json (--bundle, default: <root>/dist/<target>) and writes the host's registration of exactly those modules to --out (default: <root>/.bake/native/<target>): a SwiftPM package (ios, mac), a Gradle module (android) or a crate (windows) named BakeNativeAppModules. The app's own modules the bundles call (requires.nativeModules) get their generated contracts and BakeNativeBundleModules, from the specs in native/<name> of --root and of each bundle's app. Relative --bundle and --out paths resolve against --root, not the current directory. Files whose content is unchanged are not rewritten. --bakenative: the BakeNative checkout the Swift package and the crate reference (default: the one this bake runs from; an bake installed from npm links ios and mac against the prebuilt runtime of its toolchain package, unpacked to .bake/native/bakenative). bake build writes the default output on its own.`
|
|
1104
|
+
}), command("gen", object({
|
|
1105
|
+
command: constant("native gen"),
|
|
1106
|
+
spec: multiple(argument(path$2), { min: 1 }),
|
|
1107
|
+
out: optional(option("--out", path$2)),
|
|
1108
|
+
lang: multiple(option("--lang", choice([
|
|
1109
|
+
"swift",
|
|
1110
|
+
"kotlin",
|
|
1111
|
+
"rust"
|
|
1112
|
+
]))),
|
|
1113
|
+
swiftImport: multiple(option("--swift-import", string({ metavar: "MODULE" }))),
|
|
1114
|
+
kotlinPackage: withDefault(option("--kotlin-package", kotlinPackage), "dev.bakenative.generated"),
|
|
1115
|
+
rustCrate: withDefault(option("--rust-crate", string({ metavar: "CRATE" })), "bake_runtime"),
|
|
1116
|
+
check: option("--check")
|
|
1117
|
+
}), {
|
|
1118
|
+
brief: message`Generate a native module's contracts and glue from its spec.`,
|
|
1119
|
+
description: message`Reads each <Name>.native.ts (docs/design/native-module-specs.md) and writes, into --out (default: generated/ next to the spec), <Name>Spec.swift, <Name>Spec.kt and <snake>_spec.rs (--lang keeps some): the records, enums, the protocol / abstract class / trait the implementation conforms to, and the glue. bake build does this for an app's own modules on every build. --check fails when a generated file differs (CI).`
|
|
1120
|
+
}), command("view", command("gen", object({
|
|
1121
|
+
command: constant("native view gen"),
|
|
1122
|
+
spec: multiple(argument(path$2), { min: 1 }),
|
|
1123
|
+
out: optional(option("--out", path$2)),
|
|
1124
|
+
check: option("--check")
|
|
1125
|
+
}), {
|
|
1126
|
+
brief: message`Generate a native view's component and platform bases from its spec.`,
|
|
1127
|
+
description: message`Reads each view spec, <Name>.native.ts (or the older <Name>.view.json; docs/design/native-views.md) and writes, into --out (default: generated/ next to the spec), the JS component and its types, the web custom element base, the Swift, Kotlin and Rust bases and the commands' JSI host functions. React apps get <Name>.js and Octane apps get <Name>.tsrx, selected as for bake build. --check fails when a generated file differs (CI).`
|
|
1128
|
+
}), { brief: message`Native views from one spec.` }), command("new", object({
|
|
1129
|
+
command: constant("native new"),
|
|
1130
|
+
name: argument(string({
|
|
1131
|
+
metavar: "NAME",
|
|
1132
|
+
pattern: /^[A-Z][A-Za-z0-9]*$/,
|
|
1133
|
+
errors: { patternMismatch: message`Use an UpperCamelCase module name, such as Clipboard.` }
|
|
1134
|
+
})),
|
|
1135
|
+
dir: withDefault(option("--dir", path$2), "."),
|
|
1136
|
+
target: optional(option("--target", string({ metavar: "TARGET" }))),
|
|
1137
|
+
platform: withDefault(option("--platform", choice([
|
|
1138
|
+
"all",
|
|
1139
|
+
"apple",
|
|
1140
|
+
"ios",
|
|
1141
|
+
"macos",
|
|
1142
|
+
"android",
|
|
1143
|
+
"windows",
|
|
1144
|
+
"web"
|
|
1145
|
+
])), "all"),
|
|
1146
|
+
spec: withDefault(flag("--spec", { description: message`(the default) a spec-first module.` }), false),
|
|
1147
|
+
root: withDefault(option("--root", path$2, { description: message`The app (its bake.config.ts targets).` }), ".")
|
|
1148
|
+
}), {
|
|
1149
|
+
brief: message`Create a native module: its spec, an implementation per target and tests.`,
|
|
1150
|
+
description: message`Writes native/<name>/<Name>.native.ts in the app (--root; --dir overrides the folder) and an implementation of the generated contract for each target in its bake.config.ts (--platform keeps one): <Name>.swift (iOS and macOS), <Name>.kt, <snake>.rs, <Name>.web.ts, with tests. --target: the Kotlin package.`
|
|
1151
|
+
})), { brief: message`Scaffold native modules and generate their types.` });
|
|
1152
|
+
function readSchema(schemaPath) {
|
|
1153
|
+
if (!existsSync(schemaPath)) throw new Error(`no schema at ${schemaPath}.\nRun the host app once with BAKE_NATIVE_SCHEMA=${schemaPath} (Swift: root.modules.writeSchema(to:); Android: BakeNativeView.nativeSchemaFile, by default files/bakenative/native-modules.json of a debuggable app, \`adb shell run-as <package> cat files/bakenative/native-modules.json\`).`);
|
|
1154
|
+
return JSON.parse(readFileSync(schemaPath, "utf8"));
|
|
1155
|
+
}
|
|
1156
|
+
function nativeTypes(o) {
|
|
1157
|
+
const root = resolve(o.root);
|
|
1158
|
+
const out = resolve(root, o.out);
|
|
1159
|
+
const specs = [...appModuleSpecs(root).values()];
|
|
1160
|
+
const paths = o.schema.map((s) => resolve(root, s));
|
|
1161
|
+
const sources = paths.map((p) => (relative(dirname(out), p) || p).replaceAll("\\", "/"));
|
|
1162
|
+
const inputs = [...specs.length ? [{
|
|
1163
|
+
label: "native/*",
|
|
1164
|
+
schema: specsSchema(specs)
|
|
1165
|
+
}] : [], ...paths.map((p, i) => ({
|
|
1166
|
+
label: basename(sources[i]),
|
|
1167
|
+
schema: readSchema(p)
|
|
1168
|
+
}))];
|
|
1169
|
+
if (!inputs.length) throw new Error(`no module specs in ${join(root, "native")} (bake native new <Name>) and no --schema`);
|
|
1170
|
+
const schema = mergeNativeSchemas(inputs);
|
|
1171
|
+
checkSchemaViews(root, schema);
|
|
1172
|
+
mkdirSync(dirname(out), { recursive: true });
|
|
1173
|
+
writeFileSync(out, nativeDeclarations(schema, [...specs.length ? ["native/*/*.native.ts"] : [], ...sources].join(" + ")));
|
|
1174
|
+
const n = (schema.modules ?? []).reduce((k, m) => k + (m.members?.length ?? 0), 0);
|
|
1175
|
+
const views = schema.views?.length ? `, views ${schema.views.map((v) => v.name).join(", ")}` : "";
|
|
1176
|
+
console.log(`✓ ${relative(process.cwd(), out)} ${schema.modules?.length ?? 0} modules, ${n} members${views}`);
|
|
1177
|
+
}
|
|
1178
|
+
/** Each view the host wrote (schema version 2) is a spec this app can render (@bake-native/core's or
|
|
1179
|
+
* the app's native/views) with the same signature: else the host was built from another
|
|
1180
|
+
* version of the spec (schema drift, docs/design/native-views.md). */
|
|
1181
|
+
function checkSchemaViews(root, schema) {
|
|
1182
|
+
if (!schema.views?.length) return;
|
|
1183
|
+
const support = JSON.parse(readFileSync(join(packageRoot, "native-support.json"), "utf8"));
|
|
1184
|
+
const catalog = viewCatalog(root, {
|
|
1185
|
+
support,
|
|
1186
|
+
packageRoot,
|
|
1187
|
+
readFile: (f) => readFileSync(f, "utf8"),
|
|
1188
|
+
listDir: (d) => readdirSync(d),
|
|
1189
|
+
exists: existsSync
|
|
1190
|
+
});
|
|
1191
|
+
const drift = schema.views.flatMap((v) => {
|
|
1192
|
+
const spec = catalog.find((c) => c.name === v.name);
|
|
1193
|
+
if (!spec) return [`${v.name}: the host provides it, but no spec declares it (@bake-native/core views or native/views/${v.name}.native.ts)`];
|
|
1194
|
+
if (spec.signature !== v.signature) return [`${v.name}: the host implements signature ${v.signature}, ${spec.file} is ${spec.signature} (rebuild the host after \`bake native view gen\`)`];
|
|
1195
|
+
return [];
|
|
1196
|
+
});
|
|
1197
|
+
if (drift.length) throw new Error(`native views differ from their specs:\n ${drift.join("\n ")}`);
|
|
1198
|
+
}
|
|
1199
|
+
/** `minSdk`: bake.config.ts android.minSdk (the Android module declares it). */
|
|
1200
|
+
function nativeLink(o, minSdk, log = console.log) {
|
|
1201
|
+
const root = resolve(o.root);
|
|
1202
|
+
const bundles = (o.bundle.length ? o.bundle : [join("dist", o.target)]).map((b) => resolve(root, b));
|
|
1203
|
+
const manifests = bundles.map((b) => {
|
|
1204
|
+
const file = join(b, "manifest.json");
|
|
1205
|
+
if (!existsSync(file)) throw new Error(`${file} is missing: run \`bake build --target ${o.target}\` first`);
|
|
1206
|
+
return {
|
|
1207
|
+
file: relative(process.cwd(), file),
|
|
1208
|
+
manifest: JSON.parse(readFileSync(file, "utf8"))
|
|
1209
|
+
};
|
|
1210
|
+
});
|
|
1211
|
+
for (const m of manifests) if (m.manifest.target !== o.target) throw new Error(`${m.file} is a ${m.manifest.target} bundle, not ${o.target}`);
|
|
1212
|
+
const names = bundleModules(manifests);
|
|
1213
|
+
const out = resolve(root, o.out ?? join(".bake/native", o.target));
|
|
1214
|
+
let bakenative;
|
|
1215
|
+
let prebuilt;
|
|
1216
|
+
if (FAMILY[o.target] !== "android") {
|
|
1217
|
+
const own = existsSync(join(repo, "Package.swift")) && existsSync(join(repo, "native/rust/Cargo.toml"));
|
|
1218
|
+
const checkout = o.bakenative ? resolve(o.bakenative) : own ? repo : null;
|
|
1219
|
+
if (checkout) {
|
|
1220
|
+
if (!existsSync(join(checkout, "Package.swift"))) throw new Error(`--bakenative ${checkout}: not a BakeNative checkout (no Package.swift); clone BakeNative there or pass its path`);
|
|
1221
|
+
bakenative = checkoutRelative(out, checkout);
|
|
1222
|
+
} else if (FAMILY[o.target] === "apple") {
|
|
1223
|
+
const runtime = materializeAppleRuntime(root);
|
|
1224
|
+
bakenative = checkoutRelative(out, runtime.dir);
|
|
1225
|
+
prebuilt = `${relative(process.cwd(), runtime.dir) || "."} BakeNative ${COMPAT["@bake-native/core"]} runtime (prebuilt${runtime.written ? ", unpacked" : ", unchanged"})`;
|
|
1226
|
+
} else throw new Error(`--bakenative: the BakeNative checkout (its Package.swift) the ${o.target} registration references`);
|
|
1227
|
+
}
|
|
1228
|
+
const support = JSON.parse(readFileSync(join(packageRoot, "native-support.json"), "utf8"));
|
|
1229
|
+
const catalog = [];
|
|
1230
|
+
for (const dir of [.../* @__PURE__ */ new Set([root, ...bundles.map((b) => resolve(b, "..", ".."))])]) {
|
|
1231
|
+
const found = viewCatalog(dir, {
|
|
1232
|
+
support,
|
|
1233
|
+
packageRoot,
|
|
1234
|
+
readFile: (f) => readFileSync(f, "utf8"),
|
|
1235
|
+
listDir: (d) => readdirSync(d),
|
|
1236
|
+
exists: existsSync
|
|
1237
|
+
});
|
|
1238
|
+
for (const v of found) {
|
|
1239
|
+
const seen = catalog.find((c) => c.name === v.name);
|
|
1240
|
+
if (!seen) catalog.push({
|
|
1241
|
+
...v,
|
|
1242
|
+
root: dir
|
|
1243
|
+
});
|
|
1244
|
+
else if (seen.signature !== v.signature) throw new Error(`view ${v.name}: two apps declare different specs (${seen.root}, ${dir})`);
|
|
1245
|
+
}
|
|
1246
|
+
}
|
|
1247
|
+
const requiredViews = bundleViews(manifests);
|
|
1248
|
+
const issues = viewIssues(requiredViews, catalog, o.target);
|
|
1249
|
+
if (issues.length) throw new Error(issues.map((issue) => issue.message).join("\n"));
|
|
1250
|
+
const views = requiredViews.map((name) => {
|
|
1251
|
+
const spec = catalog.find((v) => v.name === name);
|
|
1252
|
+
const unit = spec && appViewUnit(spec.root, spec, o.target);
|
|
1253
|
+
if (!spec || !unit) throw new Error(`The bundle requires ${name}. Restore its view spec and ${o.target} implementation, or rebuild the bundle without this view.`);
|
|
1254
|
+
for (const { file, manifest } of manifests) {
|
|
1255
|
+
const required = manifest.requires?.views?.[name];
|
|
1256
|
+
if (required !== void 0 && required !== spec.signature) throw new Error(`${file} requires ${name} signature ${required}, but its current spec provides ${spec.signature}. Rebuild the bundle with the current spec or restore the matching implementation and spec.`);
|
|
1257
|
+
}
|
|
1258
|
+
return {
|
|
1259
|
+
name,
|
|
1260
|
+
signature: spec.signature,
|
|
1261
|
+
unit
|
|
1262
|
+
};
|
|
1263
|
+
});
|
|
1264
|
+
const appModuleCalls = bundleAppModules(manifests);
|
|
1265
|
+
const linked = /* @__PURE__ */ new Set([
|
|
1266
|
+
...names,
|
|
1267
|
+
...appModuleCalls.required,
|
|
1268
|
+
...appModuleCalls.optional,
|
|
1269
|
+
...manifests.flatMap(({ manifest }) => Object.keys(manifest.requires?.native ?? {}).map((key) => key.split(".")[0]))
|
|
1270
|
+
]);
|
|
1271
|
+
const specs = /* @__PURE__ */ new Map();
|
|
1272
|
+
const app = [];
|
|
1273
|
+
for (const dir of [.../* @__PURE__ */ new Set([root, ...bundles.map((b) => resolve(b, "..", ".."))])]) {
|
|
1274
|
+
for (const [name, spec] of appModuleSpecs(dir)) {
|
|
1275
|
+
const seen = specs.get(name);
|
|
1276
|
+
if (seen && JSON.stringify(seen) !== JSON.stringify(spec)) throw new Error(`native.${name}: two apps declare different specs (${dir})`);
|
|
1277
|
+
specs.set(name, spec);
|
|
1278
|
+
}
|
|
1279
|
+
for (const m of appModuleSources(appModules(dir).filter((m) => linked.has(m.module)), dir, o.target)) if (!app.some((a) => a.module === m.module)) app.push(m);
|
|
1280
|
+
}
|
|
1281
|
+
const { written } = writeRegistration(out, registrationFiles(o.target, names, {
|
|
1282
|
+
bakenative,
|
|
1283
|
+
prebuilt: !!prebuilt,
|
|
1284
|
+
views,
|
|
1285
|
+
minSdk,
|
|
1286
|
+
app,
|
|
1287
|
+
appModules: appModuleCalls,
|
|
1288
|
+
specs,
|
|
1289
|
+
out
|
|
1290
|
+
}));
|
|
1291
|
+
if (FAMILY[o.target] === "apple") {
|
|
1292
|
+
const unpinned = unpinnedPackages(out, targetNativeDeps(o.target, app, views).all.apple, relative(process.cwd(), out) || ".");
|
|
1293
|
+
if (unpinned.length) throw new Error(unpinned.map((f) => `${f.file}:${f.line}: ${f.message}`).join("\n"));
|
|
1294
|
+
}
|
|
1295
|
+
if (prebuilt) log(`✓ ${prebuilt}`);
|
|
1296
|
+
log(`✓ ${relative(process.cwd(), out) || "."} ${o.target}: ${names.join(", ") || "no first-party modules"}${app.length ? `; app modules ${app.map((m) => m.module).join(", ")}` : ""}${views.length ? `; views ${views.map((v) => v.name).join(", ")}` : ""}${written.length ? ` (${written.length} written)` : " (unchanged)"}`);
|
|
1297
|
+
}
|
|
1298
|
+
function nativeGen(o) {
|
|
1299
|
+
const { written, stale } = generateSpecs(o.spec.map((s) => resolve(s)), {
|
|
1300
|
+
out: o.out ? resolve(o.out) : void 0,
|
|
1301
|
+
langs: o.lang.length ? [...o.lang] : void 0,
|
|
1302
|
+
swiftImports: o.swiftImport.length ? [...o.swiftImport] : void 0,
|
|
1303
|
+
kotlinPackage: o.kotlinPackage,
|
|
1304
|
+
rustCrate: o.rustCrate,
|
|
1305
|
+
check: o.check
|
|
1306
|
+
});
|
|
1307
|
+
if (o.check && stale.length) throw new Error(`generated module files are stale (run bake native gen): ${stale.join(", ")}`);
|
|
1308
|
+
if (!o.check) for (const w of written) console.log(`✓ ${w}`);
|
|
1309
|
+
}
|
|
1310
|
+
async function nativeViewGen(o) {
|
|
1311
|
+
const stale = [];
|
|
1312
|
+
for (const spec of o.spec) {
|
|
1313
|
+
const file = resolve(spec);
|
|
1314
|
+
const v = readViewSpec(readFileSync(file, "utf8"), relative(process.cwd(), file).replaceAll("\\", "/"));
|
|
1315
|
+
const dir = dirname(file);
|
|
1316
|
+
const root = basename(dir) === "views" && basename(dirname(dir)) === "native" ? resolve(dir, "../..") : process.cwd();
|
|
1317
|
+
const config = await loadBakeConfig(root);
|
|
1318
|
+
const renderer = config?.config.renderer ?? (existsSync(join(root, "src/App.tsx")) ? selectRenderer(root) : "octane");
|
|
1319
|
+
const out = o.out ? resolve(o.out) : join(dir, "generated");
|
|
1320
|
+
const relativeWeb = relative(out, join(dir, `${v.name}.web.js`)).replaceAll("\\", "/");
|
|
1321
|
+
const web = relativeWeb.startsWith(".") ? relativeWeb : `./${relativeWeb}`;
|
|
1322
|
+
const clientFiles = renderer === "react" && !v.element ? (await loadReactCompiler(root)).reactViewFiles : void 0;
|
|
1323
|
+
for (const f of viewFiles(v, {
|
|
1324
|
+
clientFiles,
|
|
1325
|
+
source: basename(file),
|
|
1326
|
+
web,
|
|
1327
|
+
targets: config?.targets
|
|
1328
|
+
})) {
|
|
1329
|
+
const dest = join(out, f.path);
|
|
1330
|
+
const same = existsSync(dest) && readFileSync(dest, "utf8").replace(/\r\n/g, "\n") === f.text;
|
|
1331
|
+
if (o.check) {
|
|
1332
|
+
if (!same) stale.push(relative(process.cwd(), dest));
|
|
1333
|
+
continue;
|
|
1334
|
+
}
|
|
1335
|
+
if (!same) {
|
|
1336
|
+
mkdirSync(dirname(dest), { recursive: true });
|
|
1337
|
+
writeFileSync(dest, f.text);
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
if (!o.check) console.log(`✓ ${relative(process.cwd(), out) || "."} ${v.name} (${v.tag}, signature ${v.signature})`);
|
|
1341
|
+
}
|
|
1342
|
+
if (stale.length) throw new Error(`generated view files are stale (run bake native view gen): ${stale.join(", ")}`);
|
|
1343
|
+
}
|
|
1344
|
+
/** The spec-first layout (templates/module): <Name>.native.ts and the implementations of `targets`. */
|
|
1345
|
+
function nativeNewSpec(name, { dir, targets, pkg }) {
|
|
1346
|
+
const snake = name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase().replaceAll("-", "_");
|
|
1347
|
+
const files = Object.entries({
|
|
1348
|
+
"__NAME__.native.ts": [],
|
|
1349
|
+
"__NAME__.swift": ["ios", "mac"],
|
|
1350
|
+
"__NAME__Tests.swift": ["ios", "mac"],
|
|
1351
|
+
"__NAME__.kt": ["android"],
|
|
1352
|
+
"__NAME__Test.kt": ["android"],
|
|
1353
|
+
"__SNAKE__.rs": ["windows"],
|
|
1354
|
+
"__NAME__.web.ts": ["web"]
|
|
1355
|
+
}).filter(([, t]) => !t.length || t.some((x) => targets.includes(x))).map(([tpl]) => tpl);
|
|
1356
|
+
const out = files.map((tpl) => join(dir, tpl.replace("__NAME__", name).replace("__SNAKE__", snake)));
|
|
1357
|
+
for (const f of out) if (existsSync(f)) throw new Error(`${f} exists`);
|
|
1358
|
+
mkdirSync(dir, { recursive: true });
|
|
1359
|
+
files.forEach((tpl, i) => {
|
|
1360
|
+
const text = readFileSync(join(templates, "module", tpl), "utf8").replaceAll("__NAME__", name).replaceAll("__SNAKE__", snake).replaceAll("__PACKAGE__", pkg);
|
|
1361
|
+
writeFileSync(out[i], text.replace(/\r\n/g, "\n"));
|
|
1362
|
+
console.log(`✓ ${relative(process.cwd(), out[i])}`);
|
|
1363
|
+
});
|
|
1364
|
+
console.log(`next: write the spec (${name}.native.ts), then each implementation to match it, then tests; bake build registers the module, bake check verifies every target (docs: guides/bake-add).`);
|
|
1365
|
+
return out;
|
|
1366
|
+
}
|
|
1367
|
+
async function nativeNew({ name, platform, ...o }) {
|
|
1368
|
+
const root = resolve(o.root === "." && o.dir !== "." ? o.dir : o.root);
|
|
1369
|
+
const config = await loadBakeConfig(root);
|
|
1370
|
+
const kebab = name.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
1371
|
+
const dir = o.dir === "." || o.dir === o.root ? join(root, "native", kebab) : resolve(o.dir);
|
|
1372
|
+
const all = config?.targets ?? [
|
|
1373
|
+
"web",
|
|
1374
|
+
"ios",
|
|
1375
|
+
"android",
|
|
1376
|
+
"mac",
|
|
1377
|
+
"windows"
|
|
1378
|
+
];
|
|
1379
|
+
const targets = platform === "all" ? all : {
|
|
1380
|
+
apple: ["ios", "mac"],
|
|
1381
|
+
ios: ["ios"],
|
|
1382
|
+
macos: ["mac"],
|
|
1383
|
+
android: ["android"],
|
|
1384
|
+
windows: ["windows"],
|
|
1385
|
+
web: ["web"]
|
|
1386
|
+
}[platform];
|
|
1387
|
+
const pkg = o.target ?? `bakenative.app.${kebab.replaceAll("-", "_")}`;
|
|
1388
|
+
if (!/^[a-z_][A-Za-z0-9_]*(\.[a-z_][A-Za-z0-9_]*)*$/.test(pkg)) throw new Error(`--target ${pkg}: use a Kotlin package name, such as com.example.app`);
|
|
1389
|
+
nativeNewSpec(name, {
|
|
1390
|
+
dir,
|
|
1391
|
+
targets,
|
|
1392
|
+
pkg
|
|
1393
|
+
});
|
|
1394
|
+
}
|
|
1395
|
+
// cli/desktop-app.ts
|
|
1396
|
+
const xml = (text) => text.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">");
|
|
1397
|
+
function desktopPackager({ root, out, target, app, bakenative, viewport }) {
|
|
1398
|
+
if (target === "mac" ? process.platform !== "darwin" : process.platform !== "win32" || process.arch !== "x64") throw new Error(`Run standalone ${target} packaging on ${target === "mac" ? "macOS" : "Windows x64"}.`);
|
|
1399
|
+
const host = join(root, target === "mac" ? "macos" : "windows");
|
|
1400
|
+
if (!existsSync(join(host, target === "mac" ? "Package.swift" : "Cargo.toml"))) throw new Error(`Missing the standalone host at ${host}. Generate one with bake create --targets ${target}.`);
|
|
1401
|
+
const checkout = bakenative ? resolve(bakenative) : existsSync(join(repo, "native/rust/Cargo.toml")) ? repo : void 0;
|
|
1402
|
+
if (target === "windows" && !checkout) throw new Error("Windows standalone packaging requires --bakenative <checkout>.");
|
|
1403
|
+
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
|
|
1404
|
+
const words = (pkg.name?.split("/").at(-1) ?? "").split("-").filter(Boolean);
|
|
1405
|
+
const product = words.map((word) => word[0].toUpperCase() + word.slice(1)).join("");
|
|
1406
|
+
if (!/^[A-Za-z][A-Za-z0-9]*$/.test(product)) throw new Error("Keep the project name generated by bake create in package.json.");
|
|
1407
|
+
const name = app.name ?? words.map((word) => word[0].toUpperCase() + word.slice(1)).join(" ");
|
|
1408
|
+
const [width, height] = viewport.split("x").map(Number);
|
|
1409
|
+
if (![width, height].every((n) => Number.isSafeInteger(n) && n > 0 && n <= 16384)) throw new Error("Desktop standalone viewport requires a whole-number width and height from 1 to 16384.");
|
|
1410
|
+
const shell = {
|
|
1411
|
+
name,
|
|
1412
|
+
appId: app.appId,
|
|
1413
|
+
width,
|
|
1414
|
+
height,
|
|
1415
|
+
window: app.window,
|
|
1416
|
+
tray: app.tray
|
|
1417
|
+
};
|
|
1418
|
+
/**
|
|
1419
|
+
* The runtime's third-party notices: from a BakeNative checkout, made from its sources
|
|
1420
|
+
* (tools/release/third-party.mjs runtimeInventory, the same data as the release's); else the
|
|
1421
|
+
* ones the prebuilt framework carries.
|
|
1422
|
+
*/
|
|
1423
|
+
const runtimeNotices = async (kind, opts) => {
|
|
1424
|
+
const tool = checkout && join(checkout, "tools/release/third-party.mjs");
|
|
1425
|
+
if (!tool || !existsSync(tool)) throw new Error(`the ${kind} runtime's third-party notices need the BakeNative checkout's tools/release/third-party.mjs`);
|
|
1426
|
+
const { runtimeComponents } = await import(pathToFileURL(tool).href);
|
|
1427
|
+
return runtimeComponents(kind, opts);
|
|
1428
|
+
};
|
|
1429
|
+
/** THIRD_PARTY_NOTICES.txt / .json of the output in `dir`: the bundle's (artifacts) and the runtime's. */
|
|
1430
|
+
const writeNotices = (dir, title, artifacts, runtime) => {
|
|
1431
|
+
const bundle = artifacts[NOTICES_JSON];
|
|
1432
|
+
if (!bundle || !existsSync(bundle)) throw new Error(`the ${target} bundle has no ${NOTICES_JSON}: rebuild it with this bake`);
|
|
1433
|
+
writeOutputNotices(dir, {
|
|
1434
|
+
title,
|
|
1435
|
+
generator: `bake package --standalone (@bake-native/core ${COMPAT["@bake-native/core"]})`,
|
|
1436
|
+
components: mergeComponents(readNoticesJson(bundle), runtime)
|
|
1437
|
+
});
|
|
1438
|
+
};
|
|
1439
|
+
return async (artifacts) => {
|
|
1440
|
+
const dest = join(out, "standalone");
|
|
1441
|
+
mkdirSync(dest, { recursive: true });
|
|
1442
|
+
const work = mkdtempSync(join(dest, ".desktop-"));
|
|
1443
|
+
try {
|
|
1444
|
+
nativeLink({
|
|
1445
|
+
command: "native link",
|
|
1446
|
+
target,
|
|
1447
|
+
root,
|
|
1448
|
+
bundle: [join(out, target)],
|
|
1449
|
+
bakenative: checkout,
|
|
1450
|
+
out: void 0
|
|
1451
|
+
}, void 0, () => {});
|
|
1452
|
+
const bundle = target === "mac" ? join(host, "Sources", product, "Bundle") : join(work, "windows/bundle");
|
|
1453
|
+
rmSync(bundle, {
|
|
1454
|
+
recursive: true,
|
|
1455
|
+
force: true
|
|
1456
|
+
});
|
|
1457
|
+
mkdirSync(bundle, { recursive: true });
|
|
1458
|
+
for (const [file, source] of Object.entries(artifacts)) cpSync(source, join(bundle, file), { recursive: true });
|
|
1459
|
+
if (target === "mac") {
|
|
1460
|
+
const swift = (args) => execTool("swift", [
|
|
1461
|
+
"build",
|
|
1462
|
+
"-c",
|
|
1463
|
+
"release",
|
|
1464
|
+
"--product",
|
|
1465
|
+
product,
|
|
1466
|
+
...args
|
|
1467
|
+
], {
|
|
1468
|
+
cwd: host,
|
|
1469
|
+
timeoutSec: 1800
|
|
1470
|
+
}).trim();
|
|
1471
|
+
swift([]);
|
|
1472
|
+
const bin = swift(["--show-bin-path"]);
|
|
1473
|
+
const leaf = `${product}.app`;
|
|
1474
|
+
const contents = join(work, leaf, "Contents");
|
|
1475
|
+
const resources = join(contents, "Resources");
|
|
1476
|
+
mkdirSync(join(contents, "MacOS"), { recursive: true });
|
|
1477
|
+
mkdirSync(resources);
|
|
1478
|
+
writeFileSync(join(resources, "Shell.json"), JSON.stringify(shell));
|
|
1479
|
+
cpSync(join(bin, product), join(contents, "MacOS", product));
|
|
1480
|
+
for (const file of readdirSync(bin).filter((entry) => entry.endsWith(".bundle"))) cpSync(join(bin, file), join(resources, file), {
|
|
1481
|
+
recursive: true,
|
|
1482
|
+
verbatimSymlinks: true
|
|
1483
|
+
});
|
|
1484
|
+
if (app.icon) writeFileSync(join(resources, "AppIcon.icns"), app.icon);
|
|
1485
|
+
const strings = {
|
|
1486
|
+
CFBundleIdentifier: app.appId,
|
|
1487
|
+
CFBundleName: name,
|
|
1488
|
+
CFBundleDisplayName: name,
|
|
1489
|
+
CFBundleExecutable: product,
|
|
1490
|
+
CFBundlePackageType: "APPL",
|
|
1491
|
+
CFBundleShortVersionString: pkg.version ?? "0.0.0",
|
|
1492
|
+
LSMinimumSystemVersion: "14.0",
|
|
1493
|
+
...app.icon && { CFBundleIconFile: "AppIcon.icns" }
|
|
1494
|
+
};
|
|
1495
|
+
writeFileSync(join(contents, "Info.plist"), `<?xml version="1.0" encoding="UTF-8"?>
|
|
1496
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
1497
|
+
<plist version="1.0"><dict>${Object.entries(strings).map(([key, value]) => `<key>${key}</key><string>${xml(value)}</string>`).join("")}${app.window.showInTaskbar ? "" : "<key>LSUIElement</key><true/>"}</dict></plist>
|
|
1498
|
+
`);
|
|
1499
|
+
const exe = join(contents, "MacOS", product);
|
|
1500
|
+
const framework = checkout ? join(checkout, "native/hermes/artifacts/hermesvm.xcframework/macos-arm64/hermesvm.framework") : join(root, APPLE_RUNTIME_DIR, "BakeNative.xcframework/macos-arm64/BakeNativeAppKit.framework");
|
|
1501
|
+
mkdirSync(join(contents, "Frameworks"));
|
|
1502
|
+
execTool("ditto", [framework, join(contents, "Frameworks", basename(framework))]);
|
|
1503
|
+
const runtime = checkout ? await runtimeNotices("apple", {
|
|
1504
|
+
triples: ["aarch64-apple-darwin"],
|
|
1505
|
+
where: [`Contents/MacOS/${product}`, `Contents/Frameworks/${basename(framework)}`]
|
|
1506
|
+
}) : placedAt(readNoticesJson(join(framework, "Resources", NOTICES_JSON)), `Contents/Frameworks/${basename(framework)}`);
|
|
1507
|
+
writeNotices(resources, `${name} ${pkg.version ?? ""}`.trim() + " (macOS)", artifacts, runtime);
|
|
1508
|
+
const rpath = "@executable_path/../Frameworks";
|
|
1509
|
+
if (!execTool("otool", ["-l", exe]).includes(`path ${rpath} (`)) execTool("install_name_tool", [
|
|
1510
|
+
"-add_rpath",
|
|
1511
|
+
rpath,
|
|
1512
|
+
exe
|
|
1513
|
+
]);
|
|
1514
|
+
execTool("codesign", [
|
|
1515
|
+
"--force",
|
|
1516
|
+
"--deep",
|
|
1517
|
+
"--sign",
|
|
1518
|
+
"-",
|
|
1519
|
+
join(work, leaf)
|
|
1520
|
+
]);
|
|
1521
|
+
return publish(work, dest, leaf);
|
|
1522
|
+
}
|
|
1523
|
+
const stage = join(work, "windows");
|
|
1524
|
+
writeFileSync(join(work, "Shell.json"), JSON.stringify(shell));
|
|
1525
|
+
const resource = (file) => join(work, file).replaceAll("\\", "/");
|
|
1526
|
+
writeFileSync(resource("app.manifest"), `<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
|
1527
|
+
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
|
|
1528
|
+
<assemblyIdentity type="win32" name="${app.appId}" version="1.0.0.0" processorArchitecture="amd64"/>
|
|
1529
|
+
<description>${xml(name)}</description>
|
|
1530
|
+
</assembly>
|
|
1531
|
+
`);
|
|
1532
|
+
if (app.icon) writeFileSync(resource("app.ico"), app.icon);
|
|
1533
|
+
writeFileSync(resource("app.rc"), `#pragma code_page(65001)\n1 24 "${resource("app.manifest")}"\n${app.icon ? `1 ICON "${resource("app.ico")}"\n` : ""}`);
|
|
1534
|
+
const installed = toolchainDir();
|
|
1535
|
+
const sourceArtifacts = process.env.BAKE_HERMES_ARTIFACTS ?? join(checkout ?? repo, "native/hermes/artifacts");
|
|
1536
|
+
const dlls = ["bakenative_hermes.dll", "hermesvm.dll"];
|
|
1537
|
+
const dllDir = [join(sourceArtifacts, "windows/x64"), ...installed ? [join(installed, "bin")] : []].find((dir) => dlls.every((file) => existsSync(join(dir, file))));
|
|
1538
|
+
if (!dllDir) throw new Error("Missing the Windows Hermes DLLs. Install the Windows toolchain package or build Hermes with pnpm hermes.");
|
|
1539
|
+
const targetDir = join(root, ".bake", "desktop-cargo");
|
|
1540
|
+
execTool("cargo", [
|
|
1541
|
+
"build",
|
|
1542
|
+
"--release",
|
|
1543
|
+
"--target",
|
|
1544
|
+
"x86_64-pc-windows-msvc",
|
|
1545
|
+
"--target-dir",
|
|
1546
|
+
targetDir
|
|
1547
|
+
], {
|
|
1548
|
+
cwd: host,
|
|
1549
|
+
env: {
|
|
1550
|
+
...process.env,
|
|
1551
|
+
BAKE_HERMES_ARTIFACTS: dllDir,
|
|
1552
|
+
BAKE_DESKTOP_RC: resource("app.rc"),
|
|
1553
|
+
BAKE_DESKTOP_CONFIG: join(work, "Shell.json")
|
|
1554
|
+
},
|
|
1555
|
+
timeoutSec: 1800
|
|
1556
|
+
});
|
|
1557
|
+
cpSync(join(targetDir, "x86_64-pc-windows-msvc/release", `${product}.exe`), join(stage, `${product}.exe`));
|
|
1558
|
+
for (const file of dlls) cpSync(join(dllDir, file), join(stage, file));
|
|
1559
|
+
const vc = [];
|
|
1560
|
+
if (installed) for (const file of [
|
|
1561
|
+
"msvcp140.dll",
|
|
1562
|
+
"vcruntime140.dll",
|
|
1563
|
+
"vcruntime140_1.dll"
|
|
1564
|
+
]) {
|
|
1565
|
+
const dll = join(installed, "bin", file);
|
|
1566
|
+
if (existsSync(dll)) {
|
|
1567
|
+
cpSync(dll, join(stage, file));
|
|
1568
|
+
vc.push(file);
|
|
1569
|
+
}
|
|
1570
|
+
}
|
|
1571
|
+
const crate = readFileSync(join(host, "Cargo.toml"), "utf8").match(/^\[package\][^[]*?^name\s*=\s*"([^"]+)"/m)?.[1];
|
|
1572
|
+
if (!crate) throw new Error(`${join(host, "Cargo.toml")} has no [package] name`);
|
|
1573
|
+
const runtime = await runtimeNotices("windows", {
|
|
1574
|
+
manifest: join(host, "Cargo.toml"),
|
|
1575
|
+
pkg: crate,
|
|
1576
|
+
roots: [checkout, root],
|
|
1577
|
+
dlls: vc,
|
|
1578
|
+
where: [
|
|
1579
|
+
`${product}.exe`,
|
|
1580
|
+
...dlls,
|
|
1581
|
+
...vc
|
|
1582
|
+
]
|
|
1583
|
+
});
|
|
1584
|
+
writeNotices(stage, `${name} ${pkg.version ?? ""}`.trim() + " (Windows)", artifacts, runtime);
|
|
1585
|
+
return publish(work, dest, "windows");
|
|
1586
|
+
} finally {
|
|
1587
|
+
rmSync(work, {
|
|
1588
|
+
recursive: true,
|
|
1589
|
+
force: true
|
|
1590
|
+
});
|
|
1591
|
+
}
|
|
1592
|
+
};
|
|
1593
|
+
}
|
|
1594
|
+
function publish(work, dest, leaf) {
|
|
1595
|
+
const output = join(dest, leaf);
|
|
1596
|
+
const previous = join(work, "previous");
|
|
1597
|
+
if (existsSync(output)) renameSync(output, previous);
|
|
1598
|
+
try {
|
|
1599
|
+
renameSync(join(work, leaf), output);
|
|
1600
|
+
} catch (error) {
|
|
1601
|
+
if (existsSync(previous)) renameSync(previous, output);
|
|
1602
|
+
throw error;
|
|
1603
|
+
}
|
|
1604
|
+
return output;
|
|
1605
|
+
}
|
|
1606
|
+
// cli/dev.ts
|
|
1607
|
+
const devTargets = [
|
|
1608
|
+
"web",
|
|
1609
|
+
"windows",
|
|
1610
|
+
"ios",
|
|
1611
|
+
"mac",
|
|
1612
|
+
"android"
|
|
1613
|
+
];
|
|
1614
|
+
const targetList = {
|
|
1615
|
+
mode: "sync",
|
|
1616
|
+
metavar: "TARGETS",
|
|
1617
|
+
placeholder: ["web"],
|
|
1618
|
+
parse(input) {
|
|
1619
|
+
const targets = [];
|
|
1620
|
+
for (const token of input.split(/[\s,]+/).filter(Boolean)) {
|
|
1621
|
+
const target = devTargets.find((t) => t === token.trim());
|
|
1622
|
+
if (!target) return {
|
|
1623
|
+
success: false,
|
|
1624
|
+
error: message`Unknown target ${token}. Choose from ${devTargets.join(", ")}.`
|
|
1625
|
+
};
|
|
1626
|
+
if (!targets.includes(target)) targets.push(target);
|
|
1627
|
+
}
|
|
1628
|
+
return {
|
|
1629
|
+
success: true,
|
|
1630
|
+
value: targets
|
|
1631
|
+
};
|
|
1632
|
+
},
|
|
1633
|
+
format: (targets) => targets.join(",")
|
|
1634
|
+
};
|
|
1635
|
+
const path$1 = string({ metavar: "PATH" });
|
|
1636
|
+
const dev = command("dev", object({
|
|
1637
|
+
command: constant("dev"),
|
|
1638
|
+
targets: optional(option("-t", "--target", targetList, { description: message`Comma-separated targets to rebuild and reload: web, windows, ios, mac, android. Default: web, or the first target in bake.config.ts when it does not list web. A target the config does not list is an error.` })),
|
|
1639
|
+
root: withDefault(option("--root", path$1, { description: message`Project directory containing src/App.tsx (React) or src/App.tsrx (Octane).` }), "."),
|
|
1640
|
+
port: withDefault(option("--port", integer({
|
|
1641
|
+
min: 0,
|
|
1642
|
+
max: 65535
|
|
1643
|
+
}), { description: message`Port of the web target's server (0: any free port).` }), 5180),
|
|
1644
|
+
open: withDefault(flag("--open", { description: message`Open the web target in the default browser.` }), false),
|
|
1645
|
+
host: optional(option("--host", path$1, { description: message`Desktop host that runs the bundle from $BAKE_BUNDLE: windows, an exe (default: the staged examples/windows app); mac, a binary or .app (default: examples/mac's debug build).` })),
|
|
1646
|
+
udid: optional(option("--udid", string({ metavar: "UDID" }), { description: message`iOS: the booted simulator (default: the only booted one; bake dev never boots one).` })),
|
|
1647
|
+
bundleId: withDefault(option("--bundle-id", string({ metavar: "ID" }), { description: message`iOS: the host app's bundle identifier.` }), "com.bakenative.examples.brownfield"),
|
|
1648
|
+
iosHost: optional(option("--ios-host", path$1, { description: message`iOS: a debug simulator .app to install before the first launch.` })),
|
|
1649
|
+
serial: optional(option("--serial", string({ metavar: "SERIAL" }), { description: message`Android: the device (default: $ANDROID_SERIAL, else the only one adb lists).` })),
|
|
1650
|
+
package: withDefault(option("--package", string({ metavar: "NAME" }), { description: message`Android: the host app's package (a debug build).` }), "dev.bakenative.example"),
|
|
1651
|
+
debounce: withDefault(option("--debounce", integer({
|
|
1652
|
+
min: 0,
|
|
1653
|
+
max: 5e3
|
|
1654
|
+
}), { hidden: true }), 40),
|
|
1655
|
+
hermesc: optional(option("--hermesc", path$1, { description: message`Path to the Hermes compiler.` })),
|
|
1656
|
+
hermescFlags: withDefault(option("--hermesc-flags", string({ metavar: "FLAGS" }), { description: message`Space-separated flags passed to hermesc (-O0: about 3x faster than bake build's -O).` }), "-O0"),
|
|
1657
|
+
json: withDefault(flag("--json", { description: message`Print one JSON event per line instead of the console log.` }), false),
|
|
1658
|
+
once: withDefault(flag("--once", { description: message`Build, launch and report the first screen, then exit.` }), false),
|
|
1659
|
+
strictAot: optional(map(flag("--no-strict-aot", { description: message`Turn strict AOT off: findings are warnings (also "bakenative": { "strictAot": false } in package.json).` }), () => false))
|
|
1660
|
+
}), { brief: message`Rebuild and reload the app on every saved change.` });
|
|
1661
|
+
async function resolveDevOptions(input) {
|
|
1662
|
+
const root = resolve(input.root);
|
|
1663
|
+
const config = await loadBakeConfig(root);
|
|
1664
|
+
const targets = resolveTargets(input.targets, config, ["web"], (declared) => [declared.includes("web") ? "web" : declared[0]]);
|
|
1665
|
+
return {
|
|
1666
|
+
...input,
|
|
1667
|
+
targets,
|
|
1668
|
+
root,
|
|
1669
|
+
androidMinSdk: config?.androidMinSdk ?? 29,
|
|
1670
|
+
renderer: config?.config.renderer,
|
|
1671
|
+
fontSettings: config?.fontSettings,
|
|
1672
|
+
css: config?.css,
|
|
1673
|
+
compiler: config?.compiler,
|
|
1674
|
+
locales: config?.locales ?? [],
|
|
1675
|
+
unbaked: config ? !config.bake : false,
|
|
1676
|
+
out: resolve(root, ".bake/dev"),
|
|
1677
|
+
hermesc: input.hermesc ?? defaultHermesc(),
|
|
1678
|
+
aotCheck: true,
|
|
1679
|
+
host: input.host ? resolve(input.host) : targets.includes("windows") ? process.env.BAKE_WINDOWS_HOST : void 0,
|
|
1680
|
+
iosHost: input.iosHost ? resolve(input.iosHost) : void 0
|
|
1681
|
+
};
|
|
1682
|
+
}
|
|
1683
|
+
// bundle-files.mjs
|
|
1684
|
+
/** Little-endian `.baked` magic number (bake-core frame.rs `MAGIC`). */
|
|
1685
|
+
const FRAME_MAGIC = 0x4d52464f;
|
|
1686
|
+
/** Hermes `BytecodeFileHeader.magic` (bake-core frame.rs `HBC_MAGIC`). */
|
|
1687
|
+
const HBC_MAGIC = 2240826417119764422n;
|
|
1688
|
+
/** `BytecodeFileHeader`: magic (8), version (4), source SHA-1 (20), then `fileLength` (u32). */
|
|
1689
|
+
const HBC_FILE_LENGTH_AT = 32;
|
|
1690
|
+
/** `BytecodeFileFooter`: the SHA-1 hermesc writes over every byte before it. */
|
|
1691
|
+
const HBC_FOOTER_SIZE = 20;
|
|
1692
|
+
function fnv1a64(bytes) {
|
|
1693
|
+
let h = 14695981039346656037n;
|
|
1694
|
+
for (const b of bytes) h = BigInt.asUintN(64, (h ^ BigInt(b)) * 1099511628211n);
|
|
1695
|
+
return h;
|
|
1696
|
+
}
|
|
1697
|
+
/** bake-core `hbc_identity`: FNV-1a 64 of the bytecode footer's SHA-1 (56 bytes read); a file
|
|
1698
|
+
* that is not Hermes bytecode with a footer: FNV-1a 64 of the whole file. */
|
|
1699
|
+
function hbcIdentity(path) {
|
|
1700
|
+
const fd = openSync(path, "r");
|
|
1701
|
+
try {
|
|
1702
|
+
const len = fstatSync(fd).size;
|
|
1703
|
+
const header = Buffer.alloc(36);
|
|
1704
|
+
const footer = Buffer.alloc(HBC_FOOTER_SIZE);
|
|
1705
|
+
if (len >= header.length + HBC_FOOTER_SIZE) {
|
|
1706
|
+
readSync(fd, header, 0, header.length, 0);
|
|
1707
|
+
readSync(fd, footer, 0, HBC_FOOTER_SIZE, len - HBC_FOOTER_SIZE);
|
|
1708
|
+
if (header.readBigUInt64LE(0) === HBC_MAGIC && header.readUInt32LE(HBC_FILE_LENGTH_AT) === len) return fnv1a64(footer);
|
|
1709
|
+
}
|
|
1710
|
+
} finally {
|
|
1711
|
+
closeSync(fd);
|
|
1712
|
+
}
|
|
1713
|
+
return fnv1a64(readFileSync(path));
|
|
1714
|
+
}
|
|
1715
|
+
/** The `hbcHash` a frame (v3) or snapshot (v4) header carries (bake-core `baked_hbc_hash`); null
|
|
1716
|
+
* when the file is not a frame this runtime reads. */
|
|
1717
|
+
function bakedHbcHash(bytes) {
|
|
1718
|
+
if (bytes.length < 6 || bytes.readUInt32LE(0) !== FRAME_MAGIC) return null;
|
|
1719
|
+
const version = bytes.readUInt16LE(4);
|
|
1720
|
+
if (version === 3 && bytes.length >= 56) return bytes.readBigUInt64LE(48);
|
|
1721
|
+
if (version === 4 && bytes.length >= 80) return bytes.readBigUInt64LE(16);
|
|
1722
|
+
return null;
|
|
1723
|
+
}
|
|
1724
|
+
/**
|
|
1725
|
+
* Whether the bundle directory holds one build's files: each file manifest.json `files` names is
|
|
1726
|
+
* there with the build's SHA-256 (app.hbc, app.baked, app.css, app.js), and app.baked was baked from
|
|
1727
|
+
* this app.hbc. Returns the reasons it is not (empty: one build).
|
|
1728
|
+
*/
|
|
1729
|
+
function bundleFilesCheck(dir, manifest) {
|
|
1730
|
+
const reasons = [];
|
|
1731
|
+
const files = manifest?.files ?? {};
|
|
1732
|
+
for (const [name, sha] of Object.entries(files)) {
|
|
1733
|
+
const path = join(dir, name);
|
|
1734
|
+
if (name === "app.js" && !existsSync(path)) continue;
|
|
1735
|
+
if (!existsSync(path)) {
|
|
1736
|
+
reasons.push(`${name}: listed in manifest.json but missing (ship app.hbc, app.baked and app.css of one build together)`);
|
|
1737
|
+
continue;
|
|
1738
|
+
}
|
|
1739
|
+
const got = createHash("sha256").update(readFileSync(path)).digest("hex");
|
|
1740
|
+
if (got !== sha) reasons.push(`${name}: not the file this manifest.json was built with (sha256 ${got.slice(0, 12)}…, manifest ${String(sha).slice(0, 12)}…)`);
|
|
1741
|
+
}
|
|
1742
|
+
const hbc = join(dir, "app.hbc");
|
|
1743
|
+
const defaultFile = manifest?.frame ? manifest.frame.file : "app.baked";
|
|
1744
|
+
if (typeof defaultFile !== "string" || !/^app\.[a-z0-9]+$/.test(defaultFile) || manifest?.hostProtocol >= 4 && defaultFile !== "app.baked") return [...reasons, `manifest.json frame.file: expected app.baked, got ${JSON.stringify(defaultFile)}`];
|
|
1745
|
+
const frames = /* @__PURE__ */ new Set([defaultFile]);
|
|
1746
|
+
const locales = Array.isArray(manifest?.locales) ? manifest.locales : [];
|
|
1747
|
+
for (const [locale, entry] of Object.entries(manifest?.frames ?? {})) {
|
|
1748
|
+
const expected = locale === locales[0] ? defaultFile : `app.${locale}${extname(defaultFile)}`;
|
|
1749
|
+
if (!/^[a-zA-Z0-9-]+$/.test(locale) || !locales.includes(locale) || entry?.file !== expected) reasons.push(`manifest.json frames[${JSON.stringify(locale)}]: expected the declared locale's frame ${expected}`);
|
|
1750
|
+
else frames.add(expected);
|
|
1751
|
+
}
|
|
1752
|
+
let identity, fullHash;
|
|
1753
|
+
for (const name of frames) {
|
|
1754
|
+
const frame = join(dir, name);
|
|
1755
|
+
if (!existsSync(frame)) {
|
|
1756
|
+
if (!Object.hasOwn(files, name) && (name !== defaultFile || manifest?.frame)) reasons.push(`${name}: declared in manifest.json but missing`);
|
|
1757
|
+
continue;
|
|
1758
|
+
}
|
|
1759
|
+
if (name === defaultFile && !files[name] && !manifest?.frame) reasons.push(`${name} is not part of this manifest.json's build`);
|
|
1760
|
+
const baked = bakedHbcHash(readFileSync(frame));
|
|
1761
|
+
if (baked === null) reasons.push(`${name} has an invalid baked frame header: rebuild the bundle with \`bake build\``);
|
|
1762
|
+
else if (baked !== 0n && existsSync(hbc) && baked !== (identity ??= hbcIdentity(hbc)) && baked !== (fullHash ??= fnv1a64(readFileSync(hbc)))) reasons.push(`${name} was baked from another app.hbc: the device would not show it (ship the app.hbc and ${name} of one build)`);
|
|
1763
|
+
}
|
|
1764
|
+
return reasons;
|
|
1765
|
+
}
|
|
1766
|
+
// cli/release.ts
|
|
1767
|
+
const release = command("release", command("check", object({
|
|
1768
|
+
command: constant("release check"),
|
|
1769
|
+
bundle: argument(string({ metavar: "BUNDLE" })),
|
|
1770
|
+
against: option("--against", string({ metavar: "PACKAGE" })),
|
|
1771
|
+
json: withDefault(flag("--json"), false)
|
|
1772
|
+
}), { brief: message`Check a bundle against the installed app package.` }), { brief: message`Verify release compatibility.` });
|
|
1773
|
+
/**
|
|
1774
|
+
* A package manifest from an xcframework, a framework, a resource directory, an Android package
|
|
1775
|
+
* AAR or app APK (assets/bakenative/<id>/BakeNativePackage.json) or the file itself.
|
|
1776
|
+
*/
|
|
1777
|
+
function readPackageManifest(path) {
|
|
1778
|
+
const abs = resolve(path);
|
|
1779
|
+
if (/\.(aar|apk)$/i.test(abs)) {
|
|
1780
|
+
const m = aarPackageManifest(readFileSync(abs));
|
|
1781
|
+
if (!m) throw new Error(`no assets/bakenative/<id>/BakeNativePackage.json in ${path}`);
|
|
1782
|
+
return m;
|
|
1783
|
+
}
|
|
1784
|
+
const candidates = [
|
|
1785
|
+
abs,
|
|
1786
|
+
join(abs, "BakeNativePackage.json"),
|
|
1787
|
+
join(abs, "BakeNativeApp/BakeNativePackage.json")
|
|
1788
|
+
];
|
|
1789
|
+
if (abs.endsWith(".xcframework")) {
|
|
1790
|
+
const name = basename(abs, ".xcframework");
|
|
1791
|
+
for (const slice of [
|
|
1792
|
+
"ios-arm64",
|
|
1793
|
+
"ios-arm64-simulator",
|
|
1794
|
+
"macos-arm64"
|
|
1795
|
+
]) candidates.push(join(abs, slice, `${name}.framework/BakeNativeApp/BakeNativePackage.json`));
|
|
1796
|
+
}
|
|
1797
|
+
const file = candidates.find((c) => existsSync(c) && statSync(c).isFile());
|
|
1798
|
+
if (!file) throw new Error(`no BakeNativePackage.json in ${path}`);
|
|
1799
|
+
return JSON.parse(readFileSync(file, "utf8"));
|
|
1800
|
+
}
|
|
1801
|
+
/**
|
|
1802
|
+
* bake release check <bundle dir> --against <package>: the CI gate before an OTA release. The
|
|
1803
|
+
* bundle's `requires` against the package's `provides` (its native modules and the runtime it
|
|
1804
|
+
* was packaged with), by the rules the device applies (compat.mjs, bake-runtime compat.rs). Given
|
|
1805
|
+
* the bundle directory, also that its files are one build's (bundle-files.mjs): app.hbc, app.baked
|
|
1806
|
+
* and app.css as manifest.json lists them, and app.baked baked from this app.hbc.
|
|
1807
|
+
*/
|
|
1808
|
+
function releaseCommand(o) {
|
|
1809
|
+
const bundlePath = resolve(o.bundle);
|
|
1810
|
+
const manifestFile = statSync(bundlePath).isDirectory() ? join(bundlePath, "manifest.json") : bundlePath;
|
|
1811
|
+
const bundle = JSON.parse(readFileSync(manifestFile, "utf8"));
|
|
1812
|
+
const pkg = readPackageManifest(o.against);
|
|
1813
|
+
const compat = releaseCheck(bundle, pkg);
|
|
1814
|
+
const files = statSync(bundlePath).isDirectory() ? bundleFilesCheck(bundlePath, bundle) : [];
|
|
1815
|
+
const reasons = [...compat.reasons, ...files];
|
|
1816
|
+
const result = {
|
|
1817
|
+
ok: reasons.length === 0,
|
|
1818
|
+
reasons
|
|
1819
|
+
};
|
|
1820
|
+
if (o.json) process.stdout.write(JSON.stringify({
|
|
1821
|
+
...result,
|
|
1822
|
+
package: pkg.id ?? null,
|
|
1823
|
+
packageVersion: pkg.version ?? null
|
|
1824
|
+
}) + "\n");
|
|
1825
|
+
else if (result.ok) console.log(`✓ ${relative(process.cwd(), manifestFile)} runs in ${pkg.name} ${pkg.version} (${pkg.id}): everything it requires is provided`);
|
|
1826
|
+
else {
|
|
1827
|
+
console.log(`✗ ${relative(process.cwd(), manifestFile)} must not ship to ${pkg.name} ${pkg.version} (the device would reject it and run the embedded bundle):`);
|
|
1828
|
+
for (const r of result.reasons) console.log(` ${r}`);
|
|
1829
|
+
}
|
|
1830
|
+
process.exitCode = result.ok ? 0 : 1;
|
|
1831
|
+
}
|
|
1832
|
+
// cli/package.ts
|
|
1833
|
+
const packageCheck = command("check", object({
|
|
1834
|
+
command: constant("package check"),
|
|
1835
|
+
aar: argument(string({ metavar: "AAR" })),
|
|
1836
|
+
root: optional(option("--root", string({ metavar: "PATH" }), { description: message`App directory whose package.json declares the package (default: the BakeNativePackage.json inside the AAR, else .).` })),
|
|
1837
|
+
json: withDefault(flag("--json", { description: message`Print the report as JSON.` }), false)
|
|
1838
|
+
}), { brief: message`Check an app package AAR for undeclared third-party code.` });
|
|
1839
|
+
const packageHostCheck = command("host-check", object({
|
|
1840
|
+
command: constant("package host-check"),
|
|
1841
|
+
packages: multiple(argument(string({ metavar: "PACKAGE" })), { min: 1 }),
|
|
1842
|
+
provide: multiple(option("--provide", string({
|
|
1843
|
+
metavar: "NAME=VERSION",
|
|
1844
|
+
pattern: /^[^=]+=.+$/
|
|
1845
|
+
}), { description: message`A library version the host already links (repeatable).` })),
|
|
1846
|
+
platform: optional(option("--platform", choice(["android", "ios"]), { description: message`Check one platform (default: both).` })),
|
|
1847
|
+
json: withDefault(flag("--json", { description: message`Print the result as JSON.` }), false)
|
|
1848
|
+
}), { brief: message`Check that app packages fit in one host: shared third-party ranges overlap, identities do not collide.` });
|
|
1849
|
+
/** A package for the integration check from an .aar, a BakeNativePackage.json (or its directory), or an app directory. */
|
|
1850
|
+
function loadPackage(path) {
|
|
1851
|
+
const abs = resolve(path);
|
|
1852
|
+
const source = relative(process.cwd(), abs) || ".";
|
|
1853
|
+
const fromManifest = (m) => {
|
|
1854
|
+
const name = m.name ?? basename(abs);
|
|
1855
|
+
const id = m.id ?? `dev.bakenative.app.${name}`;
|
|
1856
|
+
return {
|
|
1857
|
+
name,
|
|
1858
|
+
id,
|
|
1859
|
+
source,
|
|
1860
|
+
thirdParty: thirdPartyDeclarations(m.thirdParty, name),
|
|
1861
|
+
android: androidIdentity(m.android, {
|
|
1862
|
+
name,
|
|
1863
|
+
id
|
|
1864
|
+
})
|
|
1865
|
+
};
|
|
1866
|
+
};
|
|
1867
|
+
if (abs.endsWith(".aar")) {
|
|
1868
|
+
const buf = readFileSync(abs);
|
|
1869
|
+
const m = aarPackageManifest(buf);
|
|
1870
|
+
if (!m) throw new Error(`${source}: no assets/bakenative/<id>/BakeNativePackage.json inside; pass the app directory instead`);
|
|
1871
|
+
const pkg = fromManifest(m);
|
|
1872
|
+
const report = checkAar(buf, {
|
|
1873
|
+
name: pkg.name,
|
|
1874
|
+
id: pkg.id,
|
|
1875
|
+
android: pkg.android,
|
|
1876
|
+
thirdParty: pkg.thirdParty
|
|
1877
|
+
});
|
|
1878
|
+
pkg.aar = {
|
|
1879
|
+
so: [...new Set(report.contents.so.map((s) => s.name))],
|
|
1880
|
+
authorities: report.contents.authorities,
|
|
1881
|
+
namespace: report.contents.namespace,
|
|
1882
|
+
kotlinModules: report.contents.kotlinModules
|
|
1883
|
+
};
|
|
1884
|
+
return {
|
|
1885
|
+
pkg,
|
|
1886
|
+
report
|
|
1887
|
+
};
|
|
1888
|
+
}
|
|
1889
|
+
const isDir = statSync(abs).isDirectory();
|
|
1890
|
+
if (isDir && existsSync(join(abs, "package.json")) && !existsSync(join(abs, "BakeNativePackage.json"))) {
|
|
1891
|
+
const cfg = packageConfig(abs);
|
|
1892
|
+
if (!cfg) throw new Error(`${source}/package.json has no "bakenative": { "package": { ... } }`);
|
|
1893
|
+
return { pkg: {
|
|
1894
|
+
name: cfg.name,
|
|
1895
|
+
id: cfg.id,
|
|
1896
|
+
source,
|
|
1897
|
+
thirdParty: cfg.thirdParty,
|
|
1898
|
+
android: cfg.android
|
|
1899
|
+
} };
|
|
1900
|
+
}
|
|
1901
|
+
const file = isDir ? join(abs, "BakeNativePackage.json") : abs;
|
|
1902
|
+
return { pkg: fromManifest(JSON.parse(readFileSync(file, "utf8"))) };
|
|
1903
|
+
}
|
|
1904
|
+
function printIssues(title, report) {
|
|
1905
|
+
for (const e of report.errors) console.log(` ✗ [${e.code}] ${e.message}\n fix: ${e.fix}`);
|
|
1906
|
+
for (const w of report.warnings) console.log(` ! [${w.code}] ${w.message}\n fix: ${w.fix}`);
|
|
1907
|
+
if (!report.errors.length && !report.warnings.length) console.log(` ✓ ${title}`);
|
|
1908
|
+
}
|
|
1909
|
+
/** bake package check <aar>: the package's own code, declared libraries in their declared form, nothing else. */
|
|
1910
|
+
function packageCheckCommand(o) {
|
|
1911
|
+
const abs = resolve(o.aar);
|
|
1912
|
+
const buf = readFileSync(abs);
|
|
1913
|
+
const embedded = o.root ? null : aarPackageManifest(buf);
|
|
1914
|
+
let pkg;
|
|
1915
|
+
if (embedded) {
|
|
1916
|
+
const name = embedded.name;
|
|
1917
|
+
const id = embedded.id;
|
|
1918
|
+
pkg = {
|
|
1919
|
+
name,
|
|
1920
|
+
id,
|
|
1921
|
+
thirdParty: thirdPartyDeclarations(embedded.thirdParty, name),
|
|
1922
|
+
android: androidIdentity(embedded.android, {
|
|
1923
|
+
name,
|
|
1924
|
+
id
|
|
1925
|
+
})
|
|
1926
|
+
};
|
|
1927
|
+
} else {
|
|
1928
|
+
const cfg = packageConfig(resolve(o.root ?? "."));
|
|
1929
|
+
if (!cfg) throw new Error(`${resolve(o.root ?? ".")}/package.json has no "bakenative": { "package": { ... } } (see guides/packaging.mdx)`);
|
|
1930
|
+
pkg = cfg;
|
|
1931
|
+
}
|
|
1932
|
+
const report = checkAar(buf, pkg);
|
|
1933
|
+
if (o.json) process.stdout.write(JSON.stringify({
|
|
1934
|
+
package: pkg.name,
|
|
1935
|
+
...report
|
|
1936
|
+
}, null, 2) + "\n");
|
|
1937
|
+
else {
|
|
1938
|
+
const c = report.contents;
|
|
1939
|
+
console.log(`${report.ok ? "✓" : "✗"} ${relative(process.cwd(), abs)} (${pkg.name}, ${pkg.android.package}): ${c.ownClasses}/${c.classes} classes own, ${c.so.length} .so, ${c.resources} resources`);
|
|
1940
|
+
printIssues("only its own code and declared libraries", report);
|
|
1941
|
+
}
|
|
1942
|
+
process.exitCode = report.ok ? 0 : 1;
|
|
1943
|
+
}
|
|
1944
|
+
/** bake package host-check <package>...: the packages one host links, together. */
|
|
1945
|
+
function packageHostCheckCommand(o) {
|
|
1946
|
+
const loaded = o.packages.map(loadPackage);
|
|
1947
|
+
const provide = Object.fromEntries(o.provide.map((p) => [p.slice(0, p.indexOf("=")), p.slice(p.indexOf("=") + 1)]));
|
|
1948
|
+
const platforms = o.platform ? [o.platform] : void 0;
|
|
1949
|
+
const result = integrateThirdParty(loaded.map((l) => l.pkg), {
|
|
1950
|
+
provide,
|
|
1951
|
+
platforms
|
|
1952
|
+
});
|
|
1953
|
+
const packageErrors = loaded.filter((l) => l.report && !l.report.ok);
|
|
1954
|
+
const ok = result.ok && !packageErrors.length;
|
|
1955
|
+
if (o.json) process.stdout.write(JSON.stringify({
|
|
1956
|
+
...result,
|
|
1957
|
+
ok,
|
|
1958
|
+
packages: loaded.map((l) => ({
|
|
1959
|
+
name: l.pkg.name,
|
|
1960
|
+
source: l.pkg.source,
|
|
1961
|
+
aar: l.report ?? null
|
|
1962
|
+
}))
|
|
1963
|
+
}, null, 2) + "\n");
|
|
1964
|
+
else {
|
|
1965
|
+
console.log(`${ok ? "✓" : "✗"} ${loaded.length} packages in one host: ${loaded.map((l) => l.pkg.name).join(", ")}`);
|
|
1966
|
+
for (const lib of result.libraries) {
|
|
1967
|
+
const who = [...lib.shared.map((s) => `${s.package} ${s.version}`), ...lib.isolated.map((s) => `${s.package} ${s.version} (isolated)`)].join(", ");
|
|
1968
|
+
const pick = lib.shared.length ? lib.range ? `host links one copy in ${lib.range}${lib.provided ? ` (provides ${lib.provided})` : ""}` : "no common version" : "no host copy";
|
|
1969
|
+
console.log(` ${lib.platform.padEnd(7)} ${lib.name}: ${pick} — ${who}`);
|
|
1970
|
+
}
|
|
1971
|
+
for (const e of result.errors) console.log(` ✗ ${e}`);
|
|
1972
|
+
for (const l of packageErrors) {
|
|
1973
|
+
console.log(` ✗ ${l.pkg.source}: the package check fails (bake package check ${l.pkg.source}):`);
|
|
1974
|
+
for (const e of l.report.errors) console.log(` [${e.code}] ${e.message}`);
|
|
1975
|
+
}
|
|
1976
|
+
for (const n of result.notes) console.log(` · ${n}`);
|
|
1977
|
+
}
|
|
1978
|
+
process.exitCode = ok ? 0 : 1;
|
|
1979
|
+
}
|
|
1980
|
+
// cli/main.ts
|
|
1981
|
+
const path = string({ metavar: "PATH" });
|
|
1982
|
+
const json = withDefault(flag("--json", { description: message`Print the build report as JSON.` }), false);
|
|
1983
|
+
const platforms = TARGETS;
|
|
1984
|
+
/** --strict-aot / --no-strict-aot: true / false; undefined when neither is given (then
|
|
1985
|
+
* "bakenative": { "strictAot" } in package.json decides, and strict is the default). */
|
|
1986
|
+
function strictAotFlag(on) {
|
|
1987
|
+
return optional(or(map(flag("--strict-aot", { description: on }), () => true), map(flag("--no-strict-aot", { description: message`Turn strict AOT off: findings are warnings (also "bakenative": { "strictAot": false } in package.json).` }), () => false)));
|
|
1988
|
+
}
|
|
1989
|
+
/** --target: optional, so a missing one can fall back to bake.config.ts (then to `fallback`). */
|
|
1990
|
+
function targetOption(fallback) {
|
|
1991
|
+
return optional(option("-t", "--target", targetList$1, { description: message`Comma-separated targets: web, ios, android, mac, windows. Default: the targets in bake.config.ts, else ${fallback}. A target the config does not list is an error.` }));
|
|
1992
|
+
}
|
|
1993
|
+
function bundleOptions(fallback) {
|
|
1994
|
+
return {
|
|
1995
|
+
targets: targetOption(fallback),
|
|
1996
|
+
root: withDefault(option("--root", path, { description: message`Project directory containing src/App.tsx (React) or src/App.tsrx (Octane).` }), "."),
|
|
1997
|
+
out: withDefault(option("--out", path, { description: message`Output directory, relative to the project root.` }), "dist"),
|
|
1998
|
+
hermesc: optional(option("--hermesc", path, { description: message`Path to the Hermes compiler.` })),
|
|
1999
|
+
hermescFlags: withDefault(option("--hermesc-flags", string({ metavar: "FLAGS" }), { description: message`Space-separated flags passed to hermesc.` }), "-O"),
|
|
2000
|
+
json,
|
|
2001
|
+
styles: multiple(option("--style", string({ metavar: "STYLESHEET" }), { description: message`A global stylesheet loaded before the app's src/styles.css, so the app's rules win (repeatable): a local CSS file or a package stylesheet.` })),
|
|
2002
|
+
noAotCheck: withDefault(flag("--no-aot-check", { hidden: true }), false),
|
|
2003
|
+
strictAot: strictAotFlag(message`Fail the build on AOT fast-path findings (the default; overrides "bakenative": { "strictAot": false }).`),
|
|
2004
|
+
viewport: withDefault(option("--viewport", string({
|
|
2005
|
+
metavar: "WIDTHxHEIGHT",
|
|
2006
|
+
pattern: /^\d+(?:\.\d+)?x\d+(?:\.\d+)?$/
|
|
2007
|
+
})), "800x600"),
|
|
2008
|
+
runtime: optional(option("--runtime", path, { description: message`Use an existing BakeNative.xcframework.` }))
|
|
2009
|
+
};
|
|
2010
|
+
}
|
|
2011
|
+
const build = object({
|
|
2012
|
+
command: constant("build"),
|
|
2013
|
+
...bundleOptions("web,mac"),
|
|
2014
|
+
bake: withDefault(flag("--bake", { description: message`Bake the first-screen snapshot.` }), false),
|
|
2015
|
+
xcframework: withDefault(flag("--xcframework", { description: message`Package the built Apple targets as Swift packages.` }), false),
|
|
2016
|
+
name: optional(option("--name", string({ metavar: "PRODUCT" }), { description: message`Swift product name for the generated XCFramework.` })),
|
|
2017
|
+
embedRuntime: withDefault(flag("--embed-runtime", { description: message`Embed the runtime in the generated XCFramework.` }), false),
|
|
2018
|
+
remoteURL: optional(option("--remote-url", string({ metavar: "URL" }), { description: message`Base URL of the zipped XCFrameworks.` }))
|
|
2019
|
+
});
|
|
2020
|
+
const pack = object({
|
|
2021
|
+
command: constant("package"),
|
|
2022
|
+
...bundleOptions("ios"),
|
|
2023
|
+
standalone: withDefault(flag("--standalone", { description: message`Package a standalone macOS or Windows app from an bake create host project.` }), false),
|
|
2024
|
+
bakenative: optional(option("--bakenative", path, { description: message`BakeNative source checkout used by the standalone host project.` }))
|
|
2025
|
+
});
|
|
2026
|
+
/** Without --target: bake build builds every target the config declares (web,mac without a
|
|
2027
|
+
* config); bake package packs the declared ones it can pack (ios; ios without a config). */
|
|
2028
|
+
async function resolveBuildOptions(input) {
|
|
2029
|
+
const root = resolve(input.root);
|
|
2030
|
+
const config = await loadBakeConfig(root);
|
|
2031
|
+
const app = config?.app;
|
|
2032
|
+
const standalone = input.command === "package" && input.standalone;
|
|
2033
|
+
if (standalone && input.runtime) throw new Error("--runtime applies to embedded packaging.");
|
|
2034
|
+
if (input.command === "package" && input.bakenative && !standalone) throw new Error("--bakenative applies to bake package --standalone");
|
|
2035
|
+
if (app && !standalone && (input.command === "package" || input.xcframework)) throw new Error("Embedded packages inherit the host identity and launch assets, tray, and window settings. Remove app from bake.config.ts when packaging a brownfield bundle.");
|
|
2036
|
+
const desktopTarget = standalone ? input.targets?.[0] : void 0;
|
|
2037
|
+
if (standalone && (input.targets?.length !== 1 || desktopTarget !== "mac" && desktopTarget !== "windows")) throw new Error("Use bake package --standalone with one target: --target mac or --target windows.");
|
|
2038
|
+
const targets = input.command === "build" || standalone ? resolveTargets(input.targets, config, ["web", "mac"]) : resolveTargets(input.targets, config, ["ios"], (declared) => {
|
|
2039
|
+
const packed = declared.filter((t) => t === "ios");
|
|
2040
|
+
if (!packed.length) throw new Error(`bake package packs ios only, and ${config.name} declares ${declared.join(", ")}`);
|
|
2041
|
+
return packed;
|
|
2042
|
+
});
|
|
2043
|
+
const out = resolve(root, input.out);
|
|
2044
|
+
let packageDesktop;
|
|
2045
|
+
if (input.command === "package" && (desktopTarget === "mac" || desktopTarget === "windows")) {
|
|
2046
|
+
if (!app) throw new Error("Set a desktop app ID in bake.config.ts for standalone packaging.");
|
|
2047
|
+
packageDesktop = desktopPackager({
|
|
2048
|
+
root,
|
|
2049
|
+
out,
|
|
2050
|
+
target: desktopTarget,
|
|
2051
|
+
app: app.resolveDesktop(desktopTarget),
|
|
2052
|
+
bakenative: input.bakenative,
|
|
2053
|
+
viewport: input.viewport
|
|
2054
|
+
});
|
|
2055
|
+
}
|
|
2056
|
+
return {
|
|
2057
|
+
...input,
|
|
2058
|
+
targets,
|
|
2059
|
+
root,
|
|
2060
|
+
packageDesktop,
|
|
2061
|
+
androidMinSdk: config?.androidMinSdk ?? 29,
|
|
2062
|
+
writeNativeApp: app && ((dir, target) => {
|
|
2063
|
+
if (target === "ios" || target === "android") writeMobileApp(dir, target, app.resolveTarget(target));
|
|
2064
|
+
}),
|
|
2065
|
+
renderer: config?.config.renderer,
|
|
2066
|
+
fontSettings: config?.fontSettings,
|
|
2067
|
+
compiler: config?.compiler,
|
|
2068
|
+
direct: config?.direct ?? {
|
|
2069
|
+
on: true,
|
|
2070
|
+
exclude: []
|
|
2071
|
+
},
|
|
2072
|
+
css: config?.css ?? { webOnly: [] },
|
|
2073
|
+
notices: config?.notices ?? [],
|
|
2074
|
+
locales: config?.locales ?? [],
|
|
2075
|
+
unbaked: config ? !config.bake : false,
|
|
2076
|
+
out,
|
|
2077
|
+
styles: input.styles.map((s) => existsSync(s) ? resolve(s) : s),
|
|
2078
|
+
bake: input.command === "package" || input.bake,
|
|
2079
|
+
aotCheck: !input.noAotCheck,
|
|
2080
|
+
strictAot: input.strictAot,
|
|
2081
|
+
hermesc: input.hermesc ?? defaultHermesc(),
|
|
2082
|
+
runtime: input.runtime ? resolve(input.runtime) : process.env.BAKE_RUNTIME_XCFRAMEWORK,
|
|
2083
|
+
remoteURL: input.command === "build" ? input.remoteURL?.replace(/\/+$/, "") : void 0
|
|
2084
|
+
};
|
|
2085
|
+
}
|
|
2086
|
+
const positive = float({ min: Number.MIN_VALUE });
|
|
2087
|
+
const parser = or(create, command("build", build, { brief: message`Build the app for web and native targets.` }), command("package", or(packageCheck, packageHostCheck, pack), { brief: message`Package an embedded iOS bundle, a standalone desktop app, or check app packages.` }), command("snap", object({
|
|
2088
|
+
command: constant("snap"),
|
|
2089
|
+
bundle: argument(string({ metavar: "BUNDLE" })),
|
|
2090
|
+
width: optional(option("--width", positive)),
|
|
2091
|
+
height: optional(option("--height", positive)),
|
|
2092
|
+
scale: optional(option("--scale", positive)),
|
|
2093
|
+
scheme: optional(option("--scheme", choice(["light", "dark"]))),
|
|
2094
|
+
json: optional(option("--json", path)),
|
|
2095
|
+
png: optional(option("--png", path))
|
|
2096
|
+
}), { hidden: true }), command("aot", object({
|
|
2097
|
+
command: constant("aot"),
|
|
2098
|
+
root: withDefault(option("--root", path, { description: message`Project directory.` }), "."),
|
|
2099
|
+
json: withDefault(flag("--json", { description: message`Print the findings as JSON.` }), false),
|
|
2100
|
+
strictAot: strictAotFlag(message`Report findings as errors and exit 1 when there are any (the default).`),
|
|
2101
|
+
direct: withDefault(flag("--direct", { hidden: true }), false)
|
|
2102
|
+
}), { brief: message`Check src/**/*.tsrx against the AOT fast path (strict by default: findings are errors).` }), command("check", object({
|
|
2103
|
+
command: constant("check"),
|
|
2104
|
+
targets: targetOption("every target"),
|
|
2105
|
+
root: withDefault(option("--root", path, { description: message`Project directory containing src/App.tsx (React) or src/App.tsrx (Octane).` }), "."),
|
|
2106
|
+
json: withDefault(flag("--json", { description: message`Print the report as JSON.` }), false),
|
|
2107
|
+
strictAot: strictAotFlag(message`Fail on AOT fast-path findings (the default; overrides "bakenative": { "strictAot": false }).`)
|
|
2108
|
+
}), { brief: message`Run the fail-closed checks (AOT, modules, markup, CSS) for every declared target, without writing bundles.` }), dev, release, native, modulesParser, command("inspect", object({
|
|
2109
|
+
command: constant("inspect"),
|
|
2110
|
+
request: inspectParser
|
|
2111
|
+
}), { brief: message`Query a running debug app.` }));
|
|
2112
|
+
async function main() {
|
|
2113
|
+
const input = run(parser, {
|
|
2114
|
+
programName: "bake",
|
|
2115
|
+
help: {
|
|
2116
|
+
command: true,
|
|
2117
|
+
option: { names: ["-h", "--help"] }
|
|
2118
|
+
},
|
|
2119
|
+
version: String(JSON.parse(readFileSync(join(packageRoot$1, "package.json"), "utf8")).version),
|
|
2120
|
+
usageLine: [{ type: "ellipsis" }],
|
|
2121
|
+
errorExitCode: 2,
|
|
2122
|
+
errorUsage: "command",
|
|
2123
|
+
showDefault: true,
|
|
2124
|
+
commandList: "top-level",
|
|
2125
|
+
helpSections: {
|
|
2126
|
+
commands: "Commands",
|
|
2127
|
+
options: "Options"
|
|
2128
|
+
}
|
|
2129
|
+
});
|
|
2130
|
+
switch (input.command) {
|
|
2131
|
+
case "build": return (await import("./build-CMsvCcZ0.mjs")).buildCommand(await resolveBuildOptions(input));
|
|
2132
|
+
case "package": {
|
|
2133
|
+
const opts = await resolveBuildOptions(input);
|
|
2134
|
+
const { buildCommand, packageCommand } = await import("./build-CMsvCcZ0.mjs");
|
|
2135
|
+
return input.standalone ? buildCommand(opts) : packageCommand(opts);
|
|
2136
|
+
}
|
|
2137
|
+
case "check": {
|
|
2138
|
+
const root = resolve(input.root);
|
|
2139
|
+
const config = await loadBakeConfig(root);
|
|
2140
|
+
const targets = resolveTargets(input.targets, config, [...platforms]);
|
|
2141
|
+
return (await import("./build-CMsvCcZ0.mjs")).checkCommand({
|
|
2142
|
+
root,
|
|
2143
|
+
targets,
|
|
2144
|
+
json: input.json,
|
|
2145
|
+
strictAot: input.strictAot,
|
|
2146
|
+
androidMinSdk: config?.androidMinSdk ?? 29,
|
|
2147
|
+
renderer: config?.config.renderer,
|
|
2148
|
+
fontSettings: config?.fontSettings,
|
|
2149
|
+
css: config?.css,
|
|
2150
|
+
compiler: config?.compiler,
|
|
2151
|
+
unbaked: config ? !config.bake : false,
|
|
2152
|
+
config: config ? config.name : null,
|
|
2153
|
+
from: input.targets ? "--target" : config ? `the targets in ${config.name}` : "no bake.config.ts: every target"
|
|
2154
|
+
});
|
|
2155
|
+
}
|
|
2156
|
+
case "aot": {
|
|
2157
|
+
const root = resolve(input.root);
|
|
2158
|
+
const config = await loadBakeConfig(root);
|
|
2159
|
+
return (await import("./build-CMsvCcZ0.mjs")).aotCommand({
|
|
2160
|
+
root,
|
|
2161
|
+
renderer: config?.config.renderer,
|
|
2162
|
+
json: input.json,
|
|
2163
|
+
strictAot: input.strictAot,
|
|
2164
|
+
direct: input.direct
|
|
2165
|
+
});
|
|
2166
|
+
}
|
|
2167
|
+
case "create": return createCommand(input);
|
|
2168
|
+
case "dev": return (await import("./dev-Cskd8Hl4.mjs")).devCommand(await resolveDevOptions(input));
|
|
2169
|
+
case "add":
|
|
2170
|
+
case "diff":
|
|
2171
|
+
case "upgrade":
|
|
2172
|
+
case "remove":
|
|
2173
|
+
case "registry build": return modulesCommand(input);
|
|
2174
|
+
case "native new": return nativeNew(input);
|
|
2175
|
+
case "native types": return nativeTypes(input);
|
|
2176
|
+
case "native link": {
|
|
2177
|
+
const config = await loadBakeConfig(resolve(input.root));
|
|
2178
|
+
resolveTargets([input.target], config, [input.target]);
|
|
2179
|
+
return nativeLink(input, config?.androidMinSdk);
|
|
2180
|
+
}
|
|
2181
|
+
case "native view gen": return nativeViewGen(input);
|
|
2182
|
+
case "native gen": return nativeGen(input);
|
|
2183
|
+
case "package check": return packageCheckCommand(input);
|
|
2184
|
+
case "package host-check": return packageHostCheckCommand(input);
|
|
2185
|
+
case "release check": return releaseCommand(input);
|
|
2186
|
+
case "inspect":
|
|
2187
|
+
process.exitCode = await inspectParsed(inspectRequest(input.request));
|
|
2188
|
+
return;
|
|
2189
|
+
case "snap": {
|
|
2190
|
+
const { command, bundle, ...options } = input;
|
|
2191
|
+
const args = [bundle];
|
|
2192
|
+
for (const [key, value] of Object.entries(options)) if (value !== void 0) args.push("--" + key, String(value));
|
|
2193
|
+
const hermesc = defaultHermesc();
|
|
2194
|
+
const prelude = hermesc ? { BAKE_FRAME_PRELUDE: (await import("./build-CMsvCcZ0.mjs")).bakePrelude(hermesc) } : {};
|
|
2195
|
+
process.stdout.write(execToolBuffer(nativeTool("bake-snap"), args, {
|
|
2196
|
+
env: {
|
|
2197
|
+
...toolProcessEnv(),
|
|
2198
|
+
...prelude
|
|
2199
|
+
},
|
|
2200
|
+
stderr: "inherit"
|
|
2201
|
+
}));
|
|
2202
|
+
return;
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
// cli/bin.ts
|
|
2207
|
+
main().catch((error) => {
|
|
2208
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
2209
|
+
process.exitCode = 2;
|
|
2210
|
+
});
|
|
2211
|
+
export {};
|