orvyn-lang 0.2.0 → 0.3.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.
Files changed (55) hide show
  1. package/GUIDE.md +149 -0
  2. package/LANGUAGE.md +744 -27
  3. package/README.md +211 -250
  4. package/brand/orvyn-sunset-animated.svg +15 -0
  5. package/package.json +3 -1
  6. package/src/cli/orvyn.js +186 -10
  7. package/src/core/signal.js +104 -6
  8. package/src/devtools/runtime.js +25 -1
  9. package/src/lang/a11y.js +102 -0
  10. package/src/lang/auth.js +239 -0
  11. package/src/lang/bundle-native.js +10 -6
  12. package/src/lang/codegen.js +428 -57
  13. package/src/lang/device.js +41 -0
  14. package/src/lang/doctor.js +60 -0
  15. package/src/lang/env.js +27 -0
  16. package/src/lang/errors.js +513 -0
  17. package/src/lang/form.js +69 -8
  18. package/src/lang/index.js +2 -1
  19. package/src/lang/lexer.js +2 -0
  20. package/src/lang/list.js +44 -0
  21. package/src/lang/native/android/MainActivity.kt +43 -4
  22. package/src/lang/native/android/OrvynDevice.kt +163 -0
  23. package/src/lang/native/android/OrvynEngine.kt +154 -7
  24. package/src/lang/native/android/OrvynRenderer.kt +518 -44
  25. package/src/lang/native/android.js +74 -11
  26. package/src/lang/native/build.js +130 -60
  27. package/src/lang/native/config.js +108 -0
  28. package/src/lang/native/ios/OrvynApp.swift +6 -0
  29. package/src/lang/native/ios/OrvynEngine.swift +266 -4
  30. package/src/lang/native/ios/OrvynViews.swift +429 -34
  31. package/src/lang/native/ios.js +75 -2
  32. package/src/lang/native-runtime.js +406 -56
  33. package/src/lang/page.js +52 -0
  34. package/src/lang/parser.js +243 -15
  35. package/src/lang/prerender.js +300 -0
  36. package/src/lang/read-import.js +11 -0
  37. package/src/lang/router.js +266 -0
  38. package/src/lang/runtime-shared.js +792 -10
  39. package/src/lang/runtime.js +362 -52
  40. package/src/lang/select.js +13 -0
  41. package/src/lang/server-code.js +233 -0
  42. package/src/lang/server-export.js +78 -0
  43. package/src/lang/server-libs.js +53 -0
  44. package/src/lang/server.js +409 -0
  45. package/src/lang/test-runner.js +134 -0
  46. package/src/lang/types.js +312 -0
  47. package/src/lang/vite-plugin.js +82 -3
  48. package/src/lang/web-overlay.js +578 -0
  49. package/src/lang/widgets.js +94 -0
  50. package/src/lang/words.js +38 -0
  51. package/src/runtime/mount.js +116 -27
  52. package/src/runtime/patch.js +90 -11
  53. package/src/runtime/style.js +11 -1
  54. package/src/styling/fluid.js +91 -4
  55. package/src/styling/spec.js +306 -0
@@ -1,10 +1,11 @@
1
1
  import { readFileSync } from "node:fs";
2
2
  import { fileURLToPath } from "node:url";
3
3
  import { join } from "node:path";
4
+ import { PERMISSIONS } from "./config.js";
4
5
  const templateDir = fileURLToPath(new URL("./android/", import.meta.url));
5
- const AGP_VERSION = "8.5.2";
6
- const KOTLIN_VERSION = "1.9.24";
7
- const GRADLE_VERSION = "8.7";
6
+ const AGP_VERSION = "8.9.1";
7
+ const KOTLIN_VERSION = "2.0.21";
8
+ const GRADLE_VERSION = "8.11.1";
8
9
  function xml(value) {
9
10
  return value.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "\\'");
10
11
  }
@@ -12,28 +13,89 @@ function versionCode(version) {
12
13
  const [major = 0, minor = 0, patch = 0] = version.split(".").map((n) => parseInt(n, 10) || 0);
13
14
  return Math.max(1, major * 1e4 + minor * 100 + patch);
14
15
  }
16
+ function signing(config) {
17
+ if (!config.keystore) return "";
18
+ const kotlin = (value) => JSON.stringify(value).replace(/\$/g, "\\$");
19
+ return ` signingConfigs {
20
+ create("release") {
21
+ storeFile = file(${kotlin(config.keystore)})
22
+ keyAlias = ${kotlin(config.keyAlias ?? "")}
23
+ storePassword = System.getenv("ORVYN_KEYSTORE_PASSWORD")
24
+ keyPassword = System.getenv("ORVYN_KEY_PASSWORD") ?: System.getenv("ORVYN_KEYSTORE_PASSWORD")
25
+ }
26
+ }
27
+
28
+ `;
29
+ }
30
+ function resources(config) {
31
+ const res = "app/src/main/res";
32
+ const files = [];
33
+ if (config.icon) files.push({ path: `${res}/drawable-nodpi/orvyn_icon.png`, content: "", copyFrom: config.icon });
34
+ const splash = config.splash;
35
+ if (!splash) return files;
36
+ if (splash.image) files.push({ path: `${res}/drawable-nodpi/orvyn_splash_image.png`, content: "", copyFrom: splash.image });
37
+ files.push({
38
+ path: `${res}/drawable/orvyn_splash.xml`,
39
+ content: `<?xml version="1.0" encoding="utf-8"?>
40
+ <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
41
+ <item android:drawable="@color/orvyn_splash_color" />${splash.image ? `
42
+ <item>
43
+ <bitmap android:gravity="center" android:src="@drawable/orvyn_splash_image" />
44
+ </item>` : ""}
45
+ </layer-list>
46
+ `
47
+ });
48
+ const theme = (extra) => `<?xml version="1.0" encoding="utf-8"?>
49
+ <resources>
50
+ <color name="orvyn_splash_color">${splash.color}</color>
51
+ <style name="OrvynTheme" parent="@android:style/Theme.Material.Light.NoActionBar">
52
+ <item name="android:windowBackground">@drawable/orvyn_splash</item>${extra}
53
+ </style>
54
+ </resources>
55
+ `;
56
+ files.push({ path: `${res}/values/orvyn.xml`, content: theme("") });
57
+ files.push({
58
+ path: `${res}/values-v31/orvyn.xml`,
59
+ content: theme(`
60
+ <item name="android:windowSplashScreenBackground">@color/orvyn_splash_color</item>`).replace(/ +<color name.*\n/, "")
61
+ });
62
+ return files;
63
+ }
15
64
  function generateAndroidProject(appJs, config) {
16
65
  const minSdk = config.minSdk ?? 24;
17
- const targetSdk = config.targetSdk ?? 34;
66
+ const targetSdk = config.targetSdk ?? 36;
18
67
  const kotlinDir = "app/src/main/java/dev/orvyn/runtime";
19
68
  const rootName = config.appName.replace(/[^A-Za-z0-9 _-]/g, "") || "OrvynApp";
20
- const kotlin = ["MainActivity.kt", "OrvynEngine.kt", "OrvynRenderer.kt"].map((name) => ({
69
+ const kotlin = ["MainActivity.kt", "OrvynEngine.kt", "OrvynRenderer.kt", "OrvynDevice.kt"].map((name) => ({
21
70
  path: `${kotlinDir}/${name}`,
22
71
  content: readFileSync(join(templateDir, name), "utf-8")
23
72
  }));
73
+ const permissions = ["INTERNET", ...Object.keys(config.permissions ?? {}).flatMap((name) => PERMISSIONS[name].android)].map((name) => ` <uses-permission android:name="android.permission.${name}" />`).join("\n");
24
74
  return [
25
75
  ...kotlin,
76
+ ...resources(config),
77
+ // debug builds only: live reload loads code from your computer over http
78
+ {
79
+ path: "app/src/debug/AndroidManifest.xml",
80
+ content: `<?xml version="1.0" encoding="utf-8"?>
81
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
82
+ <application android:usesCleartextTraffic="true" />
83
+ </manifest>
84
+ `
85
+ },
26
86
  { path: "app/src/main/assets/app.js", content: appJs },
27
87
  {
28
88
  path: "app/src/main/AndroidManifest.xml",
29
89
  content: `<?xml version="1.0" encoding="utf-8"?>
30
90
  <manifest xmlns:android="http://schemas.android.com/apk/res/android">
31
91
 
32
- <uses-permission android:name="android.permission.INTERNET" />
92
+ ${permissions}
33
93
 
34
94
  <application
35
- android:label="${xml(config.appName)}"
36
- android:theme="@android:style/Theme.Material.Light.NoActionBar">
95
+ android:enableOnBackInvokedCallback="false"
96
+ android:label="${xml(config.appName)}"${config.icon ? `
97
+ android:icon="@drawable/orvyn_icon"` : ""}
98
+ android:theme="${config.splash ? "@style/OrvynTheme" : "@android:style/Theme.Material.Light.NoActionBar"}">
37
99
  <activity
38
100
  android:name="dev.orvyn.runtime.MainActivity"
39
101
  android:exported="true"
@@ -62,13 +124,14 @@ android {
62
124
  applicationId = ${JSON.stringify(config.appId)}
63
125
  minSdk = ${minSdk}
64
126
  targetSdk = ${targetSdk}
65
- versionCode = ${versionCode(config.version)}
127
+ versionCode = ${config.build ?? versionCode(config.version)}
66
128
  versionName = ${JSON.stringify(config.version)}
67
129
  }
68
130
 
69
- buildTypes {
131
+ ${signing(config)} buildTypes {
70
132
  release {
71
- isMinifyEnabled = false
133
+ isMinifyEnabled = false${config.keystore ? `
134
+ signingConfig = signingConfigs.getByName("release")` : ""}
72
135
  }
73
136
  }
74
137
 
@@ -1,40 +1,19 @@
1
1
  import { spawnSync } from "node:child_process";
2
- import { existsSync, mkdirSync, rmSync, watch, writeFileSync } from "node:fs";
2
+ import { copyFileSync, existsSync, mkdirSync, rmSync, watch, writeFileSync } from "node:fs";
3
3
  import { createServer } from "node:http";
4
- import { basename, dirname, join, resolve } from "node:path";
5
- import { pathToFileURL } from "node:url";
4
+ import { dirname, join, resolve } from "node:path";
6
5
  import { bundleNative } from "../bundle-native.js";
6
+ import { loadEnv } from "../env.js";
7
+ import { loadNativeConfig, releaseProblems } from "./config.js";
7
8
  import { generateIOSProject, iosTargetName } from "./ios.js";
8
9
  import { generateAndroidProject } from "./android.js";
9
- async function loadConfig(cwd, entry) {
10
- const configPath = ["orvyn.config.js", "orvyn.config.mjs", "orvyn.config.ts"].map((name2) => join(cwd, name2)).find((path) => existsSync(path));
11
- let native = {};
12
- if (configPath) {
13
- try {
14
- const mod = await import(pathToFileURL(configPath).href);
15
- native = mod.default?.native || {};
16
- } catch (error) {
17
- console.warn(`[Orvyn] Could not read ${basename(configPath)} (${error.message}). Using default app name and id.`);
18
- }
19
- }
20
- const name = basename(entry, ".orv");
21
- const appName = native.appName || name.charAt(0).toUpperCase() + name.slice(1);
22
- return {
23
- appName,
24
- appId: native.appId || `com.orvyn.${name.toLowerCase().replace(/[^a-z0-9]/g, "")}`,
25
- version: native.version || "1.0.0",
26
- iosDeploymentTarget: native.ios?.deploymentTarget,
27
- teamId: native.ios?.teamId,
28
- minSdk: native.android?.minSdk,
29
- targetSdk: native.android?.targetSdk
30
- };
31
- }
32
10
  function writeFiles(outDir, files) {
33
11
  rmSync(outDir, { recursive: true, force: true });
34
12
  for (const file of files) {
35
13
  const full = join(outDir, file.path);
36
14
  mkdirSync(dirname(full), { recursive: true });
37
- writeFileSync(full, file.content);
15
+ if (file.copyFrom) copyFileSync(file.copyFrom, full);
16
+ else writeFileSync(full, file.content);
38
17
  }
39
18
  }
40
19
  function has(command, args = ["--version"]) {
@@ -43,19 +22,33 @@ function has(command, args = ["--version"]) {
43
22
  }
44
23
  async function buildNativeApp(target, entry, options) {
45
24
  const { cwd, log } = options;
46
- const config = await loadConfig(cwd, entry);
25
+ const config = await loadNativeConfig(cwd, entry);
47
26
  const outDir = join(cwd, "dist", target);
48
- log(`[Orvyn] Compiling ${entry} for ${target === "ios" ? "iOS" : "Android"}...`);
49
- const appJs = await bundleNative(resolve(cwd, entry));
27
+ if (options.release) {
28
+ const problems = releaseProblems(target, config);
29
+ if (problems.length) {
30
+ throw new Error(`Not ready for a release build:
31
+ ${problems.map((p) => ` - ${p}`).join("\n")}
32
+ Run "orvyn doctor" to check again.`);
33
+ }
34
+ }
35
+ const env = await loadEnv(cwd, options.defaultEnv ?? "prod");
36
+ log(`[Orvyn] Compiling ${entry} for ${target === "ios" ? "iOS" : "Android"} (${env.name})...`);
37
+ const appJs = await bundleNative(resolve(cwd, entry), { appId: config.appId, env });
38
+ for (const [, need] of appJs.matchAll(/__orvyn_needs_(camera|location)/g)) {
39
+ if (!(need in (config.permissions ?? {}))) {
40
+ throw new Error(`This app uses the ${need}. Add to orvyn.config.js: native: { permissions: { ${need}: "Why you need it" } }`);
41
+ }
42
+ }
50
43
  if (target === "ios") {
51
44
  writeFiles(outDir, generateIOSProject(appJs, config));
52
45
  const name = iosTargetName(config.appName);
53
46
  log(`[Orvyn] \u2713 Xcode project \u2192 dist/ios/${name}.xcodeproj`);
54
- return compileIOS(outDir, name, log);
47
+ return options.release ? releaseIOS(outDir, name, config, log) : compileIOS(outDir, name, log);
55
48
  }
56
49
  writeFiles(outDir, generateAndroidProject(appJs, config));
57
50
  log("[Orvyn] \u2713 Android Studio project \u2192 dist/android/");
58
- return compileAndroid(outDir, log);
51
+ return compileAndroid(outDir, log, Boolean(options.release));
59
52
  }
60
53
  function compileIOS(outDir, name, log) {
61
54
  if (!has("xcodebuild", ["-version"])) {
@@ -93,7 +86,64 @@ ${result.stderr}`.split("\n").filter((line) => line.includes("error:")).slice(0,
93
86
  log(` To run on a real iPhone or publish: open dist/ios/${name}.xcodeproj in Xcode`);
94
87
  return { outDir, compiled: true, appPath };
95
88
  }
96
- function compileAndroid(outDir, log) {
89
+ function iosReleaseSteps(outDir, name) {
90
+ const archive = join(outDir, "build", `${name}.xcarchive`);
91
+ return [
92
+ [
93
+ "-project",
94
+ `${name}.xcodeproj`,
95
+ "-scheme",
96
+ name,
97
+ "-configuration",
98
+ "Release",
99
+ "-destination",
100
+ "generic/platform=iOS",
101
+ "-archivePath",
102
+ archive,
103
+ "-allowProvisioningUpdates",
104
+ "archive"
105
+ ],
106
+ [
107
+ "-exportArchive",
108
+ "-archivePath",
109
+ archive,
110
+ "-exportOptionsPlist",
111
+ join(outDir, "ExportOptions.plist"),
112
+ "-exportPath",
113
+ join(outDir, "build", "ipa"),
114
+ "-allowProvisioningUpdates"
115
+ ]
116
+ ];
117
+ }
118
+ function exportOptions(config) {
119
+ return `<?xml version="1.0" encoding="UTF-8"?>
120
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
121
+ <plist version="1.0">
122
+ <dict>
123
+ <key>method</key>
124
+ <string>${config.exportMethod ?? "app-store-connect"}</string>
125
+ <key>teamID</key>
126
+ <string>${config.teamId}</string>
127
+ </dict>
128
+ </plist>
129
+ `;
130
+ }
131
+ function releaseIOS(outDir, name, config, log) {
132
+ if (!has("xcodebuild", ["-version"])) throw new Error("A release build needs Xcode");
133
+ writeFileSync(join(outDir, "ExportOptions.plist"), exportOptions(config));
134
+ log("[Orvyn] Archiving and signing with Xcode...");
135
+ for (const args of iosReleaseSteps(outDir, name)) {
136
+ const result = spawnSync("xcodebuild", args, { cwd: outDir, encoding: "utf-8", maxBuffer: 256 * 1024 * 1024 });
137
+ if (result.status !== 0) {
138
+ `${result.stdout}
139
+ ${result.stderr}`.split("\n").filter((line) => line.includes("error:")).slice(0, 10).forEach((line) => log(` ${line.trim()}`));
140
+ throw new Error("iOS release build failed");
141
+ }
142
+ }
143
+ log("[Orvyn] \u2713 Signed app \u2192 dist/ios/build/ipa/");
144
+ return { outDir, compiled: true };
145
+ }
146
+ function compileAndroid(outDir, log, release = false) {
97
147
  const sdk = process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT || join(process.env.HOME || "", "Library/Android/sdk");
98
148
  const hasSdk = existsSync(sdk);
99
149
  const hasJava = has("java", ["-version"]);
@@ -107,24 +157,26 @@ function compileAndroid(outDir, log) {
107
157
  log(`[Orvyn] Not compiled into an APK here (missing: ${missing}).`);
108
158
  log(" Open dist/android/ in Android Studio and press Run,");
109
159
  log(" or install those tools and run this command again.");
160
+ if (release) throw new Error("No release build was made");
110
161
  return { outDir, compiled: false };
111
162
  }
112
163
  writeFileSync(join(outDir, "local.properties"), `sdk.dir=${sdk}
113
164
  `);
114
- log("[Orvyn] Building APK with Gradle...");
115
- const result = spawnSync("gradle", ["assembleDebug", "--quiet"], { cwd: outDir, stdio: "inherit" });
165
+ log(`[Orvyn] Building ${release ? "a signed app bundle" : "APK"} with Gradle...`);
166
+ const result = spawnSync("gradle", [release ? "bundleRelease" : "assembleDebug", "--quiet"], { cwd: outDir, stdio: "inherit" });
116
167
  if (result.status !== 0) {
117
168
  log("[Orvyn] \u2717 Android build failed (see the Gradle errors above)");
118
169
  throw new Error("Android build failed");
119
170
  }
120
- const appPath = join(outDir, "app/build/outputs/apk/debug/app-debug.apk");
121
- log("[Orvyn] \u2713 Android app built \u2192 dist/android/app/build/outputs/apk/debug/app-debug.apk");
171
+ const output = release ? "app/build/outputs/bundle/release/app-release.aab" : "app/build/outputs/apk/debug/app-debug.apk";
172
+ const appPath = join(outDir, output);
173
+ log(`[Orvyn] \u2713 Android app built \u2192 dist/android/${output}`);
122
174
  return { outDir, compiled: true, appPath };
123
175
  }
124
176
  async function runNativeApp(target, entry, options) {
125
177
  const { log } = options;
126
- const result = await buildNativeApp(target, entry, options);
127
- const config = await loadConfig(options.cwd, entry);
178
+ const result = await buildNativeApp(target, entry, { ...options, defaultEnv: "dev" });
179
+ const config = await loadNativeConfig(options.cwd, entry);
128
180
  if (!result.compiled || !result.appPath) {
129
181
  throw new Error(`Can't run: the ${target} app was not compiled on this computer`);
130
182
  }
@@ -151,15 +203,12 @@ async function runNativeApp(target, entry, options) {
151
203
  const DEV_PORT = 8790;
152
204
  async function devNativeApp(target, entry, options) {
153
205
  const { cwd, log } = options;
154
- if (target !== "ios") {
155
- throw new Error("Live reload is iOS-only for now. For Android use: orvyn run android " + entry);
156
- }
157
206
  let code = "";
158
207
  let version = 0;
159
208
  const rebuild = async (reason) => {
160
209
  const started = Date.now();
161
210
  try {
162
- code = await bundleNative(resolve(cwd, entry));
211
+ code = await bundleNative(resolve(cwd, entry), { dev: true, env: await loadEnv(cwd, "dev") });
163
212
  version++;
164
213
  log(`[Orvyn] ${reason} \u2192 reloaded in ${Date.now() - started}ms`);
165
214
  } catch (error) {
@@ -186,22 +235,11 @@ async function devNativeApp(target, entry, options) {
186
235
  server.once("error", (error) => fail(error.code === "EADDRINUSE" ? new Error(`Port ${DEV_PORT} is busy. Is another "orvyn dev ios" running?`) : error));
187
236
  server.listen(DEV_PORT, "127.0.0.1", () => done());
188
237
  });
189
- const result = await buildNativeApp(target, entry, options);
190
- const config = await loadConfig(cwd, entry);
191
- if (!result.appPath) throw new Error("The iOS app was not compiled");
192
- const device = pickSimulator();
193
- if (!device) throw new Error("No iPhone simulator found. Add one in Xcode \u2192 Settings \u2192 Platforms");
238
+ const result = await buildNativeApp(target, entry, { ...options, defaultEnv: "dev" });
239
+ const config = await loadNativeConfig(cwd, entry);
240
+ if (!result.appPath) throw new Error(`The ${target} app was not compiled. Run "orvyn doctor"`);
194
241
  const devUrl = `http://127.0.0.1:${DEV_PORT}`;
195
- log(`[Orvyn] Starting ${device.name}...`);
196
- spawnSync("xcrun", ["simctl", "boot", device.udid], { stdio: "ignore" });
197
- spawnSync("open", ["-a", "Simulator"], { stdio: "ignore" });
198
- spawnSync("xcrun", ["simctl", "bootstatus", device.udid, "-b"], { stdio: "ignore" });
199
- spawnSync("xcrun", ["simctl", "install", device.udid, result.appPath], { stdio: "ignore" });
200
- const launch = () => spawnSync(
201
- "xcrun",
202
- ["simctl", "launch", "--terminate-running-process", device.udid, config.appId],
203
- { stdio: "ignore", env: { ...process.env, SIMCTL_CHILD_ORVYN_DEV_SERVER: devUrl } }
204
- );
242
+ const { deviceName, launch } = target === "ios" ? startIOSDev(result.appPath, config.appId, devUrl, log) : startAndroidDev(result.appPath, config.appId, devUrl);
205
243
  launch();
206
244
  const watchDir = dirname(resolve(cwd, entry));
207
245
  let timer = null;
@@ -211,11 +249,11 @@ async function devNativeApp(target, entry, options) {
211
249
  timer = setTimeout(() => rebuild(`${file} changed`), 80);
212
250
  });
213
251
  log("");
214
- log(`[Orvyn] \u2713 ${config.appName} is running on ${device.name} with live reload`);
252
+ log(`[Orvyn] \u2713 ${config.appName} is running on ${deviceName} with live reload`);
215
253
  log("");
216
254
  log(" Save any .orv file \u2192 the app reloads by itself");
217
255
  log(" r \u2192 reload now");
218
- log(" Cmd+R in simulator \u2192 reload now");
256
+ if (target === "ios") log(" Cmd+R in simulator \u2192 reload now");
219
257
  log(" l \u2192 relaunch the app");
220
258
  log(" q \u2192 quit");
221
259
  log("");
@@ -239,6 +277,36 @@ async function devNativeApp(target, entry, options) {
239
277
  await new Promise(() => {
240
278
  });
241
279
  }
280
+ function startIOSDev(appPath, appId, devUrl, log) {
281
+ const device = pickSimulator();
282
+ if (!device) throw new Error("No iPhone simulator found. Add one in Xcode \u2192 Settings \u2192 Platforms");
283
+ log(`[Orvyn] Starting ${device.name}...`);
284
+ spawnSync("xcrun", ["simctl", "boot", device.udid], { stdio: "ignore" });
285
+ spawnSync("open", ["-a", "Simulator"], { stdio: "ignore" });
286
+ spawnSync("xcrun", ["simctl", "bootstatus", device.udid, "-b"], { stdio: "ignore" });
287
+ spawnSync("xcrun", ["simctl", "install", device.udid, appPath], { stdio: "ignore" });
288
+ return {
289
+ deviceName: device.name,
290
+ launch: () => spawnSync(
291
+ "xcrun",
292
+ ["simctl", "launch", "--terminate-running-process", device.udid, appId],
293
+ { stdio: "ignore", env: { ...process.env, SIMCTL_CHILD_ORVYN_DEV_SERVER: devUrl } }
294
+ )
295
+ };
296
+ }
297
+ function startAndroidDev(appPath, appId, devUrl) {
298
+ const adb = (...args) => spawnSync("adb", args, { encoding: "utf-8" });
299
+ if (adb("install", "-r", appPath).status !== 0) {
300
+ throw new Error("adb install failed. Start an Android emulator or connect a phone first");
301
+ }
302
+ if (adb("reverse", `tcp:${DEV_PORT}`, `tcp:${DEV_PORT}`).status !== 0) {
303
+ throw new Error("adb reverse failed. Connect only one device or emulator");
304
+ }
305
+ return {
306
+ deviceName: "Android",
307
+ launch: () => adb("shell", "am", "start", "-S", "-n", `${appId}/dev.orvyn.runtime.MainActivity`, "--es", "orvynDevServer", devUrl)
308
+ };
309
+ }
242
310
  function pickSimulator() {
243
311
  const result = spawnSync("xcrun", ["simctl", "list", "devices", "available", "--json"], { encoding: "utf-8" });
244
312
  if (result.status !== 0) return null;
@@ -248,5 +316,7 @@ function pickSimulator() {
248
316
  export {
249
317
  buildNativeApp,
250
318
  devNativeApp,
319
+ exportOptions,
320
+ iosReleaseSteps,
251
321
  runNativeApp
252
322
  };
@@ -0,0 +1,108 @@
1
+ import { closeSync, existsSync, openSync, readSync } from "node:fs";
2
+ import { basename, join, resolve } from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ const PERMISSIONS = {
5
+ camera: { ios: ["NSCameraUsageDescription"], android: ["CAMERA"], why: "use the camera" },
6
+ microphone: { ios: ["NSMicrophoneUsageDescription"], android: ["RECORD_AUDIO"], why: "use the microphone" },
7
+ location: { ios: ["NSLocationWhenInUseUsageDescription"], android: ["ACCESS_COARSE_LOCATION", "ACCESS_FINE_LOCATION"], why: "use your location" },
8
+ photos: { ios: ["NSPhotoLibraryUsageDescription"], android: ["READ_MEDIA_IMAGES"], why: "use your photos" },
9
+ contacts: { ios: ["NSContactsUsageDescription"], android: ["READ_CONTACTS"], why: "use your contacts" },
10
+ // iPhone asks for notifications while the app runs; there is nothing to declare
11
+ notifications: { ios: [], android: ["POST_NOTIFICATIONS"], why: "send notifications" }
12
+ };
13
+ function configFile(dir) {
14
+ return ["orvyn.config.js", "orvyn.config.mjs", "orvyn.config.ts"].map((name) => join(dir, name)).find((path) => existsSync(path));
15
+ }
16
+ function pngInfo(path) {
17
+ const header = Buffer.alloc(26);
18
+ const file = openSync(path, "r");
19
+ try {
20
+ readSync(file, header, 0, 26, 0);
21
+ } finally {
22
+ closeSync(file);
23
+ }
24
+ if (header.toString("hex", 0, 8) !== "89504e470d0a1a0a") return null;
25
+ return { width: header.readUInt32BE(16), height: header.readUInt32BE(20), alpha: header[25] === 4 || header[25] === 6 };
26
+ }
27
+ function image(cwd, value, label) {
28
+ const path = resolve(cwd, String(value));
29
+ if (!existsSync(path)) throw new Error(`${label}: file not found: ${value}`);
30
+ if (!pngInfo(path)) throw new Error(`${label} must be a PNG file: ${value}`);
31
+ return path;
32
+ }
33
+ async function loadNativeConfig(cwd, entry) {
34
+ const path = configFile(cwd);
35
+ let native = {};
36
+ if (path) {
37
+ try {
38
+ native = (await import(pathToFileURL(path).href)).default?.native || {};
39
+ } catch (error) {
40
+ throw new Error(`Could not read ${basename(path)}: ${error.message}`);
41
+ }
42
+ }
43
+ let icon;
44
+ if (native.icon) {
45
+ icon = image(cwd, native.icon, "native.icon");
46
+ const info = pngInfo(icon);
47
+ if (info.width !== 1024 || info.height !== 1024) {
48
+ throw new Error(`native.icon must be 1024 x 1024 pixels, but is ${info.width} x ${info.height}`);
49
+ }
50
+ }
51
+ let splash;
52
+ if (native.splash) {
53
+ const color = native.splash.color ?? "#ffffff";
54
+ if (!/^#[0-9a-fA-F]{6}$/.test(color)) throw new Error(`native.splash.color must look like "#1d4ed8"`);
55
+ splash = { color, ...native.splash.image ? { image: image(cwd, native.splash.image, "native.splash.image") } : {} };
56
+ }
57
+ const permissions = {};
58
+ const asked = Array.isArray(native.permissions) ? native.permissions.map((name2) => [name2, ""]) : Object.entries(native.permissions ?? {});
59
+ for (const [name2, reason] of asked) {
60
+ if (!Object.hasOwn(PERMISSIONS, name2)) {
61
+ throw new Error(`Unknown permission "${name2}". Available: ${Object.keys(PERMISSIONS).join(", ")}`);
62
+ }
63
+ permissions[name2] = String(reason || "");
64
+ }
65
+ const name = basename(entry, ".orv");
66
+ const appName = native.appName || name.charAt(0).toUpperCase() + name.slice(1);
67
+ return {
68
+ appName,
69
+ appId: native.appId || `com.orvyn.${name.toLowerCase().replace(/[^a-z0-9]/g, "")}`,
70
+ version: native.version || "1.0.0",
71
+ build: native.build,
72
+ icon,
73
+ splash,
74
+ permissions,
75
+ iosDeploymentTarget: native.ios?.deploymentTarget,
76
+ teamId: native.ios?.teamId,
77
+ exportMethod: native.ios?.exportMethod,
78
+ keystore: native.android?.keystore ? resolve(cwd, native.android.keystore) : void 0,
79
+ keyAlias: native.android?.keyAlias,
80
+ minSdk: native.android?.minSdk,
81
+ targetSdk: native.android?.targetSdk
82
+ };
83
+ }
84
+ function releaseProblems(target, config, env = process.env) {
85
+ const problems = [];
86
+ if (/^com\.(example|orvyn)\./.test(config.appId)) problems.push(`Set native.appId to your own id (not "${config.appId}")`);
87
+ if (!config.icon) problems.push("Add native.icon: a 1024 x 1024 PNG");
88
+ if (target === "ios") {
89
+ if (config.icon && pngInfo(config.icon)?.alpha) problems.push("The App Store refuses icons with transparency. Export native.icon without an alpha channel");
90
+ if (!config.teamId) problems.push("Add native.ios.teamId (Apple Developer \u2192 Membership details)");
91
+ for (const [name, reason] of Object.entries(config.permissions ?? {})) {
92
+ if (!reason && PERMISSIONS[name].ios.length) problems.push(`Say why you need "${name}": permissions: { ${name}: "To ..." }`);
93
+ }
94
+ } else {
95
+ if (!config.keystore) problems.push("Add native.android.keystore: the path to your signing key");
96
+ else if (!existsSync(config.keystore)) problems.push(`Keystore not found: ${config.keystore}`);
97
+ if (!config.keyAlias) problems.push("Add native.android.keyAlias");
98
+ if (!env.ORVYN_KEYSTORE_PASSWORD) problems.push("Set the ORVYN_KEYSTORE_PASSWORD environment variable");
99
+ }
100
+ return problems;
101
+ }
102
+ export {
103
+ PERMISSIONS,
104
+ configFile,
105
+ loadNativeConfig,
106
+ pngInfo,
107
+ releaseProblems
108
+ };
@@ -1,9 +1,15 @@
1
1
  // Generated by Orvyn. Do not edit; rebuild with `orvyn build ios app.orv`.
2
2
 
3
+ import Foundation
3
4
  import SwiftUI
4
5
 
5
6
  @main
6
7
  struct OrvynMainApp: App {
8
+ init() {
9
+ // AsyncImage loads through the shared cache; give it room for pictures
10
+ URLCache.shared = URLCache(memoryCapacity: 50_000_000, diskCapacity: 200_000_000)
11
+ }
12
+
7
13
  var body: some Scene {
8
14
  WindowGroup {
9
15
  OrvynRootView()