@elumixor/devkit 0.9.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 +162 -94
- package/package.json +2 -1
- package/src/apple.ts +118 -0
- package/src/bin/devkit.ts +46 -45
- package/src/build-targets/capacitor-ios.ts +34 -0
- package/src/build-targets/tauri-macos.ts +36 -0
- package/src/build-targets/web.ts +80 -0
- package/src/build-targets/xcode.ts +9 -0
- package/src/build.ts +5 -72
- package/src/config.ts +95 -78
- package/src/deploy-targets/fastlane-ios.ts +2 -14
- package/src/deploy.ts +6 -260
- package/src/dev-targets/capacitor-ios.ts +54 -0
- package/src/dev-targets/xcode-sim.ts +43 -0
- package/src/dev.ts +76 -29
- package/src/graph.ts +258 -0
- package/src/run-target.ts +64 -0
- package/src/web-build.ts +13 -0
- package/src/sim.ts +0 -51
package/src/graph.ts
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { $ } from "bun";
|
|
5
|
+
import { type GenerateConfig, type Named, type Phase, type Step, withNeeds } from "./config.ts";
|
|
6
|
+
|
|
7
|
+
const PALETTE: readonly string[] = ["magenta", "cyan", "yellow", "green", "blue", "red"];
|
|
8
|
+
const COLORS: Record<string, string> = {
|
|
9
|
+
black: "30",
|
|
10
|
+
red: "31",
|
|
11
|
+
green: "32",
|
|
12
|
+
yellow: "33",
|
|
13
|
+
blue: "34",
|
|
14
|
+
magenta: "35",
|
|
15
|
+
cyan: "36",
|
|
16
|
+
white: "37",
|
|
17
|
+
gray: "90",
|
|
18
|
+
};
|
|
19
|
+
const SPINNER = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
|
|
20
|
+
const FRAME_MS = 80;
|
|
21
|
+
const TAIL_ON_FAILURE = 25;
|
|
22
|
+
|
|
23
|
+
const paint = (text: string, color: string) => `\x1b[${COLORS[color] ?? "37"}m${text}\x1b[0m`;
|
|
24
|
+
const dim = (text: string) => `\x1b[2m${text}\x1b[0m`;
|
|
25
|
+
const bold = (text: string) => `\x1b[1m${text}\x1b[0m`;
|
|
26
|
+
|
|
27
|
+
type Status = "waiting" | "running" | "done" | "failed" | "skipped";
|
|
28
|
+
|
|
29
|
+
/** One step's progress, and everything the board needs to draw its line. */
|
|
30
|
+
interface Job {
|
|
31
|
+
target: Named<Step> & { command: string };
|
|
32
|
+
label: string;
|
|
33
|
+
color: string;
|
|
34
|
+
status: Status;
|
|
35
|
+
note: string;
|
|
36
|
+
startedAt?: number;
|
|
37
|
+
endedAt?: number;
|
|
38
|
+
lines: string[];
|
|
39
|
+
logPath: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface GraphOptions {
|
|
43
|
+
dry?: boolean;
|
|
44
|
+
verbose?: boolean;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Run one phase's steps, in parallel where they don't depend on each other.
|
|
49
|
+
*
|
|
50
|
+
* A build or a deploy is several long compiles that each print thousands of lines, and
|
|
51
|
+
* interleaving all of it is unreadable — so on a terminal this draws one line per platform (what
|
|
52
|
+
* it's doing, for how long) and keeps the full output in `.devkit/<phase>/<name>.log`, printing
|
|
53
|
+
* the tail of whichever one failed. Anywhere else — CI, a pipe, a log file — it falls back to
|
|
54
|
+
* prefixed streaming, because a redrawing board in a file is worse than useless.
|
|
55
|
+
*/
|
|
56
|
+
export async function runGraph(
|
|
57
|
+
phase: Exclude<Phase, "dev">,
|
|
58
|
+
targets: Named<Step>[],
|
|
59
|
+
only: string[],
|
|
60
|
+
generate: GenerateConfig | undefined,
|
|
61
|
+
options: GraphOptions = {},
|
|
62
|
+
) {
|
|
63
|
+
if (!targets.length) throw new Error(`No "devkit.${phase}" platforms in package.json`);
|
|
64
|
+
|
|
65
|
+
for (const target of targets) {
|
|
66
|
+
const missing = (target.needs ?? []).filter((need) => !targets.some((other) => other.name === need));
|
|
67
|
+
if (missing.length)
|
|
68
|
+
throw new Error(`${target.name} needs unknown platform${missing.length > 1 ? "s" : ""}: ${missing.join(", ")}`);
|
|
69
|
+
if (!target.command && !target.type) throw new Error(`${target.name} needs a "command" or a "type"`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const jobs = withNeeds(targets, only).map((target, index) => toJob(phase, target, index));
|
|
73
|
+
if (options.dry) return printPlan(phase, jobs, generate);
|
|
74
|
+
|
|
75
|
+
const logDir = resolve(process.cwd(), ".devkit", phase);
|
|
76
|
+
mkdirSync(logDir, { recursive: true });
|
|
77
|
+
|
|
78
|
+
const live = Boolean(process.stdout.isTTY) && !options.verbose;
|
|
79
|
+
console.log(
|
|
80
|
+
bold(`\n${phase}ing ${jobs.map((job) => job.label).join(", ")}`) +
|
|
81
|
+
dim(live ? ` · logs in ./.devkit/${phase}` : ""),
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
// Generated sources — a typed API client, say — are read by every platform's compile, so they
|
|
85
|
+
// are written once here rather than by each of them at the same time as the others read them.
|
|
86
|
+
if (generate) {
|
|
87
|
+
console.log(dim(` ${generate.command}`));
|
|
88
|
+
await $`sh -c ${generate.command}`.cwd(resolve(process.cwd(), generate.cwd ?? "."));
|
|
89
|
+
process.env.SKIP_CLIENT_GEN = "1";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
console.log();
|
|
93
|
+
const board = live ? startBoard(jobs) : null;
|
|
94
|
+
|
|
95
|
+
// Each step waits on the gates of the steps it needs, so the graph runs itself: independent
|
|
96
|
+
// platforms start together, dependents start the moment their last dependency lands.
|
|
97
|
+
const gates = new Map(jobs.map((job) => [job.label, gate()]));
|
|
98
|
+
|
|
99
|
+
const started = Date.now();
|
|
100
|
+
await Promise.all(
|
|
101
|
+
jobs.map(async (job) => {
|
|
102
|
+
const needs = (job.target.needs ?? []).map((name) => jobs.find((other) => other.label === name)) as Job[];
|
|
103
|
+
await Promise.all(needs.map((need) => gates.get(need.label)?.promise));
|
|
104
|
+
await runJob(job, needs, live);
|
|
105
|
+
gates.get(job.label)?.open();
|
|
106
|
+
}),
|
|
107
|
+
);
|
|
108
|
+
board?.stop();
|
|
109
|
+
|
|
110
|
+
report(phase, jobs, Date.now() - started);
|
|
111
|
+
if (jobs.some((job) => job.status !== "done")) process.exitCode = 1;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function toJob(phase: Phase, target: Named<Step>, index: number): Job {
|
|
115
|
+
// A built-in target has no shell command of its own — it runs through `devkit _run`, which
|
|
116
|
+
// looks its options back up from this same config by phase and name.
|
|
117
|
+
const command = target.command ?? `devkit _run ${phase} ${JSON.stringify(target.name)}`;
|
|
118
|
+
return {
|
|
119
|
+
target: { ...target, command },
|
|
120
|
+
label: target.name,
|
|
121
|
+
color: target.color ?? (PALETTE[index % PALETTE.length] as string),
|
|
122
|
+
status: "waiting",
|
|
123
|
+
note: target.needs?.length ? `waiting for ${target.needs.join(", ")}` : "",
|
|
124
|
+
lines: [],
|
|
125
|
+
logPath: resolve(process.cwd(), ".devkit", phase, `${target.name}.log`),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Runs one step's command to completion, unless something it needed didn't get there. */
|
|
130
|
+
async function runJob(job: Job, needs: Job[], live: boolean) {
|
|
131
|
+
const blocker = needs.find((need) => need.status !== "done");
|
|
132
|
+
if (blocker) {
|
|
133
|
+
job.status = "skipped";
|
|
134
|
+
job.note = `skipped — ${blocker.label} ${blocker.status === "failed" ? "failed" : "never ran"}`;
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
job.status = "running";
|
|
139
|
+
job.startedAt = Date.now();
|
|
140
|
+
job.note = job.target.command;
|
|
141
|
+
|
|
142
|
+
const code = await new Promise<number>((done) => {
|
|
143
|
+
const child = spawn(job.target.command, { shell: true, stdio: ["ignore", "pipe", "pipe"] });
|
|
144
|
+
for (const stream of [child.stdout, child.stderr]) {
|
|
145
|
+
let rest = "";
|
|
146
|
+
stream.on("data", (chunk: Buffer) => {
|
|
147
|
+
const parts = (rest + chunk.toString()).split("\n");
|
|
148
|
+
rest = parts.pop() ?? "";
|
|
149
|
+
for (const line of parts) {
|
|
150
|
+
job.lines.push(line);
|
|
151
|
+
job.note = line.trim() || job.note;
|
|
152
|
+
if (!live) console.log(`${paint(`[${job.label}]`, job.color)} ${line}`);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
child.on("close", (status) => done(status ?? 1));
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
job.endedAt = Date.now();
|
|
160
|
+
job.status = code === 0 ? "done" : "failed";
|
|
161
|
+
job.note = code === 0 ? "done" : `exit ${code}`;
|
|
162
|
+
writeFileSync(job.logPath, `${job.lines.join("\n")}\n`);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** Redraws the board until stopped. One line per platform, in the order they were configured. */
|
|
166
|
+
function startBoard(jobs: Job[]) {
|
|
167
|
+
let drawn = 0;
|
|
168
|
+
let frame = 0;
|
|
169
|
+
|
|
170
|
+
const draw = () => {
|
|
171
|
+
// A pty with no window size reports 0 — treat that as a sane default rather than clipping to nothing.
|
|
172
|
+
const width = process.stdout.columns || 100;
|
|
173
|
+
const pad = Math.max(...jobs.map((job) => job.label.length));
|
|
174
|
+
const lines = jobs.map((job) => {
|
|
175
|
+
const mark =
|
|
176
|
+
job.status === "running"
|
|
177
|
+
? paint(SPINNER[frame % SPINNER.length] as string, job.color)
|
|
178
|
+
: job.status === "done"
|
|
179
|
+
? paint("✓", "green")
|
|
180
|
+
: job.status === "failed"
|
|
181
|
+
? paint("✗", "red")
|
|
182
|
+
: job.status === "skipped"
|
|
183
|
+
? dim("–")
|
|
184
|
+
: dim("·");
|
|
185
|
+
const time = job.startedAt ? dim(` ${elapsed(job)}`) : "";
|
|
186
|
+
const head = `${mark} ${paint(job.label.padEnd(pad), job.color)}${time} `;
|
|
187
|
+
// The note is whatever the step last printed, so it has to be cut to the terminal rather
|
|
188
|
+
// than wrapped — a wrapped line breaks the cursor arithmetic that redraws this block.
|
|
189
|
+
const room = Math.max(10, width - visibleLength(head) - 1);
|
|
190
|
+
return head + dim(clip(job.note, room));
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
process.stdout.write(`${drawn ? `\x1b[${drawn}A` : ""}${lines.map((line) => `\x1b[2K${line}`).join("\n")}\n`);
|
|
194
|
+
drawn = lines.length;
|
|
195
|
+
frame++;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
process.stdout.write("\x1b[?25l");
|
|
199
|
+
draw();
|
|
200
|
+
const timer = setInterval(draw, FRAME_MS);
|
|
201
|
+
|
|
202
|
+
return {
|
|
203
|
+
stop() {
|
|
204
|
+
clearInterval(timer);
|
|
205
|
+
draw();
|
|
206
|
+
process.stdout.write("\x1b[?25h");
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function report(phase: Phase, jobs: Job[], total: number) {
|
|
212
|
+
const failed = jobs.filter((job) => job.status === "failed");
|
|
213
|
+
for (const job of failed) {
|
|
214
|
+
console.log(`\n${paint(`── ${job.label} failed`, "red")} ${dim(job.logPath)}`);
|
|
215
|
+
for (const line of job.lines.slice(-TAIL_ON_FAILURE)) console.log(dim(` ${line}`));
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const done = jobs.filter((job) => job.status === "done").length;
|
|
219
|
+
const skipped = jobs.filter((job) => job.status === "skipped").length;
|
|
220
|
+
const parts = [
|
|
221
|
+
failed.length ? paint(`${failed.length} failed`, "red") : paint("all good", "green"),
|
|
222
|
+
skipped ? dim(`${skipped} skipped`) : "",
|
|
223
|
+
dim(duration(total)),
|
|
224
|
+
].filter(Boolean);
|
|
225
|
+
console.log(`\n${bold(`${done}/${jobs.length} ${phase === "build" ? "built" : "deployed"}`)} · ${parts.join(" · ")}\n`);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function printPlan(phase: Phase, jobs: Job[], generate: GenerateConfig | undefined) {
|
|
229
|
+
console.log(bold(`\n${phase} plan\n`));
|
|
230
|
+
if (generate) console.log(` ${paint("generate", "gray")}\n ${dim(generate.command)}`);
|
|
231
|
+
for (const job of jobs) {
|
|
232
|
+
const after = job.target.needs?.length ? dim(` after ${job.target.needs.join(", ")}`) : "";
|
|
233
|
+
console.log(` ${paint(job.label, job.color)}${after}\n ${dim(job.target.command)}`);
|
|
234
|
+
}
|
|
235
|
+
console.log();
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** A promise plus the handle that settles it — one per step, opened when that step ends. */
|
|
239
|
+
function gate() {
|
|
240
|
+
let open!: () => void;
|
|
241
|
+
const promise = new Promise<void>((resolve) => {
|
|
242
|
+
open = resolve;
|
|
243
|
+
});
|
|
244
|
+
return { promise, open };
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const elapsed = (job: Job) => duration((job.endedAt ?? Date.now()) - (job.startedAt ?? Date.now()));
|
|
248
|
+
|
|
249
|
+
function duration(ms: number) {
|
|
250
|
+
const seconds = Math.round(ms / 1000);
|
|
251
|
+
return seconds < 60 ? `${seconds}s` : `${Math.floor(seconds / 60)}m${String(seconds % 60).padStart(2, "0")}s`;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Colour codes take no space on screen, so the board has to measure what a reader would see.
|
|
255
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: an escape sequence is the thing being matched
|
|
256
|
+
const ANSI = /\x1b\[[0-9;]*m/g;
|
|
257
|
+
const visibleLength = (text: string) => text.replace(ANSI, "").length;
|
|
258
|
+
const clip = (text: string, room: number) => (text.length <= room ? text : `${text.slice(0, room - 1)}…`);
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { buildCapacitorIos } from "./build-targets/capacitor-ios.ts";
|
|
2
|
+
import { buildTauriMacos } from "./build-targets/tauri-macos.ts";
|
|
3
|
+
import { buildWeb } from "./build-targets/web.ts";
|
|
4
|
+
import { buildXcode } from "./build-targets/xcode.ts";
|
|
5
|
+
import { loadConfig, type Phase, phaseOf } from "./config.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
|
+
import { devCapacitorIos } from "./dev-targets/capacitor-ios.ts";
|
|
10
|
+
import { devXcodeSim } from "./dev-targets/xcode-sim.ts";
|
|
11
|
+
|
|
12
|
+
/** Flags a dev target may be given from the command line, passed straight through to it. */
|
|
13
|
+
export interface TargetFlags {
|
|
14
|
+
real?: boolean;
|
|
15
|
+
device?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// biome-ignore lint/suspicious/noExplicitAny: each target validates its own options shape
|
|
19
|
+
type Target = (options: any, flags: TargetFlags) => Promise<void>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* What a `type` in the config means, per phase.
|
|
23
|
+
*
|
|
24
|
+
* The same word means different things in different phases on purpose: `capacitor-ios` builds the
|
|
25
|
+
* iPhone app when a build asks for it, runs it against the dev server when dev does, and ships it
|
|
26
|
+
* to TestFlight when a deploy does. The platform is the name; the phase says what to do with it.
|
|
27
|
+
*/
|
|
28
|
+
const TARGETS: Record<Phase, Record<string, Target>> = {
|
|
29
|
+
dev: {
|
|
30
|
+
"capacitor-ios": devCapacitorIos,
|
|
31
|
+
"xcode-sim": devXcodeSim,
|
|
32
|
+
},
|
|
33
|
+
build: {
|
|
34
|
+
web: buildWeb,
|
|
35
|
+
"tauri-macos": buildTauriMacos,
|
|
36
|
+
"capacitor-ios": buildCapacitorIos,
|
|
37
|
+
xcode: buildXcode,
|
|
38
|
+
},
|
|
39
|
+
deploy: {
|
|
40
|
+
vercel: deployVercel,
|
|
41
|
+
"tauri-macos": deployTauriMacos,
|
|
42
|
+
"fastlane-ios": deployFastlaneIos,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Runs one built-in target, looked back up by phase and platform name.
|
|
48
|
+
*
|
|
49
|
+
* A typed step has no shell command of its own, so the graph (and `concurrently`, for dev) spawns
|
|
50
|
+
* `devkit _run <phase> <platform>` and this reads the same config back — which keeps every step a
|
|
51
|
+
* process of its own, with its own log file and its own line on the board.
|
|
52
|
+
*/
|
|
53
|
+
export async function runTarget(phase: Phase, name: string, flags: TargetFlags = {}) {
|
|
54
|
+
const step = phaseOf(loadConfig(), phase).find((entry) => entry.name === name);
|
|
55
|
+
if (!step) throw new Error(`No "devkit.${phase}.${name}" in package.json`);
|
|
56
|
+
if (!step.type) throw new Error(`"devkit.${phase}.${name}" has no "type"`);
|
|
57
|
+
|
|
58
|
+
const target = TARGETS[phase][step.type];
|
|
59
|
+
if (!target) {
|
|
60
|
+
const known = Object.keys(TARGETS[phase]).join(", ");
|
|
61
|
+
throw new Error(`Unknown ${phase} type "${step.type}" — known types: ${known}`);
|
|
62
|
+
}
|
|
63
|
+
await target(step.options ?? {}, flags);
|
|
64
|
+
}
|
package/src/web-build.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every native shell carries its own copy of the web app, built with its own API base URL — and
|
|
3
|
+
* `devkit build` runs those builds beside each other. Vite, SvelteKit and the output directory all
|
|
4
|
+
* default to one place per project, so each build is given its own or they overwrite each other's
|
|
5
|
+
* files halfway through.
|
|
6
|
+
*/
|
|
7
|
+
export function isolatedWebEnv(suffix: string): Record<string, string> {
|
|
8
|
+
return {
|
|
9
|
+
BUILD_DIR: `build-${suffix}`,
|
|
10
|
+
KIT_DIR: `.svelte-kit-${suffix}`,
|
|
11
|
+
VITE_CACHE_DIR: `node_modules/.vite-${suffix}`,
|
|
12
|
+
};
|
|
13
|
+
}
|
package/src/sim.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { resolve } from "node:path";
|
|
2
|
-
import { $ } from "bun";
|
|
3
|
-
import { loadConfig } from "./config.ts";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Build an Apple app and run it on a simulator, without going through Xcode.
|
|
7
|
-
*
|
|
8
|
-
* A watch app usually has no sign-in of its own, so on a simulator with no paired phone it can
|
|
9
|
-
* only show its signed-out screen. `preview` launches it with the app's own preview flag set
|
|
10
|
-
* instead, which is the point of running it here at all: gestures have to be felt.
|
|
11
|
-
*/
|
|
12
|
-
export async function runSim(options: { real?: boolean; device?: string } = {}) {
|
|
13
|
-
const { sim } = loadConfig();
|
|
14
|
-
if (!sim) throw new Error('No "devkit.sim" config in package.json');
|
|
15
|
-
|
|
16
|
-
const project = resolve(process.cwd(), sim.project);
|
|
17
|
-
const derived = resolve(process.cwd(), sim.derivedDataDir ?? "build/sim");
|
|
18
|
-
const sdk = sim.sdk ?? "watchsimulator";
|
|
19
|
-
const deviceName = options.device ?? process.env.DEVKIT_SIM_DEVICE ?? sim.device;
|
|
20
|
-
const preview = !options.real;
|
|
21
|
-
|
|
22
|
-
const udid = await boot(deviceName);
|
|
23
|
-
|
|
24
|
-
await $`xcodebuild -project ${project} -scheme ${sim.scheme} -configuration Debug \
|
|
25
|
-
-destination id=${udid} -derivedDataPath ${derived} build`.quiet();
|
|
26
|
-
|
|
27
|
-
await $`xcrun simctl install ${udid} ${derived}/Build/Products/Debug-${sdk}/${sim.scheme}.app`;
|
|
28
|
-
await $`xcrun simctl terminate ${udid} ${sim.bundleId}`.nothrow().quiet();
|
|
29
|
-
// `SIMCTL_CHILD_` is how simctl passes an environment on to the app it launches.
|
|
30
|
-
await $`xcrun simctl launch ${udid} ${sim.bundleId}`.env({
|
|
31
|
-
...process.env,
|
|
32
|
-
...(preview && sim.previewEnv ? { [`SIMCTL_CHILD_${sim.previewEnv}`]: "1" } : {}),
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
console.log(`${sim.scheme} running on ${deviceName}${preview && sim.previewEnv ? " with sample data" : ""}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/** Boots the simulator if it isn't already up, and returns its device id. */
|
|
39
|
-
async function boot(deviceName: string) {
|
|
40
|
-
const { devices } = await $`xcrun simctl list devices available -j`.quiet().json();
|
|
41
|
-
// The same model exists once per installed runtime; the newest one is the one to use.
|
|
42
|
-
const runtimes = Object.keys(devices).sort().reverse();
|
|
43
|
-
const match = runtimes
|
|
44
|
-
.flatMap((runtime) => devices[runtime] as { name: string; udid: string; state: string }[])
|
|
45
|
-
.find((device) => device.name === deviceName);
|
|
46
|
-
|
|
47
|
-
if (!match) throw new Error(`No simulator called "${deviceName}" — see \`xcrun simctl list devices available\``);
|
|
48
|
-
if (match.state !== "Booted") await $`xcrun simctl boot ${match.udid}`;
|
|
49
|
-
await $`open -a Simulator`;
|
|
50
|
-
return match.udid;
|
|
51
|
-
}
|