@protobase/cli 0.44.2 → 0.44.4
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/package.js +1 -1
- package/dist/mobile/capture-child.js +11 -0
- package/dist/mobile/development-signing.js +24 -0
- package/dist/mobile/development-team.js +11 -0
- package/dist/mobile/ios-device.js +47 -0
- package/dist/mobile/register.js +2 -1
- package/dist/mobile/run.js +9 -1
- package/package.json +6 -6
- package/skills/protobase/references/features/build-and-run.md +1 -1
- package/skills/protobase/references/guides/mobile-app.md +11 -1
- package/skills/protobase/references/reference/cli.md +2 -2
package/dist/cli/package.js
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { promisify } from "node:util";
|
|
3
|
+
//#region src/mobile/capture-child.ts
|
|
4
|
+
/** Runs `command` with `args` as given, never through a shell, in `cwd` with exactly `env`, and gives its stdout. */
|
|
5
|
+
const captureChild = async (command, args, { cwd, env }) => (await promisify(execFile)(command, args, {
|
|
6
|
+
cwd,
|
|
7
|
+
env,
|
|
8
|
+
encoding: "utf8"
|
|
9
|
+
})).stdout;
|
|
10
|
+
//#endregion
|
|
11
|
+
export { captureChild };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { runChild } from "./child-process.js";
|
|
2
|
+
import { captureChild } from "./capture-child.js";
|
|
3
|
+
import { withDevelopmentTeam } from "./development-team.js";
|
|
4
|
+
import { connectedDevice, listIosTargets, provisioningBuildArgs } from "./ios-device.js";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
7
|
+
//#region src/mobile/development-signing.ts
|
|
8
|
+
/**
|
|
9
|
+
* Signs the iOS project `cap add` generated in `ws` for development by `team`, on every run since the project is
|
|
10
|
+
* generated anew, and builds it once for the target, the connected device without one, letting Xcode create the
|
|
11
|
+
* development profile. Gives the target for `cap run`.
|
|
12
|
+
*/
|
|
13
|
+
const signForDevelopment = async ({ ws, env, team, target }, { run = runChild, capture = captureChild }) => {
|
|
14
|
+
const pbxproj = path.join(ws, "ios", "App", "App.xcodeproj", "project.pbxproj");
|
|
15
|
+
await writeFile(pbxproj, withDevelopmentTeam(await readFile(pbxproj, "utf8"), team));
|
|
16
|
+
const chosen = target ?? connectedDevice(await listIosTargets(ws, env, capture));
|
|
17
|
+
await run("xcrun", provisioningBuildArgs(ws, chosen), {
|
|
18
|
+
cwd: path.join(ws, "ios", "App"),
|
|
19
|
+
env
|
|
20
|
+
});
|
|
21
|
+
return chosen;
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { signForDevelopment };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
//#region src/mobile/development-team.ts
|
|
2
|
+
const anchor = "CODE_SIGN_STYLE = Automatic;";
|
|
3
|
+
/** The project.pbxproj with `team` as the app target's DEVELOPMENT_TEAM, a team id `--team` checked. */
|
|
4
|
+
const withDevelopmentTeam = (pbxproj, team) => {
|
|
5
|
+
if (pbxproj.includes("DEVELOPMENT_TEAM")) throw new Error("project.pbxproj already names a DEVELOPMENT_TEAM, unlike Capacitor's template");
|
|
6
|
+
const parts = pbxproj.split(anchor);
|
|
7
|
+
if (parts.length !== 3) throw new Error(`project.pbxproj has \`${anchor}\` ${parts.length - 1} times, not 2 as in Capacitor's template`);
|
|
8
|
+
return parts.join(`${anchor}\n\t\t\t\tDEVELOPMENT_TEAM = ${team};`);
|
|
9
|
+
};
|
|
10
|
+
//#endregion
|
|
11
|
+
export { withDevelopmentTeam };
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { installedPackage } from "./installed-package.js";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
//#region src/mobile/ios-device.ts
|
|
4
|
+
/** The connected iPhone or iPad in native-run's `ios --list --json`, the list `cap run` picks its target from. */
|
|
5
|
+
const connectedDevice = (list) => {
|
|
6
|
+
const { devices } = JSON.parse(list);
|
|
7
|
+
const [device, ...more] = devices;
|
|
8
|
+
if (!device) throw new Error("--team signs the app for an iPhone, and none is connected: connect it and unlock it, or pass --target");
|
|
9
|
+
if (more.length > 0) throw new Error(`Several devices are connected: pass --target with one of ${devices.map(({ id, name }) => `${id} (${name ?? "unnamed"})`).join(", ")}`);
|
|
10
|
+
return device.id;
|
|
11
|
+
};
|
|
12
|
+
/** Lists the iOS targets with the workspace's own native-run, the one Capacitor runs. */
|
|
13
|
+
const listIosTargets = (ws, env, capture) => {
|
|
14
|
+
const { bin } = installedPackage(ws, "native-run");
|
|
15
|
+
if (!bin?.["native-run"]) throw new Error(`${path.join(ws, "node_modules", "native-run")} has no native-run command`);
|
|
16
|
+
return capture("node", [
|
|
17
|
+
path.join(ws, "node_modules", "native-run", bin["native-run"]),
|
|
18
|
+
"ios",
|
|
19
|
+
"--list",
|
|
20
|
+
"--json"
|
|
21
|
+
], {
|
|
22
|
+
cwd: ws,
|
|
23
|
+
env
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* xcodebuild's arguments for the build `cap run ios --target <target>` makes, the same destination and derived data so
|
|
28
|
+
* Capacitor's own build after it has nothing left to do, but allowed to create the team's development profile and
|
|
29
|
+
* register the device with it, which Capacitor's build is not.
|
|
30
|
+
*/
|
|
31
|
+
const provisioningBuildArgs = (ws, target) => [
|
|
32
|
+
"xcodebuild",
|
|
33
|
+
"-project",
|
|
34
|
+
"App.xcodeproj",
|
|
35
|
+
"-scheme",
|
|
36
|
+
"App",
|
|
37
|
+
"-configuration",
|
|
38
|
+
"Debug",
|
|
39
|
+
"-destination",
|
|
40
|
+
`id=${target}`,
|
|
41
|
+
"-derivedDataPath",
|
|
42
|
+
path.join(ws, "ios", "DerivedData", target),
|
|
43
|
+
"-allowProvisioningUpdates",
|
|
44
|
+
"-allowProvisioningDeviceRegistration"
|
|
45
|
+
];
|
|
46
|
+
//#endregion
|
|
47
|
+
export { connectedDevice, listIosTargets, provisioningBuildArgs };
|
package/dist/mobile/register.js
CHANGED
|
@@ -9,7 +9,7 @@ const registerMobile = (program) => {
|
|
|
9
9
|
const api = "--api <url>";
|
|
10
10
|
const apiHelp = "the server the app calls (default: the auth issuer, the project's baseURL)";
|
|
11
11
|
const extend = "merge the protobase.config.ts and protobase.ui.tsx in this folder before the project's, repeatable";
|
|
12
|
-
mobile.command("run").description("Generate the native project and run the app in a simulator, an emulator or on a device").argument("<platform>", "ios or android", parsePlatform).option(api, apiHelp).option("--target <id>", "the device or simulator to run on (default: Capacitor asks)").option("--live", "open the running protobase dev instead of the app's own files, reloading as you save", false).option("--port <port>", "the port of protobase dev, for --live", parsePort, 5173).option("--extend <dir>", extend, collect, []).action(async (chosen, opts) => {
|
|
12
|
+
mobile.command("run").description("Generate the native project and run the app in a simulator, an emulator or on a device").argument("<platform>", "ios or android", parsePlatform).option(api, apiHelp).option("--target <id>", "the device or simulator to run on (default: Capacitor asks)").option("--team <id>", "iOS: your Apple Developer team id, which signs the app to run on your iPhone", parseTeamId).option("--live", "open the running protobase dev instead of the app's own files, reloading as you save", false).option("--port <port>", "the port of protobase dev, for --live", parsePort, 5173).option("--extend <dir>", extend, collect, []).action(async (chosen, opts) => {
|
|
13
13
|
const { mobileRun } = await import("./run.js");
|
|
14
14
|
await mobileRun({
|
|
15
15
|
projectDir: process.cwd(),
|
|
@@ -17,6 +17,7 @@ const registerMobile = (program) => {
|
|
|
17
17
|
extensions: resolveExtensions(opts.extend),
|
|
18
18
|
...opts.api !== void 0 && { api: opts.api },
|
|
19
19
|
...opts.target && { target: opts.target },
|
|
20
|
+
...opts.team && { team: opts.team },
|
|
20
21
|
...opts.live && { live: opts.port }
|
|
21
22
|
}, out);
|
|
22
23
|
});
|
package/dist/mobile/run.js
CHANGED
|
@@ -11,6 +11,7 @@ import { childEnv, envFileKeys, projectEnvFiles } from "./child-env.js";
|
|
|
11
11
|
import { generatePlatform } from "./generate.js";
|
|
12
12
|
import { checkMobileConfig } from "./mobile-config.js";
|
|
13
13
|
import { loadMobileProject } from "./load-project.js";
|
|
14
|
+
import { signForDevelopment } from "./development-signing.js";
|
|
14
15
|
import { mobileSpec, prepareWorkspace, workspaceDir, workspacePackageJson } from "./workspace.js";
|
|
15
16
|
import path from "node:path";
|
|
16
17
|
import { defaultAppName } from "@protobase/server";
|
|
@@ -65,12 +66,19 @@ const prepare = async ({ projectDir, platform, api, extensions, live, release },
|
|
|
65
66
|
const summary = (projectDir, { ws, url, fingerprint }) => `workspace ${path.relative(projectDir, ws)}, api ${url.origin}, native fingerprint ${fingerprint}\n`;
|
|
66
67
|
/** `protobase mobile run`: generates the native project and runs the app on a simulator, emulator or device. */
|
|
67
68
|
const mobileRun = async (input, out, deps = {}) => {
|
|
69
|
+
if (input.platform === "android" && input.team) throw new Error("--team is for iOS: Android runs the app signed with its debug key");
|
|
68
70
|
const prepared = await prepare(input, deps);
|
|
69
71
|
out(summary(input.projectDir, prepared));
|
|
72
|
+
const target = input.team ? await signForDevelopment({
|
|
73
|
+
ws: prepared.ws,
|
|
74
|
+
env: prepared.env,
|
|
75
|
+
team: input.team,
|
|
76
|
+
...input.target && { target: input.target }
|
|
77
|
+
}, deps) : input.target;
|
|
70
78
|
await prepared.cap(capRunArgs({
|
|
71
79
|
platform: input.platform,
|
|
72
80
|
url: prepared.url,
|
|
73
|
-
...
|
|
81
|
+
...target && { target },
|
|
74
82
|
...input.live !== void 0 && { live: input.live }
|
|
75
83
|
}));
|
|
76
84
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@protobase/cli",
|
|
3
|
-
"version": "0.44.
|
|
3
|
+
"version": "0.44.4",
|
|
4
4
|
"description": "The protobase command: scaffold, doctor, dev, build and serve a Protobase project.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"@better-auth/core": "^1.7.12",
|
|
37
37
|
"@hono/node-server": "^2.1.3",
|
|
38
38
|
"@hono/vite-dev-server": "^0.26.1",
|
|
39
|
-
"@protobase/layout": "0.44.
|
|
40
|
-
"@protobase/query": "0.44.
|
|
41
|
-
"@protobase/schema": "0.44.
|
|
42
|
-
"@protobase/server": "0.44.
|
|
43
|
-
"@protobase/ui": "0.44.
|
|
39
|
+
"@protobase/layout": "0.44.4",
|
|
40
|
+
"@protobase/query": "0.44.4",
|
|
41
|
+
"@protobase/schema": "0.44.4",
|
|
42
|
+
"@protobase/server": "0.44.4",
|
|
43
|
+
"@protobase/ui": "0.44.4",
|
|
44
44
|
"@react-email/render": "^2.1.0",
|
|
45
45
|
"@scalar/hono-api-reference": "^0.12.10",
|
|
46
46
|
"@tailwindcss/vite": "^4.3.3",
|
|
@@ -19,4 +19,4 @@ Develop, build and run an app, on servers, in containers and on phones.
|
|
|
19
19
|
- [Separate worker](../reference/cli.md#worker): Jobs and event delivery in their own process.
|
|
20
20
|
- [Container images](../guides/deploy.md#images): A runtime image for each release, for amd64 and arm64.
|
|
21
21
|
- [Self-hosted image](../guides/deploy.md#a-self-hosted-image): One image with the app inside that serves, migrates and creates the first admin.
|
|
22
|
-
- [Mobile apps](../guides/mobile-app.md) (beta): Runs an app on iOS and Android, with sign-in, and builds signed store releases from a section in its config.
|
|
22
|
+
- [Mobile apps](../guides/mobile-app.md) (beta): Runs an app on iOS and Android, also on your own iPhone, with sign-in, and builds signed store releases from a section in its config.
|
|
@@ -53,10 +53,20 @@ protobase mobile run ios
|
|
|
53
53
|
|
|
54
54
|
The first run installs Capacitor into `.protobase/mobile/`, which ignores itself in git. Every run builds the app's files as [`protobase build`](../reference/cli.md#build) does and generates the native project from your config again, so never edit the projects in `.protobase/mobile/` by hand. Your own package.json gains nothing.
|
|
55
55
|
|
|
56
|
+
In the app, the admin keeps clear of the status bar, the notch, the home indicator and Android's system bars, and it does not zoom: a focused input leaves the page at its scale, and so does a pinch. <gap>The status bar's text cannot follow the theme chosen in the app, only the phone's light or dark mode, because setting the status bar's style is not implemented.</gap>
|
|
57
|
+
|
|
56
58
|
The app calls the server at the project's auth `baseURL`; pass `--api https://shop.example.com` for another one. Plain http is only for a server on this machine (`localhost`) or, on the Android emulator, its host `10.0.2.2`; any other server needs https. An Android phone on USB reaches a server on `localhost` through a forwarded port; an iPhone needs an https server. The app's UI plugins load from the device only when the server serves a built bundle (`protobase serve dist`): against `protobase dev`, use `--live`.
|
|
57
59
|
|
|
58
60
|
`--target <id>` picks the simulator, emulator or device; without it Capacitor asks.
|
|
59
61
|
|
|
62
|
+
To run on your iPhone, connect it, turn on its Developer Mode and pass your Apple team id, from a paid Apple Developer membership or the free personal team of the Apple ID you added in Xcode's settings:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
protobase mobile run ios --team ABCDE12345
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Every run signs the app for development with that team, letting Xcode create the profile and register the phone, and installs it on the connected iPhone, or on `--target` when several are connected. The first time, trust your developer certificate on the phone in Settings, General, VPN & Device Management. A free team signs only an `appId` no one else has taken.
|
|
69
|
+
|
|
60
70
|
## 4. Live reload
|
|
61
71
|
|
|
62
72
|
```sh
|
|
@@ -72,7 +82,7 @@ With `--live` the app opens the running `protobase dev` instead of its own files
|
|
|
72
82
|
protobase mobile open ios
|
|
73
83
|
```
|
|
74
84
|
|
|
75
|
-
opens the generated project in Xcode, or Android Studio for `android`. To run on an iPhone, pick a signing team in
|
|
85
|
+
opens the generated project in Xcode, or Android Studio for `android`. To run it from Xcode on an iPhone, pick a signing team in Signing & Capabilities, or use `protobase mobile run ios --team`.
|
|
76
86
|
|
|
77
87
|
## 6. Build a release
|
|
78
88
|
|
|
@@ -537,7 +537,7 @@ Remove `supabase-import/` to import again.
|
|
|
537
537
|
## `mobile`
|
|
538
538
|
|
|
539
539
|
```sh
|
|
540
|
-
protobase mobile run <ios|android> [--api <url>] [--target <id>] [--live] [--port 5173] [--extend <dir>]
|
|
540
|
+
protobase mobile run <ios|android> [--api <url>] [--target <id>] [--team <id>] [--live] [--port 5173] [--extend <dir>]
|
|
541
541
|
protobase mobile open <ios|android> [--api <url>] [--extend <dir>]
|
|
542
542
|
protobase mobile build <ios|android> --app-version <x.y.z> --build-number <n> [--api <url>] [--out mobile-release] [--extend <dir>]
|
|
543
543
|
[--team <id> [--certificate <name> --profile <name>]]
|
|
@@ -547,7 +547,7 @@ Builds the project in the current directory as an iOS or Android app with Capaci
|
|
|
547
547
|
|
|
548
548
|
- It installs `@protobase/mobile`, of the CLI's version, which pins Capacitor and its plugins, with the section's `plugins` into `.protobase/mobile/` with npm, when that changed. It builds the app's files as [`build`](#build) does and keeps only `public/`, its `index.html` naming the API origin; writes `capacitor.config.json`, compiling in only the section's plugins; and generates the platform's native project again, replacing the last one.
|
|
549
549
|
- `--api` is the server the app calls, the project's auth `baseURL` by default: an http or https origin, plain http only to `localhost`, `127.0.0.1` and, on iOS, `[::1]`, or on Android `10.0.2.2`. An Android app calling `localhost` gets the port forwarded.
|
|
550
|
-
- `run` runs the app on `--target`, or asks for one. With `--live` it opens `protobase dev` on `localhost:--port` instead of its own files. `open` opens the native project in Xcode or Android Studio.
|
|
550
|
+
- `run` runs the app on `--target`, or asks for one. On iOS, `--team` writes the Apple team id into the generated project and builds it once with xcodebuild allowed to create the development profile and register the device, `--target` or the one connected device, before Capacitor runs it there. With `--live` it opens `protobase dev` on `localhost:--port` instead of its own files. `open` opens the native project in Xcode or Android Studio.
|
|
551
551
|
- `build` makes a signed release, an `.aab` (Android) or `.ipa` (iOS), and copies it to `--out`, which ignores itself in git when the command creates it, as `<appId>-<version>-<build number>`. Android signs through Gradle with the keystore, alias and passwords in `PROTOBASE_ANDROID_KEYSTORE`, `PROTOBASE_ANDROID_KEY_ALIAS`, `PROTOBASE_ANDROID_KEYSTORE_PASSWORD` and `PROTOBASE_ANDROID_KEY_PASSWORD`; iOS runs Capacitor's build with `--team`, and `--certificate` with `--profile` for manual signing.
|
|
552
552
|
- A release calls an https server that is not this machine, and `--app-version` (one to three numbers) and `--build-number` (1 to 2100000000) are required.
|
|
553
553
|
- npm and Capacitor get the CLI's environment without any variable named in the current directory's `.env*` files, nor the four `PROTOBASE_ANDROID_*` signing variables, which only Gradle gets, and with `CI=true`, which keeps Capacitor's telemetry off.
|