@elumixor/devkit 0.9.0 → 0.10.1

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,103 +21,181 @@ 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:
31
-
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 |
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.
41
91
 
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 |
69
151
 
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.
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.
74
155
 
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.
156
+ ### Built-in build targets
77
157
 
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 |
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.
83
161
 
84
- ## Build
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>" }` |
85
169
 
86
- `devkit build` packs a client-rendered web app and a Nitro API into one Vercel deployment: the app
87
- as static files, the API as the one serverless function behind them. Same origin, so the web client
88
- calls the API without CORS.
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`.
89
173
 
90
- ```jsonc
91
- "devkit": {
92
- "build": {
93
- "frontendDir": "apps/frontend",
94
- "backendDir": "apps/backend",
95
- "apiPrefixes": ["mobile", "health"],
96
- "clientCommand": "bunx nitro-client",
97
- "include": { "dist/download": "download" }
98
- }
99
- }
100
- ```
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.
101
184
 
102
- | key | meaning |
103
- | --------------- | ------------------------------------------------------------------------------ |
104
- | `frontendDir` | web app dir, run with `bun run build` (default `apps/frontend`) |
105
- | `backendDir` | Nitro dir (default `apps/backend`) |
106
- | `webBuildDir` | where the web build lands inside `frontendDir` (default `build`) |
107
- | `apiPrefixes` | paths the API owns; every other path answers with the app shell |
108
- | `clientCommand` | run in `backendDir` first, unless `SKIP_CLIENT_GEN` is set |
109
- | `include` | staged dirs to serve alongside the web files, as `{ "<source>": "<url path>" }` |
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.
110
199
 
111
200
  ## Versions
112
201
 
@@ -133,28 +222,6 @@ such setting and carry the number themselves.
133
222
  `devkit release <prefix>` tags the current commit `<prefix>-v<timestamp>` and pushes the tag, which
134
223
  is how a CI release is asked for.
135
224
 
136
- ## Simulator
137
-
138
- `devkit sim` builds an Apple target and launches it on a simulator without opening Xcode. A watch
139
- app has no sign-in of its own, so `previewEnv` is what lets it run on a simulator with no paired
140
- phone; `--real` leaves it unset and talks to the real API.
141
-
142
- ```jsonc
143
- "devkit": {
144
- "sim": {
145
- "project": "apps/frontend/ios/App/App.xcodeproj",
146
- "scheme": "BalanceWatch",
147
- "bundleId": "com.example.app.watchkitapp",
148
- "device": "Apple Watch Series 11 (46mm)",
149
- "previewEnv": "BALANCE_WATCH_PREVIEW"
150
- }
151
- }
152
- ```
153
-
154
- `--device`, or `DEVKIT_SIM_DEVICE`, overrides the configured simulator — everyone's list of
155
- installed ones differs. `sdk` (default `watchsimulator`) and `derivedDataDir` (default `build/sim`)
156
- are there for a phone target.
157
-
158
225
  ## Setting up a machine
159
226
 
160
227
  A repo usually needs a couple of gitignored files before it will run — `.env`, `infra/terraform.tfvars` — and those cannot be fetched back from a host. Vercel, for one, stores Terraform-managed variables write-only and hands them back from `vercel env pull` as *empty strings*, which looks like it worked and quietly leaves you with a `.env` full of blanks.
@@ -172,7 +239,6 @@ Declare what to sync and what to run:
172
239
 
173
240
  ```jsonc
174
241
  "devkit": {
175
- "apps": { /* ... */ },
176
242
  "setup": {
177
243
  "secrets": [".env", "infra/terraform.tfvars"],
178
244
  "env": [{ "file": ".env", "example": ".env.example" }],
@@ -208,13 +274,15 @@ Changed a `.env`? Run `devkit secrets push`, or the next machine gets a stale co
208
274
 
209
275
  ## Bins
210
276
 
211
- - `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.
212
280
  - `devkit clone <owner/repo> [dir]` — clone, decrypt secrets, run setup.
213
281
  - `devkit setup [root] [--dry]` — validate secrets, install, `terraform init`, run steps.
214
- - `devkit deploy [targets...] [--dry] [--verbose]` — run the release targets, in parallel.
215
- - `devkit build` — build the web app and the API into one Vercel output.
216
- - `devkit sim [--real] [--device <name>]` — build and launch the app on a simulator.
217
282
  - `devkit version` — write the source version into every file that declares one.
218
283
  - `devkit release <prefix>` — tag this commit `<prefix>-v<timestamp>` and push it.
219
284
  - `devkit secrets push|pull [root]` — sync the encrypted secrets.
220
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.9.0",
3
+ "version": "0.10.1",
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,121 @@
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
+ // The destination says which SDK each target compiles against, and `-sdk` would override that
45
+ // for all of them at once — which is how an iPhone build of a project that embeds a watch app
46
+ // ends up compiling the watch widget for iOS and failing on its deployment target.
47
+ await $`xcodebuild -project ${project} -scheme ${options.scheme} -configuration ${configuration} \
48
+ -destination ${destination} -derivedDataPath ${derived} \
49
+ CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO build`;
50
+ }
51
+
52
+ /** Boots the named simulator if it isn't already up, and returns its device id. */
53
+ export async function bootSimulator(deviceName: string) {
54
+ const { devices } = await $`xcrun simctl list devices available -j`.quiet().json();
55
+ // The same model exists once per installed runtime; the newest one is the one to use.
56
+ const runtimes = Object.keys(devices).sort().reverse();
57
+ const match = runtimes
58
+ .flatMap((runtime) => devices[runtime] as { name: string; udid: string; state: string }[])
59
+ .find((device) => device.name === deviceName);
60
+
61
+ if (!match) throw new Error(`No simulator called "${deviceName}" — see \`xcrun simctl list devices available\``);
62
+ if (match.state !== "Booted") await $`xcrun simctl boot ${match.udid}`;
63
+ await $`open -a Simulator`;
64
+ return match.udid;
65
+ }
66
+
67
+ /** Replaces whatever copy of the app is on the simulator with this one, and starts it. */
68
+ export async function installAndLaunch(udid: string, appPath: string, bundleId: string, env: Record<string, string> = {}) {
69
+ if (!existsSync(appPath)) throw new Error(`No app bundle at ${appPath}`);
70
+ await $`xcrun simctl terminate ${udid} ${bundleId}`.nothrow().quiet();
71
+ await $`xcrun simctl install ${udid} ${appPath}`;
72
+ // `SIMCTL_CHILD_` is how simctl passes an environment on to the app it launches.
73
+ const child = Object.fromEntries(Object.entries(env).map(([key, value]) => [`SIMCTL_CHILD_${key}`, value]));
74
+ await $`xcrun simctl launch ${udid} ${bundleId}`.env({ ...process.env, ...child });
75
+ }
76
+
77
+ /**
78
+ * Rebuilds and relaunches whenever native sources change, and never returns.
79
+ *
80
+ * Swift has no hot reload, so this is what "live" means on the native side: the edit-to-app loop
81
+ * is one save long instead of a trip through Xcode. The web half of a Capacitor app doesn't come
82
+ * through here at all — Vite already replaced it in the running webview.
83
+ */
84
+ export async function rerunOnChange(dirs: string[], run: () => Promise<void>) {
85
+ let running = false;
86
+ let again = false;
87
+
88
+ const cycle = async () => {
89
+ if (running) {
90
+ again = true;
91
+ return;
92
+ }
93
+ running = true;
94
+ try {
95
+ await run();
96
+ } catch (error) {
97
+ console.error(error instanceof Error ? error.message : error);
98
+ }
99
+ running = false;
100
+ if (again) {
101
+ again = false;
102
+ void cycle();
103
+ }
104
+ };
105
+
106
+ let pending: ReturnType<typeof setTimeout> | undefined;
107
+ for (const dir of dirs) {
108
+ const path = resolve(process.cwd(), dir);
109
+ if (!existsSync(path)) continue;
110
+ watch(path, { recursive: true }, (_event, file) => {
111
+ // Xcode and SPM write into these trees constantly; only sources are worth a rebuild.
112
+ if (file && !/\.(swift|m|h|plist|entitlements|xcconfig|storyboard|xib)$/.test(file)) return;
113
+ clearTimeout(pending);
114
+ pending = setTimeout(() => void cycle(), 300);
115
+ });
116
+ }
117
+
118
+ if (dirs.length) console.log(`Watching ${dirs.join(", ")} — saving a source file rebuilds and relaunches`);
119
+ // A dev process that ends kills the ones running beside it, so this one stays up until Ctrl-C.
120
+ await new Promise<never>(() => {});
121
+ }
package/src/bin/devkit.ts CHANGED
@@ -4,16 +4,13 @@ import { parseArgs } from "node:util";
4
4
  import pkg from "../../package.json" with { type: "json" };
5
5
  import { runBuild } from "../build.ts";
6
6
  import { runClone } from "../clone.ts";
7
- import { loadConfig } from "../config.ts";
7
+ import { PHASES, type Phase } from "../config.ts";
8
8
  import { runDeploy } from "../deploy.ts";
9
- import { deployFastlaneIos } from "../deploy-targets/fastlane-ios.ts";
10
- import { deployTauriMacos } from "../deploy-targets/tauri-macos.ts";
11
- import { deployVercel } from "../deploy-targets/vercel.ts";
12
9
  import { runDev } from "../dev.ts";
13
10
  import { runRelease } from "../release.ts";
11
+ import { runTarget } from "../run-target.ts";
14
12
  import { pullSecrets, pushSecrets } from "../secrets.ts";
15
13
  import { runSetup } from "../setup.ts";
16
- import { runSim } from "../sim.ts";
17
14
  import { runVersion } from "../version.ts";
18
15
 
19
16
  const { values, positionals } = parseArgs({
@@ -34,21 +31,25 @@ if (values.version) {
34
31
  process.exit(0);
35
32
  }
36
33
 
37
- const usage = `usage: devkit [root] [--open] [--dry] run the dev processes (default)
38
- 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
39
40
  devkit setup [root] [--dry] validate secrets, install, terraform init, run steps
40
- devkit deploy [targets...] run the configured deploys, in parallel
41
- devkit build build the web app and the API into one Vercel output
42
- devkit sim [--real] [--device n] build and launch the app on a simulator
41
+ devkit clone <owner/repo> [dir] clone, decrypt secrets, set up
43
42
  devkit version write the source version into every file that declares one
44
43
  devkit release <prefix> tag this commit <prefix>-v<timestamp> and push it
45
44
  devkit secrets push|pull [root] sync age-encrypted secrets
46
45
 
47
- root path to the folder holding the devkit config (default: cwd)
48
- --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
49
50
  --dry print what would run without running it
50
- --verbose stream every line instead of drawing the live board (deploy)
51
- --real run the simulator build against the real API instead of sample data
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
52
53
  --device simulator to run on, overriding the configured one
53
54
  --version print the devkit version`;
54
55
 
@@ -57,7 +58,15 @@ if (values.help) {
57
58
  process.exit(0);
58
59
  }
59
60
 
60
- 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
+ }
61
70
 
62
71
  function chdirTo(dir?: string) {
63
72
  if (dir) process.chdir(resolve(dir));
@@ -65,6 +74,26 @@ function chdirTo(dir?: string) {
65
74
 
66
75
  try {
67
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
+ }
68
97
  case "clone": {
69
98
  const [repo, dir] = rest;
70
99
  if (!repo) throw new Error("usage: devkit clone <owner/repo> [dir]");
@@ -76,14 +105,6 @@ try {
76
105
  await runSetup(values.dry);
77
106
  break;
78
107
  }
79
- case "build": {
80
- await runBuild();
81
- break;
82
- }
83
- case "sim": {
84
- await runSim({ real: values.real, device: values.device });
85
- break;
86
- }
87
108
  case "version": {
88
109
  await runVersion();
89
110
  break;
@@ -92,23 +113,6 @@ try {
92
113
  await runRelease(rest[0] ?? "");
93
114
  break;
94
115
  }
95
- case "deploy": {
96
- await runDeploy(rest, { dry: values.dry, verbose: values.verbose });
97
- break;
98
- }
99
- // Internal: how a built-in `type`d deploy target actually runs — spawned as its own process
100
- // by `runDeploy` so it gets the same line-capture and log file as a hand-written `command`.
101
- case "_deploy-target": {
102
- const [name] = rest;
103
- const { deploy } = loadConfig();
104
- const target = deploy.find((t) => t.name === name);
105
- if (!target?.type) throw new Error(`No deploy target ${name} with a "type"`);
106
- if (target.type === "vercel") await deployVercel(target.options);
107
- else if (target.type === "tauri-macos") await deployTauriMacos(target.options);
108
- else if (target.type === "fastlane-ios") await deployFastlaneIos(target.options);
109
- else throw new Error(`Unknown deploy target type: ${target.type}`);
110
- break;
111
- }
112
116
  case "secrets": {
113
117
  const [action, dir] = rest;
114
118
  chdirTo(dir);
@@ -117,11 +121,8 @@ try {
117
121
  else throw new Error("usage: devkit secrets push|pull [root]");
118
122
  break;
119
123
  }
120
- default: {
121
- // No subcommand — the original `devkit [root]` behaviour.
122
- chdirTo(command);
123
- await runDev(values.open, values.dry);
124
- }
124
+ default:
125
+ throw new Error(`Unknown command "${head}"\n\n${usage}`);
125
126
  }
126
127
  } catch (error) {
127
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
+ }