feat: add one-command mobile simulator dev loop
Adds `mobile:sim:dev` / `sim:dev` to build, install, launch, and stream the iOS simulator in one command Updates mobile docs and serve-sim guidance with the new workflow and correct preview URL behavior Bumps `serve-sim` to a newer version
This commit is contained in:
@@ -25,6 +25,7 @@ Run these from `packages/mobile`, or use the root `mobile:*` aliases.
|
||||
- `bun run build:android:debug`: builds a debug Android APK without launching an emulator.
|
||||
- `bun run build:ios:simulator`: builds an iOS Simulator app without launching Xcode or Simulator.
|
||||
- `bun run sim:run`: boots a simulator if needed, installs the built iOS app, and launches it.
|
||||
- `bun run sim:dev`: one-command dev loop — builds the simulator app, installs + launches it, starts the `serve-sim` stream, and prints the preview URL; Ctrl+C stops the stream. Pass `--no-build` to skip the build step.
|
||||
- `bun run sim:serve`: starts `serve-sim` in detached JSON mode and prints the browser preview URL.
|
||||
- `bun run sim:list`: lists running `serve-sim` streams.
|
||||
- `bun run sim:kill`: stops running `serve-sim` streams.
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"sim:install": "node scripts/with-mobile-env.mjs \"node scripts/ios-sim.mjs install\"",
|
||||
"sim:launch": "node scripts/with-mobile-env.mjs \"node scripts/ios-sim.mjs launch\"",
|
||||
"sim:run": "node scripts/with-mobile-env.mjs \"node scripts/ios-sim.mjs run\"",
|
||||
"sim:dev": "node scripts/with-mobile-env.mjs \"node scripts/ios-sim-dev.mjs\"",
|
||||
"sim:serve": "node scripts/with-mobile-env.mjs \"serve-sim --detach -q\"",
|
||||
"sim:list": "node scripts/with-mobile-env.mjs \"serve-sim --list -q\"",
|
||||
"sim:kill": "node scripts/with-mobile-env.mjs \"serve-sim --kill\"",
|
||||
@@ -42,7 +43,7 @@
|
||||
"@capacitor/cli": "^8.4.1",
|
||||
"@capacitor/ios": "^8.4.1",
|
||||
"@types/node": "^24.3.1",
|
||||
"serve-sim": "^0.1.34",
|
||||
"serve-sim": "^0.1.45",
|
||||
"typescript": "~5.9.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
// One-command simulator dev loop: build the simulator app, install + launch it,
|
||||
// start the serve-sim browser stream, and print the preview URL.
|
||||
// The process then stays in the foreground so Ctrl+C stops the stream helpers.
|
||||
//
|
||||
// Pass --no-build to skip the (slow) web + xcodebuild step and just relaunch the
|
||||
// previously built app with a fresh stream.
|
||||
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { dirname, join } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const mobileRoot = join(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
// serve-sim resolves from the package bin dir; plain `serve-sim` is not on PATH
|
||||
// when this script is invoked outside `bun run`.
|
||||
const env = {
|
||||
...process.env,
|
||||
PATH: `${join(mobileRoot, 'node_modules', '.bin')}:${process.env.PATH || ''}`,
|
||||
};
|
||||
|
||||
const run = (command, args, options = {}) => {
|
||||
const result = spawnSync(command, args, {
|
||||
cwd: mobileRoot,
|
||||
env,
|
||||
encoding: 'utf8',
|
||||
stdio: options.capture ? ['ignore', 'pipe', 'inherit'] : 'inherit',
|
||||
});
|
||||
if (result.status !== 0) {
|
||||
console.error(`[ios-sim-dev] ${command} ${args.join(' ')} exited with ${result.status ?? result.signal}`);
|
||||
process.exit(result.status ?? 1);
|
||||
}
|
||||
return result.stdout?.trim() ?? '';
|
||||
};
|
||||
|
||||
if (!process.argv.includes('--no-build')) {
|
||||
run('node', ['scripts/ios-sim-build.mjs']);
|
||||
}
|
||||
|
||||
run('node', ['scripts/ios-sim.mjs', 'run']);
|
||||
|
||||
const serveOutput = run('serve-sim', ['--detach', '-q'], { capture: true });
|
||||
let url;
|
||||
try {
|
||||
url = JSON.parse(serveOutput).url;
|
||||
} catch {
|
||||
// fall through to the guard below
|
||||
}
|
||||
if (!url) {
|
||||
console.error(`[ios-sim-dev] Unexpected serve-sim output: ${serveOutput}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`[ios-sim-dev] Stream ready at ${url}`);
|
||||
console.log('[ios-sim-dev] Press Ctrl+C to stop the stream (the simulator stays running).');
|
||||
|
||||
const stop = () => {
|
||||
spawnSync('serve-sim', ['--kill'], { cwd: mobileRoot, env, stdio: 'inherit' });
|
||||
process.exit(0);
|
||||
};
|
||||
process.on('SIGINT', stop);
|
||||
process.on('SIGTERM', stop);
|
||||
// Keep the foreground process alive until a signal arrives.
|
||||
setInterval(() => {}, 1 << 30);
|
||||
Reference in New Issue
Block a user