orvyn-lang 0.2.0 → 0.4.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 (63) hide show
  1. package/GUIDE.md +198 -0
  2. package/LANGUAGE.md +818 -30
  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 +207 -16
  7. package/src/core/signal.js +104 -6
  8. package/src/devtools/runtime.js +25 -1
  9. package/src/lang/a11y.js +152 -0
  10. package/src/lang/auth.js +239 -0
  11. package/src/lang/bundle-native.js +10 -6
  12. package/src/lang/codegen.js +615 -58
  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 +65 -4
  22. package/src/lang/native/android/OrvynDevice.kt +163 -0
  23. package/src/lang/native/android/OrvynEngine.kt +176 -7
  24. package/src/lang/native/android/OrvynRenderer.kt +970 -50
  25. package/src/lang/native/android.js +74 -11
  26. package/src/lang/native/assets.js +39 -0
  27. package/src/lang/native/build.js +140 -63
  28. package/src/lang/native/compatibility.js +57 -0
  29. package/src/lang/native/config.js +108 -0
  30. package/src/lang/native/ios/OrvynApp.swift +6 -0
  31. package/src/lang/native/ios/OrvynEngine.swift +291 -4
  32. package/src/lang/native/ios/OrvynViews.swift +769 -41
  33. package/src/lang/native/ios.js +81 -2
  34. package/src/lang/native-runtime.js +541 -55
  35. package/src/lang/native-size.js +53 -0
  36. package/src/lang/page-files.js +71 -0
  37. package/src/lang/page.js +63 -0
  38. package/src/lang/parser.js +278 -15
  39. package/src/lang/prerender.js +300 -0
  40. package/src/lang/read-import.js +12 -0
  41. package/src/lang/router.js +266 -0
  42. package/src/lang/runtime-shared.js +796 -10
  43. package/src/lang/runtime.js +399 -51
  44. package/src/lang/select.js +13 -0
  45. package/src/lang/server-code.js +233 -0
  46. package/src/lang/server-export.js +78 -0
  47. package/src/lang/server-libs.js +53 -0
  48. package/src/lang/server.js +409 -0
  49. package/src/lang/style-check.js +60 -0
  50. package/src/lang/test-runner.js +134 -0
  51. package/src/lang/types.js +317 -0
  52. package/src/lang/vite-plugin.js +108 -6
  53. package/src/lang/web-overlay.js +578 -0
  54. package/src/lang/widgets.js +94 -0
  55. package/src/lang/words.js +38 -0
  56. package/src/runtime/animations.js +24 -0
  57. package/src/runtime/appear.js +73 -0
  58. package/src/runtime/marquee.js +57 -0
  59. package/src/runtime/mount.js +120 -27
  60. package/src/runtime/patch.js +90 -11
  61. package/src/runtime/style.js +50 -9
  62. package/src/styling/fluid.js +129 -6
  63. package/src/styling/spec.js +319 -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
 
@@ -0,0 +1,39 @@
1
+ import { existsSync, readdirSync, statSync } from "node:fs";
2
+ import { join, relative, sep } from "node:path";
3
+ const IMAGE_TYPES = {
4
+ png: "image/png",
5
+ jpg: "image/jpeg",
6
+ jpeg: "image/jpeg",
7
+ webp: "image/webp",
8
+ gif: "image/gif",
9
+ avif: "image/avif"
10
+ };
11
+ function publicImages(cwd) {
12
+ const root = join(cwd, "public");
13
+ const found = [];
14
+ const visit = (dir) => {
15
+ for (const name of readdirSync(dir).sort()) {
16
+ const full = join(dir, name);
17
+ if (statSync(full).isDirectory()) {
18
+ visit(full);
19
+ continue;
20
+ }
21
+ const ext = name.split(".").pop()?.toLowerCase() ?? "";
22
+ if (IMAGE_TYPES[ext]) found.push({ path: "/" + relative(root, full).split(sep).join("/"), file: full });
23
+ }
24
+ };
25
+ if (existsSync(root)) visit(root);
26
+ return found;
27
+ }
28
+ function nativeAssetPrelude(cwd) {
29
+ return `globalThis.__orvynAssets = ${JSON.stringify(publicImages(cwd).map((image) => image.path))};
30
+ `;
31
+ }
32
+ function bundledImages(cwd, folder) {
33
+ return publicImages(cwd).map((image) => ({ path: folder + image.path, content: "", copyFrom: image.file }));
34
+ }
35
+ export {
36
+ bundledImages,
37
+ nativeAssetPrelude,
38
+ publicImages
39
+ };
@@ -1,40 +1,21 @@
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
- }
10
+ import { bundledImages, nativeAssetPrelude } from "./assets.js";
11
+ import { checkNativeProject } from "./compatibility.js";
32
12
  function writeFiles(outDir, files) {
33
13
  rmSync(outDir, { recursive: true, force: true });
34
14
  for (const file of files) {
35
15
  const full = join(outDir, file.path);
36
16
  mkdirSync(dirname(full), { recursive: true });
37
- writeFileSync(full, file.content);
17
+ if (file.copyFrom) copyFileSync(file.copyFrom, full);
18
+ else writeFileSync(full, file.content);
38
19
  }
39
20
  }
40
21
  function has(command, args = ["--version"]) {
@@ -43,19 +24,36 @@ function has(command, args = ["--version"]) {
43
24
  }
44
25
  async function buildNativeApp(target, entry, options) {
45
26
  const { cwd, log } = options;
46
- const config = await loadConfig(cwd, entry);
27
+ const config = await loadNativeConfig(cwd, entry);
47
28
  const outDir = join(cwd, "dist", target);
48
- log(`[Orvyn] Compiling ${entry} for ${target === "ios" ? "iOS" : "Android"}...`);
49
- const appJs = await bundleNative(resolve(cwd, entry));
29
+ if (options.release) {
30
+ const problems = releaseProblems(target, config);
31
+ if (problems.length) {
32
+ throw new Error(`Not ready for a release build:
33
+ ${problems.map((p) => ` - ${p}`).join("\n")}
34
+ Run "orvyn doctor" to check again.`);
35
+ }
36
+ }
37
+ const env = await loadEnv(cwd, options.defaultEnv ?? "prod");
38
+ for (const warning of checkNativeProject(resolve(cwd, entry))) {
39
+ log(`[Orvyn] \u26A0 ${warning.file}:${warning.line}:${warning.col} ${warning.message}`);
40
+ }
41
+ log(`[Orvyn] Compiling ${entry} for ${target === "ios" ? "iOS" : "Android"} (${env.name})...`);
42
+ const appJs = nativeAssetPrelude(cwd) + await bundleNative(resolve(cwd, entry), { appId: config.appId, env });
43
+ for (const [, need] of appJs.matchAll(/__orvyn_needs_(camera|location)/g)) {
44
+ if (!(need in (config.permissions ?? {}))) {
45
+ throw new Error(`This app uses the ${need}. Add to orvyn.config.js: native: { permissions: { ${need}: "Why you need it" } }`);
46
+ }
47
+ }
50
48
  if (target === "ios") {
51
- writeFiles(outDir, generateIOSProject(appJs, config));
49
+ writeFiles(outDir, [...generateIOSProject(appJs, config), ...bundledImages(cwd, `${iosTargetName(config.appName)}/public`)]);
52
50
  const name = iosTargetName(config.appName);
53
51
  log(`[Orvyn] \u2713 Xcode project \u2192 dist/ios/${name}.xcodeproj`);
54
- return compileIOS(outDir, name, log);
52
+ return options.release ? releaseIOS(outDir, name, config, log) : compileIOS(outDir, name, log);
55
53
  }
56
- writeFiles(outDir, generateAndroidProject(appJs, config));
54
+ writeFiles(outDir, [...generateAndroidProject(appJs, config), ...bundledImages(cwd, "app/src/main/assets/public")]);
57
55
  log("[Orvyn] \u2713 Android Studio project \u2192 dist/android/");
58
- return compileAndroid(outDir, log);
56
+ return compileAndroid(outDir, log, Boolean(options.release));
59
57
  }
60
58
  function compileIOS(outDir, name, log) {
61
59
  if (!has("xcodebuild", ["-version"])) {
@@ -93,7 +91,64 @@ ${result.stderr}`.split("\n").filter((line) => line.includes("error:")).slice(0,
93
91
  log(` To run on a real iPhone or publish: open dist/ios/${name}.xcodeproj in Xcode`);
94
92
  return { outDir, compiled: true, appPath };
95
93
  }
96
- function compileAndroid(outDir, log) {
94
+ function iosReleaseSteps(outDir, name) {
95
+ const archive = join(outDir, "build", `${name}.xcarchive`);
96
+ return [
97
+ [
98
+ "-project",
99
+ `${name}.xcodeproj`,
100
+ "-scheme",
101
+ name,
102
+ "-configuration",
103
+ "Release",
104
+ "-destination",
105
+ "generic/platform=iOS",
106
+ "-archivePath",
107
+ archive,
108
+ "-allowProvisioningUpdates",
109
+ "archive"
110
+ ],
111
+ [
112
+ "-exportArchive",
113
+ "-archivePath",
114
+ archive,
115
+ "-exportOptionsPlist",
116
+ join(outDir, "ExportOptions.plist"),
117
+ "-exportPath",
118
+ join(outDir, "build", "ipa"),
119
+ "-allowProvisioningUpdates"
120
+ ]
121
+ ];
122
+ }
123
+ function exportOptions(config) {
124
+ return `<?xml version="1.0" encoding="UTF-8"?>
125
+ <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
126
+ <plist version="1.0">
127
+ <dict>
128
+ <key>method</key>
129
+ <string>${config.exportMethod ?? "app-store-connect"}</string>
130
+ <key>teamID</key>
131
+ <string>${config.teamId}</string>
132
+ </dict>
133
+ </plist>
134
+ `;
135
+ }
136
+ function releaseIOS(outDir, name, config, log) {
137
+ if (!has("xcodebuild", ["-version"])) throw new Error("A release build needs Xcode");
138
+ writeFileSync(join(outDir, "ExportOptions.plist"), exportOptions(config));
139
+ log("[Orvyn] Archiving and signing with Xcode...");
140
+ for (const args of iosReleaseSteps(outDir, name)) {
141
+ const result = spawnSync("xcodebuild", args, { cwd: outDir, encoding: "utf-8", maxBuffer: 256 * 1024 * 1024 });
142
+ if (result.status !== 0) {
143
+ `${result.stdout}
144
+ ${result.stderr}`.split("\n").filter((line) => line.includes("error:")).slice(0, 10).forEach((line) => log(` ${line.trim()}`));
145
+ throw new Error("iOS release build failed");
146
+ }
147
+ }
148
+ log("[Orvyn] \u2713 Signed app \u2192 dist/ios/build/ipa/");
149
+ return { outDir, compiled: true };
150
+ }
151
+ function compileAndroid(outDir, log, release = false) {
97
152
  const sdk = process.env.ANDROID_HOME || process.env.ANDROID_SDK_ROOT || join(process.env.HOME || "", "Library/Android/sdk");
98
153
  const hasSdk = existsSync(sdk);
99
154
  const hasJava = has("java", ["-version"]);
@@ -107,24 +162,26 @@ function compileAndroid(outDir, log) {
107
162
  log(`[Orvyn] Not compiled into an APK here (missing: ${missing}).`);
108
163
  log(" Open dist/android/ in Android Studio and press Run,");
109
164
  log(" or install those tools and run this command again.");
165
+ if (release) throw new Error("No release build was made");
110
166
  return { outDir, compiled: false };
111
167
  }
112
168
  writeFileSync(join(outDir, "local.properties"), `sdk.dir=${sdk}
113
169
  `);
114
- log("[Orvyn] Building APK with Gradle...");
115
- const result = spawnSync("gradle", ["assembleDebug", "--quiet"], { cwd: outDir, stdio: "inherit" });
170
+ log(`[Orvyn] Building ${release ? "a signed app bundle" : "APK"} with Gradle...`);
171
+ const result = spawnSync("gradle", [release ? "bundleRelease" : "assembleDebug", "--quiet"], { cwd: outDir, stdio: "inherit" });
116
172
  if (result.status !== 0) {
117
173
  log("[Orvyn] \u2717 Android build failed (see the Gradle errors above)");
118
174
  throw new Error("Android build failed");
119
175
  }
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");
176
+ const output = release ? "app/build/outputs/bundle/release/app-release.aab" : "app/build/outputs/apk/debug/app-debug.apk";
177
+ const appPath = join(outDir, output);
178
+ log(`[Orvyn] \u2713 Android app built \u2192 dist/android/${output}`);
122
179
  return { outDir, compiled: true, appPath };
123
180
  }
124
181
  async function runNativeApp(target, entry, options) {
125
182
  const { log } = options;
126
- const result = await buildNativeApp(target, entry, options);
127
- const config = await loadConfig(options.cwd, entry);
183
+ const result = await buildNativeApp(target, entry, { ...options, defaultEnv: "dev" });
184
+ const config = await loadNativeConfig(options.cwd, entry);
128
185
  if (!result.compiled || !result.appPath) {
129
186
  throw new Error(`Can't run: the ${target} app was not compiled on this computer`);
130
187
  }
@@ -151,15 +208,14 @@ async function runNativeApp(target, entry, options) {
151
208
  const DEV_PORT = 8790;
152
209
  async function devNativeApp(target, entry, options) {
153
210
  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
211
  let code = "";
158
212
  let version = 0;
213
+ const launchAssets = nativeAssetPrelude(cwd);
159
214
  const rebuild = async (reason) => {
160
215
  const started = Date.now();
161
216
  try {
162
- code = await bundleNative(resolve(cwd, entry));
217
+ if (nativeAssetPrelude(cwd) !== launchAssets) log("[Orvyn] public/ images changed. Restart `orvyn dev` to put them in the app");
218
+ code = launchAssets + await bundleNative(resolve(cwd, entry), { dev: true, env: await loadEnv(cwd, "dev") });
163
219
  version++;
164
220
  log(`[Orvyn] ${reason} \u2192 reloaded in ${Date.now() - started}ms`);
165
221
  } catch (error) {
@@ -186,36 +242,25 @@ async function devNativeApp(target, entry, options) {
186
242
  server.once("error", (error) => fail(error.code === "EADDRINUSE" ? new Error(`Port ${DEV_PORT} is busy. Is another "orvyn dev ios" running?`) : error));
187
243
  server.listen(DEV_PORT, "127.0.0.1", () => done());
188
244
  });
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");
245
+ const result = await buildNativeApp(target, entry, { ...options, defaultEnv: "dev" });
246
+ const config = await loadNativeConfig(cwd, entry);
247
+ if (!result.appPath) throw new Error(`The ${target} app was not compiled. Run "orvyn doctor"`);
194
248
  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
- );
249
+ const { deviceName, launch } = target === "ios" ? startIOSDev(result.appPath, config.appId, devUrl, log) : startAndroidDev(result.appPath, config.appId, devUrl);
205
250
  launch();
206
251
  const watchDir = dirname(resolve(cwd, entry));
207
252
  let timer = null;
208
253
  watch(watchDir, { recursive: true }, (_event, file) => {
209
- if (!file || !String(file).endsWith(".orv")) return;
254
+ if (!file || !/\.(orv|m?js|ts)$/.test(String(file))) return;
210
255
  if (timer) clearTimeout(timer);
211
256
  timer = setTimeout(() => rebuild(`${file} changed`), 80);
212
257
  });
213
258
  log("");
214
- log(`[Orvyn] \u2713 ${config.appName} is running on ${device.name} with live reload`);
259
+ log(`[Orvyn] \u2713 ${config.appName} is running on ${deviceName} with live reload`);
215
260
  log("");
216
261
  log(" Save any .orv file \u2192 the app reloads by itself");
217
262
  log(" r \u2192 reload now");
218
- log(" Cmd+R in simulator \u2192 reload now");
263
+ if (target === "ios") log(" Cmd+R in simulator \u2192 reload now");
219
264
  log(" l \u2192 relaunch the app");
220
265
  log(" q \u2192 quit");
221
266
  log("");
@@ -239,6 +284,36 @@ async function devNativeApp(target, entry, options) {
239
284
  await new Promise(() => {
240
285
  });
241
286
  }
287
+ function startIOSDev(appPath, appId, devUrl, log) {
288
+ const device = pickSimulator();
289
+ if (!device) throw new Error("No iPhone simulator found. Add one in Xcode \u2192 Settings \u2192 Platforms");
290
+ log(`[Orvyn] Starting ${device.name}...`);
291
+ spawnSync("xcrun", ["simctl", "boot", device.udid], { stdio: "ignore" });
292
+ spawnSync("open", ["-a", "Simulator"], { stdio: "ignore" });
293
+ spawnSync("xcrun", ["simctl", "bootstatus", device.udid, "-b"], { stdio: "ignore" });
294
+ spawnSync("xcrun", ["simctl", "install", device.udid, appPath], { stdio: "ignore" });
295
+ return {
296
+ deviceName: device.name,
297
+ launch: () => spawnSync(
298
+ "xcrun",
299
+ ["simctl", "launch", "--terminate-running-process", device.udid, appId],
300
+ { stdio: "ignore", env: { ...process.env, SIMCTL_CHILD_ORVYN_DEV_SERVER: devUrl } }
301
+ )
302
+ };
303
+ }
304
+ function startAndroidDev(appPath, appId, devUrl) {
305
+ const adb = (...args) => spawnSync("adb", args, { encoding: "utf-8" });
306
+ if (adb("install", "-r", appPath).status !== 0) {
307
+ throw new Error("adb install failed. Start an Android emulator or connect a phone first");
308
+ }
309
+ if (adb("reverse", `tcp:${DEV_PORT}`, `tcp:${DEV_PORT}`).status !== 0) {
310
+ throw new Error("adb reverse failed. Connect only one device or emulator");
311
+ }
312
+ return {
313
+ deviceName: "Android",
314
+ launch: () => adb("shell", "am", "start", "-S", "-n", `${appId}/dev.orvyn.runtime.MainActivity`, "--es", "orvynDevServer", devUrl)
315
+ };
316
+ }
242
317
  function pickSimulator() {
243
318
  const result = spawnSync("xcrun", ["simctl", "list", "devices", "available", "--json"], { encoding: "utf-8" });
244
319
  if (result.status !== 0) return null;
@@ -248,5 +323,7 @@ function pickSimulator() {
248
323
  export {
249
324
  buildNativeApp,
250
325
  devNativeApp,
326
+ exportOptions,
327
+ iosReleaseSteps,
251
328
  runNativeApp
252
329
  };
@@ -0,0 +1,57 @@
1
+ import { STYLE_SPEC } from "../../styling/spec.js";
2
+ import { collectProjectPrograms } from "../page-files.js";
3
+ import { nativeSize } from "../native-size.js";
4
+ const SIZE_PROPS = /* @__PURE__ */ new Set(["width", "height", "minWidth", "minHeight", "maxWidth", "maxHeight", "size"]);
5
+ function textIn(value) {
6
+ if (!value || typeof value !== "object") return [];
7
+ if (Array.isArray(value)) return value.flatMap(textIn);
8
+ const node = value;
9
+ const own = node.kind === "String" && Array.isArray(node.parts) ? node.parts.filter((p) => typeof p === "string") : [];
10
+ return [...own, ...Object.values(node).flatMap((child) => typeof child === "object" ? textIn(child) : [])];
11
+ }
12
+ function checkNativeCompatibility(program) {
13
+ const warnings = [];
14
+ const visit = (node) => {
15
+ if (node.kind === "ViewIf") {
16
+ node.then.forEach(visit);
17
+ node.else?.forEach(visit);
18
+ return;
19
+ }
20
+ if (node.kind === "ViewFor") {
21
+ node.body.forEach(visit);
22
+ return;
23
+ }
24
+ if (node.name === "Image" && node.arg && textIn(node.arg).some((text) => /\.svg(\?|#|$)/i.test(text))) {
25
+ warnings.push({ line: node.line, col: node.col, message: `Native: SVG images don't show in the installed app. Use a .png or .jpg copy.` });
26
+ }
27
+ for (const prop of node.props) {
28
+ const name = prop.key;
29
+ if (STYLE_SPEC[name]?.support === "web") {
30
+ warnings.push({ line: node.line, col: node.col, message: `Native: "${name}" only works on the web; the installed app ignores it.` });
31
+ }
32
+ const expr = prop.value.kind === "Expr" ? prop.value.expr : null;
33
+ if (SIZE_PROPS.has(name) && expr?.kind === "String" && expr.parts.length === 1 && typeof expr.parts[0] === "string") {
34
+ const raw = expr.parts[0];
35
+ if (/\bclamp\(/.test(raw)) {
36
+ warnings.push({ line: node.line, col: node.col, message: `Native: ${name}: "${raw}" uses clamp(), which the installed app cannot calculate. Use a number or a mobile value.` });
37
+ } else if (/\b(?:calc|min|max)\(|\d+(?:vw|vh|rem|em)\b/.test(raw)) {
38
+ if (nativeSize(raw, { width: 390, height: 844 }) === void 0) {
39
+ warnings.push({ line: node.line, col: node.col, message: `Native: ${name}: "${raw}" cannot be calculated on phones. Use a number or a mobile value.` });
40
+ }
41
+ }
42
+ }
43
+ }
44
+ node.children.forEach(visit);
45
+ };
46
+ for (const decl of program.body) if (decl.kind === "Screen") decl.body.forEach(visit);
47
+ return warnings;
48
+ }
49
+ function checkNativeProject(entry) {
50
+ return collectProjectPrograms(entry).flatMap(
51
+ ({ file, program }) => checkNativeCompatibility(program).map((warning) => ({ ...warning, file }))
52
+ );
53
+ }
54
+ export {
55
+ checkNativeCompatibility,
56
+ checkNativeProject
57
+ };
@@ -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()