@moku-labs/game 0.15.121 → 0.15.122
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 +3 -3
- package/dist/cli.mjs +204 -63
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -163,10 +163,10 @@ The engine bin `moku-game` serves, builds and packs a game folder. A game writes
|
|
|
163
163
|
| Command | Does |
|
|
164
164
|
|---|---|
|
|
165
165
|
| `moku-game dev [--port 3000] [--packed]` | Serves the game with hot reload. Prints the bound URL, also for `--port 0`. On the raw files it runs the scan of `keys` at start and on a save of an asset or a strings file. Restarts its server when the installed engine changes |
|
|
166
|
-
| `moku-game build [--out dist/web] [--debug[=full] [--editor host:port]]` | Packs the assets and builds the page; `--debug` adds the editor's page agent (read and cosmetic commands), `--debug=full` every command; `--editor` names where the agent finds the editor (default `127.0.0.1:47600`). A debug page is never shipped: a release page that carries the agent is refused |
|
|
167
|
-
| `moku-game native build <target> [--simulator] [--debug[=full] [--editor host:port]]` | Builds the native app: `ios`, `macos`, `android`; `--debug` builds an Android or iOS debug app beside the store app |
|
|
166
|
+
| `moku-game build [--out dist/web] [--debug[=full] [--editor host:port\|lan]]` | Packs the assets and builds the page; `--debug` adds the editor's page agent (read and cosmetic commands), `--debug=full` every command; `--editor` names where the agent finds the editor (default `127.0.0.1:47600`), `lan` this computer's LAN IPv4 at port 47600 and `lan:<port>` at that port, for a phone on the same Wi-Fi. A debug page is never shipped: a release page that carries the agent is refused |
|
|
167
|
+
| `moku-game native build <target> [--simulator] [--debug[=full] [--editor host:port\|lan]]` | Builds the native app: `ios`, `macos`, `android`; `--debug` builds an Android or iOS debug app beside the store app. An iOS debug build for a device exports for `debugging` and then prints the two `xcrun devicectl` lines that install its `.ipa` from `dist-native/ios-debug` on an iPhone by cable |
|
|
168
168
|
| `moku-game native build <target> --store --build-number <n>` | A store build: an `.aab` on `android`, an `.ipa` for App Store Connect on `ios`. The version comes from `package.json`, the signing from `native.signing`. Everything wrong is refused at once, before anything compiles |
|
|
169
|
-
| `moku-game native build <target> --store --dev --build-number <n
|
|
169
|
+
| `moku-game native build <target> --store --dev --build-number <n> [--editor host:port\|lan]` | The test app of `native.dev`: store-signed, under its own `.dev` id, with the overlay, in `dist-native-dev`; no editor link, unless `--editor` gives one; the link on a dev build is iOS only for now (the build then asks for the local network) |
|
|
170
170
|
| `moku-game native build ios --store [--dev] --build-number <n> --upload` | The iOS store build, then the upload of its `.ipa` to App Store Connect with the App Store Connect key of `native.signing.apple`, or of `APPLE_API_KEY`, `APPLE_API_ISSUER`, `APPLE_API_KEY_PATH`; TestFlight shows it after Apple processes it |
|
|
171
171
|
| `moku-game native dev <target>` | Runs the native shell on the dev server |
|
|
172
172
|
| `moku-game native doctor`, `native clean` | Checks or removes the native project; `clean` also the test and iOS debug projects |
|
package/dist/cli.mjs
CHANGED
|
@@ -3,7 +3,7 @@ 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
|
+
import { homedir, networkInterfaces } from "node:os";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
import { createBrandConsole } from "@moku-labs/common/cli";
|
|
9
9
|
import { parseArgs } from "node:util";
|
|
@@ -1549,13 +1549,15 @@ async function serveChild(run, deps) {
|
|
|
1549
1549
|
* the agent and control flags, a marked title, a build id and the app id. The output works from any
|
|
1550
1550
|
* http sub-path and from the Tauri protocol: every link starts with `./`, and the page reads
|
|
1551
1551
|
* `manifest.json` next to itself. Under `MOKU_NATIVE_PROFILE=dev`, a test app's web build, the page
|
|
1552
|
-
* must be a debug page
|
|
1552
|
+
* must be a debug page with control, with no link to the editor unless `--editor` gives one. Node
|
|
1553
|
+
* and Bun only: the bin bundles it.
|
|
1553
1554
|
*/
|
|
1554
1555
|
/** The address the page agent of a debug page dials without `--editor`. */
|
|
1555
1556
|
const DEFAULT_EDITOR = "127.0.0.1:47600";
|
|
1556
1557
|
/**
|
|
1557
|
-
* What a test app's page holds in place of an address
|
|
1558
|
-
* overlay works alone. A contract with the editor, see
|
|
1558
|
+
* What a test app's page holds in place of an address, no link unless `--editor`: the editor's
|
|
1559
|
+
* agent opens no socket and the overlay works alone. A contract with the editor, see
|
|
1560
|
+
* `__MOKU_GAME_EDITOR__`.
|
|
1559
1561
|
*/
|
|
1560
1562
|
const EDITOR_OFF = "off";
|
|
1561
1563
|
/** `MOKU_NATIVE_PROFILE` of a test app's web build. */
|
|
@@ -2009,15 +2011,13 @@ function refuseTestAppRelease(run, env) {
|
|
|
2009
2011
|
throw new Error("[game] build: MOKU_NATIVE_PROFILE is dev: a dev page carries the overlay.");
|
|
2010
2012
|
}
|
|
2011
2013
|
/**
|
|
2012
|
-
* Refuses the
|
|
2013
|
-
*
|
|
2014
|
+
* Refuses the flag that has no place on a test app's page: a tester runs every command. Its link
|
|
2015
|
+
* to the editor is the person's choice, so `--editor` passes.
|
|
2014
2016
|
*
|
|
2015
|
-
* @param run - The flags of the run.
|
|
2016
2017
|
* @param level - The profile of the run.
|
|
2017
|
-
* @throws {Error} When `--
|
|
2018
|
+
* @throws {Error} When `--debug=read` was given.
|
|
2018
2019
|
*/
|
|
2019
|
-
function refuseTestAppFlags(
|
|
2020
|
-
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
|
+
function refuseTestAppFlags(level) {
|
|
2021
2021
|
if (level === "read") throw new Error("[game] build: MOKU_NATIVE_PROFILE is dev: a dev page runs every command.\n Build it with --debug.");
|
|
2022
2022
|
}
|
|
2023
2023
|
/**
|
|
@@ -2050,22 +2050,22 @@ function resolveAgent(root, resolve) {
|
|
|
2050
2050
|
/**
|
|
2051
2051
|
* What a debug run builds its page with: the editor's page agent must resolve from the game, the
|
|
2052
2052
|
* engine the page bundles is fingerprinted, and the app id comes from the native identifier. A test
|
|
2053
|
-
* app's page (`MOKU_NATIVE_PROFILE=dev`) holds
|
|
2054
|
-
* reads
|
|
2053
|
+
* app's page (`MOKU_NATIVE_PROFILE=dev`) holds the address of `--editor`, or `EDITOR_OFF` without
|
|
2054
|
+
* it, over an editor that reads `"off"`.
|
|
2055
2055
|
*
|
|
2056
2056
|
* @param run - The flags of a debug run.
|
|
2057
2057
|
* @param level - Its profile.
|
|
2058
2058
|
* @param settings - The resolved config, for the native identifier.
|
|
2059
2059
|
* @param deps - The resolver, the clock and the environment.
|
|
2060
|
-
* @returns The debug page and the
|
|
2060
|
+
* @returns The debug page, the engine fingerprint, and whether the page is a test app's.
|
|
2061
2061
|
* @throws {Error} With the install line when the game cannot resolve `@moku-labs/editor`, when it
|
|
2062
|
-
* cannot resolve `@moku-labs/game/hot`, and under the dev profile for `--
|
|
2063
|
-
*
|
|
2062
|
+
* cannot resolve `@moku-labs/game/hot`, and under the dev profile for `--debug=read` and an editor
|
|
2063
|
+
* that does not read `"off"`.
|
|
2064
2064
|
*/
|
|
2065
2065
|
function debugPageOf(run, level, settings, deps) {
|
|
2066
2066
|
const profile = deps.env.MOKU_NATIVE_PROFILE;
|
|
2067
2067
|
const isTestApp = profile === TEST_APP_PROFILE;
|
|
2068
|
-
if (isTestApp) refuseTestAppFlags(
|
|
2068
|
+
if (isTestApp) refuseTestAppFlags(level);
|
|
2069
2069
|
const agent = resolveAgent(run.root, deps.resolve);
|
|
2070
2070
|
if (isTestApp) refuseOldEditor(agent);
|
|
2071
2071
|
const engine = engineFingerprint(run.root, hotPluginOf(run.root, deps.resolve));
|
|
@@ -2074,27 +2074,31 @@ function debugPageOf(run, level, settings, deps) {
|
|
|
2074
2074
|
level,
|
|
2075
2075
|
build: buildIdOf(deps.now()),
|
|
2076
2076
|
engine: engine.id,
|
|
2077
|
-
editor: isTestApp ? EDITOR_OFF :
|
|
2077
|
+
editor: run.editor ?? (isTestApp ? EDITOR_OFF : DEFAULT_EDITOR),
|
|
2078
2078
|
app: appIdOf(settings.native, profile)
|
|
2079
2079
|
},
|
|
2080
|
-
engine
|
|
2080
|
+
engine,
|
|
2081
|
+
testApp: isTestApp
|
|
2081
2082
|
};
|
|
2082
2083
|
}
|
|
2083
2084
|
/**
|
|
2084
2085
|
* The warning a debug build prints before its size line: the profile, the build id, the engine and
|
|
2085
|
-
* the editor address, and what the page is for: never a store, or a test app's track
|
|
2086
|
+
* the editor address, and what the page is for: never a store, or a test app's track, with or
|
|
2087
|
+
* without its link to the editor.
|
|
2086
2088
|
*
|
|
2087
2089
|
* @param run - The flags of the run.
|
|
2088
2090
|
* @param debug - The debug page and the engine fingerprint.
|
|
2089
2091
|
* @param debug.page - What the page was built with.
|
|
2090
2092
|
* @param debug.engine - The engine it bundles.
|
|
2093
|
+
* @param debug.testApp - Whether the page is a test app's (`MOKU_NATIVE_PROFILE=dev`).
|
|
2091
2094
|
* @returns The line.
|
|
2092
2095
|
*/
|
|
2093
2096
|
function debugWarning(run, debug) {
|
|
2094
|
-
const { page, engine } = debug;
|
|
2097
|
+
const { page, engine, testApp } = debug;
|
|
2095
2098
|
const control = page.level === "full" ? "every command, the state-changing ones too" : "read and cosmetic commands";
|
|
2096
2099
|
const engineText = engineLine(engine, run.root).slice(7);
|
|
2097
|
-
const
|
|
2100
|
+
const testAppUse = page.editor === EDITOR_OFF ? "This is a DEV page for the store test track: overlay, no editor link." : `This is a DEV page for the store test track, with an editor link to ${page.editor}.`;
|
|
2101
|
+
const use = testApp ? testAppUse : "Never ship it to a store.";
|
|
2098
2102
|
return `build: a DEBUG page with the editor agent, control: ${control}. Build ${page.build}, engine ${engineText}, editor ${page.editor}. ${use}`;
|
|
2099
2103
|
}
|
|
2100
2104
|
/**
|
|
@@ -2133,6 +2137,49 @@ async function runBuild(run, deps) {
|
|
|
2133
2137
|
return 0;
|
|
2134
2138
|
}
|
|
2135
2139
|
//#endregion
|
|
2140
|
+
//#region src/app/lan.ts
|
|
2141
|
+
/**
|
|
2142
|
+
* Name prefixes of a Wi-Fi or wired card (macOS `en0`, Linux `wlan0`, `eth0`): their addresses are
|
|
2143
|
+
* tried first, so a VPN tunnel (`utun3`) a phone cannot reach is not picked.
|
|
2144
|
+
*/
|
|
2145
|
+
const CARD_PREFIXES = [
|
|
2146
|
+
"en",
|
|
2147
|
+
"wl",
|
|
2148
|
+
"eth"
|
|
2149
|
+
];
|
|
2150
|
+
/**
|
|
2151
|
+
* The first non-internal IPv4 address of the interfaces whose name passes a test.
|
|
2152
|
+
*
|
|
2153
|
+
* @param interfaces - The interface table.
|
|
2154
|
+
* @param named - The name test.
|
|
2155
|
+
* @returns The address, or `undefined`.
|
|
2156
|
+
* @example
|
|
2157
|
+
* ```ts
|
|
2158
|
+
* firstIpv4Of({ en0: [{ address: "192.168.1.5", family: "IPv4", internal: false }] }, () => true); // "192.168.1.5"
|
|
2159
|
+
* ```
|
|
2160
|
+
*/
|
|
2161
|
+
function firstIpv4Of(interfaces, named) {
|
|
2162
|
+
for (const [name, addresses] of Object.entries(interfaces)) {
|
|
2163
|
+
const found = named(name) ? addresses?.find((entry) => entry.family === "IPv4" && !entry.internal) : void 0;
|
|
2164
|
+
if (found !== void 0) return found.address;
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
/**
|
|
2168
|
+
* The LAN address of this computer: the first non-internal IPv4 of an interface whose name starts
|
|
2169
|
+
* with `en`, `wl` or `eth`, else the first non-internal IPv4 of any interface, else `undefined`
|
|
2170
|
+
* (the loopback only, or IPv6 only).
|
|
2171
|
+
*
|
|
2172
|
+
* @param interfaces - The interface table.
|
|
2173
|
+
* @returns The address, or `undefined`.
|
|
2174
|
+
* @example
|
|
2175
|
+
* ```ts
|
|
2176
|
+
* lanAddressOf({ utun3: [{ address: "10.8.0.2", family: "IPv4", internal: false }], en0: [{ address: "192.168.1.5", family: "IPv4", internal: false }] }); // "192.168.1.5"
|
|
2177
|
+
* ```
|
|
2178
|
+
*/
|
|
2179
|
+
function lanAddressOf(interfaces) {
|
|
2180
|
+
return firstIpv4Of(interfaces, (name) => CARD_PREFIXES.some((prefix) => name.startsWith(prefix))) ?? firstIpv4Of(interfaces, () => true);
|
|
2181
|
+
}
|
|
2182
|
+
//#endregion
|
|
2136
2183
|
//#region src/app/native.ts
|
|
2137
2184
|
/**
|
|
2138
2185
|
* @file The native verbs of `moku-game`: a game's `config.ts` as the config of `@moku-labs/native`,
|
|
@@ -2156,6 +2203,8 @@ const DEBUG_PROJECT = ".moku/tauri-debug";
|
|
|
2156
2203
|
const STORE_OUT = "dist-native";
|
|
2157
2204
|
/** Where the test apps land: native delivers one to `<outDir>/<target>`, as it does a store app. */
|
|
2158
2205
|
const DEV_OUT = "dist-native-dev";
|
|
2206
|
+
/** The `Info.plist` line of a linked test app on iOS: why it asks for the local network. */
|
|
2207
|
+
const LOCAL_NETWORK_USAGE = "The debug link to the moku editor on your computer, over the local network.";
|
|
2159
2208
|
/** The line of an `--upload` that finds no App Store Connect key, in `config.ts` or the env. */
|
|
2160
2209
|
const NO_UPLOAD_KEY = "--upload needs an App Store Connect key. Add apiKeyId, apiIssuer and apiKeyPath to native.signing.apple, or set APPLE_API_KEY, APPLE_API_ISSUER and APPLE_API_KEY_PATH.";
|
|
2161
2210
|
/**
|
|
@@ -2302,6 +2351,19 @@ function uploadFolderOf(cwd, store) {
|
|
|
2302
2351
|
return path.join(cwd, store.dev === true ? DEV_OUT : STORE_OUT, "ios");
|
|
2303
2352
|
}
|
|
2304
2353
|
/**
|
|
2354
|
+
* The folder native leaves the `.ipa` of an iOS debug device build in, under `dist-native`.
|
|
2355
|
+
*
|
|
2356
|
+
* @param cwd - The game folder.
|
|
2357
|
+
* @returns The folder, absolute.
|
|
2358
|
+
* @example
|
|
2359
|
+
* ```ts
|
|
2360
|
+
* debugFolderOf("/g"); // "/g/dist-native/ios-debug"
|
|
2361
|
+
* ```
|
|
2362
|
+
*/
|
|
2363
|
+
function debugFolderOf(cwd) {
|
|
2364
|
+
return path.join(cwd, STORE_OUT, "ios-debug");
|
|
2365
|
+
}
|
|
2366
|
+
/**
|
|
2305
2367
|
* The password variables of an Android signing block that are unset or empty, by name only. The
|
|
2306
2368
|
* key password falls back to the keystore's.
|
|
2307
2369
|
*
|
|
@@ -2525,23 +2587,27 @@ function appOf(settings, identity, extras) {
|
|
|
2525
2587
|
/**
|
|
2526
2588
|
* The signing block of the native config. A debug build keeps native's SDK key, so it takes no
|
|
2527
2589
|
* upload key, and neither does a plain build without its passwords, which Gradle would refuse only
|
|
2528
|
-
* after the compile; a store build on iOS exports for App Store Connect, and
|
|
2590
|
+
* after the compile; a store build on iOS exports for App Store Connect, and an iOS debug build for
|
|
2591
|
+
* a device exports for debugging, so a registered iPhone installs it by cable.
|
|
2529
2592
|
*
|
|
2530
2593
|
* @param native - The native section.
|
|
2531
2594
|
* @param where - The game folder and the home folder.
|
|
2532
2595
|
* @param target - The target of the verb.
|
|
2533
|
-
* @param extras - The debug profile and the build number of this run
|
|
2596
|
+
* @param extras - The debug profile and the build number of this run; it also reads `simulator`
|
|
2597
|
+
* and `unsigned`.
|
|
2534
2598
|
* @returns The block, empty when there is nothing to pass.
|
|
2535
2599
|
*/
|
|
2536
2600
|
function signingOf(native, where, target, extras) {
|
|
2537
2601
|
const android = native.signing?.android;
|
|
2538
2602
|
const teamId = native.signing?.apple?.teamId;
|
|
2539
2603
|
const isStoreIos = target === "ios" && extras.buildNumber !== void 0;
|
|
2604
|
+
const isDebugDevice = target === "ios" && extras.debug !== void 0 && extras.simulator !== true;
|
|
2540
2605
|
const keyStaysOut = android === void 0 || extras.debug !== void 0 || extras.unsigned === true;
|
|
2541
2606
|
const apple = {
|
|
2542
2607
|
...teamId === void 0 ? {} : { teamId },
|
|
2543
2608
|
...target === "ios" ? { iosMinimumSystemVersion: native.ios?.minimumVersion ?? IOS_MINIMUM } : {},
|
|
2544
|
-
...isStoreIos ? { exportMethod: "app-store-connect" } : {}
|
|
2609
|
+
...isStoreIos ? { exportMethod: "app-store-connect" } : {},
|
|
2610
|
+
...isDebugDevice ? { exportMethod: "debugging" } : {}
|
|
2545
2611
|
};
|
|
2546
2612
|
return {
|
|
2547
2613
|
...keyStaysOut ? {} : { android: {
|
|
@@ -2552,14 +2618,42 @@ function signingOf(native, where, target, extras) {
|
|
|
2552
2618
|
};
|
|
2553
2619
|
}
|
|
2554
2620
|
/**
|
|
2555
|
-
* The
|
|
2621
|
+
* The `Info.plist` keys of a test app with an editor link on iOS, over the game's own: the local
|
|
2622
|
+
* network line, unless the game wrote its own, and `NSAllowsLocalNetworking` added to the game's
|
|
2623
|
+
* App Transport Security dict, or the dict made. An ATS value that is no dict stays as it is.
|
|
2624
|
+
*
|
|
2625
|
+
* @param infoPlist - The game's `native.ios.infoPlist`.
|
|
2626
|
+
* @returns The keys.
|
|
2627
|
+
* @example
|
|
2628
|
+
* ```ts
|
|
2629
|
+
* linkedPlistOf({ NSAppTransportSecurity: { NSAllowsArbitraryLoadsInWebContent: true } }); // { NSLocalNetworkUsageDescription: "The debug link to the moku editor on your computer, over the local network.", NSAppTransportSecurity: { NSAllowsArbitraryLoadsInWebContent: true, NSAllowsLocalNetworking: true } }
|
|
2630
|
+
* ```
|
|
2631
|
+
*/
|
|
2632
|
+
function linkedPlistOf(infoPlist = {}) {
|
|
2633
|
+
const security = infoPlist.NSAppTransportSecurity;
|
|
2634
|
+
const isDict = typeof security === "object" && !Array.isArray(security);
|
|
2635
|
+
return {
|
|
2636
|
+
NSLocalNetworkUsageDescription: LOCAL_NETWORK_USAGE,
|
|
2637
|
+
...infoPlist,
|
|
2638
|
+
NSAppTransportSecurity: isDict ? {
|
|
2639
|
+
...security,
|
|
2640
|
+
NSAllowsLocalNetworking: true
|
|
2641
|
+
} : security ?? { NSAllowsLocalNetworking: true }
|
|
2642
|
+
};
|
|
2643
|
+
}
|
|
2644
|
+
/**
|
|
2645
|
+
* The iOS block of the native config. Native takes the manifest as an absolute path only. A test
|
|
2646
|
+
* app with an editor link on iOS adds the local network keys; native adds them itself to a debug
|
|
2647
|
+
* app.
|
|
2556
2648
|
*
|
|
2557
2649
|
* @param native - The native section.
|
|
2558
2650
|
* @param cwd - The game folder.
|
|
2651
|
+
* @param target - The target of the verb.
|
|
2652
|
+
* @param extras - The dev flag and the editor link of this run.
|
|
2559
2653
|
* @returns The block, empty when the game adds nothing to the bundle.
|
|
2560
2654
|
*/
|
|
2561
|
-
function iosBundleOf(native, cwd) {
|
|
2562
|
-
const infoPlist = native.ios?.infoPlist;
|
|
2655
|
+
function iosBundleOf(native, cwd, target, extras) {
|
|
2656
|
+
const infoPlist = target === "ios" && extras.dev === true && extras.editor !== void 0 ? linkedPlistOf(native.ios?.infoPlist) : native.ios?.infoPlist;
|
|
2563
2657
|
const manifest = native.ios?.privacyManifest;
|
|
2564
2658
|
return {
|
|
2565
2659
|
...infoPlist === void 0 ? {} : { infoPlist },
|
|
@@ -2603,7 +2697,8 @@ function testProjectsOf(cwd) {
|
|
|
2603
2697
|
* builds its web page with the same profile and `--editor`; on Android its name and identifier stay
|
|
2604
2698
|
* the game's and native renames it, on iOS the engine does, in a project of its own. A dev build is
|
|
2605
2699
|
* a store build of the test app of `native.dev`, in its own project and output folders, with the
|
|
2606
|
-
* full debug page. A build number means a store
|
|
2700
|
+
* full debug page, linked to the editor when `extras.editor` is set. A build number means a store
|
|
2701
|
+
* build.
|
|
2607
2702
|
*
|
|
2608
2703
|
* @param settings - The resolved `config.ts` of the game.
|
|
2609
2704
|
* @param where - The game folder, the command that runs `moku-game` and the home folder.
|
|
@@ -2625,7 +2720,10 @@ function nativeConfigOf(settings, where, target, extras = {}) {
|
|
|
2625
2720
|
app: appOf(settings, appIdentityOf(native, target, extras), extras),
|
|
2626
2721
|
web: {
|
|
2627
2722
|
cwd: where.cwd,
|
|
2628
|
-
build: webBuildOf(where, isTestApp ? {
|
|
2723
|
+
build: webBuildOf(where, isTestApp ? {
|
|
2724
|
+
level: "full",
|
|
2725
|
+
editor: extras.editor
|
|
2726
|
+
} : extras.debug),
|
|
2629
2727
|
devCommand: `${where.command} dev --port ${DEV_PORT}`,
|
|
2630
2728
|
devUrl: `http://127.0.0.1:${DEV_PORT}`,
|
|
2631
2729
|
dist: path.join(where.cwd, "dist/web")
|
|
@@ -2636,7 +2734,7 @@ function nativeConfigOf(settings, where, target, extras = {}) {
|
|
|
2636
2734
|
};
|
|
2637
2735
|
const targets = native.targets ?? (target === void 0 ? void 0 : [target]);
|
|
2638
2736
|
const signing = signingOf(native, where, target, extras);
|
|
2639
|
-
const ios = iosBundleOf(native, where.cwd);
|
|
2737
|
+
const ios = iosBundleOf(native, where.cwd, target, extras);
|
|
2640
2738
|
if (targets !== void 0) config.targets = targets;
|
|
2641
2739
|
if (Object.keys(signing).length > 0) config.signing = signing;
|
|
2642
2740
|
if (Object.keys(ios).length > 0) config.ios = ios;
|
|
@@ -2691,13 +2789,15 @@ async function runVerb(cli, verb, target, options) {
|
|
|
2691
2789
|
}
|
|
2692
2790
|
/**
|
|
2693
2791
|
* What this run adds to the native config. A version that is not `x.y.z` stays out, and native
|
|
2694
|
-
* falls back to its own; `--store` has refused one before this reads it.
|
|
2792
|
+
* falls back to its own; `--store` has refused one before this reads it. The editor of a test app
|
|
2793
|
+
* goes on its own, a debug app's in its profile.
|
|
2695
2794
|
*
|
|
2696
2795
|
* @param options - The verb options.
|
|
2697
2796
|
* @returns The extras of `nativeConfigOf`.
|
|
2698
2797
|
*/
|
|
2699
2798
|
function extrasOf(options) {
|
|
2700
|
-
const { debug, editor, store, unsigned, version } = options;
|
|
2799
|
+
const { debug, editor, store, unsigned, version, simulator } = options;
|
|
2800
|
+
const isLinkedTestApp = debug === void 0 && store?.dev === true && editor !== void 0;
|
|
2701
2801
|
return {
|
|
2702
2802
|
...debug === void 0 ? {} : { debug: {
|
|
2703
2803
|
level: debug,
|
|
@@ -2705,6 +2805,8 @@ function extrasOf(options) {
|
|
|
2705
2805
|
} },
|
|
2706
2806
|
...store === void 0 ? {} : { buildNumber: store.buildNumber },
|
|
2707
2807
|
...store?.dev === true ? { dev: true } : {},
|
|
2808
|
+
...isLinkedTestApp ? { editor } : {},
|
|
2809
|
+
...simulator === void 0 ? {} : { simulator },
|
|
2708
2810
|
...unsigned === void 0 ? {} : { unsigned },
|
|
2709
2811
|
...version !== void 0 && STORE_VERSION.test(version) ? { version } : {}
|
|
2710
2812
|
};
|
|
@@ -3016,8 +3118,9 @@ async function runVisual(command, deps) {
|
|
|
3016
3118
|
* `parseArgs`, then one of `dev`, `build`, `native <verb>`, `keys`, `pack`, `visual` or `help`.
|
|
3017
3119
|
* Every seam of the process (the console, the environment, spawning, signals, the watcher, the
|
|
3018
3120
|
* keys watch, the asset scanner, native, Bun's resolver, the visual test runner, the home folder,
|
|
3019
|
-
* the file check, the folder listing, the game's version) comes in as
|
|
3020
|
-
* command with stubs. It returns the exit code and never exits itself. A
|
|
3121
|
+
* the file check, the folder listing, the network interfaces, the game's version) comes in as
|
|
3122
|
+
* `deps`, so a test runs a command with stubs. It returns the exit code and never exits itself. A
|
|
3123
|
+
* plain function, on no API.
|
|
3021
3124
|
*/
|
|
3022
3125
|
/** The flags every command takes. */
|
|
3023
3126
|
const GLOBAL_OPTIONS = [
|
|
@@ -3118,6 +3221,10 @@ const MAX_PORT = 65535;
|
|
|
3118
3221
|
const MAX_BUILD_NUMBER = 21e8;
|
|
3119
3222
|
/** A host of `--editor`: a name or an IPv4 address, or an IPv6 address in brackets. */
|
|
3120
3223
|
const EDITOR_HOST = /^(?:[\w.-]+|\[[\da-f:.]+\])$/i;
|
|
3224
|
+
/** The host of `--editor` that stands for the LAN address of this computer: `lan` or `lan:<port>`. */
|
|
3225
|
+
const LAN_HOST = "lan";
|
|
3226
|
+
/** The port of `--editor lan` without one: the editor's LAN listener. */
|
|
3227
|
+
const EDITOR_PORT = "47600";
|
|
3121
3228
|
/** The value a bare `--debug` reads as: the full profile, with no alias note. */
|
|
3122
3229
|
const BARE_DEBUG = "";
|
|
3123
3230
|
/** The one line `--debug=full` prints: the alias builds the same page as `--debug`. */
|
|
@@ -3127,10 +3234,10 @@ const USAGE = [
|
|
|
3127
3234
|
"moku-game <command> [options]",
|
|
3128
3235
|
"",
|
|
3129
3236
|
" dev [--port 3000] [--packed] serve the game with hot reload",
|
|
3130
|
-
" build [--out dist/web] [--debug [--editor host:port]] pack the assets and build the page; --debug adds the editor agent and control",
|
|
3131
|
-
" native build <target> [--simulator] [--debug [--editor host:port]] build the native app (ios, macos, android)",
|
|
3237
|
+
" build [--out dist/web] [--debug [--editor host:port|lan]] pack the assets and build the page; --debug adds the editor agent and control",
|
|
3238
|
+
" native build <target> [--simulator] [--debug [--editor host:port|lan]] build the native app (ios, macos, android)",
|
|
3132
3239
|
" native build <target> --store --build-number <n> a store build: an .aab on android, an .ipa on ios",
|
|
3133
|
-
" native build <target> --store --dev --build-number <n> a store-signed test app from native.dev",
|
|
3240
|
+
" native build <target> --store --dev --build-number <n> [--editor host:port|lan] a store-signed test app from native.dev",
|
|
3134
3241
|
" native build ios --store --build-number <n> --upload a store build, then the upload to App Store Connect",
|
|
3135
3242
|
" native dev <target> run the native shell on the dev server",
|
|
3136
3243
|
" native doctor | native clean check or remove the native project",
|
|
@@ -3281,23 +3388,31 @@ function noteFullAlias(parsed, ui) {
|
|
|
3281
3388
|
if (parsed.values.debug === "full") ui.info(FULL_ALIAS_NOTE);
|
|
3282
3389
|
}
|
|
3283
3390
|
/**
|
|
3284
|
-
* Reads `--editor`: the `host:port` the page agent of a debug page dials.
|
|
3391
|
+
* Reads `--editor`: the `host:port` the page agent of a debug page dials. `lan` stands for the LAN
|
|
3392
|
+
* address of this computer at port 47600, `lan:<port>` at that port; only then are the interfaces
|
|
3393
|
+
* read.
|
|
3285
3394
|
*
|
|
3286
3395
|
* @param value - The value of the flag.
|
|
3287
3396
|
* @param command - The command word, for the message.
|
|
3397
|
+
* @param interfaces - The network interfaces of this computer.
|
|
3288
3398
|
* @returns The address.
|
|
3289
|
-
* @throws {Error} When the value is not a host and a whole port from 1 to 65535
|
|
3399
|
+
* @throws {Error} When the value is not a host and a whole port from 1 to 65535, or `lan` finds no
|
|
3400
|
+
* LAN address.
|
|
3290
3401
|
* @example
|
|
3291
3402
|
* ```ts
|
|
3292
|
-
* editorOf("192.168.1.
|
|
3403
|
+
* editorOf("lan:47601", "build", () => ({ en0: [{ address: "192.168.1.5", family: "IPv4", internal: false }] })); // "192.168.1.5:47601"
|
|
3293
3404
|
* ```
|
|
3294
3405
|
*/
|
|
3295
|
-
function editorOf(value, command
|
|
3296
|
-
const
|
|
3297
|
-
const
|
|
3298
|
-
const
|
|
3406
|
+
function editorOf(value, command, interfaces) {
|
|
3407
|
+
const given = value === LAN_HOST ? `${LAN_HOST}:${EDITOR_PORT}` : value;
|
|
3408
|
+
const colon = given.lastIndexOf(":");
|
|
3409
|
+
const host = given.slice(0, Math.max(colon, 0));
|
|
3410
|
+
const port = given.slice(colon + 1);
|
|
3299
3411
|
if (!(colon > 0 && EDITOR_HOST.test(host) && /^\d+$/.test(port) && Number(port) >= 1 && Number(port) <= MAX_PORT)) throw new Error(`[game] ${command}: --editor takes host:port, got "${value}".`);
|
|
3300
|
-
return
|
|
3412
|
+
if (host !== LAN_HOST) return given;
|
|
3413
|
+
const lan = lanAddressOf(interfaces());
|
|
3414
|
+
if (lan === void 0) throw new Error(`[game] ${command}: --editor lan found no LAN address on this computer.\n Connect to a Wi-Fi or give --editor host:port.`);
|
|
3415
|
+
return `${lan}:${port}`;
|
|
3301
3416
|
}
|
|
3302
3417
|
/**
|
|
3303
3418
|
* Reads `--port`: an integer 0-65535, 3000 when left out.
|
|
@@ -3380,7 +3495,7 @@ async function runNativeVerb(parsed, deps) {
|
|
|
3380
3495
|
const verb = nativeVerbOf(word);
|
|
3381
3496
|
refuseExtra(parsed, 2);
|
|
3382
3497
|
const store = nativeStoreOf(parsed, verb, target);
|
|
3383
|
-
const debug = nativeDebugOf(parsed, verb, target);
|
|
3498
|
+
const debug = nativeDebugOf(parsed, verb, target, deps.interfaces);
|
|
3384
3499
|
noteFullAlias(parsed, deps.ui);
|
|
3385
3500
|
const settings = await loadSettings(parsed.root);
|
|
3386
3501
|
const version = deps.readPackageVersion(parsed.root);
|
|
@@ -3403,9 +3518,30 @@ async function runNativeVerb(parsed, deps) {
|
|
|
3403
3518
|
warnIosStore(settings, target, deps.ui);
|
|
3404
3519
|
} else if (isPlainAndroidBuild) leaveKeyOut(settings, options, deps);
|
|
3405
3520
|
if (!await deps.native(verb, settings, where, options)) return 1;
|
|
3521
|
+
if (verb === "build" && target === "ios" && debug.debug !== void 0) printInstallLines(parsed, deps);
|
|
3406
3522
|
return options.store?.upload === true ? uploadIpa(settings, where, options.store, deps) : 0;
|
|
3407
3523
|
}
|
|
3408
3524
|
/**
|
|
3525
|
+
* Prints how the `.ipa` of a green iOS debug device build reaches an iPhone by cable: the two
|
|
3526
|
+
* `xcrun devicectl` lines with the newest `.ipa` of the debug folder, or the way through Xcode when
|
|
3527
|
+
* the folder has none. A simulator build has no `.ipa`, so it prints nothing.
|
|
3528
|
+
*
|
|
3529
|
+
* @param parsed - The command line.
|
|
3530
|
+
* @param deps - The seams of the process.
|
|
3531
|
+
*/
|
|
3532
|
+
function printInstallLines(parsed, deps) {
|
|
3533
|
+
if (parsed.values.simulator === true) return;
|
|
3534
|
+
const folder = debugFolderOf(parsed.root);
|
|
3535
|
+
const ipa = newestIpaOf(folder, deps);
|
|
3536
|
+
if (ipa === void 0) {
|
|
3537
|
+
deps.ui.info(`native: no .ipa in ${folder}; open it in Xcode → Window → Devices and Simulators to install.`);
|
|
3538
|
+
return;
|
|
3539
|
+
}
|
|
3540
|
+
deps.ui.info("native: install it on an iPhone by cable:");
|
|
3541
|
+
deps.ui.line(" xcrun devicectl list devices");
|
|
3542
|
+
deps.ui.line(` xcrun devicectl device install app --device <name or id> "${ipa}"`);
|
|
3543
|
+
}
|
|
3544
|
+
/**
|
|
3409
3545
|
* Picks the newest `.ipa` of a folder by the time it was written.
|
|
3410
3546
|
*
|
|
3411
3547
|
* @param folder - The folder native leaves the `.ipa` in.
|
|
@@ -3520,25 +3656,29 @@ function warnIosStore(settings, target, ui) {
|
|
|
3520
3656
|
}
|
|
3521
3657
|
/**
|
|
3522
3658
|
* Reads `--debug` and `--editor` of `moku-game native`: they go with `native build android` and
|
|
3523
|
-
* `native build ios` only for now.
|
|
3659
|
+
* `native build ios` only for now. A dev store build (`--store --dev`) takes `--editor` alone,
|
|
3660
|
+
* which `nativeStoreOf` has let through.
|
|
3524
3661
|
*
|
|
3525
3662
|
* @param parsed - The command line.
|
|
3526
3663
|
* @param verb - The native verb.
|
|
3527
3664
|
* @param target - The target the command line names, unchecked.
|
|
3528
|
-
* @
|
|
3529
|
-
* @
|
|
3530
|
-
*
|
|
3665
|
+
* @param interfaces - The network interfaces of this computer, for `--editor lan`.
|
|
3666
|
+
* @returns The profile and the editor address, `lan` read to the LAN address, each only when given.
|
|
3667
|
+
* @throws {Error} When either goes with another verb, `--editor` comes without `--debug` outside a
|
|
3668
|
+
* dev store build, a value is refused, or the target is neither `android` nor `ios`.
|
|
3531
3669
|
*/
|
|
3532
|
-
function nativeDebugOf(parsed, verb, target) {
|
|
3670
|
+
function nativeDebugOf(parsed, verb, target, interfaces) {
|
|
3533
3671
|
const debug = debugLevelOf(parsed.values.debug, "native");
|
|
3534
3672
|
const editor = parsed.values.editor;
|
|
3673
|
+
const isTestApp = parsed.values.store === true && parsed.values.dev === true;
|
|
3535
3674
|
if (debug === void 0 && editor === void 0) return {};
|
|
3536
3675
|
if (verb !== "build") throw new Error("[game] native: --debug goes with native build only.");
|
|
3676
|
+
if (isTestApp && editor !== void 0) return { editor: editorOf(editor, "native", interfaces) };
|
|
3537
3677
|
if (debug === void 0) throw new Error("[game] native: --editor goes with --debug.");
|
|
3538
3678
|
if (target !== void 0 && target !== "android" && target !== "ios") throw new Error(`[game] native: --debug builds Android and iOS only for now (got ${target}).`);
|
|
3539
3679
|
return editor === void 0 ? { debug } : {
|
|
3540
3680
|
debug,
|
|
3541
|
-
editor: editorOf(editor, "native")
|
|
3681
|
+
editor: editorOf(editor, "native", interfaces)
|
|
3542
3682
|
};
|
|
3543
3683
|
}
|
|
3544
3684
|
/**
|
|
@@ -3572,8 +3712,8 @@ function refuseWithoutStore(parsed) {
|
|
|
3572
3712
|
/**
|
|
3573
3713
|
* Reads `--store`, `--build-number`, `--dev` and `--upload` of `moku-game native`, before any
|
|
3574
3714
|
* config is read: they go with `native build ios` and `native build android` only, one number for
|
|
3575
|
-
* both stores, `--dev` turns the store build into the test app,
|
|
3576
|
-
* App Store Connect.
|
|
3715
|
+
* both stores, `--dev` turns the store build into the test app, which may take `--editor`, and
|
|
3716
|
+
* `--upload` sends an iOS one to App Store Connect.
|
|
3577
3717
|
*
|
|
3578
3718
|
* @param parsed - The command line.
|
|
3579
3719
|
* @param verb - The native verb.
|
|
@@ -3581,7 +3721,8 @@ function refuseWithoutStore(parsed) {
|
|
|
3581
3721
|
* @returns The store flag, the number, `dev` and `upload`, or nothing without them.
|
|
3582
3722
|
* @throws {Error} When the first two go without each other or with another verb or target, when
|
|
3583
3723
|
* `--dev` or `--upload` goes without `--store`, when `--upload` goes with another target than
|
|
3584
|
-
* ios, when `--debug
|
|
3724
|
+
* ios, when `--debug` or `--simulator` comes along, when `--editor` comes without `--dev`, or when
|
|
3725
|
+
* the number is refused.
|
|
3585
3726
|
*/
|
|
3586
3727
|
function nativeStoreOf(parsed, verb, target) {
|
|
3587
3728
|
const { store, dev, upload, "build-number": number } = parsed.values;
|
|
@@ -3590,13 +3731,11 @@ function nativeStoreOf(parsed, verb, target) {
|
|
|
3590
3731
|
return {};
|
|
3591
3732
|
}
|
|
3592
3733
|
if (verb !== "build") throw new Error("[game] native: --store goes with native build only.");
|
|
3593
|
-
const clash = [
|
|
3594
|
-
"debug",
|
|
3595
|
-
"editor",
|
|
3596
|
-
"simulator"
|
|
3597
|
-
].find((flag) => parsed.values[flag] !== void 0);
|
|
3734
|
+
const clash = ["debug", "simulator"].find((flag) => parsed.values[flag] !== void 0);
|
|
3598
3735
|
if (clash !== void 0) throw new Error(`[game] native: --store does not go with --${clash}.`);
|
|
3736
|
+
if (parsed.values.editor !== void 0 && dev !== true) throw new Error("[game] native: --editor goes with --debug or --store --dev.");
|
|
3599
3737
|
if (target !== "ios" && target !== "android") throw new Error(`[game] native: --store builds ios or android, got ${target ?? "no target"}.`);
|
|
3738
|
+
if (parsed.values.editor !== void 0 && target === "android") throw new Error("[game] native: --store --dev --editor builds ios only for now.\n On Android use native build android --debug --editor host:port|lan.");
|
|
3600
3739
|
if (number === void 0) throw new Error("[game] native: --store needs --build-number, the number of this upload.");
|
|
3601
3740
|
const buildNumber = buildNumberOf(number);
|
|
3602
3741
|
if (upload === true && target !== "ios") throw new Error("[game] native: --upload goes with ios.");
|
|
@@ -3684,7 +3823,7 @@ function hop(argv, parsed, deps) {
|
|
|
3684
3823
|
}
|
|
3685
3824
|
/**
|
|
3686
3825
|
* Runs `moku-game build`: a release page, or with `--debug` a debug page whose agent dials
|
|
3687
|
-
* `--editor` (`--debug=read` for the rare read-only page).
|
|
3826
|
+
* `--editor`, `lan` read to the LAN address (`--debug=read` for the rare read-only page).
|
|
3688
3827
|
*
|
|
3689
3828
|
* @param parsed - The command line.
|
|
3690
3829
|
* @param deps - The process seams.
|
|
@@ -3703,7 +3842,7 @@ function runBuildCommand(parsed, deps) {
|
|
|
3703
3842
|
out: path.resolve(deps.cwd, out),
|
|
3704
3843
|
servePlugins: parsed.servePlugins,
|
|
3705
3844
|
...debug === void 0 ? {} : { debug },
|
|
3706
|
-
...editor === void 0 ? {} : { editor: editorOf(editor) }
|
|
3845
|
+
...editor === void 0 ? {} : { editor: editorOf(editor, "build", deps.interfaces) }
|
|
3707
3846
|
}, deps);
|
|
3708
3847
|
}
|
|
3709
3848
|
/**
|
|
@@ -4146,7 +4285,8 @@ function keysSeams(ui) {
|
|
|
4146
4285
|
* started with, Bun's spawn and resolver, the signals, `fs.watch`, the keys watch, the asset
|
|
4147
4286
|
* scanner with the string tools, native, the visual test runner, loaded only by
|
|
4148
4287
|
* `moku-game visual`, and what a native build reads: the home folder, the file check, the folder
|
|
4149
|
-
* listing of `--upload` and the
|
|
4288
|
+
* listing of `--upload` and of the install lines, the network interfaces of `--editor lan` and the
|
|
4289
|
+
* version of the game's `package.json`.
|
|
4150
4290
|
*
|
|
4151
4291
|
* @returns The seams of this process.
|
|
4152
4292
|
*/
|
|
@@ -4178,6 +4318,7 @@ function processDeps() {
|
|
|
4178
4318
|
home: homedir(),
|
|
4179
4319
|
exists: existsSync,
|
|
4180
4320
|
listFiles,
|
|
4321
|
+
interfaces: () => networkInterfaces(),
|
|
4181
4322
|
readPackageVersion: packageVersionOf
|
|
4182
4323
|
};
|
|
4183
4324
|
}
|