@moku-labs/game 0.15.86 → 0.15.87

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/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { t as resolveConfig } from "./config-Cn1VZ-tx.mjs";
1
+ import { n as resolveConfig } from "./config-BYx_7HL1.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";
@@ -70,15 +70,16 @@ function isBelow(file, folder) {
70
70
  return relative !== "" && relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative);
71
71
  }
72
72
  /**
73
- * Walks up from a folder to the first one whose `package.json` names the engine.
73
+ * Walks up from a folder to the first one whose `package.json` names a package.
74
74
  *
75
75
  * @param start - The folder to start in.
76
- * @returns The engine folder and its fields, or `undefined` at the top of the disk.
76
+ * @param name - The name of the package.
77
+ * @returns The package folder and its fields, or `undefined` at the top of the disk.
77
78
  */
78
- function engineFolderOf(start) {
79
+ function packageFolderOf(start, name) {
79
80
  for (let folder = start;; folder = path.dirname(folder)) {
80
81
  const fields = packageOf(folder);
81
- if (fields?.name === ENGINE_PACKAGE) return {
82
+ if (fields?.name === name) return {
82
83
  folder,
83
84
  fields
84
85
  };
@@ -86,6 +87,17 @@ function engineFolderOf(start) {
86
87
  }
87
88
  }
88
89
  /**
90
+ * Reads the version of the package a resolved file belongs to.
91
+ *
92
+ * @param file - The file, absolute.
93
+ * @param name - The name of the package.
94
+ * @returns The version, or `undefined` with no such package above the file or no string there.
95
+ */
96
+ function packageVersionAbove(file, name) {
97
+ const version = packageFolderOf(path.dirname(file), name)?.fields.version;
98
+ return typeof version === "string" ? version : void 0;
99
+ }
100
+ /**
89
101
  * Lists the files under a folder, at any depth.
90
102
  *
91
103
  * @param folder - The folder.
@@ -194,7 +206,7 @@ function installRootOf(root) {
194
206
  * ```
195
207
  */
196
208
  function engineFingerprint(root, hotPlugin) {
197
- const found = engineFolderOf(path.dirname(hotPlugin));
209
+ const found = packageFolderOf(path.dirname(hotPlugin), ENGINE_PACKAGE);
198
210
  if (found === void 0) return {
199
211
  id: "unknown",
200
212
  version: "unknown",
@@ -1520,9 +1532,10 @@ function untilStopped(server, deps) {
1520
1532
  async function serveChild(run, deps) {
1521
1533
  const server = serveOn(run, (await deps.loadPage(path.join(run.root, ".moku", "index.html"))).default);
1522
1534
  const assets = run.packed ? "packed build" : "raw assets";
1535
+ const stopped = untilStopped(server, deps);
1523
1536
  deps.ui.info(`${path.basename(run.root)}: dev server, ${assets}. Ctrl+C stops it.`);
1524
1537
  deps.ui.line(server.url.href);
1525
- return untilStopped(server, deps);
1538
+ return stopped;
1526
1539
  }
1527
1540
  //#endregion
1528
1541
  //#region src/app/build.ts
@@ -1534,11 +1547,23 @@ async function serveChild(run, deps) {
1534
1547
  * `--debug` the page is a debug page instead: the editor's page agent, the game's `.dev` modules,
1535
1548
  * the agent and control flags, a marked title, a build id and the app id. The output works from any
1536
1549
  * http sub-path and from the Tauri protocol: every link starts with `./`, and the page reads
1537
- * `manifest.json` next to itself. Node and Bun only: the bin bundles it.
1550
+ * `manifest.json` next to itself. Under `MOKU_NATIVE_PROFILE=dev`, a test app's web build, the page
1551
+ * must be a debug page, with control and no link to the editor. Node and Bun only: the bin bundles it.
1538
1552
  */
1539
1553
  /** The address the page agent of a debug page dials without `--editor`. */
1540
1554
  const DEFAULT_EDITOR = "127.0.0.1:47600";
1541
1555
  /**
1556
+ * What a test app's page holds in place of an address: the editor's agent opens no socket and the
1557
+ * overlay works alone. A contract with the editor, see `__MOKU_GAME_EDITOR__`.
1558
+ */
1559
+ const EDITOR_OFF = "off";
1560
+ /** `MOKU_NATIVE_PROFILE` of a test app's web build. */
1561
+ const TEST_APP_PROFILE = "dev";
1562
+ /** The package of the editor. */
1563
+ const EDITOR_PACKAGE = "@moku-labs/editor";
1564
+ /** The first editor that reads `EDITOR_OFF`: any before it takes the word for an address. */
1565
+ const EDITOR_READS_OFF = "0.10.19";
1566
+ /**
1542
1567
  * The two strings the editor's agent bundle always carries: the bridge's default path and the
1543
1568
  * prefix of every editor error. A contract between the engine, the editor and `@moku-labs/native`.
1544
1569
  */
@@ -1712,19 +1737,38 @@ function buildIdOf(now) {
1712
1737
  /**
1713
1738
  * The app id a debug page carries, so the editor pairs a device stream with its project: the
1714
1739
  * native bundle identifier, with `.debug` when native builds its debug app
1715
- * (`MOKU_NATIVE_PROFILE=debug`), which installs under that id.
1740
+ * (`MOKU_NATIVE_PROFILE=debug`), which installs under that id, and `native.dev.identifier` for a
1741
+ * test app (`MOKU_NATIVE_PROFILE=dev`).
1716
1742
  *
1717
- * @param identifier - `native.identifier` of `config.ts`, `undefined` without a native section.
1743
+ * @param native - `native` of `config.ts`, `undefined` without a native section.
1718
1744
  * @param profile - `MOKU_NATIVE_PROFILE` of the run.
1719
- * @returns The app id, or `undefined` without an identifier.
1745
+ * @returns The app id, or `undefined` without a native section.
1746
+ * @example
1747
+ * ```ts
1748
+ * appIdOf({ name: "Timber", identifier: "com.mokulabs.timber" }, "debug"); // "com.mokulabs.timber.debug"
1749
+ * ```
1750
+ */
1751
+ function appIdOf(native, profile) {
1752
+ if (native === void 0) return void 0;
1753
+ if (profile === "debug") return `${native.identifier}.debug`;
1754
+ return profile === TEST_APP_PROFILE ? native.dev?.identifier ?? native.identifier : native.identifier;
1755
+ }
1756
+ /**
1757
+ * Tells whether an editor reads `"off"` in `__MOKU_GAME_EDITOR__` and opens no socket.
1758
+ *
1759
+ * @param version - The version of the installed editor, unchecked.
1760
+ * @returns True for `0.10.19` and any later `x.y.z`; false for anything older or unreadable.
1720
1761
  * @example
1721
1762
  * ```ts
1722
- * appIdOf("com.mokulabs.timber", "debug"); // "com.mokulabs.timber.debug"
1763
+ * editorReadsOff("0.9.30"); // false
1723
1764
  * ```
1724
1765
  */
1725
- function appIdOf(identifier, profile) {
1726
- if (identifier === void 0) return void 0;
1727
- return profile === "debug" ? `${identifier}.debug` : identifier;
1766
+ function editorReadsOff(version) {
1767
+ const parts = /^(\d+)\.(\d+)\.(\d+)$/.exec(version ?? "")?.slice(1);
1768
+ if (parts === void 0) return false;
1769
+ const lowest = EDITOR_READS_OFF.split(".");
1770
+ const firstDifference = parts.map((part, index) => Number(part) - Number(lowest[index])).find((difference) => difference !== 0);
1771
+ return firstDifference === void 0 || firstDifference > 0;
1728
1772
  }
1729
1773
  /**
1730
1774
  * The `define` map of a page: a release page defines the three flags `false`; a debug page the
@@ -1951,38 +1995,93 @@ function refuseStoreDebug(run, env) {
1951
1995
  throw new Error("[game] build: MOKU_NATIVE_PROFILE is store: a store page must not carry the editor agent.\n Build the store app without --debug.");
1952
1996
  }
1953
1997
  /**
1998
+ * Refuses a release page when Tauri runs the web build of a test app: `MOKU_NATIVE_PROFILE=dev`.
1999
+ * Native lets the agent through that profile, so its own check would not stop a page with no
2000
+ * overlay.
2001
+ *
2002
+ * @param run - The flags of the run.
2003
+ * @param env - The environment the bin started with.
2004
+ * @throws {Error} When the profile is `dev` and the run is a release run.
2005
+ */
2006
+ function refuseTestAppRelease(run, env) {
2007
+ if (run.debug !== void 0 || env.MOKU_NATIVE_PROFILE !== TEST_APP_PROFILE) return;
2008
+ throw new Error("[game] build: MOKU_NATIVE_PROFILE is dev: a dev page carries the overlay.");
2009
+ }
2010
+ /**
2011
+ * Refuses the flags that have no place on a test app's page: its agent dials nothing, and a tester
2012
+ * runs every command.
2013
+ *
2014
+ * @param run - The flags of the run.
2015
+ * @param level - The profile of the run.
2016
+ * @throws {Error} When `--editor` or `--debug=read` was given.
2017
+ */
2018
+ function refuseTestAppFlags(run, level) {
2019
+ if (run.editor !== void 0) throw new Error("[game] build: MOKU_NATIVE_PROFILE is dev: a dev page has no editor link.\n Build it without --editor.");
2020
+ if (level === "read") throw new Error("[game] build: MOKU_NATIVE_PROFILE is dev: a dev page runs every command.\n Build it with --debug.");
2021
+ }
2022
+ /**
2023
+ * Refuses an editor that does not read `"off"`: its agent would take the word for an address and
2024
+ * dial for ever on a tester's phone. A version that cannot be read is refused too.
2025
+ *
2026
+ * @param agent - The file the editor's page agent resolves to.
2027
+ * @throws {Error} Naming the version found.
2028
+ */
2029
+ function refuseOldEditor(agent) {
2030
+ const version = packageVersionAbove(agent, EDITOR_PACKAGE);
2031
+ if (editorReadsOff(version)) return;
2032
+ throw new Error(`[game] build: a dev page needs ${EDITOR_PACKAGE} ${EDITOR_READS_OFF} or newer, found ${version ?? "no readable version"}.\n An older one dials the editor for ever. Run: bun add -d ${EDITOR_PACKAGE}@latest.`);
2033
+ }
2034
+ /**
2035
+ * Finds the editor's page agent the game resolves.
2036
+ *
2037
+ * @param root - The game folder.
2038
+ * @param resolve - Bun's resolver.
2039
+ * @returns The file.
2040
+ * @throws {Error} With the install line when the game cannot resolve `@moku-labs/editor`.
2041
+ */
2042
+ function resolveAgent(root, resolve) {
2043
+ try {
2044
+ return resolve(DEBUG_AGENT, root);
2045
+ } catch (error) {
2046
+ throw new Error("[game] build --debug needs @moku-labs/editor in the game.\n Install it: bun add -d @moku-labs/editor.", { cause: error });
2047
+ }
2048
+ }
2049
+ /**
1954
2050
  * What a debug run builds its page with: the editor's page agent must resolve from the game, the
1955
- * engine the page bundles is fingerprinted, and the app id comes from the native identifier.
2051
+ * engine the page bundles is fingerprinted, and the app id comes from the native identifier. A test
2052
+ * app's page (`MOKU_NATIVE_PROFILE=dev`) holds `EDITOR_OFF` for an address, over an editor that
2053
+ * reads it.
1956
2054
  *
1957
2055
  * @param run - The flags of a debug run.
1958
2056
  * @param level - Its profile.
1959
2057
  * @param settings - The resolved config, for the native identifier.
1960
2058
  * @param deps - The resolver, the clock and the environment.
1961
2059
  * @returns The debug page and the engine fingerprint.
1962
- * @throws {Error} With the install line when the game cannot resolve `@moku-labs/editor`, and
1963
- * when it cannot resolve `@moku-labs/game/hot`.
2060
+ * @throws {Error} With the install line when the game cannot resolve `@moku-labs/editor`, when it
2061
+ * cannot resolve `@moku-labs/game/hot`, and under the dev profile for `--editor`, `--debug=read`
2062
+ * and an editor that does not read `"off"`.
1964
2063
  */
1965
2064
  function debugPageOf(run, level, settings, deps) {
1966
- try {
1967
- deps.resolve(DEBUG_AGENT, run.root);
1968
- } catch (error) {
1969
- throw new Error("[game] build --debug needs @moku-labs/editor in the game.\n Install it: bun add -d @moku-labs/editor.", { cause: error });
1970
- }
2065
+ const profile = deps.env.MOKU_NATIVE_PROFILE;
2066
+ const isTestApp = profile === TEST_APP_PROFILE;
2067
+ if (isTestApp) refuseTestAppFlags(run, level);
2068
+ const agent = resolveAgent(run.root, deps.resolve);
2069
+ if (isTestApp) refuseOldEditor(agent);
1971
2070
  const engine = engineFingerprint(run.root, hotPluginOf(run.root, deps.resolve));
1972
2071
  return {
1973
2072
  page: {
1974
2073
  level,
1975
2074
  build: buildIdOf(deps.now()),
1976
2075
  engine: engine.id,
1977
- editor: run.editor ?? "127.0.0.1:47600",
1978
- app: appIdOf(settings.native?.identifier, deps.env.MOKU_NATIVE_PROFILE)
2076
+ editor: isTestApp ? EDITOR_OFF : run.editor ?? DEFAULT_EDITOR,
2077
+ app: appIdOf(settings.native, profile)
1979
2078
  },
1980
2079
  engine
1981
2080
  };
1982
2081
  }
1983
2082
  /**
1984
2083
  * The warning a debug build prints before its size line: the profile, the build id, the engine and
1985
- * the editor address.
2084
+ * the editor address, and what the page is for: never a store, or a test app's track.
1986
2085
  *
1987
2086
  * @param run - The flags of the run.
1988
2087
  * @param debug - The debug page and the engine fingerprint.
@@ -1994,7 +2093,8 @@ function debugWarning(run, debug) {
1994
2093
  const { page, engine } = debug;
1995
2094
  const control = page.level === "full" ? "every command, the state-changing ones too" : "read and cosmetic commands";
1996
2095
  const engineText = engineLine(engine, run.root).slice(7);
1997
- return `build: a DEBUG page with the editor agent, control: ${control}. Build ${page.build}, engine ${engineText}, editor ${page.editor}. Never ship it to a store.`;
2096
+ const use = page.editor === EDITOR_OFF ? "This is a DEV page for the store test track: overlay, no editor link." : "Never ship it to a store.";
2097
+ return `build: a DEBUG page with the editor agent, control: ${control}. Build ${page.build}, engine ${engineText}, editor ${page.editor}. ${use}`;
1998
2098
  }
1999
2099
  /**
2000
2100
  * Builds the page of a game: packs the assets, replaces the output folder with the bundled page,
@@ -2011,6 +2111,7 @@ function debugWarning(run, debug) {
2011
2111
  */
2012
2112
  async function runBuild(run, deps) {
2013
2113
  refuseStoreDebug(run, deps.env);
2114
+ refuseTestAppRelease(run, deps.env);
2014
2115
  const settings = await loadGame(run.root);
2015
2116
  refuseOut(run.root, run.out);
2016
2117
  const debug = run.debug === void 0 ? void 0 : debugPageOf(run, run.debug, settings, deps);
@@ -2044,6 +2145,16 @@ const DEV_PORT = 5173;
2044
2145
  const IOS_MINIMUM = "26.0";
2045
2146
  /** The version shape a store takes, and the only one the engine hands native: `1.2.3`. */
2046
2147
  const STORE_VERSION = /^\d+\.\d+\.\d+$/;
2148
+ /** The Tauri project of the players' app, and of an Android debug app beside it. */
2149
+ const STORE_PROJECT = ".moku/tauri";
2150
+ /** The project of the test app: a full Rust build of its own. */
2151
+ const DEV_PROJECT = ".moku/tauri-dev";
2152
+ /** The project of the iOS debug app: tauri refuses a renamed app in one tree. */
2153
+ const DEBUG_PROJECT = ".moku/tauri-debug";
2154
+ /** Where the players' apps land, and the debug ones, which native files under `-debug` folders. */
2155
+ const STORE_OUT = "dist-native";
2156
+ /** Where the test apps land: native delivers one to `<outDir>/<target>`, as it does a store app. */
2157
+ const DEV_OUT = "dist-native-dev";
2047
2158
  /**
2048
2159
  * The native section of a resolved config.
2049
2160
  *
@@ -2144,6 +2255,20 @@ function testSuffixes() {
2144
2255
  ]);
2145
2256
  }
2146
2257
  /**
2258
+ * The problem of a test app's identifier: it must end in `.dev`, the word the real one may not.
2259
+ *
2260
+ * @param dev - `native.dev` of a raw config: the checks of `resolveConfig` have not run on it.
2261
+ * @returns One line, or none for a good identifier.
2262
+ * @example
2263
+ * ```ts
2264
+ * devIdentifierProblems({ identifier: "com.acme.t.dev" }); // []
2265
+ * ```
2266
+ */
2267
+ function devIdentifierProblems(dev) {
2268
+ if (dev === void 0) return ["No native.dev in config.ts. Add identifier, ending in .dev."];
2269
+ return dev.identifier.endsWith(".dev") ? [] : [`The test identifier ${dev.identifier} does not end in .dev. Fix native.dev.identifier.`];
2270
+ }
2271
+ /**
2147
2272
  * The problem of an identifier that names a test build.
2148
2273
  *
2149
2274
  * @param identifier - `native.identifier`.
@@ -2176,7 +2301,7 @@ function storeProblems(input) {
2176
2301
  return [
2177
2302
  ...input.target === "android" ? androidProblems(native, input) : appleProblems(native),
2178
2303
  ...versionProblems(input.version),
2179
- ...identifierProblems(native.identifier)
2304
+ ...input.store.dev === true ? devIdentifierProblems(native.dev) : identifierProblems(native.identifier)
2180
2305
  ];
2181
2306
  }
2182
2307
  /**
@@ -2211,20 +2336,50 @@ function webBuildOf(where, debug) {
2211
2336
  return `${where.command} build ${level}${editor}`;
2212
2337
  }
2213
2338
  /**
2339
+ * The app this run builds: the game's, the test app of a dev build, or on iOS the debug app, which
2340
+ * the engine names since native renames only on Android.
2341
+ *
2342
+ * @param native - The native section.
2343
+ * @param target - The target of the verb.
2344
+ * @param extras - The debug profile and the dev flag of this run.
2345
+ * @returns The name, the identifier and the icon, when there is one.
2346
+ * @example
2347
+ * ```ts
2348
+ * appIdentityOf({ name: "T", identifier: "com.x.t" }, "ios", { debug: { level: "full" } }); // { name: "T (debug)", identifier: "com.x.t.debug", icon: undefined }
2349
+ * ```
2350
+ */
2351
+ function appIdentityOf(native, target, extras) {
2352
+ const { name, identifier, icon, dev } = native;
2353
+ if (extras.dev === true && dev !== void 0) return {
2354
+ name: dev.name ?? `${name} DEV`,
2355
+ identifier: dev.identifier,
2356
+ icon: dev.icon ?? icon
2357
+ };
2358
+ return target === "ios" && extras.debug !== void 0 ? {
2359
+ name: `${name} (debug)`,
2360
+ identifier: `${identifier}.debug`,
2361
+ icon
2362
+ } : {
2363
+ name,
2364
+ identifier,
2365
+ icon
2366
+ };
2367
+ }
2368
+ /**
2214
2369
  * The app block of the native config: the identity and the window, and what this run adds.
2215
2370
  *
2216
2371
  * @param settings - The resolved `config.ts` of the game.
2217
- * @param native - The native section.
2372
+ * @param identity - The app this run builds.
2218
2373
  * @param extras - The version and the build number of this run.
2219
2374
  * @returns The app block.
2220
2375
  */
2221
- function appOf(settings, native, extras) {
2376
+ function appOf(settings, identity, extras) {
2222
2377
  return {
2223
- name: native.name,
2224
- identifier: native.identifier,
2378
+ name: identity.name,
2379
+ identifier: identity.identifier,
2225
2380
  orientation: settings.page.orientation,
2226
2381
  backgroundColor: settings.page.background,
2227
- ...native.icon === void 0 ? {} : { icon: native.icon },
2382
+ ...identity.icon === void 0 ? {} : { icon: identity.icon },
2228
2383
  ...extras.version === void 0 ? {} : { version: extras.version },
2229
2384
  ...extras.buildNumber === void 0 ? {} : { buildNumber: String(extras.buildNumber) },
2230
2385
  ...settings.system.includes("keepAwake") ? { keepScreenOn: true } : {}
@@ -2275,17 +2430,48 @@ function iosBundleOf(native, cwd) {
2275
2430
  };
2276
2431
  }
2277
2432
  /**
2433
+ * The project folder of one run: a test app and an iOS debug app each have their own, since tauri
2434
+ * refuses to rename an app in one tree.
2435
+ *
2436
+ * @param target - The target of the verb.
2437
+ * @param extras - The debug profile and the dev flag of this run.
2438
+ * @returns The folder, relative to the game.
2439
+ * @example
2440
+ * ```ts
2441
+ * projectOf("android", { debug: { level: "full" } }); // ".moku/tauri"
2442
+ * ```
2443
+ */
2444
+ function projectOf(target, extras) {
2445
+ if (extras.dev === true) return DEV_PROJECT;
2446
+ return target === "ios" && extras.debug !== void 0 ? DEBUG_PROJECT : STORE_PROJECT;
2447
+ }
2448
+ /**
2449
+ * Lists the test projects of a game, which `moku-game native clean` removes too.
2450
+ *
2451
+ * @param cwd - The game folder.
2452
+ * @returns The absolute folders, whether they exist or not.
2453
+ * @example
2454
+ * ```ts
2455
+ * testProjectsOf("/g"); // ["/g/.moku/tauri-dev", "/g/.moku/tauri-debug"]
2456
+ * ```
2457
+ */
2458
+ function testProjectsOf(cwd) {
2459
+ return [DEV_PROJECT, DEBUG_PROJECT].map((folder) => path.join(cwd, folder));
2460
+ }
2461
+ /**
2278
2462
  * Maps a game's resolved `config.ts` to the config of `@moku-labs/native`: the app from `native`
2279
2463
  * and `page`, the web build through `moku-game`, the system rows, the targets, the signing, the
2280
2464
  * iOS bundle, and the Tauri project and output folders under the game. An Android app composes
2281
2465
  * 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.
2466
+ * builds its web page with the same profile and `--editor`; on Android its name and identifier stay
2467
+ * the game's and native renames it, on iOS the engine does, in a project of its own. A dev build is
2468
+ * a store build of the test app of `native.dev`, in its own project and output folders, with the
2469
+ * full debug page. A build number means a store build.
2284
2470
  *
2285
2471
  * @param settings - The resolved `config.ts` of the game.
2286
2472
  * @param where - The game folder, the command that runs `moku-game` and the home folder.
2287
2473
  * @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.
2474
+ * @param extras - What this run adds: the debug profile, the dev flag, the build number, the version.
2289
2475
  * @returns The config for `createApp({ config })` of `@moku-labs/native`.
2290
2476
  * @throws {Error} When `config.ts` has no native section.
2291
2477
  * @example
@@ -2297,18 +2483,19 @@ function iosBundleOf(native, cwd) {
2297
2483
  function nativeConfigOf(settings, where, target, extras = {}) {
2298
2484
  const native = nativeSectionOf(settings);
2299
2485
  const rows = systemRowsOf(settings);
2486
+ const isTestApp = extras.dev === true;
2300
2487
  const config = {
2301
- app: appOf(settings, native, extras),
2488
+ app: appOf(settings, appIdentityOf(native, target, extras), extras),
2302
2489
  web: {
2303
2490
  cwd: where.cwd,
2304
- build: webBuildOf(where, extras.debug),
2491
+ build: webBuildOf(where, isTestApp ? { level: "full" } : extras.debug),
2305
2492
  devCommand: `${where.command} dev --port ${DEV_PORT}`,
2306
2493
  devUrl: `http://127.0.0.1:${DEV_PORT}`,
2307
2494
  dist: path.join(where.cwd, "dist/web")
2308
2495
  },
2309
2496
  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")
2497
+ projectDir: path.join(where.cwd, projectOf(target, extras)),
2498
+ outDir: path.join(where.cwd, isTestApp ? DEV_OUT : STORE_OUT)
2312
2499
  };
2313
2500
  const targets = native.targets ?? (target === void 0 ? void 0 : [target]);
2314
2501
  const signing = signingOf(native, where, target, extras);
@@ -2350,6 +2537,7 @@ async function runVerb(cli, verb, target, options) {
2350
2537
  target,
2351
2538
  simulator: options.simulator,
2352
2539
  ...options.debug === void 0 ? {} : { debug: true },
2540
+ ...options.store?.dev === true ? { dev: true } : {},
2353
2541
  ...options.store !== void 0 && target === "android" ? { aab: true } : {}
2354
2542
  };
2355
2543
  await cli.build(build);
@@ -2379,6 +2567,7 @@ function extrasOf(options) {
2379
2567
  editor
2380
2568
  } },
2381
2569
  ...store === void 0 ? {} : { buildNumber: store.buildNumber },
2570
+ ...store?.dev === true ? { dev: true } : {},
2382
2571
  ...unsigned === void 0 ? {} : { unsigned },
2383
2572
  ...version !== void 0 && STORE_VERSION.test(version) ? { version } : {}
2384
2573
  };
@@ -2404,14 +2593,37 @@ function refuseStoreProblems(settings, where, options) {
2404
2593
  if (problems.length > 0) throw new Error(`[game] native --store: fix these before a store build.\n ${problems.join("\n ")}`);
2405
2594
  }
2406
2595
  /**
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.
2596
+ * Runs one verb on a native app of its own over one config, and stops the app.
2597
+ *
2598
+ * @param native - The `@moku-labs/native` module.
2599
+ * @param config - The native config.
2600
+ * @param verb - The native verb.
2601
+ * @param target - The checked target.
2602
+ * @param options - The verb options.
2603
+ * @returns True when the verb succeeded, false when it failed.
2604
+ */
2605
+ async function runApp(native, config, verb, target, options) {
2606
+ const app = native.createApp({ config });
2607
+ await app.start();
2608
+ try {
2609
+ return await runVerb(app.cli, verb, target, options);
2610
+ } catch {
2611
+ return false;
2612
+ } finally {
2613
+ await app.stop();
2614
+ }
2615
+ }
2616
+ /**
2617
+ * Runs one native verb through `@moku-labs/native` over the game's config: once, or for `clean`
2618
+ * once per project folder, one after the other. Native's cli prints the progress and the failure
2619
+ * itself.
2409
2620
  *
2410
2621
  * @param verb - The native verb: build, dev, doctor or clean.
2411
2622
  * @param settings - The resolved `config.ts` of the game.
2412
2623
  * @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.
2624
+ * @param options - The target, the simulator flag, the debug profile, the version, the store build,
2625
+ * the test projects of a `clean`.
2626
+ * @returns True when the verb succeeded, false when it failed on any folder.
2415
2627
  * @throws {Error} When `config.ts` has no native section, a store build has a problem, before
2416
2628
  * anything loads, `@moku-labs/native` is not installed, or the target is unknown or missing.
2417
2629
  */
@@ -2419,18 +2631,19 @@ async function runNative(verb, settings, where, options) {
2419
2631
  nativeSectionOf(settings);
2420
2632
  refuseStoreProblems(settings, where, options);
2421
2633
  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 });
2634
+ throw new Error("[game] moku-game native needs @moku-labs/native.\n Install it: bun add -d @moku-labs/native@^0.3.13.", { cause: error });
2423
2635
  });
2424
2636
  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();
2637
+ const config = nativeConfigOf(settings, where, target, extrasOf(options));
2638
+ let passed = await runApp(native, config, verb, target, options);
2639
+ for (const project of options.testProjects ?? []) {
2640
+ const cleaned = await runApp(native, {
2641
+ ...config,
2642
+ projectDir: project
2643
+ }, verb, target, options);
2644
+ passed &&= cleaned;
2433
2645
  }
2646
+ return passed;
2434
2647
  }
2435
2648
  //#endregion
2436
2649
  //#region src/app/visual.ts
@@ -2659,6 +2872,7 @@ const ALL_OPTIONS = {
2659
2872
  debug: { type: "string" },
2660
2873
  editor: { type: "string" },
2661
2874
  store: { type: "boolean" },
2875
+ dev: { type: "boolean" },
2662
2876
  "build-number": { type: "string" }
2663
2877
  };
2664
2878
  /** The flags of `visual` that `parseVisualArgv` reads, in the runner's words. */
@@ -2676,6 +2890,7 @@ const COMMAND_OPTIONS = {
2676
2890
  "debug",
2677
2891
  "editor",
2678
2892
  "store",
2893
+ "dev",
2679
2894
  "build-number"
2680
2895
  ],
2681
2896
  keys: ["check"],
@@ -2723,6 +2938,7 @@ const USAGE = [
2723
2938
  " build [--out dist/web] [--debug [--editor host:port]] pack the assets and build the page; --debug adds the editor agent and control",
2724
2939
  " native build <target> [--simulator] [--debug [--editor host:port]] build the native app (ios, macos, android)",
2725
2940
  " native build <target> --store --build-number <n> a store build: an .aab on android, an .ipa on ios",
2941
+ " native build <target> --store --dev --build-number <n> a store-signed test app from native.dev",
2726
2942
  " native dev <target> run the native shell on the dev server",
2727
2943
  " native doctor | native clean check or remove the native project",
2728
2944
  " keys [--check] write generated/assets.ts and generated/manifest.json",
@@ -2872,8 +3088,7 @@ function noteFullAlias(parsed, ui) {
2872
3088
  if (parsed.values.debug === "full") ui.info(FULL_ALIAS_NOTE);
2873
3089
  }
2874
3090
  /**
2875
- * Reads `--editor`: the `host:port` the page agent of a debug page dials, 127.0.0.1:47600 when
2876
- * left out.
3091
+ * Reads `--editor`: the `host:port` the page agent of a debug page dials.
2877
3092
  *
2878
3093
  * @param value - The value of the flag.
2879
3094
  * @param command - The command word, for the message.
@@ -2885,7 +3100,6 @@ function noteFullAlias(parsed, ui) {
2885
3100
  * ```
2886
3101
  */
2887
3102
  function editorOf(value, command = "build") {
2888
- if (value === void 0) return DEFAULT_EDITOR;
2889
3103
  const colon = value.lastIndexOf(":");
2890
3104
  const host = value.slice(0, Math.max(colon, 0));
2891
3105
  const port = value.slice(colon + 1);
@@ -2946,6 +3160,19 @@ function selfCommand(parsed, deps) {
2946
3160
  ].map((word) => JSON.stringify(word)).join(" ");
2947
3161
  }
2948
3162
  /**
3163
+ * Reads the verb of `moku-game native`.
3164
+ *
3165
+ * @param word - The first argument after `native`.
3166
+ * @returns The verb.
3167
+ * @throws {Error} When the verb is missing or unknown.
3168
+ */
3169
+ function nativeVerbOf(word) {
3170
+ const verb = NATIVE_VERBS.find((name) => name === word);
3171
+ if (word === void 0) throw new Error("[game] native: name a verb: build, dev, doctor, clean.");
3172
+ if (verb === void 0) throw new Error(`[game] native: no verb "${word}". Name one of build, dev, doctor, clean.`);
3173
+ return verb;
3174
+ }
3175
+ /**
2949
3176
  * Runs `moku-game native <verb> [<target>]` through native.
2950
3177
  *
2951
3178
  * @param parsed - The command line.
@@ -2955,9 +3182,7 @@ function selfCommand(parsed, deps) {
2955
3182
  */
2956
3183
  async function runNativeVerb(parsed, deps) {
2957
3184
  const [word, target] = parsed.rest;
2958
- const verb = NATIVE_VERBS.find((name) => name === word);
2959
- if (word === void 0) throw new Error("[game] native: name a verb: build, dev, doctor, clean.");
2960
- if (verb === void 0) throw new Error(`[game] native: no verb "${word}". Name one of build, dev, doctor, clean.`);
3185
+ const verb = nativeVerbOf(word);
2961
3186
  refuseExtra(parsed, 2);
2962
3187
  const store = nativeStoreOf(parsed, verb, target);
2963
3188
  const debug = nativeDebugOf(parsed, verb, target);
@@ -2973,20 +3198,57 @@ async function runNativeVerb(parsed, deps) {
2973
3198
  ...target === void 0 ? {} : { target },
2974
3199
  ...verb === "build" && parsed.values.simulator === true ? { simulator: true } : {},
2975
3200
  ...debug,
2976
- ...version === void 0 ? {} : { version }
3201
+ ...version === void 0 ? {} : { version },
3202
+ ...verb === "clean" ? testProjectsThere(parsed.root, deps) : {}
2977
3203
  };
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.");
3204
+ if (debug.debug !== void 0 && target !== void 0) deps.ui.warn("native: a DEBUG app with the editor agent, installed beside the store app. Never ship it to a store.");
3205
+ const isPlainAndroidBuild = verb === "build" && target === "android" && debug.debug === void 0;
2979
3206
  if (store.store === true) {
2980
- options.store = {
2981
- buildNumber: store.buildNumber,
2982
- env: deps.env,
2983
- exists: deps.exists
2984
- };
3207
+ options.store = storeBlockOf(store, settings, deps);
2985
3208
  warnIosStore(settings, target, deps.ui);
2986
- } else if (verb === "build" && target === "android" && debug.debug === void 0) leaveKeyOut(settings, options, deps);
3209
+ } else if (isPlainAndroidBuild) leaveKeyOut(settings, options, deps);
2987
3210
  return await deps.native(verb, settings, where, options) ? 0 : 1;
2988
3211
  }
2989
3212
  /**
3213
+ * The store block of a verb: the number, the test app's mark, and the seams of the store checks.
3214
+ *
3215
+ * @param store - What `--store` read to.
3216
+ * @param settings - The resolved `config.ts` of the game.
3217
+ * @param deps - The seams of the process.
3218
+ * @returns The block.
3219
+ * @throws {Error} When `--dev` comes with no `native.dev`.
3220
+ */
3221
+ function storeBlockOf(store, settings, deps) {
3222
+ if (store.dev === true) refuseNoTestApp(settings);
3223
+ return {
3224
+ buildNumber: store.buildNumber,
3225
+ ...store.dev === true ? { dev: true } : {},
3226
+ env: deps.env,
3227
+ exists: deps.exists
3228
+ };
3229
+ }
3230
+ /**
3231
+ * Finds the test projects of a game, for `moku-game native clean`.
3232
+ *
3233
+ * @param root - The game folder.
3234
+ * @param deps - The seams of the process.
3235
+ * @returns The projects that exist, none of the key when there is no such folder.
3236
+ */
3237
+ function testProjectsThere(root, deps) {
3238
+ const testProjects = testProjectsOf(root).filter((folder) => deps.exists(folder));
3239
+ return testProjects.length === 0 ? {} : { testProjects };
3240
+ }
3241
+ /**
3242
+ * Refuses `--dev` for a game with no test app, with a line native could not give.
3243
+ *
3244
+ * @param settings - The resolved `config.ts` of the game.
3245
+ * @throws {Error} When `config.ts` has no `native.dev`.
3246
+ */
3247
+ function refuseNoTestApp(settings) {
3248
+ if (settings.native?.dev !== void 0) return;
3249
+ throw new Error("[game] native --dev: config.ts has no native.dev.\n Add native.dev: { identifier } with an id ending in .dev.");
3250
+ }
3251
+ /**
2990
3252
  * Keeps a plain Android build going without its passwords: Gradle would refuse the signing block
2991
3253
  * only after the compile, and a teammate with no key still builds. The result is an unsigned `.apk`.
2992
3254
  *
@@ -3014,15 +3276,15 @@ function warnIosStore(settings, target, ui) {
3014
3276
  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
3277
  }
3016
3278
  /**
3017
- * Reads `--debug` and `--editor` of `moku-game native`: they go with `native build android`
3018
- * only in this release.
3279
+ * Reads `--debug` and `--editor` of `moku-game native`: they go with `native build android` and
3280
+ * `native build ios` only for now.
3019
3281
  *
3020
3282
  * @param parsed - The command line.
3021
3283
  * @param verb - The native verb.
3022
3284
  * @param target - The target the command line names, unchecked.
3023
3285
  * @returns The profile and the editor address as given, each only when given.
3024
3286
  * @throws {Error} When either goes with another verb, `--editor` comes without `--debug`, a value
3025
- * is refused, or the target is not `android`.
3287
+ * is refused, or the target is neither `android` nor `ios`.
3026
3288
  */
3027
3289
  function nativeDebugOf(parsed, verb, target) {
3028
3290
  const debug = debugLevelOf(parsed.values.debug, "native");
@@ -3030,7 +3292,7 @@ function nativeDebugOf(parsed, verb, target) {
3030
3292
  if (debug === void 0 && editor === void 0) return {};
3031
3293
  if (verb !== "build") throw new Error("[game] native: --debug goes with native build only.");
3032
3294
  if (debug === void 0) throw new Error("[game] native: --editor goes with --debug.");
3033
- if (target !== void 0 && target !== "android") throw new Error(`[game] native: --debug builds Android only in this release (got ${target}).`);
3295
+ if (target !== void 0 && target !== "android" && target !== "ios") throw new Error(`[game] native: --debug builds Android and iOS only for now (got ${target}).`);
3034
3296
  return editor === void 0 ? { debug } : {
3035
3297
  debug,
3036
3298
  editor: editorOf(editor, "native")
@@ -3053,18 +3315,21 @@ function buildNumberOf(value) {
3053
3315
  throw new Error(`[game] native: --build-number takes an integer from 1 to ${MAX_BUILD_NUMBER}, got "${value}".`);
3054
3316
  }
3055
3317
  /**
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.
3318
+ * Reads `--store`, `--build-number` and `--dev` of `moku-game native`, before any config is read:
3319
+ * they go with `native build ios` and `native build android` only, one number for both stores, and
3320
+ * `--dev` turns the store build into the test app.
3058
3321
  *
3059
3322
  * @param parsed - The command line.
3060
3323
  * @param verb - The native verb.
3061
3324
  * @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.
3325
+ * @returns The store flag, the number and `dev`, or nothing without them.
3326
+ * @throws {Error} When the first two go without each other or with another verb or target, when
3327
+ * `--dev` goes without `--store`, when `--debug`, `--editor` or `--simulator` comes along, or when
3328
+ * the number is refused.
3065
3329
  */
3066
3330
  function nativeStoreOf(parsed, verb, target) {
3067
- const { store, "build-number": number } = parsed.values;
3331
+ const { store, dev, "build-number": number } = parsed.values;
3332
+ if (store !== true && dev === true) throw new Error("[game] native: --dev goes with --store.");
3068
3333
  if (store !== true && number === void 0) return {};
3069
3334
  if (store !== true) throw new Error("[game] native: --build-number goes with --store.");
3070
3335
  if (verb !== "build") throw new Error("[game] native: --store goes with native build only.");
@@ -3076,9 +3341,14 @@ function nativeStoreOf(parsed, verb, target) {
3076
3341
  if (clash !== void 0) throw new Error(`[game] native: --store does not go with --${clash}.`);
3077
3342
  if (target !== "ios" && target !== "android") throw new Error(`[game] native: --store builds ios or android, got ${target ?? "no target"}.`);
3078
3343
  if (number === void 0) throw new Error("[game] native: --store needs --build-number, the number of this upload.");
3079
- return {
3344
+ const buildNumber = buildNumberOf(number);
3345
+ return dev === true ? {
3346
+ store: true,
3347
+ buildNumber,
3348
+ dev: true
3349
+ } : {
3080
3350
  store: true,
3081
- buildNumber: buildNumberOf(number)
3351
+ buildNumber
3082
3352
  };
3083
3353
  }
3084
3354
  /**
@@ -3176,10 +3446,8 @@ function runBuildCommand(parsed, deps) {
3176
3446
  root: parsed.root,
3177
3447
  out: path.resolve(deps.cwd, out),
3178
3448
  servePlugins: parsed.servePlugins,
3179
- ...debug === void 0 ? {} : {
3180
- debug,
3181
- editor: editorOf(editor)
3182
- }
3449
+ ...debug === void 0 ? {} : { debug },
3450
+ ...editor === void 0 ? {} : { editor: editorOf(editor) }
3183
3451
  }, deps);
3184
3452
  }
3185
3453
  /**