()
| 19 | }); |
| 20 | |
| 21 | async function main() { |
| 22 | const args = parseArgs(process.argv.slice(2)); |
| 23 | if (args.help || !args.file) { |
| 24 | printUsage(); |
| 25 | process.exit(args.help ? 0 : 2); |
| 26 | } |
| 27 | |
| 28 | const sourceFile = path.resolve(String(args.file)); |
| 29 | const udid = String(args.udid ?? findBootedSimulatorUDID()); |
| 30 | if (!udid) { |
| 31 | throw new Error( |
| 32 | "No simulator UDID supplied and no booted simulator was found.", |
| 33 | ); |
| 34 | } |
| 35 | |
| 36 | const buildRoot = path.resolve( |
| 37 | String(args.buildRoot ?? path.join(".simdeck-preview", "build")), |
| 38 | ); |
| 39 | const bundleId = String(args.bundleId ?? DEFAULT_BUNDLE_ID); |
| 40 | const minIos = String(args.minIos ?? DEFAULT_MIN_IOS); |
| 41 | const targetArch = String( |
| 42 | args.arch ?? (process.arch === "arm64" ? "arm64" : "x86_64"), |
| 43 | ); |
| 44 | const sdkPath = runText("xcrun", [ |
| 45 | "--sdk", |
| 46 | "iphonesimulator", |
| 47 | "--show-sdk-path", |
| 48 | ]).trim(); |
| 49 | const context = { |
| 50 | buildRoot, |
| 51 | bundleId, |
| 52 | minIos, |
| 53 | sdkPath, |
| 54 | target: `${targetArch}-apple-ios${minIos}-simulator`, |
| 55 | udid, |
| 56 | }; |
| 57 | fs.mkdirSync(buildRoot, { recursive: true }); |
| 58 | const xcode = resolveXcodeContext(args, context); |
| 59 | |
| 60 | const host = buildHostApp(context, Boolean(args.rebuildHost)); |
| 61 | const shouldInstallHost = |
| 62 | host.rebuilt || Boolean(xcode && !args.skipXcodeBuild); |
| 63 | if (xcode && shouldInstallHost) { |
| 64 | overlayXcodeAppBundle(host.appPath, xcode); |
| 65 | } |
| 66 | installAndLaunchHost(context, host.appPath, shouldInstallHost); |
| 67 | await reloadPreview(context, sourceFile, args, xcode); |
| 68 | |
| 69 | if (args.watch) { |
| 70 | console.log(`[simdeck-preview] watching ${sourceFile}`); |
| 71 | watchFiles( |
| 72 | [ |
| 73 | sourceFile, |
| 74 | ...arrayArg(args.extraSwift).map((item) => path.resolve(item)), |
| 75 | ], |
| 76 | () => { |
| 77 | reloadPreview(context, sourceFile, args, xcode).catch((error) => { |
| 78 | console.error(`[simdeck-preview] reload failed: ${error.message}`); |
no test coverage detected