MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / main

Function main

scripts/experimental/swiftui-preview.mjs:21–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

19});
20
21async 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}`);

Callers 1

Calls 13

printUsageFunction · 0.85
findBootedSimulatorUDIDFunction · 0.85
resolveXcodeContextFunction · 0.85
buildHostAppFunction · 0.85
overlayXcodeAppBundleFunction · 0.85
installAndLaunchHostFunction · 0.85
reloadPreviewFunction · 0.85
watchFilesFunction · 0.85
arrayArgFunction · 0.85
logMethod · 0.80
errorMethod · 0.80
parseArgsFunction · 0.70

Tested by

no test coverage detected