@moku-labs/game 0.15.84 → 0.15.86
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/README.md +2 -1
- package/dist/app/page.d.mts +1 -1
- package/dist/app/page.mjs +1 -1
- package/dist/app/system.d.mts +3 -3
- package/dist/app.d.mts +4 -4
- package/dist/app.mjs +1 -1
- package/dist/assets.d.mts +1 -1
- package/dist/cli.mjs +519 -185
- package/dist/{commands-DKjkHK5b.d.mts → commands-CeBF2nRY.d.mts} +5 -5
- package/dist/{config-HpC-p8Ow.mjs → config-Cn1VZ-tx.mjs} +77 -4
- package/dist/control.d.mts +4 -4
- package/dist/{define-DcB9KOfh.d.mts → define-N-2nQNK_.d.mts} +2 -2
- package/dist/{headless-B8JIqsZk.d.mts → headless-DtDdn5gg.d.mts} +1 -1
- package/dist/{index-DTHVVLFB.d.mts → index-Bn0pFiae.d.mts} +3 -3
- package/dist/index.d.mts +4 -4
- package/dist/index.mjs +1 -1
- package/dist/inspect.d.mts +6 -6
- package/dist/jsx-dev-runtime.d.mts +1 -1
- package/dist/jsx-runtime.d.mts +1 -1
- package/dist/{runtime-B3CsJr_p.d.mts → runtime-DOvgFNLH.d.mts} +1 -1
- package/dist/{src-D1J2QlGK.mjs → src-BFa-zMmW.mjs} +1132 -89
- package/dist/testing.d.mts +4 -4
- package/dist/testing.mjs +1 -1
- package/dist/{types-DJCC9CAp.d.mts → types-C5gLBKbm.d.mts} +16 -6
- package/dist/{types-DfHytzox.d.mts → types-CbVXXqPs.d.mts} +130 -16
- package/dist/{types-D-5dwalj.d.mts → types-CyPbo757.d.mts} +45 -7
- package/dist/{types-DsRV-ph1.d.mts → types-DNWWlVky.d.mts} +2 -2
- package/dist/{types-CPWi_CLI.d.mts → types-OBpR0u05.d.mts} +1 -1
- package/dist/{visual-B76IxxTL.d.mts → visual-Di8ecxYD.d.mts} +6 -6
- package/dist/visual.d.mts +1 -1
- package/llms.txt +3 -2
- package/package.json +3 -3
package/dist/cli.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { t as resolveConfig } from "./config-
|
|
1
|
+
import { t as resolveConfig } from "./config-Cn1VZ-tx.mjs";
|
|
2
2
|
import { t as findFeatureOwners } from "./features-DowEilZm.mjs";
|
|
3
3
|
import { r as watchTree, t as createBatcher, x as isSkippedFolder$1 } from "./watch-BSgptowj.mjs";
|
|
4
4
|
import { a as runCli$1, i as compileStrings, n as importStrings, t as exportStrings } from "./assets-BRTUagOC.mjs";
|
|
5
5
|
import { constants, copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, watch, writeFileSync } from "node:fs";
|
|
6
|
+
import { homedir } from "node:os";
|
|
6
7
|
import path from "node:path";
|
|
7
8
|
import { createBrandConsole } from "@moku-labs/common/cli";
|
|
8
9
|
import { parseArgs } from "node:util";
|
|
@@ -44,6 +45,16 @@ function packageOf(folder) {
|
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
48
|
+
* Reads the `version` of a folder's `package.json`.
|
|
49
|
+
*
|
|
50
|
+
* @param folder - The folder.
|
|
51
|
+
* @returns The version, or `undefined` for a missing or broken file, or one with no string there.
|
|
52
|
+
*/
|
|
53
|
+
function packageVersionOf(folder) {
|
|
54
|
+
const version = packageOf(folder)?.version;
|
|
55
|
+
return typeof version === "string" ? version : void 0;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
47
58
|
* Tells whether a path lies inside a folder, the folder itself left out.
|
|
48
59
|
*
|
|
49
60
|
* @param file - The path.
|
|
@@ -2020,6 +2031,408 @@ async function runBuild(run, deps) {
|
|
|
2020
2031
|
return 0;
|
|
2021
2032
|
}
|
|
2022
2033
|
//#endregion
|
|
2034
|
+
//#region src/app/native.ts
|
|
2035
|
+
/**
|
|
2036
|
+
* @file The native verbs of `moku-game`: a game's `config.ts` as the config of `@moku-labs/native`,
|
|
2037
|
+
* and one verb run over it. Node only, no package export: the bin bundles it. The only file of the
|
|
2038
|
+
* engine that imports `@moku-labs/native`, and only with `import()`, so a web-only game never
|
|
2039
|
+
* loads it.
|
|
2040
|
+
*/
|
|
2041
|
+
/** The port of the dev server Tauri's shell starts and loads. */
|
|
2042
|
+
const DEV_PORT = 5173;
|
|
2043
|
+
/** The iOS minimum of a game that names none. Native's own default is older. */
|
|
2044
|
+
const IOS_MINIMUM = "26.0";
|
|
2045
|
+
/** The version shape a store takes, and the only one the engine hands native: `1.2.3`. */
|
|
2046
|
+
const STORE_VERSION = /^\d+\.\d+\.\d+$/;
|
|
2047
|
+
/**
|
|
2048
|
+
* The native section of a resolved config.
|
|
2049
|
+
*
|
|
2050
|
+
* @param settings - The resolved `config.ts` of the game.
|
|
2051
|
+
* @returns The native section.
|
|
2052
|
+
* @throws {Error} When `config.ts` has no native section.
|
|
2053
|
+
*/
|
|
2054
|
+
function nativeSectionOf(settings) {
|
|
2055
|
+
if (settings.native === void 0) throw new Error("[game] config.ts has no native section.\n Add native: { name, identifier } to config.ts.");
|
|
2056
|
+
return settings.native;
|
|
2057
|
+
}
|
|
2058
|
+
/**
|
|
2059
|
+
* Makes a keystore path absolute, since Gradle reads a relative one under `gen/android/app`: `~/`
|
|
2060
|
+
* starts at the home folder, anything else at the game folder.
|
|
2061
|
+
*
|
|
2062
|
+
* @param keystore - The path `config.ts` gives.
|
|
2063
|
+
* @param cwd - The game folder.
|
|
2064
|
+
* @param home - The home folder.
|
|
2065
|
+
* @returns The absolute path.
|
|
2066
|
+
* @example
|
|
2067
|
+
* ```ts
|
|
2068
|
+
* resolveKeystore("~/keys/upload.jks", "/g", "/home/a"); // "/home/a/keys/upload.jks"
|
|
2069
|
+
* ```
|
|
2070
|
+
*/
|
|
2071
|
+
function resolveKeystore(keystore, cwd, home) {
|
|
2072
|
+
return keystore.startsWith("~/") ? path.join(home, keystore.slice(2)) : path.resolve(cwd, keystore);
|
|
2073
|
+
}
|
|
2074
|
+
/**
|
|
2075
|
+
* The password variables of an Android signing block that are unset or empty, by name only. The
|
|
2076
|
+
* key password falls back to the keystore's.
|
|
2077
|
+
*
|
|
2078
|
+
* @param android - `native.signing.android`, when the game has one.
|
|
2079
|
+
* @param env - The environment.
|
|
2080
|
+
* @returns The names of the variables.
|
|
2081
|
+
* @example
|
|
2082
|
+
* ```ts
|
|
2083
|
+
* missingPasswords({ keystorePath: "k.jks", keystorePasswordEnv: "KS", keyAlias: "a" }, { KS: "" }); // ["KS"]
|
|
2084
|
+
* ```
|
|
2085
|
+
*/
|
|
2086
|
+
function missingPasswords(android, env) {
|
|
2087
|
+
if (android === void 0) return [];
|
|
2088
|
+
return [.../* @__PURE__ */ new Set([android.keystorePasswordEnv, android.keyPasswordEnv ?? android.keystorePasswordEnv])].filter((name) => (env[name] ?? "") === "");
|
|
2089
|
+
}
|
|
2090
|
+
/**
|
|
2091
|
+
* The problems of the Android row of a store build: the signing block, the keystore file, and the
|
|
2092
|
+
* two password variables, by name only.
|
|
2093
|
+
*
|
|
2094
|
+
* @param native - The native section.
|
|
2095
|
+
* @param input - The store build.
|
|
2096
|
+
* @returns One line per problem.
|
|
2097
|
+
*/
|
|
2098
|
+
function androidProblems(native, input) {
|
|
2099
|
+
const android = native.signing?.android;
|
|
2100
|
+
if (android === void 0) return ["No native.signing.android in config.ts. Add keystorePath, keystorePasswordEnv and keyAlias."];
|
|
2101
|
+
const keystore = resolveKeystore(android.keystorePath, input.cwd, input.home);
|
|
2102
|
+
return [...input.store.exists(keystore) ? [] : [`The keystore ${keystore} is not a file.`], ...missingPasswords(android, input.store.env).map((name) => `The env var ${name} is not set. It holds a signing password.`)];
|
|
2103
|
+
}
|
|
2104
|
+
/**
|
|
2105
|
+
* The problem of the iOS row of a store build: the Apple signing block. Keys stay in the env, and
|
|
2106
|
+
* Tauri reads them.
|
|
2107
|
+
*
|
|
2108
|
+
* @param native - The native section.
|
|
2109
|
+
* @returns One line, or none with the block.
|
|
2110
|
+
*/
|
|
2111
|
+
function appleProblems(native) {
|
|
2112
|
+
return native.signing?.apple === void 0 ? ["No native.signing.apple in config.ts. Add teamId."] : [];
|
|
2113
|
+
}
|
|
2114
|
+
/**
|
|
2115
|
+
* The problem of a `package.json` version a store build cannot ship.
|
|
2116
|
+
*
|
|
2117
|
+
* @param version - The version, unchecked.
|
|
2118
|
+
* @returns One line, or none for an `x.y.z`.
|
|
2119
|
+
* @example
|
|
2120
|
+
* ```ts
|
|
2121
|
+
* versionProblems("1.2"); // ['package.json has version "1.2". Use x.y.z, such as 1.0.0.']
|
|
2122
|
+
* ```
|
|
2123
|
+
*/
|
|
2124
|
+
function versionProblems(version) {
|
|
2125
|
+
if (version === void 0) return ["package.json has no version. Add one, such as 1.0.0."];
|
|
2126
|
+
return STORE_VERSION.test(version) ? [] : [`package.json has version "${version}". Use x.y.z, such as 1.0.0.`];
|
|
2127
|
+
}
|
|
2128
|
+
/**
|
|
2129
|
+
* The last parts of an identifier that never goes to a store.
|
|
2130
|
+
*
|
|
2131
|
+
* @returns The set of words.
|
|
2132
|
+
* @example
|
|
2133
|
+
* ```ts
|
|
2134
|
+
* testSuffixes().has("soak"); // true
|
|
2135
|
+
* ```
|
|
2136
|
+
*/
|
|
2137
|
+
function testSuffixes() {
|
|
2138
|
+
return /* @__PURE__ */ new Set([
|
|
2139
|
+
"soak",
|
|
2140
|
+
"debug",
|
|
2141
|
+
"dev",
|
|
2142
|
+
"test",
|
|
2143
|
+
"staging"
|
|
2144
|
+
]);
|
|
2145
|
+
}
|
|
2146
|
+
/**
|
|
2147
|
+
* The problem of an identifier that names a test build.
|
|
2148
|
+
*
|
|
2149
|
+
* @param identifier - `native.identifier`.
|
|
2150
|
+
* @returns One line, or none for a real identifier.
|
|
2151
|
+
* @example
|
|
2152
|
+
* ```ts
|
|
2153
|
+
* identifierProblems("com.acme.t"); // []
|
|
2154
|
+
* ```
|
|
2155
|
+
*/
|
|
2156
|
+
function identifierProblems(identifier) {
|
|
2157
|
+
const last = identifier.slice(identifier.lastIndexOf(".") + 1);
|
|
2158
|
+
return testSuffixes().has(last) ? [`The identifier ${identifier} ends in .${last}. A store build ships the real identifier.`] : [];
|
|
2159
|
+
}
|
|
2160
|
+
/**
|
|
2161
|
+
* Everything that stops a store build, all at once, so one run shows every fix. A message names a
|
|
2162
|
+
* field, a path, a value of `package.json` or an env var, never the value of a variable.
|
|
2163
|
+
*
|
|
2164
|
+
* @param input - The store build.
|
|
2165
|
+
* @returns One line per problem, none for a build that can go.
|
|
2166
|
+
* @throws {Error} When `config.ts` has no native section.
|
|
2167
|
+
* @example
|
|
2168
|
+
* ```ts
|
|
2169
|
+
* const settings = resolveConfig({ page: { title: "T" }, native: { name: "T", identifier: "com.acme.t" } });
|
|
2170
|
+
* const store = { buildNumber: 12, env: {}, exists: () => true };
|
|
2171
|
+
* storeProblems({ settings, target: "ios", cwd: "/g", home: "/home/a", version: "1.2.3", store }); // ["No native.signing.apple in config.ts. Add teamId."]
|
|
2172
|
+
* ```
|
|
2173
|
+
*/
|
|
2174
|
+
function storeProblems(input) {
|
|
2175
|
+
const native = nativeSectionOf(input.settings);
|
|
2176
|
+
return [
|
|
2177
|
+
...input.target === "android" ? androidProblems(native, input) : appleProblems(native),
|
|
2178
|
+
...versionProblems(input.version),
|
|
2179
|
+
...identifierProblems(native.identifier)
|
|
2180
|
+
];
|
|
2181
|
+
}
|
|
2182
|
+
/**
|
|
2183
|
+
* The system rows native packages: one per system plugin that needs a Tauri capability. The
|
|
2184
|
+
* webview's own events and wake lock serve `lifecycle` and `keepAwake`, so they need no row. A
|
|
2185
|
+
* `"store"` save needs the store row even when `system` leaves it out.
|
|
2186
|
+
*
|
|
2187
|
+
* @param settings - The resolved `config.ts` of the game.
|
|
2188
|
+
* @returns The rows, in the order of `config.system`.
|
|
2189
|
+
*/
|
|
2190
|
+
function systemRowsOf(settings) {
|
|
2191
|
+
const names = settings.system.filter((name) => name !== "lifecycle" && name !== "keepAwake");
|
|
2192
|
+
if (settings.save === "store" && !names.includes("store")) names.push("store");
|
|
2193
|
+
return names.map((name) => ({ name }));
|
|
2194
|
+
}
|
|
2195
|
+
/**
|
|
2196
|
+
* The web build command native runs: `moku-game build`, with the debug profile and the editor
|
|
2197
|
+
* address of a debug app.
|
|
2198
|
+
*
|
|
2199
|
+
* @param where - The game folder and the command that runs `moku-game`.
|
|
2200
|
+
* @param debug - The debug profile, or `undefined` for a store app.
|
|
2201
|
+
* @returns The command.
|
|
2202
|
+
* @example
|
|
2203
|
+
* ```ts
|
|
2204
|
+
* webBuildOf({ cwd: "/g", command: '"bun" "/g/bin/moku-game.mjs"', home: "/home/a" }, { level: "full", editor: "192.168.1.20:47600" }); // '"bun" "/g/bin/moku-game.mjs" build --debug --editor 192.168.1.20:47600'
|
|
2205
|
+
* ```
|
|
2206
|
+
*/
|
|
2207
|
+
function webBuildOf(where, debug) {
|
|
2208
|
+
if (debug === void 0) return `${where.command} build`;
|
|
2209
|
+
const level = debug.level === "full" ? "--debug" : "--debug=read";
|
|
2210
|
+
const editor = debug.editor === void 0 ? "" : ` --editor ${debug.editor}`;
|
|
2211
|
+
return `${where.command} build ${level}${editor}`;
|
|
2212
|
+
}
|
|
2213
|
+
/**
|
|
2214
|
+
* The app block of the native config: the identity and the window, and what this run adds.
|
|
2215
|
+
*
|
|
2216
|
+
* @param settings - The resolved `config.ts` of the game.
|
|
2217
|
+
* @param native - The native section.
|
|
2218
|
+
* @param extras - The version and the build number of this run.
|
|
2219
|
+
* @returns The app block.
|
|
2220
|
+
*/
|
|
2221
|
+
function appOf(settings, native, extras) {
|
|
2222
|
+
return {
|
|
2223
|
+
name: native.name,
|
|
2224
|
+
identifier: native.identifier,
|
|
2225
|
+
orientation: settings.page.orientation,
|
|
2226
|
+
backgroundColor: settings.page.background,
|
|
2227
|
+
...native.icon === void 0 ? {} : { icon: native.icon },
|
|
2228
|
+
...extras.version === void 0 ? {} : { version: extras.version },
|
|
2229
|
+
...extras.buildNumber === void 0 ? {} : { buildNumber: String(extras.buildNumber) },
|
|
2230
|
+
...settings.system.includes("keepAwake") ? { keepScreenOn: true } : {}
|
|
2231
|
+
};
|
|
2232
|
+
}
|
|
2233
|
+
/**
|
|
2234
|
+
* The signing block of the native config. A debug build keeps native's SDK key, so it takes no
|
|
2235
|
+
* upload key, and neither does a plain build without its passwords, which Gradle would refuse only
|
|
2236
|
+
* after the compile; a store build on iOS exports for App Store Connect, and only that one does.
|
|
2237
|
+
*
|
|
2238
|
+
* @param native - The native section.
|
|
2239
|
+
* @param where - The game folder and the home folder.
|
|
2240
|
+
* @param target - The target of the verb.
|
|
2241
|
+
* @param extras - The debug profile and the build number of this run.
|
|
2242
|
+
* @returns The block, empty when there is nothing to pass.
|
|
2243
|
+
*/
|
|
2244
|
+
function signingOf(native, where, target, extras) {
|
|
2245
|
+
const android = native.signing?.android;
|
|
2246
|
+
const teamId = native.signing?.apple?.teamId;
|
|
2247
|
+
const isStoreIos = target === "ios" && extras.buildNumber !== void 0;
|
|
2248
|
+
const keyStaysOut = android === void 0 || extras.debug !== void 0 || extras.unsigned === true;
|
|
2249
|
+
const apple = {
|
|
2250
|
+
...teamId === void 0 ? {} : { teamId },
|
|
2251
|
+
...target === "ios" ? { iosMinimumSystemVersion: native.ios?.minimumVersion ?? IOS_MINIMUM } : {},
|
|
2252
|
+
...isStoreIos ? { exportMethod: "app-store-connect" } : {}
|
|
2253
|
+
};
|
|
2254
|
+
return {
|
|
2255
|
+
...keyStaysOut ? {} : { android: {
|
|
2256
|
+
...android,
|
|
2257
|
+
keystorePath: resolveKeystore(android.keystorePath, where.cwd, where.home)
|
|
2258
|
+
} },
|
|
2259
|
+
...Object.keys(apple).length === 0 ? {} : { apple }
|
|
2260
|
+
};
|
|
2261
|
+
}
|
|
2262
|
+
/**
|
|
2263
|
+
* The iOS block of the native config. Native takes the manifest as an absolute path only.
|
|
2264
|
+
*
|
|
2265
|
+
* @param native - The native section.
|
|
2266
|
+
* @param cwd - The game folder.
|
|
2267
|
+
* @returns The block, empty when the game adds nothing to the bundle.
|
|
2268
|
+
*/
|
|
2269
|
+
function iosBundleOf(native, cwd) {
|
|
2270
|
+
const infoPlist = native.ios?.infoPlist;
|
|
2271
|
+
const manifest = native.ios?.privacyManifest;
|
|
2272
|
+
return {
|
|
2273
|
+
...infoPlist === void 0 ? {} : { infoPlist },
|
|
2274
|
+
...manifest === void 0 ? {} : { privacyManifest: path.resolve(cwd, manifest) }
|
|
2275
|
+
};
|
|
2276
|
+
}
|
|
2277
|
+
/**
|
|
2278
|
+
* Maps a game's resolved `config.ts` to the config of `@moku-labs/native`: the app from `native`
|
|
2279
|
+
* and `page`, the web build through `moku-game`, the system rows, the targets, the signing, the
|
|
2280
|
+
* iOS bundle, and the Tauri project and output folders under the game. An Android app composes
|
|
2281
|
+
* native's `shell` system first, the one that sets `globalThis.__MOKU_NATIVE__`. A debug app
|
|
2282
|
+
* builds its web page with the same profile and `--editor`; its name and identifier stay the
|
|
2283
|
+
* game's. A build number means a store build.
|
|
2284
|
+
*
|
|
2285
|
+
* @param settings - The resolved `config.ts` of the game.
|
|
2286
|
+
* @param where - The game folder, the command that runs `moku-game` and the home folder.
|
|
2287
|
+
* @param target - The target of the verb, used when `config.ts` names no targets.
|
|
2288
|
+
* @param extras - What this run adds: the debug profile, the build number, the version.
|
|
2289
|
+
* @returns The config for `createApp({ config })` of `@moku-labs/native`.
|
|
2290
|
+
* @throws {Error} When `config.ts` has no native section.
|
|
2291
|
+
* @example
|
|
2292
|
+
* ```ts
|
|
2293
|
+
* const where = { cwd: "/g", command: '"/usr/local/bin/bun" "/g/node_modules/@moku-labs/game/bin/moku-game.mjs" "--root" "/g"', home: "/home/a" };
|
|
2294
|
+
* nativeConfigOf(resolveConfig({ page: { title: "T" }, native: { name: "T", identifier: "com.x.t" } }), where, "ios").web.dist; // "/g/dist/web"
|
|
2295
|
+
* ```
|
|
2296
|
+
*/
|
|
2297
|
+
function nativeConfigOf(settings, where, target, extras = {}) {
|
|
2298
|
+
const native = nativeSectionOf(settings);
|
|
2299
|
+
const rows = systemRowsOf(settings);
|
|
2300
|
+
const config = {
|
|
2301
|
+
app: appOf(settings, native, extras),
|
|
2302
|
+
web: {
|
|
2303
|
+
cwd: where.cwd,
|
|
2304
|
+
build: webBuildOf(where, extras.debug),
|
|
2305
|
+
devCommand: `${where.command} dev --port ${DEV_PORT}`,
|
|
2306
|
+
devUrl: `http://127.0.0.1:${DEV_PORT}`,
|
|
2307
|
+
dist: path.join(where.cwd, "dist/web")
|
|
2308
|
+
},
|
|
2309
|
+
system: target === "android" ? [{ name: "shell" }, ...rows.filter((row) => row.name !== "shell")] : rows,
|
|
2310
|
+
projectDir: path.join(where.cwd, ".moku/tauri"),
|
|
2311
|
+
outDir: path.join(where.cwd, "dist-native")
|
|
2312
|
+
};
|
|
2313
|
+
const targets = native.targets ?? (target === void 0 ? void 0 : [target]);
|
|
2314
|
+
const signing = signingOf(native, where, target, extras);
|
|
2315
|
+
const ios = iosBundleOf(native, where.cwd);
|
|
2316
|
+
if (targets !== void 0) config.targets = targets;
|
|
2317
|
+
if (Object.keys(signing).length > 0) config.signing = signing;
|
|
2318
|
+
if (Object.keys(ios).length > 0) config.ios = ios;
|
|
2319
|
+
return config;
|
|
2320
|
+
}
|
|
2321
|
+
/**
|
|
2322
|
+
* Checks the target of a verb against the targets native knows. `build` and `dev` need one.
|
|
2323
|
+
*
|
|
2324
|
+
* @param known - The `TARGETS` of `@moku-labs/native`.
|
|
2325
|
+
* @param verb - The native verb.
|
|
2326
|
+
* @param given - The target the command line names, unchecked.
|
|
2327
|
+
* @returns The target, or `undefined` for a `doctor` or `clean` over every target.
|
|
2328
|
+
* @throws {Error} When the target is unknown, or `build` or `dev` names none.
|
|
2329
|
+
*/
|
|
2330
|
+
function targetOf(known, verb, given) {
|
|
2331
|
+
const target = known.find((name) => name === given);
|
|
2332
|
+
if (given !== void 0 && target === void 0) throw new Error(`[game] No native target "${given}".\n Name one of ${known.join(", ")}.`);
|
|
2333
|
+
if (target === void 0 && verb === "build") throw new Error("[game] moku-game native build needs a target.\n Run: moku-game native build ios --simulator.");
|
|
2334
|
+
if (target === void 0 && verb === "dev") throw new Error("[game] moku-game native dev needs a target.\n Run: moku-game native dev ios.");
|
|
2335
|
+
return target;
|
|
2336
|
+
}
|
|
2337
|
+
/**
|
|
2338
|
+
* Runs one verb on the cli of a started native app.
|
|
2339
|
+
*
|
|
2340
|
+
* @param cli - The cli of the native app.
|
|
2341
|
+
* @param verb - The native verb.
|
|
2342
|
+
* @param target - The checked target.
|
|
2343
|
+
* @param options - The simulator flag, the debug profile of a debug app, and the store flag.
|
|
2344
|
+
* @returns The boolean of `doctor`, true for the other verbs once they finish.
|
|
2345
|
+
*/
|
|
2346
|
+
async function runVerb(cli, verb, target, options) {
|
|
2347
|
+
switch (verb) {
|
|
2348
|
+
case "build": {
|
|
2349
|
+
const build = {
|
|
2350
|
+
target,
|
|
2351
|
+
simulator: options.simulator,
|
|
2352
|
+
...options.debug === void 0 ? {} : { debug: true },
|
|
2353
|
+
...options.store !== void 0 && target === "android" ? { aab: true } : {}
|
|
2354
|
+
};
|
|
2355
|
+
await cli.build(build);
|
|
2356
|
+
return true;
|
|
2357
|
+
}
|
|
2358
|
+
case "dev":
|
|
2359
|
+
await cli.dev({ target });
|
|
2360
|
+
return true;
|
|
2361
|
+
case "doctor": return cli.doctor({ target });
|
|
2362
|
+
case "clean":
|
|
2363
|
+
await cli.clean({ target });
|
|
2364
|
+
return true;
|
|
2365
|
+
}
|
|
2366
|
+
}
|
|
2367
|
+
/**
|
|
2368
|
+
* What this run adds to the native config. A version that is not `x.y.z` stays out, and native
|
|
2369
|
+
* falls back to its own; `--store` has refused one before this reads it.
|
|
2370
|
+
*
|
|
2371
|
+
* @param options - The verb options.
|
|
2372
|
+
* @returns The extras of `nativeConfigOf`.
|
|
2373
|
+
*/
|
|
2374
|
+
function extrasOf(options) {
|
|
2375
|
+
const { debug, editor, store, unsigned, version } = options;
|
|
2376
|
+
return {
|
|
2377
|
+
...debug === void 0 ? {} : { debug: {
|
|
2378
|
+
level: debug,
|
|
2379
|
+
editor
|
|
2380
|
+
} },
|
|
2381
|
+
...store === void 0 ? {} : { buildNumber: store.buildNumber },
|
|
2382
|
+
...unsigned === void 0 ? {} : { unsigned },
|
|
2383
|
+
...version !== void 0 && STORE_VERSION.test(version) ? { version } : {}
|
|
2384
|
+
};
|
|
2385
|
+
}
|
|
2386
|
+
/**
|
|
2387
|
+
* Throws every problem of a store build as one error. A plain build passes untouched.
|
|
2388
|
+
*
|
|
2389
|
+
* @param settings - The resolved `config.ts` of the game.
|
|
2390
|
+
* @param where - The game folder and the home folder.
|
|
2391
|
+
* @param options - The verb options.
|
|
2392
|
+
* @throws {Error} With a line per problem.
|
|
2393
|
+
*/
|
|
2394
|
+
function refuseStoreProblems(settings, where, options) {
|
|
2395
|
+
if (options.store === void 0) return;
|
|
2396
|
+
const problems = storeProblems({
|
|
2397
|
+
settings,
|
|
2398
|
+
target: options.target === "ios" ? "ios" : "android",
|
|
2399
|
+
cwd: where.cwd,
|
|
2400
|
+
home: where.home,
|
|
2401
|
+
version: options.version,
|
|
2402
|
+
store: options.store
|
|
2403
|
+
});
|
|
2404
|
+
if (problems.length > 0) throw new Error(`[game] native --store: fix these before a store build.\n ${problems.join("\n ")}`);
|
|
2405
|
+
}
|
|
2406
|
+
/**
|
|
2407
|
+
* Runs one native verb through `@moku-labs/native` over the game's config. Native's cli prints
|
|
2408
|
+
* the progress and the failure itself.
|
|
2409
|
+
*
|
|
2410
|
+
* @param verb - The native verb: build, dev, doctor or clean.
|
|
2411
|
+
* @param settings - The resolved `config.ts` of the game.
|
|
2412
|
+
* @param where - The game folder, the command that runs `moku-game` and the home folder.
|
|
2413
|
+
* @param options - The target, the simulator flag, the debug profile, the version, the store build.
|
|
2414
|
+
* @returns True when the verb succeeded, false when it failed.
|
|
2415
|
+
* @throws {Error} When `config.ts` has no native section, a store build has a problem, before
|
|
2416
|
+
* anything loads, `@moku-labs/native` is not installed, or the target is unknown or missing.
|
|
2417
|
+
*/
|
|
2418
|
+
async function runNative(verb, settings, where, options) {
|
|
2419
|
+
nativeSectionOf(settings);
|
|
2420
|
+
refuseStoreProblems(settings, where, options);
|
|
2421
|
+
const native = await import("@moku-labs/native").catch((error) => {
|
|
2422
|
+
throw new Error("[game] moku-game native needs @moku-labs/native.\n Install it: bun add -d @moku-labs/native@^0.3.12.", { cause: error });
|
|
2423
|
+
});
|
|
2424
|
+
const target = targetOf(native.TARGETS, verb, options.target);
|
|
2425
|
+
const app = native.createApp({ config: nativeConfigOf(settings, where, target, extrasOf(options)) });
|
|
2426
|
+
await app.start();
|
|
2427
|
+
try {
|
|
2428
|
+
return await runVerb(app.cli, verb, target, options);
|
|
2429
|
+
} catch {
|
|
2430
|
+
return false;
|
|
2431
|
+
} finally {
|
|
2432
|
+
await app.stop();
|
|
2433
|
+
}
|
|
2434
|
+
}
|
|
2435
|
+
//#endregion
|
|
2023
2436
|
//#region src/app/visual.ts
|
|
2024
2437
|
/**
|
|
2025
2438
|
* @file `moku-game visual`: the visual tests of a game from the bin. It imports the tests module,
|
|
@@ -2199,9 +2612,9 @@ async function runVisual(command, deps) {
|
|
|
2199
2612
|
* @file The command line of `moku-game`: the arguments read per command with `node:util`
|
|
2200
2613
|
* `parseArgs`, then one of `dev`, `build`, `native <verb>`, `keys`, `pack`, `visual` or `help`.
|
|
2201
2614
|
* Every seam of the process (the console, the environment, spawning, signals, the watcher, the
|
|
2202
|
-
* keys watch, the asset scanner, native, Bun's resolver, the visual test runner
|
|
2203
|
-
* `deps`, so a test runs a command with stubs. It
|
|
2204
|
-
* plain function, on no API.
|
|
2615
|
+
* keys watch, the asset scanner, native, Bun's resolver, the visual test runner, the home folder,
|
|
2616
|
+
* the file check, the game's version) comes in as `deps`, so a test runs a command with stubs. It
|
|
2617
|
+
* returns the exit code and never exits itself. A plain function, on no API.
|
|
2205
2618
|
*/
|
|
2206
2619
|
/** The flags every command takes. */
|
|
2207
2620
|
const GLOBAL_OPTIONS = [
|
|
@@ -2244,7 +2657,9 @@ const ALL_OPTIONS = {
|
|
|
2244
2657
|
dir: { type: "string" },
|
|
2245
2658
|
webgl: { type: "boolean" },
|
|
2246
2659
|
debug: { type: "string" },
|
|
2247
|
-
editor: { type: "string" }
|
|
2660
|
+
editor: { type: "string" },
|
|
2661
|
+
store: { type: "boolean" },
|
|
2662
|
+
"build-number": { type: "string" }
|
|
2248
2663
|
};
|
|
2249
2664
|
/** The flags of `visual` that `parseVisualArgv` reads, in the runner's words. */
|
|
2250
2665
|
const VISUAL_FLAGS = /^(?:update|only|no-pixels|pixels|dir|webgl|no-verify-frames)$/;
|
|
@@ -2259,7 +2674,9 @@ const COMMAND_OPTIONS = {
|
|
|
2259
2674
|
native: [
|
|
2260
2675
|
"simulator",
|
|
2261
2676
|
"debug",
|
|
2262
|
-
"editor"
|
|
2677
|
+
"editor",
|
|
2678
|
+
"store",
|
|
2679
|
+
"build-number"
|
|
2263
2680
|
],
|
|
2264
2681
|
keys: ["check"],
|
|
2265
2682
|
pack: ["no-cache"],
|
|
@@ -2290,6 +2707,8 @@ const VISUAL_TESTS = path.join("tests", "visual", "index.ts");
|
|
|
2290
2707
|
const DEFAULT_PORT = "3000";
|
|
2291
2708
|
/** The highest port number. */
|
|
2292
2709
|
const MAX_PORT = 65535;
|
|
2710
|
+
/** The highest `--build-number`, the top of an Android `versionCode`. */
|
|
2711
|
+
const MAX_BUILD_NUMBER = 21e8;
|
|
2293
2712
|
/** A host of `--editor`: a name or an IPv4 address, or an IPv6 address in brackets. */
|
|
2294
2713
|
const EDITOR_HOST = /^(?:[\w.-]+|\[[\da-f:.]+\])$/i;
|
|
2295
2714
|
/** The value a bare `--debug` reads as: the full profile, with no alias note. */
|
|
@@ -2303,6 +2722,7 @@ const USAGE = [
|
|
|
2303
2722
|
" dev [--port 3000] [--packed] serve the game with hot reload",
|
|
2304
2723
|
" build [--out dist/web] [--debug [--editor host:port]] pack the assets and build the page; --debug adds the editor agent and control",
|
|
2305
2724
|
" native build <target> [--simulator] [--debug [--editor host:port]] build the native app (ios, macos, android)",
|
|
2725
|
+
" native build <target> --store --build-number <n> a store build: an .aab on android, an .ipa on ios",
|
|
2306
2726
|
" native dev <target> run the native shell on the dev server",
|
|
2307
2727
|
" native doctor | native clean check or remove the native project",
|
|
2308
2728
|
" keys [--check] write generated/assets.ts and generated/manifest.json",
|
|
@@ -2539,22 +2959,61 @@ async function runNativeVerb(parsed, deps) {
|
|
|
2539
2959
|
if (word === void 0) throw new Error("[game] native: name a verb: build, dev, doctor, clean.");
|
|
2540
2960
|
if (verb === void 0) throw new Error(`[game] native: no verb "${word}". Name one of build, dev, doctor, clean.`);
|
|
2541
2961
|
refuseExtra(parsed, 2);
|
|
2962
|
+
const store = nativeStoreOf(parsed, verb, target);
|
|
2542
2963
|
const debug = nativeDebugOf(parsed, verb, target);
|
|
2543
2964
|
noteFullAlias(parsed, deps.ui);
|
|
2544
2965
|
const settings = await loadSettings(parsed.root);
|
|
2966
|
+
const version = deps.readPackageVersion(parsed.root);
|
|
2545
2967
|
const where = {
|
|
2546
2968
|
cwd: parsed.root,
|
|
2547
|
-
command: selfCommand(parsed, deps)
|
|
2969
|
+
command: selfCommand(parsed, deps),
|
|
2970
|
+
home: deps.home
|
|
2548
2971
|
};
|
|
2549
2972
|
const options = {
|
|
2550
2973
|
...target === void 0 ? {} : { target },
|
|
2551
2974
|
...verb === "build" && parsed.values.simulator === true ? { simulator: true } : {},
|
|
2552
|
-
...debug
|
|
2975
|
+
...debug,
|
|
2976
|
+
...version === void 0 ? {} : { version }
|
|
2553
2977
|
};
|
|
2554
2978
|
if (debug.debug !== void 0 && target === "android") deps.ui.warn("native: a DEBUG app with the editor agent, installed beside the store app. Never ship it to a store.");
|
|
2979
|
+
if (store.store === true) {
|
|
2980
|
+
options.store = {
|
|
2981
|
+
buildNumber: store.buildNumber,
|
|
2982
|
+
env: deps.env,
|
|
2983
|
+
exists: deps.exists
|
|
2984
|
+
};
|
|
2985
|
+
warnIosStore(settings, target, deps.ui);
|
|
2986
|
+
} else if (verb === "build" && target === "android" && debug.debug === void 0) leaveKeyOut(settings, options, deps);
|
|
2555
2987
|
return await deps.native(verb, settings, where, options) ? 0 : 1;
|
|
2556
2988
|
}
|
|
2557
2989
|
/**
|
|
2990
|
+
* Keeps a plain Android build going without its passwords: Gradle would refuse the signing block
|
|
2991
|
+
* only after the compile, and a teammate with no key still builds. The result is an unsigned `.apk`.
|
|
2992
|
+
*
|
|
2993
|
+
* @param settings - The resolved `config.ts` of the game.
|
|
2994
|
+
* @param options - The verb options.
|
|
2995
|
+
* @param deps - The seams of the process.
|
|
2996
|
+
*/
|
|
2997
|
+
function leaveKeyOut(settings, options, deps) {
|
|
2998
|
+
const missing = missingPasswords(settings.native?.signing?.android, deps.env);
|
|
2999
|
+
if (missing.length === 0) return;
|
|
3000
|
+
options.unsigned = true;
|
|
3001
|
+
deps.ui.warn(`native: ${missing.join(", ")} not set, so this build is an unsigned .apk.`);
|
|
3002
|
+
}
|
|
3003
|
+
/**
|
|
3004
|
+
* Warns about what App Store Connect asks for on an iOS store build. Neither stops the build.
|
|
3005
|
+
*
|
|
3006
|
+
* @param settings - The resolved `config.ts` of the game.
|
|
3007
|
+
* @param target - The target the command line names.
|
|
3008
|
+
* @param ui - The console.
|
|
3009
|
+
*/
|
|
3010
|
+
function warnIosStore(settings, target, ui) {
|
|
3011
|
+
const native = settings.native;
|
|
3012
|
+
if (target !== "ios" || native === void 0) return;
|
|
3013
|
+
if (native.ios?.privacyManifest === void 0) ui.warn("native: --store on ios with no native.ios.privacyManifest. App Store Connect asks for one.");
|
|
3014
|
+
if (native.ios?.infoPlist?.ITSAppUsesNonExemptEncryption === void 0) ui.warn("native: --store on ios with no ITSAppUsesNonExemptEncryption in native.ios.infoPlist. App Store Connect asks on every upload without it.");
|
|
3015
|
+
}
|
|
3016
|
+
/**
|
|
2558
3017
|
* Reads `--debug` and `--editor` of `moku-game native`: they go with `native build android`
|
|
2559
3018
|
* only in this release.
|
|
2560
3019
|
*
|
|
@@ -2578,6 +3037,51 @@ function nativeDebugOf(parsed, verb, target) {
|
|
|
2578
3037
|
};
|
|
2579
3038
|
}
|
|
2580
3039
|
/**
|
|
3040
|
+
* Reads `--build-number`: a whole number from 1 to the top of an Android `versionCode`.
|
|
3041
|
+
*
|
|
3042
|
+
* @param value - The value of the flag.
|
|
3043
|
+
* @returns The number.
|
|
3044
|
+
* @throws {Error} When the value is anything else.
|
|
3045
|
+
* @example
|
|
3046
|
+
* ```ts
|
|
3047
|
+
* buildNumberOf("12"); // 12
|
|
3048
|
+
* ```
|
|
3049
|
+
*/
|
|
3050
|
+
function buildNumberOf(value) {
|
|
3051
|
+
const number = Number(value);
|
|
3052
|
+
if (/^\d+$/.test(value) && number >= 1 && number <= MAX_BUILD_NUMBER) return number;
|
|
3053
|
+
throw new Error(`[game] native: --build-number takes an integer from 1 to ${MAX_BUILD_NUMBER}, got "${value}".`);
|
|
3054
|
+
}
|
|
3055
|
+
/**
|
|
3056
|
+
* Reads `--store` and `--build-number` of `moku-game native`, before any config is read: they go
|
|
3057
|
+
* with `native build ios` and `native build android` only, one number for both stores.
|
|
3058
|
+
*
|
|
3059
|
+
* @param parsed - The command line.
|
|
3060
|
+
* @param verb - The native verb.
|
|
3061
|
+
* @param target - The target the command line names, unchecked.
|
|
3062
|
+
* @returns The store flag and the number, or nothing without them.
|
|
3063
|
+
* @throws {Error} When either goes without the other or with another verb or target, when `--debug`,
|
|
3064
|
+
* `--editor` or `--simulator` comes along, or when the number is refused.
|
|
3065
|
+
*/
|
|
3066
|
+
function nativeStoreOf(parsed, verb, target) {
|
|
3067
|
+
const { store, "build-number": number } = parsed.values;
|
|
3068
|
+
if (store !== true && number === void 0) return {};
|
|
3069
|
+
if (store !== true) throw new Error("[game] native: --build-number goes with --store.");
|
|
3070
|
+
if (verb !== "build") throw new Error("[game] native: --store goes with native build only.");
|
|
3071
|
+
const clash = [
|
|
3072
|
+
"debug",
|
|
3073
|
+
"editor",
|
|
3074
|
+
"simulator"
|
|
3075
|
+
].find((flag) => parsed.values[flag] !== void 0);
|
|
3076
|
+
if (clash !== void 0) throw new Error(`[game] native: --store does not go with --${clash}.`);
|
|
3077
|
+
if (target !== "ios" && target !== "android") throw new Error(`[game] native: --store builds ios or android, got ${target ?? "no target"}.`);
|
|
3078
|
+
if (number === void 0) throw new Error("[game] native: --store needs --build-number, the number of this upload.");
|
|
3079
|
+
return {
|
|
3080
|
+
store: true,
|
|
3081
|
+
buildNumber: buildNumberOf(number)
|
|
3082
|
+
};
|
|
3083
|
+
}
|
|
3084
|
+
/**
|
|
2581
3085
|
* Runs `moku-game keys` or `pack` through the asset scanner, with the layers of `config.ts`.
|
|
2582
3086
|
*
|
|
2583
3087
|
* @param parsed - The command line.
|
|
@@ -3035,180 +3539,6 @@ async function watchKeysAt(root, settings, seams, options = {}) {
|
|
|
3035
3539
|
return { close };
|
|
3036
3540
|
}
|
|
3037
3541
|
//#endregion
|
|
3038
|
-
//#region src/app/native.ts
|
|
3039
|
-
/**
|
|
3040
|
-
* @file The native verbs of `moku-game`: a game's `config.ts` as the config of `@moku-labs/native`,
|
|
3041
|
-
* and one verb run over it. Node only, no package export: the bin bundles it. The only file of the
|
|
3042
|
-
* engine that imports `@moku-labs/native`, and only with `import()`, so a web-only game never
|
|
3043
|
-
* loads it.
|
|
3044
|
-
*/
|
|
3045
|
-
/** The port of the dev server Tauri's shell starts and loads. */
|
|
3046
|
-
const DEV_PORT = 5173;
|
|
3047
|
-
/**
|
|
3048
|
-
* The native section of a resolved config.
|
|
3049
|
-
*
|
|
3050
|
-
* @param settings - The resolved `config.ts` of the game.
|
|
3051
|
-
* @returns The native section.
|
|
3052
|
-
* @throws {Error} When `config.ts` has no native section.
|
|
3053
|
-
*/
|
|
3054
|
-
function nativeSectionOf(settings) {
|
|
3055
|
-
if (settings.native === void 0) throw new Error("[game] config.ts has no native section.\n Add native: { name, identifier } to config.ts.");
|
|
3056
|
-
return settings.native;
|
|
3057
|
-
}
|
|
3058
|
-
/**
|
|
3059
|
-
* The system rows native packages: one per system plugin that needs a Tauri capability. The
|
|
3060
|
-
* webview's own events and wake lock serve `lifecycle` and `keepAwake`, so they need no row. A
|
|
3061
|
-
* `"store"` save needs the store row even when `system` leaves it out.
|
|
3062
|
-
*
|
|
3063
|
-
* @param settings - The resolved `config.ts` of the game.
|
|
3064
|
-
* @returns The rows, in the order of `config.system`.
|
|
3065
|
-
*/
|
|
3066
|
-
function systemRowsOf(settings) {
|
|
3067
|
-
const names = settings.system.filter((name) => name !== "lifecycle" && name !== "keepAwake");
|
|
3068
|
-
if (settings.save === "store" && !names.includes("store")) names.push("store");
|
|
3069
|
-
return names.map((name) => ({ name }));
|
|
3070
|
-
}
|
|
3071
|
-
/**
|
|
3072
|
-
* The web build command native runs: `moku-game build`, with the debug profile and the editor
|
|
3073
|
-
* address of a debug app.
|
|
3074
|
-
*
|
|
3075
|
-
* @param where - The game folder and the command that runs `moku-game`.
|
|
3076
|
-
* @param debug - The debug profile, or `undefined` for a store app.
|
|
3077
|
-
* @returns The command.
|
|
3078
|
-
* @example
|
|
3079
|
-
* ```ts
|
|
3080
|
-
* webBuildOf({ cwd: "/g", command: '"bun" "/g/bin/moku-game.mjs"' }, { level: "full", editor: "192.168.1.20:47600" }); // '"bun" "/g/bin/moku-game.mjs" build --debug --editor 192.168.1.20:47600'
|
|
3081
|
-
* ```
|
|
3082
|
-
*/
|
|
3083
|
-
function webBuildOf(where, debug) {
|
|
3084
|
-
if (debug === void 0) return `${where.command} build`;
|
|
3085
|
-
const level = debug.level === "full" ? "--debug" : "--debug=read";
|
|
3086
|
-
const editor = debug.editor === void 0 ? "" : ` --editor ${debug.editor}`;
|
|
3087
|
-
return `${where.command} build ${level}${editor}`;
|
|
3088
|
-
}
|
|
3089
|
-
/**
|
|
3090
|
-
* Maps a game's resolved `config.ts` to the config of `@moku-labs/native`: the app from `native`
|
|
3091
|
-
* and `page`, the web build through `moku-game`, the system rows, the targets, and the Tauri
|
|
3092
|
-
* project and output folders under the game. An Android app composes native's `shell` system
|
|
3093
|
-
* first, the one that sets `globalThis.__MOKU_NATIVE__`. A debug app builds its web page with the
|
|
3094
|
-
* same profile and `--editor`; its name and identifier stay the game's.
|
|
3095
|
-
*
|
|
3096
|
-
* @param settings - The resolved `config.ts` of the game.
|
|
3097
|
-
* @param where - The game folder and the command that runs `moku-game`.
|
|
3098
|
-
* @param target - The target of the verb, used when `config.ts` names no targets.
|
|
3099
|
-
* @param debug - The debug profile of a debug app; left out for a store app.
|
|
3100
|
-
* @returns The config for `createApp({ config })` of `@moku-labs/native`.
|
|
3101
|
-
* @throws {Error} When `config.ts` has no native section.
|
|
3102
|
-
* @example
|
|
3103
|
-
* ```ts
|
|
3104
|
-
* const where = { cwd: "/g", command: '"/usr/local/bin/bun" "/g/node_modules/@moku-labs/game/bin/moku-game.mjs" "--root" "/g"' };
|
|
3105
|
-
* nativeConfigOf(resolveConfig({ page: { title: "T" }, native: { name: "T", identifier: "com.x.t" } }), where, "ios").web.dist; // "/g/dist/web"
|
|
3106
|
-
* ```
|
|
3107
|
-
*/
|
|
3108
|
-
function nativeConfigOf(settings, where, target, debug) {
|
|
3109
|
-
const native = nativeSectionOf(settings);
|
|
3110
|
-
const rows = systemRowsOf(settings);
|
|
3111
|
-
const config = {
|
|
3112
|
-
app: {
|
|
3113
|
-
name: native.name,
|
|
3114
|
-
identifier: native.identifier,
|
|
3115
|
-
orientation: settings.page.orientation,
|
|
3116
|
-
backgroundColor: settings.page.background
|
|
3117
|
-
},
|
|
3118
|
-
web: {
|
|
3119
|
-
cwd: where.cwd,
|
|
3120
|
-
build: webBuildOf(where, debug),
|
|
3121
|
-
devCommand: `${where.command} dev --port ${DEV_PORT}`,
|
|
3122
|
-
devUrl: `http://127.0.0.1:${DEV_PORT}`,
|
|
3123
|
-
dist: path.join(where.cwd, "dist/web")
|
|
3124
|
-
},
|
|
3125
|
-
system: target === "android" ? [{ name: "shell" }, ...rows.filter((row) => row.name !== "shell")] : rows,
|
|
3126
|
-
projectDir: path.join(where.cwd, ".moku/tauri"),
|
|
3127
|
-
outDir: path.join(where.cwd, "dist-native")
|
|
3128
|
-
};
|
|
3129
|
-
const targets = native.targets ?? (target === void 0 ? void 0 : [target]);
|
|
3130
|
-
if (native.icon !== void 0) config.app.icon = native.icon;
|
|
3131
|
-
if (targets !== void 0) config.targets = targets;
|
|
3132
|
-
return config;
|
|
3133
|
-
}
|
|
3134
|
-
/**
|
|
3135
|
-
* Checks the target of a verb against the targets native knows. `build` and `dev` need one.
|
|
3136
|
-
*
|
|
3137
|
-
* @param known - The `TARGETS` of `@moku-labs/native`.
|
|
3138
|
-
* @param verb - The native verb.
|
|
3139
|
-
* @param given - The target the command line names, unchecked.
|
|
3140
|
-
* @returns The target, or `undefined` for a `doctor` or `clean` over every target.
|
|
3141
|
-
* @throws {Error} When the target is unknown, or `build` or `dev` names none.
|
|
3142
|
-
*/
|
|
3143
|
-
function targetOf(known, verb, given) {
|
|
3144
|
-
const target = known.find((name) => name === given);
|
|
3145
|
-
if (given !== void 0 && target === void 0) throw new Error(`[game] No native target "${given}".\n Name one of ${known.join(", ")}.`);
|
|
3146
|
-
if (target === void 0 && verb === "build") throw new Error("[game] moku-game native build needs a target.\n Run: moku-game native build ios --simulator.");
|
|
3147
|
-
if (target === void 0 && verb === "dev") throw new Error("[game] moku-game native dev needs a target.\n Run: moku-game native dev ios.");
|
|
3148
|
-
return target;
|
|
3149
|
-
}
|
|
3150
|
-
/**
|
|
3151
|
-
* Runs one verb on the cli of a started native app.
|
|
3152
|
-
*
|
|
3153
|
-
* @param cli - The cli of the native app.
|
|
3154
|
-
* @param verb - The native verb.
|
|
3155
|
-
* @param target - The checked target.
|
|
3156
|
-
* @param options - The simulator flag, and the debug profile of a debug app.
|
|
3157
|
-
* @returns The boolean of `doctor`, true for the other verbs once they finish.
|
|
3158
|
-
*/
|
|
3159
|
-
async function runVerb(cli, verb, target, options) {
|
|
3160
|
-
switch (verb) {
|
|
3161
|
-
case "build": {
|
|
3162
|
-
const build = {
|
|
3163
|
-
target,
|
|
3164
|
-
simulator: options.simulator,
|
|
3165
|
-
...options.debug === void 0 ? {} : { debug: true }
|
|
3166
|
-
};
|
|
3167
|
-
await cli.build(build);
|
|
3168
|
-
return true;
|
|
3169
|
-
}
|
|
3170
|
-
case "dev":
|
|
3171
|
-
await cli.dev({ target });
|
|
3172
|
-
return true;
|
|
3173
|
-
case "doctor": return cli.doctor({ target });
|
|
3174
|
-
case "clean":
|
|
3175
|
-
await cli.clean({ target });
|
|
3176
|
-
return true;
|
|
3177
|
-
}
|
|
3178
|
-
}
|
|
3179
|
-
/**
|
|
3180
|
-
* Runs one native verb through `@moku-labs/native` over the game's config. Native's cli prints
|
|
3181
|
-
* the progress and the failure itself.
|
|
3182
|
-
*
|
|
3183
|
-
* @param verb - The native verb: build, dev, doctor or clean.
|
|
3184
|
-
* @param settings - The resolved `config.ts` of the game.
|
|
3185
|
-
* @param where - The game folder and the command that runs `moku-game`.
|
|
3186
|
-
* @param options - The target, the simulator flag, and the debug profile of a debug app.
|
|
3187
|
-
* @returns True when the verb succeeded, false when it failed.
|
|
3188
|
-
* @throws {Error} When `config.ts` has no native section, `@moku-labs/native` is not installed, or
|
|
3189
|
-
* the target is unknown or missing.
|
|
3190
|
-
*/
|
|
3191
|
-
async function runNative(verb, settings, where, options) {
|
|
3192
|
-
nativeSectionOf(settings);
|
|
3193
|
-
const native = await import("@moku-labs/native").catch((error) => {
|
|
3194
|
-
throw new Error("[game] moku-game native needs @moku-labs/native.\n Install it: bun add -d @moku-labs/native@^0.3.9.", { cause: error });
|
|
3195
|
-
});
|
|
3196
|
-
const target = targetOf(native.TARGETS, verb, options.target);
|
|
3197
|
-
const debug = options.debug === void 0 ? void 0 : {
|
|
3198
|
-
level: options.debug,
|
|
3199
|
-
editor: options.editor
|
|
3200
|
-
};
|
|
3201
|
-
const app = native.createApp({ config: nativeConfigOf(settings, where, target, debug) });
|
|
3202
|
-
await app.start();
|
|
3203
|
-
try {
|
|
3204
|
-
return await runVerb(app.cli, verb, target, options);
|
|
3205
|
-
} catch {
|
|
3206
|
-
return false;
|
|
3207
|
-
} finally {
|
|
3208
|
-
await app.stop();
|
|
3209
|
-
}
|
|
3210
|
-
}
|
|
3211
|
-
//#endregion
|
|
3212
3542
|
//#region src/cli.ts
|
|
3213
3543
|
/**
|
|
3214
3544
|
* @file The `@moku-labs/game/cli` door, node and bun only: the `moku-game` bin and the editor's
|
|
@@ -3274,8 +3604,9 @@ function keysSeams(ui) {
|
|
|
3274
3604
|
/**
|
|
3275
3605
|
* The real process behind the command line: the branded console, the environment the bin
|
|
3276
3606
|
* started with, Bun's spawn and resolver, the signals, `fs.watch`, the keys watch, the asset
|
|
3277
|
-
* scanner with the string tools, native,
|
|
3278
|
-
* `moku-game visual
|
|
3607
|
+
* scanner with the string tools, native, the visual test runner, loaded only by
|
|
3608
|
+
* `moku-game visual`, and what a native build reads: the home folder, the file check and the
|
|
3609
|
+
* version of the game's `package.json`.
|
|
3279
3610
|
*
|
|
3280
3611
|
* @returns The seams of this process.
|
|
3281
3612
|
*/
|
|
@@ -3303,7 +3634,10 @@ function processDeps() {
|
|
|
3303
3634
|
resolve: bunResolve,
|
|
3304
3635
|
loadPage: (file) => import(file),
|
|
3305
3636
|
visual: () => import("./visual.mjs"),
|
|
3306
|
-
now: () => Date.now()
|
|
3637
|
+
now: () => Date.now(),
|
|
3638
|
+
home: homedir(),
|
|
3639
|
+
exists: existsSync,
|
|
3640
|
+
readPackageVersion: packageVersionOf
|
|
3307
3641
|
};
|
|
3308
3642
|
}
|
|
3309
3643
|
/**
|