@elumixor/devkit 0.8.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,17 @@
1
1
  # @elumixor/devkit
2
2
 
3
- Dev orchestrator for bun monorepos. One config, and `bun run dev` frees the ports, runs every app side-by-side with colored prefixes, prints the local URLs, and (with `--open`) opens the browser once the server is live.
3
+ Dev orchestrator for bun monorepos. One config lists the platforms a product ships on — a web app, a
4
+ Mac shell, an iPhone app, a watch app — and three commands do the three things anyone ever does with
5
+ them:
6
+
7
+ ```bash
8
+ devkit dev # run every platform side by side
9
+ devkit build # build every platform, in parallel
10
+ devkit deploy # ship every platform, in dependency order
11
+ ```
12
+
13
+ Every one of them takes a platform: `devkit dev:iphone`, `devkit build:mac`, `devkit deploy:web`.
14
+ So does a positional, for a shell that completes them: `devkit build mac iwatch`.
4
15
 
5
16
  ## Install
6
17
 
@@ -10,76 +21,206 @@ bun add -d @elumixor/devkit
10
21
 
11
22
  ## Configure
12
23
 
13
- Add a `devkit` block to your root `package.json`:
24
+ Add a `devkit` block to your root `package.json`. Three phases, each a map of platform name to one
25
+ step, and a platform means the same thing in all three:
14
26
 
15
27
  ```jsonc
16
28
  {
17
29
  "scripts": {
18
- "dev": "devkit",
19
- "dev:open": "devkit --open"
30
+ "dev": "devkit dev",
31
+ "build": "devkit build",
32
+ "deploy": "devkit deploy"
20
33
  },
21
34
  "devkit": {
22
- "apps": {
23
- "backend": { "port": 10000 },
24
- "frontend": { "port": 3000, "open": true }
35
+ "generate": { "command": "bunx nitro-client", "cwd": "apps/backend" },
36
+ "dev": {
37
+ "web": {
38
+ "processes": {
39
+ "backend": { "filter": "@app/backend", "port": 3100 },
40
+ "frontend": { "port": 8081, "open": true }
41
+ }
42
+ },
43
+ "mac": { "command": "bunx tauri dev", "cwd": "apps/frontend", "needs": ["web"] }
44
+ },
45
+ "build": {
46
+ "web": { "type": "web", "options": { "apiPrefixes": ["api"] } },
47
+ "mac": { "type": "tauri-macos" }
48
+ },
49
+ "deploy": {
50
+ "mac": { "type": "tauri-macos" },
51
+ "web": { "type": "vercel", "needs": ["mac"] }
25
52
  }
26
53
  }
27
54
  }
28
55
  ```
29
56
 
30
- Each app is keyed by its name, and runs `bun --filter <name> dev` by default. Override with:
57
+ `needs` is what makes one command enough. Naming a platform also runs the platforms it depends on —
58
+ `devkit dev:mac` starts the web stack the Mac window points at, `devkit deploy:web` builds the
59
+ installer the site hands out first. Steps with no `needs` all start at once.
60
+
61
+ `generate` runs once before a build or a deploy graph, ahead of everything running in parallel. It
62
+ is for sources every platform's compile reads — a typed API client generated from the routes — which
63
+ must not be written by one build while another is reading them. It sets `SKIP_CLIENT_GEN=1` for the
64
+ steps it runs before.
65
+
66
+ ## Dev
67
+
68
+ `devkit dev` frees the ports, prints the local URLs, runs everything side by side with coloured
69
+ prefixes, and (with `--open`) opens the browser once the server is live. A platform is either one
70
+ process or a `processes` map — a web platform is a client and an API, and neither is worth naming as
71
+ a platform of its own.
72
+
73
+ | field | meaning |
74
+ | ----------- | ----------------------------------------------------------------------------- |
75
+ | `processes` | several processes under this platform, keyed by name |
76
+ | `filter` | explicit `bun --filter <target>` (defaults to the process key) |
77
+ | `cwd` | run `bun run --cwd <cwd> <script>` instead of `--filter` |
78
+ | `script` | script to run in the workspace (default `dev`) |
79
+ | `command` | raw shell command, overrides the above (e.g. `vite dev`) |
80
+ | `type` | a built-in dev target — see below |
81
+ | `port` | freed on start and shown in the URL banner |
82
+ | `needs` | platforms that must be running too |
83
+ | `color` | prefix colour; one is picked for you otherwise |
84
+ | `open` | with `--open`, open this process's URL when its port comes up |
85
+
86
+ ### Built-in dev targets
87
+
88
+ **`capacitor-ios`** runs the iPhone app on a simulator against the running dev server. The webview
89
+ loads the page over the network rather than from the bundle, so every web edit is live the moment
90
+ Vite has it. Native edits still need a compile — that is what `watch` is for.
31
91
 
32
- | field | meaning |
33
- | --------- | ----------------------------------------------------------------- |
34
- | `filter` | explicit `bun --filter <target>` (defaults to the name) |
35
- | `cwd` | run `bun --cwd <cwd> run <script>` instead of `--filter` |
36
- | `script` | script to run in the workspace (default `dev`) |
37
- | `command` | raw shell command, overrides the above (e.g. `vite dev`) |
38
- | `port` | freed on start and shown in the URL banner |
39
- | `color` | prefix color (blue, magenta, green, yellow, cyan, red); one is picked for you otherwise |
40
- | `open` | with `--open`, open this app's URL when its port comes up |
41
-
42
- ## Deploy
92
+ ```jsonc
93
+ "iphone": {
94
+ "type": "capacitor-ios",
95
+ "needs": ["web"],
96
+ "options": {
97
+ "project": "apps/frontend/ios/App/App.xcodeproj",
98
+ "scheme": "App",
99
+ "bundleId": "com.example.app",
100
+ "device": "iPhone 17 Pro",
101
+ "port": 8081,
102
+ "watch": ["apps/frontend/ios/App/App"]
103
+ }
104
+ }
105
+ ```
43
106
 
44
- `devkit deploy` runs the release steps of a repo the same way `devkit` runs its dev processes:
45
- side by side, with one line each.
107
+ **`xcode-sim`** builds any Apple scheme and launches it on a simulator without opening Xcode. A
108
+ watch app has no sign-in of its own, so `previewEnv` is what lets it run on a simulator with no
109
+ paired phone; `--real` leaves it unset and talks to the real API.
46
110
 
47
111
  ```jsonc
48
- {
49
- "scripts": { "deploy": "devkit deploy" },
50
- "devkit": {
51
- "deploy": {
52
- "desktop": { "command": "bun scripts/deploy-desktop.ts" },
53
- "vercel": { "command": "bun scripts/deploy-vercel.ts", "needs": ["desktop"] },
54
- "ios": { "command": "bun scripts/deploy-ios.ts" }
55
- }
112
+ "iwatch": {
113
+ "type": "xcode-sim",
114
+ "options": {
115
+ "project": "apps/frontend/ios/App/App.xcodeproj",
116
+ "scheme": "BalanceWatch",
117
+ "sdk": "watchsimulator",
118
+ "bundleId": "com.example.app.watchkitapp",
119
+ "device": "Apple Watch Series 11 (46mm)",
120
+ "previewEnv": "APP_WATCH_PREVIEW",
121
+ "watch": ["apps/frontend/ios/App/WatchApp"]
56
122
  }
57
123
  }
58
124
  ```
59
125
 
126
+ `--device`, or `DEVKIT_SIM_DEVICE`, overrides the configured simulator — everyone's list of
127
+ installed ones differs. Saving a watched source rebuilds and relaunches; Swift has no hot reload, so
128
+ this is what "live" means on the native side.
129
+
130
+ ## Build and deploy
131
+
132
+ Both draw the same board: one line per platform, with a spinner, how long it has been running and
133
+ the last line it printed. The full output goes to `.devkit/<phase>/<platform>.log`, and the tail of
134
+ whichever platform failed is printed at the end — a release prints tens of thousands of lines, and
135
+ interleaving all of them is unreadable. Piped output (CI, a log file) gets prefixed streaming lines
136
+ instead.
137
+
60
138
  ```bash
61
- bun run deploy # every target
62
- bun run deploy ios # one target, plus whatever it needs
139
+ devkit build # every platform
140
+ devkit build:iphone # one platform, plus whatever it needs
63
141
  devkit deploy --dry # print the plan
64
142
  devkit deploy --verbose # stream every line instead of the live board
65
143
  ```
66
144
 
67
- Targets with no `needs` start together; one with `needs` waits for those, so a build that another
68
- target packages up can run first without serialising the whole release.
145
+ | field | meaning |
146
+ | --------- | ------------------------------------------------------------- |
147
+ | `command` | shell command that performs this step |
148
+ | `type` | a built-in target instead, configured by `options` |
149
+ | `needs` | platforms that must finish first |
150
+ | `color` | colour of this platform's line; one is picked for you otherwise |
151
+
152
+ Each native shell carries its own copy of the web app, built with its own API base URL, and
153
+ `devkit build` runs those builds beside each other — so each is given its own `BUILD_DIR`,
154
+ `KIT_DIR` and `VITE_CACHE_DIR` rather than overwriting the others' files halfway through.
155
+
156
+ ### Built-in build targets
69
157
 
70
- Each target shows a spinner, how long it has been running and the last line it printed. The full
71
- output goes to `.devkit/deploy/<name>.log`, and the tail of whichever target failed is printed at
72
- the end — a release prints tens of thousands of lines, and interleaving all of them is unreadable.
73
- Piped output (CI, a log file) gets prefixed streaming lines instead of the board.
158
+ **`web`** packs a client-rendered web app and a Nitro API into one Vercel deployment: the app as
159
+ static files, the API as the one serverless function behind them. Same origin, so the web client
160
+ calls the API without CORS.
74
161
 
75
- Each target is keyed by its name — that is what the board shows, what `needs` points at, and what
76
- you type on the command line.
162
+ | option | meaning |
163
+ | ------------- | ------------------------------------------------------------------------------ |
164
+ | `frontendDir` | web app dir, run with `bun run build` (default `apps/frontend`) |
165
+ | `backendDir` | Nitro dir (default `apps/backend`) |
166
+ | `webBuildDir` | where the web build lands inside `frontendDir` (default `build`) |
167
+ | `apiPrefixes` | paths the API owns; every other path answers with the app shell |
168
+ | `include` | staged dirs to serve alongside the web files, as `{ "<source>": "<url path>" }` |
77
169
 
78
- | field | meaning |
79
- | --------- | -------------------------------------------------- |
80
- | `command` | shell command that performs this deploy |
81
- | `needs` | targets that must finish first |
82
- | `color` | colour of this target's line; one is picked for you otherwise |
170
+ **`tauri-macos`** builds the macOS app and nothing else — no Developer ID, no notarization, no
171
+ install. It answers "does the Mac shell still compile against this frontend"; shipping is the deploy
172
+ target of the same name. Options: `frontendDir`, `bundles` (default `app`), `webSuffix`.
173
+
174
+ **`capacitor-ios`** builds the web bundle, syncs it into the Xcode project and compiles the iOS app
175
+ for a simulator — the whole chain a TestFlight release goes through, minus the signing and the
176
+ upload. Options: `frontendDir`, `iosDir`, `webSuffix`, plus `project`, `scheme`, `configuration`,
177
+ `sdk`, `derivedDataDir`.
178
+
179
+ **`xcode`** compiles one scheme for a simulator: a watch app, a widget, anything native that carries
180
+ no web bundle of its own. Options: `project`, `scheme`, `configuration`, `sdk`, `derivedDataDir`.
181
+
182
+ Simulator builds are compiled with signing off, so a machine that has never seen the team's
183
+ provisioning profiles can still tell you whether the app compiles.
184
+
185
+ ### Built-in deploy targets
186
+
187
+ **`vercel`** builds here and uploads the finished output, rather than handing Vercel the repo and
188
+ waiting for it to build the same thing again. Options: `cwd`.
189
+
190
+ **`tauri-macos`** builds, signs and notarizes the macOS app if this machine has a Developer ID
191
+ certificate, stages the DMG and a manifest for the web deploy to hand out, and refreshes the local
192
+ install if there is one. Options: `frontendDir`, `stageDir`, `installIfPresent`, and the App Store
193
+ Connect key env var names.
194
+
195
+ **`fastlane-ios`** builds the web bundle against the deployed API, syncs it into the Xcode project
196
+ and hands the archive to fastlane, which signs the app, the watch app and the widget and uploads to
197
+ TestFlight. Options: `frontendDir`, `iosDir`, `lane`, `defaultApiBaseUrl`, `apiBaseUrlEnv`, and the
198
+ key env var names.
199
+
200
+ ## Versions
201
+
202
+ `devkit version` reads one version and writes it into every other file that declares one, so the
203
+ App Store, the installer and the number at the bottom of settings can't drift apart.
204
+
205
+ ```jsonc
206
+ "devkit": {
207
+ "version": {
208
+ "source": "apps/frontend/src-tauri/tauri.conf.json",
209
+ "packages": ["package.json", "apps/frontend/package.json"],
210
+ "cargo": ["apps/frontend/src-tauri/Cargo.toml"],
211
+ "xcodeProjects": ["apps/frontend/ios/App/App.xcodeproj/project.pbxproj"],
212
+ "marketingVersionPlists": ["apps/frontend/ios/App/App/Info.plist"],
213
+ "plists": ["apps/frontend/ios/App/WatchApp/Info.plist"]
214
+ }
215
+ }
216
+ ```
217
+
218
+ Targets in an Xcode project read `$(MARKETING_VERSION)` from the project, so their plists are
219
+ pointed at it rather than at a number — `plists` is for targets wired in by a script, which have no
220
+ such setting and carry the number themselves.
221
+
222
+ `devkit release <prefix>` tags the current commit `<prefix>-v<timestamp>` and pushes the tag, which
223
+ is how a CI release is asked for.
83
224
 
84
225
  ## Setting up a machine
85
226
 
@@ -98,7 +239,6 @@ Declare what to sync and what to run:
98
239
 
99
240
  ```jsonc
100
241
  "devkit": {
101
- "apps": { /* ... */ },
102
242
  "setup": {
103
243
  "secrets": [".env", "infra/terraform.tfvars"],
104
244
  "env": [{ "file": ".env", "example": ".env.example" }],
@@ -134,8 +274,15 @@ Changed a `.env`? Run `devkit secrets push`, or the next machine gets a stale co
134
274
 
135
275
  ## Bins
136
276
 
137
- - `devkit [root] [--open] [--dry] [--version]` — the orchestrator above. `root` is an optional path to the folder holding the `devkit` config (defaults to the current directory); `--dry` prints the resolved commands and URLs without running anything.
277
+ - `devkit dev [platforms...] [--open] [--dry]` — run the dev processes. `devkit` on its own does the same.
278
+ - `devkit build [platforms...] [--dry] [--verbose]` — build the platforms, in parallel.
279
+ - `devkit deploy [platforms...] [--dry] [--verbose]` — ship the platforms, in dependency order.
138
280
  - `devkit clone <owner/repo> [dir]` — clone, decrypt secrets, run setup.
139
281
  - `devkit setup [root] [--dry]` — validate secrets, install, `terraform init`, run steps.
282
+ - `devkit version` — write the source version into every file that declares one.
283
+ - `devkit release <prefix>` — tag this commit `<prefix>-v<timestamp>` and push it.
140
284
  - `devkit secrets push|pull [root]` — sync the encrypted secrets.
141
285
  - `free-port <port>` — kill whatever is listening on a port (handy in a `predev`).
286
+
287
+ Any of `dev`, `build` and `deploy` also take a platform as a suffix — `devkit build:mac` — which is
288
+ what reads best in a `package.json` script.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elumixor/devkit",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Dev orchestrator for bun monorepos — free ports, run apps side-by-side, open the browser when ready",
5
5
  "author": "elumixor",
6
6
  "license": "ISC",
@@ -20,6 +20,7 @@
20
20
  "build": "tsc --noEmit",
21
21
  "typecheck": "tsc --noEmit",
22
22
  "lint": "biome lint src",
23
+ "release": "npm version patch -m \"Release v%s\" && git push --follow-tags",
23
24
  "release:patch": "npm version patch -m \"Release v%s\" && git push --follow-tags",
24
25
  "release:minor": "npm version minor -m \"Release v%s\" && git push --follow-tags",
25
26
  "release:major": "npm version major -m \"Release v%s\" && git push --follow-tags"
package/src/apple.ts ADDED
@@ -0,0 +1,118 @@
1
+ import { watch } from "node:fs";
2
+ import { existsSync } from "node:fs";
3
+ import { join, resolve } from "node:path";
4
+ import { $ } from "bun";
5
+
6
+ /** What every Apple target here needs to name a build: which project, which scheme, where to. */
7
+ export interface XcodeBuild {
8
+ /** Path to the `.xcodeproj`, relative to the root. */
9
+ project: string;
10
+ /** Scheme to build; also the name of the built `.app`. */
11
+ scheme: string;
12
+ /** `Debug` or `Release` (default `Debug`). */
13
+ configuration?: string;
14
+ /** Simulator SDK to build against (default `iphonesimulator`). */
15
+ sdk?: string;
16
+ /** Derived data dir, relative to the root (default `build/<scheme>`). */
17
+ derivedDataDir?: string;
18
+ }
19
+
20
+ /** Where a built product lands, given the same options the build was given. */
21
+ export function productPath(options: XcodeBuild, root = process.cwd()) {
22
+ const configuration = options.configuration ?? "Debug";
23
+ const sdk = options.sdk ?? "iphonesimulator";
24
+ const derived = resolve(root, options.derivedDataDir ?? `build/${options.scheme}`);
25
+ return join(derived, "Build/Products", `${configuration}-${sdk}`, `${options.scheme}.app`);
26
+ }
27
+
28
+ /**
29
+ * Compiles a scheme for a simulator.
30
+ *
31
+ * Signing is off: a simulator runs unsigned code, and asking for a certificate would make a build
32
+ * that only tells you whether the app compiles fail on a machine that has never seen the team's
33
+ * provisioning profiles.
34
+ */
35
+ export async function xcodeBuild(options: XcodeBuild & { destination?: string }) {
36
+ const root = process.cwd();
37
+ const project = resolve(root, options.project);
38
+ if (!existsSync(project)) throw new Error(`No Xcode project at ${project}`);
39
+ const configuration = options.configuration ?? "Debug";
40
+ const sdk = options.sdk ?? "iphonesimulator";
41
+ const derived = resolve(root, options.derivedDataDir ?? `build/${options.scheme}`);
42
+ const destination = options.destination ?? `generic/platform=${sdk === "watchsimulator" ? "watchOS" : "iOS"} Simulator`;
43
+
44
+ await $`xcodebuild -project ${project} -scheme ${options.scheme} -configuration ${configuration} \
45
+ -sdk ${sdk} -destination ${destination} -derivedDataPath ${derived} \
46
+ CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO build`;
47
+ }
48
+
49
+ /** Boots the named simulator if it isn't already up, and returns its device id. */
50
+ export async function bootSimulator(deviceName: string) {
51
+ const { devices } = await $`xcrun simctl list devices available -j`.quiet().json();
52
+ // The same model exists once per installed runtime; the newest one is the one to use.
53
+ const runtimes = Object.keys(devices).sort().reverse();
54
+ const match = runtimes
55
+ .flatMap((runtime) => devices[runtime] as { name: string; udid: string; state: string }[])
56
+ .find((device) => device.name === deviceName);
57
+
58
+ if (!match) throw new Error(`No simulator called "${deviceName}" — see \`xcrun simctl list devices available\``);
59
+ if (match.state !== "Booted") await $`xcrun simctl boot ${match.udid}`;
60
+ await $`open -a Simulator`;
61
+ return match.udid;
62
+ }
63
+
64
+ /** Replaces whatever copy of the app is on the simulator with this one, and starts it. */
65
+ export async function installAndLaunch(udid: string, appPath: string, bundleId: string, env: Record<string, string> = {}) {
66
+ if (!existsSync(appPath)) throw new Error(`No app bundle at ${appPath}`);
67
+ await $`xcrun simctl terminate ${udid} ${bundleId}`.nothrow().quiet();
68
+ await $`xcrun simctl install ${udid} ${appPath}`;
69
+ // `SIMCTL_CHILD_` is how simctl passes an environment on to the app it launches.
70
+ const child = Object.fromEntries(Object.entries(env).map(([key, value]) => [`SIMCTL_CHILD_${key}`, value]));
71
+ await $`xcrun simctl launch ${udid} ${bundleId}`.env({ ...process.env, ...child });
72
+ }
73
+
74
+ /**
75
+ * Rebuilds and relaunches whenever native sources change, and never returns.
76
+ *
77
+ * Swift has no hot reload, so this is what "live" means on the native side: the edit-to-app loop
78
+ * is one save long instead of a trip through Xcode. The web half of a Capacitor app doesn't come
79
+ * through here at all — Vite already replaced it in the running webview.
80
+ */
81
+ export async function rerunOnChange(dirs: string[], run: () => Promise<void>) {
82
+ let running = false;
83
+ let again = false;
84
+
85
+ const cycle = async () => {
86
+ if (running) {
87
+ again = true;
88
+ return;
89
+ }
90
+ running = true;
91
+ try {
92
+ await run();
93
+ } catch (error) {
94
+ console.error(error instanceof Error ? error.message : error);
95
+ }
96
+ running = false;
97
+ if (again) {
98
+ again = false;
99
+ void cycle();
100
+ }
101
+ };
102
+
103
+ let pending: ReturnType<typeof setTimeout> | undefined;
104
+ for (const dir of dirs) {
105
+ const path = resolve(process.cwd(), dir);
106
+ if (!existsSync(path)) continue;
107
+ watch(path, { recursive: true }, (_event, file) => {
108
+ // Xcode and SPM write into these trees constantly; only sources are worth a rebuild.
109
+ if (file && !/\.(swift|m|h|plist|entitlements|xcconfig|storyboard|xib)$/.test(file)) return;
110
+ clearTimeout(pending);
111
+ pending = setTimeout(() => void cycle(), 300);
112
+ });
113
+ }
114
+
115
+ if (dirs.length) console.log(`Watching ${dirs.join(", ")} — saving a source file rebuilds and relaunches`);
116
+ // A dev process that ends kills the ones running beside it, so this one stays up until Ctrl-C.
117
+ await new Promise<never>(() => {});
118
+ }
package/src/bin/devkit.ts CHANGED
@@ -1,20 +1,23 @@
1
1
  #!/usr/bin/env bun
2
- import { parseArgs } from "node:util";
3
2
  import { resolve } from "node:path";
4
- import { loadConfig } from "../config.ts";
3
+ import { parseArgs } from "node:util";
4
+ import pkg from "../../package.json" with { type: "json" };
5
+ import { runBuild } from "../build.ts";
6
+ import { runClone } from "../clone.ts";
7
+ import { PHASES, type Phase } from "../config.ts";
5
8
  import { runDeploy } from "../deploy.ts";
6
- import { deployFastlaneIos } from "../deploy-targets/fastlane-ios.ts";
7
- import { deployTauriMacos } from "../deploy-targets/tauri-macos.ts";
8
- import { deployVercel } from "../deploy-targets/vercel.ts";
9
9
  import { runDev } from "../dev.ts";
10
- import { runSetup } from "../setup.ts";
11
- import { runClone } from "../clone.ts";
10
+ import { runRelease } from "../release.ts";
11
+ import { runTarget } from "../run-target.ts";
12
12
  import { pullSecrets, pushSecrets } from "../secrets.ts";
13
- import pkg from "../../package.json" with { type: "json" };
13
+ import { runSetup } from "../setup.ts";
14
+ import { runVersion } from "../version.ts";
14
15
 
15
16
  const { values, positionals } = parseArgs({
16
17
  options: {
17
18
  open: { type: "boolean", default: false },
19
+ real: { type: "boolean", default: false },
20
+ device: { type: "string" },
18
21
  dry: { type: "boolean", default: false },
19
22
  verbose: { type: "boolean", default: false },
20
23
  version: { type: "boolean", short: "v", default: false },
@@ -28,16 +31,26 @@ if (values.version) {
28
31
  process.exit(0);
29
32
  }
30
33
 
31
- const usage = `usage: devkit [root] [--open] [--dry] run the dev processes (default)
32
- devkit clone <owner/repo> [dir] clone, decrypt secrets, set up
34
+ const usage = `usage: devkit dev [platforms...] run the dev processes (default)
35
+ devkit dev:<platform> run one platform, and whatever it needs
36
+ devkit build [platforms...] build every platform, in parallel
37
+ devkit build:<platform> build one platform
38
+ devkit deploy [platforms...] deploy every platform, in dependency order
39
+ devkit deploy:<platform> deploy one platform
33
40
  devkit setup [root] [--dry] validate secrets, install, terraform init, run steps
34
- devkit deploy [targets...] run the configured deploys, in parallel
41
+ devkit clone <owner/repo> [dir] clone, decrypt secrets, set up
42
+ devkit version write the source version into every file that declares one
43
+ devkit release <prefix> tag this commit <prefix>-v<timestamp> and push it
35
44
  devkit secrets push|pull [root] sync age-encrypted secrets
36
45
 
37
- root path to the folder holding the devkit config (default: cwd)
38
- --open open each app's URL in the browser once its port is live
46
+ Platforms are whatever "devkit.dev", "devkit.build" and "devkit.deploy" name in package.json —
47
+ typically web, mac, iphone, iwatch. Naming one also runs the platforms it declares in "needs".
48
+
49
+ --open open each dev process's URL in the browser once its port is live
39
50
  --dry print what would run without running it
40
- --verbose stream every line instead of drawing the live board (deploy)
51
+ --verbose stream every line instead of drawing the live board (build, deploy)
52
+ --real run a simulator against the real API instead of sample data
53
+ --device simulator to run on, overriding the configured one
41
54
  --version print the devkit version`;
42
55
 
43
56
  if (values.help) {
@@ -45,7 +58,15 @@ if (values.help) {
45
58
  process.exit(0);
46
59
  }
47
60
 
48
- const [command, ...rest] = positionals;
61
+ const [head, ...rest] = positionals;
62
+ // `devkit build:mac` and `devkit build mac` are the same thing — a colon is what a package.json
63
+ // script reads best, a positional is what a shell completes best.
64
+ const [command, suffix] = (head ?? "dev").split(":");
65
+ const platforms = [...(suffix ? [suffix] : []), ...(isPhase(command) ? rest : [])];
66
+
67
+ function isPhase(name: string | undefined): name is Phase {
68
+ return PHASES.includes(name as Phase);
69
+ }
49
70
 
50
71
  function chdirTo(dir?: string) {
51
72
  if (dir) process.chdir(resolve(dir));
@@ -53,6 +74,26 @@ function chdirTo(dir?: string) {
53
74
 
54
75
  try {
55
76
  switch (command) {
77
+ case "dev": {
78
+ await runDev(platforms, { open: values.open, dry: values.dry });
79
+ break;
80
+ }
81
+ case "build": {
82
+ await runBuild(platforms, { dry: values.dry, verbose: values.verbose });
83
+ break;
84
+ }
85
+ case "deploy": {
86
+ await runDeploy(platforms, { dry: values.dry, verbose: values.verbose });
87
+ break;
88
+ }
89
+ // Internal: how a `type`d step actually runs — spawned as its own process by the graph (or by
90
+ // `concurrently`, for dev) so it gets that step's own line on the board and its own log file.
91
+ case "_run": {
92
+ const [phase, name] = rest;
93
+ if (!isPhase(phase) || !name) throw new Error("usage: devkit _run <phase> <platform>");
94
+ await runTarget(phase, name, { real: values.real, device: values.device });
95
+ break;
96
+ }
56
97
  case "clone": {
57
98
  const [repo, dir] = rest;
58
99
  if (!repo) throw new Error("usage: devkit clone <owner/repo> [dir]");
@@ -64,21 +105,12 @@ try {
64
105
  await runSetup(values.dry);
65
106
  break;
66
107
  }
67
- case "deploy": {
68
- await runDeploy(rest, { dry: values.dry, verbose: values.verbose });
108
+ case "version": {
109
+ await runVersion();
69
110
  break;
70
111
  }
71
- // Internal: how a built-in `type`d deploy target actually runs — spawned as its own process
72
- // by `runDeploy` so it gets the same line-capture and log file as a hand-written `command`.
73
- case "_deploy-target": {
74
- const [name] = rest;
75
- const { deploy } = loadConfig();
76
- const target = deploy.find((t) => t.name === name);
77
- if (!target?.type) throw new Error(`No deploy target ${name} with a "type"`);
78
- if (target.type === "vercel") await deployVercel(target.options);
79
- else if (target.type === "tauri-macos") await deployTauriMacos(target.options);
80
- else if (target.type === "fastlane-ios") await deployFastlaneIos(target.options);
81
- else throw new Error(`Unknown deploy target type: ${target.type}`);
112
+ case "release": {
113
+ await runRelease(rest[0] ?? "");
82
114
  break;
83
115
  }
84
116
  case "secrets": {
@@ -89,11 +121,8 @@ try {
89
121
  else throw new Error("usage: devkit secrets push|pull [root]");
90
122
  break;
91
123
  }
92
- default: {
93
- // No subcommand — the original `devkit [root]` behaviour.
94
- chdirTo(command);
95
- await runDev(values.open, values.dry);
96
- }
124
+ default:
125
+ throw new Error(`Unknown command "${head}"\n\n${usage}`);
97
126
  }
98
127
  } catch (error) {
99
128
  console.error(error instanceof Error ? error.message : error);
@@ -0,0 +1,34 @@
1
+ import { existsSync } from "node:fs";
2
+ import { join } from "node:path";
3
+ import { $ } from "bun";
4
+ import { type XcodeBuild, xcodeBuild } from "../apple.ts";
5
+ import { isolatedWebEnv } from "../web-build.ts";
6
+
7
+ export interface CapacitorIosBuildOptions extends XcodeBuild {
8
+ /** Capacitor dir, holding `capacitor.config.ts` and `ios/` (default `apps/frontend`). */
9
+ frontendDir?: string;
10
+ /** iOS project dir (default `<frontendDir>/ios`). */
11
+ iosDir?: string;
12
+ /** Suffix for this build's own web output, kit and cache dirs (default `ios`). */
13
+ webSuffix?: string;
14
+ }
15
+
16
+ /**
17
+ * Builds the web bundle, syncs it into the Xcode project and compiles the iOS app for a
18
+ * simulator — the whole chain a TestFlight release goes through, minus the signing and the upload.
19
+ */
20
+ export async function buildCapacitorIos(options: CapacitorIosBuildOptions) {
21
+ const frontendDir = options.frontendDir ?? "apps/frontend";
22
+ const iosDir = options.iosDir ?? join(frontendDir, "ios");
23
+ const env = { ...process.env, ...isolatedWebEnv(options.webSuffix ?? "ios") };
24
+
25
+ await $`bun run build`.cwd(frontendDir).env(env);
26
+ await $`bunx cap sync ios`.cwd(frontendDir).env(env);
27
+
28
+ // `cap sync` reports a failed copy and still exits 0, which would compile whatever web assets
29
+ // the project happened to be carrying from a previous build.
30
+ const bundled = join(iosDir, "App/App/public/index.html");
31
+ if (!existsSync(bundled)) throw new Error(`cap sync didn't copy the web build — no ${bundled}`);
32
+
33
+ await xcodeBuild(options);
34
+ }
@@ -0,0 +1,36 @@
1
+ import { $ } from "bun";
2
+ import { isolatedWebEnv } from "../web-build.ts";
3
+
4
+ export interface TauriMacosBuildOptions {
5
+ /** Tauri project dir, holding `src-tauri` (default `apps/frontend`). */
6
+ frontendDir?: string;
7
+ /** Bundles to produce (default `app` — the `.app`, which is what a check needs). */
8
+ bundles?: string;
9
+ /** Suffix for this build's own web output, kit and cache dirs (default `mac`). */
10
+ webSuffix?: string;
11
+ }
12
+
13
+ /**
14
+ * Builds the macOS app, and nothing else: no Developer ID, no notarization, no install.
15
+ *
16
+ * This is the build that answers "does the Mac shell still compile against this frontend" while
17
+ * the other platforms are answering the same question for themselves. Signing and shipping belong
18
+ * to the `tauri-macos` *deploy* target, which does its own release build.
19
+ */
20
+ export async function buildTauriMacos(options: TauriMacosBuildOptions = {}) {
21
+ const frontendDir = options.frontendDir ?? "apps/frontend";
22
+ const bundles = options.bundles ?? "app";
23
+ const suffix = options.webSuffix ?? "mac";
24
+ const env = isolatedWebEnv(suffix);
25
+
26
+ // Tauri reads `frontendDist` from its own config file, which has no environment override — so
27
+ // the directory the isolated web build writes into is pointed at through a config overlay.
28
+ const overlay = JSON.stringify({ build: { frontendDist: `../${env.BUILD_DIR}` } });
29
+
30
+ await $`bunx tauri build --bundles ${bundles} --config ${overlay}`.cwd(frontendDir).env({
31
+ ...process.env,
32
+ ...env,
33
+ // macOS refuses an unsigned bundle outright; ad-hoc is enough for a build nobody downloads.
34
+ APPLE_SIGNING_IDENTITY: "-",
35
+ });
36
+ }