orvyn-lang 0.1.1 → 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.
- package/GUIDE.md +149 -0
- package/LANGUAGE.md +877 -24
- package/README.md +227 -131
- package/brand/orvyn-sunset-animated.svg +15 -0
- package/package.json +3 -1
- package/src/cli/orvyn.js +216 -489
- package/src/core/signal.js +104 -6
- package/src/devtools/runtime.js +25 -1
- package/src/lang/a11y.js +102 -0
- package/src/lang/auth.js +239 -0
- package/src/lang/bundle-native.js +10 -6
- package/src/lang/codegen.js +498 -64
- package/src/lang/device.js +41 -0
- package/src/lang/doctor.js +60 -0
- package/src/lang/env.js +27 -0
- package/src/lang/errors.js +513 -0
- package/src/lang/form.js +160 -0
- package/src/lang/index.js +2 -1
- package/src/lang/lexer.js +2 -0
- package/src/lang/list.js +44 -0
- package/src/lang/native/android/MainActivity.kt +43 -4
- package/src/lang/native/android/OrvynDevice.kt +163 -0
- package/src/lang/native/android/OrvynEngine.kt +154 -7
- package/src/lang/native/android/OrvynRenderer.kt +519 -40
- package/src/lang/native/android.js +74 -11
- package/src/lang/native/build.js +130 -60
- package/src/lang/native/config.js +108 -0
- package/src/lang/native/ios/OrvynApp.swift +6 -0
- package/src/lang/native/ios/OrvynEngine.swift +268 -4
- package/src/lang/native/ios/OrvynViews.swift +429 -31
- package/src/lang/native/ios.js +75 -2
- package/src/lang/native-runtime.js +423 -57
- package/src/lang/page.js +52 -0
- package/src/lang/parser.js +243 -15
- package/src/lang/prerender.js +300 -0
- package/src/lang/read-import.js +11 -0
- package/src/lang/router.js +266 -0
- package/src/lang/runtime-shared.js +820 -10
- package/src/lang/runtime.js +375 -52
- package/src/lang/select.js +13 -0
- package/src/lang/server-code.js +233 -0
- package/src/lang/server-export.js +78 -0
- package/src/lang/server-libs.js +53 -0
- package/src/lang/server.js +409 -0
- package/src/lang/test-runner.js +134 -0
- package/src/lang/types.js +312 -0
- package/src/lang/validation.js +55 -0
- package/src/lang/vite-plugin.js +82 -3
- package/src/lang/web-overlay.js +578 -0
- package/src/lang/widgets.js +94 -0
- package/src/lang/words.js +38 -0
- package/src/runtime/mount.js +116 -27
- package/src/runtime/patch.js +90 -11
- package/src/runtime/style.js +11 -1
- package/src/styling/fluid.js +91 -4
- package/src/styling/spec.js +306 -0
- package/src/core/context.js +0 -19
- package/src/core/lifecycle.js +0 -8
- package/src/core/resource.js +0 -27
- package/src/core/router.js +0 -20
- package/src/core/theme.js +0 -10
- package/src/devtools/devicePreview/PreviewFrame.js +0 -214
- package/src/devtools/devicePreview/index.js +0 -6
- package/src/devtools/overlay.js +0 -105
- package/src/runtime/createRenderer.js +0 -22
- package/src/runtime/h.js +0 -93
- package/src/runtime/hydrate.js +0 -59
- package/src/runtime/jsx-dev-runtime.js +0 -7
- package/src/runtime/jsx-runtime.js +0 -13
- package/src/runtime/partialHydration.js +0 -154
- package/src/runtime/platform.js +0 -135
- package/src/runtime/renderToStream.js +0 -127
- package/src/runtime/renderToString.js +0 -121
- package/src/runtime/resume.js +0 -62
package/src/cli/orvyn.js
CHANGED
|
@@ -18,6 +18,23 @@ let command =
|
|
|
18
18
|
let args =
|
|
19
19
|
process.argv.slice(3)
|
|
20
20
|
|
|
21
|
+
// --env staging (or --env=staging) works with every command
|
|
22
|
+
const envAt = args.findIndex(arg => arg === "--env" || arg.startsWith("--env="))
|
|
23
|
+
if (envAt >= 0) {
|
|
24
|
+
const inline = args[envAt].includes("=")
|
|
25
|
+
const name = inline ? args[envAt].slice("--env=".length) : args[envAt + 1]
|
|
26
|
+
if (!name || name.startsWith("-")) {
|
|
27
|
+
process.stdout.write("--env needs a name, like --env prod\n")
|
|
28
|
+
process.exit(1)
|
|
29
|
+
}
|
|
30
|
+
process.env.ORVYN_ENV = name
|
|
31
|
+
args.splice(envAt, inline ? 1 : 2)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const releaseAt = args.indexOf("--release")
|
|
35
|
+
const release = releaseAt >= 0
|
|
36
|
+
if (release) args.splice(releaseAt, 1)
|
|
37
|
+
|
|
21
38
|
// ---------------------------------------------------------------------------
|
|
22
39
|
// Orvyn language projects get short commands:
|
|
23
40
|
// orvyn dev | ios | android | check | build | preview
|
|
@@ -46,7 +63,8 @@ if (orvEntry && !hasOrvArg) {
|
|
|
46
63
|
command = "dev"
|
|
47
64
|
args = ["ios", orvEntry, ...args]
|
|
48
65
|
} else if (command === "android") {
|
|
49
|
-
|
|
66
|
+
// live reload, like the iPhone
|
|
67
|
+
command = "dev"
|
|
50
68
|
args = ["android", orvEntry, ...args]
|
|
51
69
|
} else if (
|
|
52
70
|
(command === "dev" || command === "run" || command === "build") &&
|
|
@@ -63,21 +81,6 @@ if (orvEntry && !hasOrvArg) {
|
|
|
63
81
|
args = platform === "web" ? args.slice(1) : args
|
|
64
82
|
}
|
|
65
83
|
}
|
|
66
|
-
|
|
67
|
-
const targets =
|
|
68
|
-
new Set([
|
|
69
|
-
"web",
|
|
70
|
-
"ios",
|
|
71
|
-
"android",
|
|
72
|
-
"universal"
|
|
73
|
-
])
|
|
74
|
-
|
|
75
|
-
const nativeTargets =
|
|
76
|
-
new Set([
|
|
77
|
-
"ios",
|
|
78
|
-
"android"
|
|
79
|
-
])
|
|
80
|
-
|
|
81
84
|
function log(message = "") {
|
|
82
85
|
process.stdout.write(`${message}\n`)
|
|
83
86
|
}
|
|
@@ -148,419 +151,6 @@ function viteBinary() {
|
|
|
148
151
|
: "vite"
|
|
149
152
|
}
|
|
150
153
|
|
|
151
|
-
function walk(
|
|
152
|
-
dir,
|
|
153
|
-
files = []
|
|
154
|
-
) {
|
|
155
|
-
if (!existsSync(dir)) {
|
|
156
|
-
return files
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
for (const entry of readdirSync(dir)) {
|
|
160
|
-
if (
|
|
161
|
-
entry === "node_modules" ||
|
|
162
|
-
entry === "dist"
|
|
163
|
-
) {
|
|
164
|
-
continue
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const file =
|
|
168
|
-
join(dir, entry)
|
|
169
|
-
|
|
170
|
-
const stat =
|
|
171
|
-
statSync(file)
|
|
172
|
-
|
|
173
|
-
if (stat.isDirectory()) {
|
|
174
|
-
walk(file, files)
|
|
175
|
-
} else {
|
|
176
|
-
files.push(file)
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return files
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function readJson(path) {
|
|
184
|
-
if (!existsSync(path)) {
|
|
185
|
-
return null
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return JSON.parse(
|
|
189
|
-
readFileSync(path, "utf8")
|
|
190
|
-
)
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function formatBytes(bytes) {
|
|
194
|
-
if (bytes < 1024) {
|
|
195
|
-
return `${bytes} B`
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (bytes < 1024 * 1024) {
|
|
199
|
-
return `${(bytes / 1024).toFixed(2)} KB`
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
return `${(bytes / 1024 / 1024).toFixed(2)} MB`
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function targetFromArgs(
|
|
206
|
-
fallback = "web"
|
|
207
|
-
) {
|
|
208
|
-
const target =
|
|
209
|
-
args[0]
|
|
210
|
-
|
|
211
|
-
if (targets.has(target)) {
|
|
212
|
-
return {
|
|
213
|
-
target,
|
|
214
|
-
rest: args.slice(1)
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return {
|
|
219
|
-
target: fallback,
|
|
220
|
-
rest: args
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
function logRenderer(target) {
|
|
225
|
-
log("[Orvyn Renderer]")
|
|
226
|
-
log(`Target: ${target}`)
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
function nativeTree(target) {
|
|
230
|
-
return {
|
|
231
|
-
type: target === "ios"
|
|
232
|
-
? "UIView"
|
|
233
|
-
: "View",
|
|
234
|
-
props: {},
|
|
235
|
-
children: []
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
function nativeManifest(target) {
|
|
240
|
-
return {
|
|
241
|
-
framework: "orvyn",
|
|
242
|
-
target,
|
|
243
|
-
renderer: target,
|
|
244
|
-
entry: existsSync(join(cwd, "src", "main.tsx"))
|
|
245
|
-
? "src/main.tsx"
|
|
246
|
-
: "src/main.ts",
|
|
247
|
-
generatedAt: new Date().toISOString(),
|
|
248
|
-
output: "view-tree-description",
|
|
249
|
-
tree: nativeTree(target),
|
|
250
|
-
notes: [
|
|
251
|
-
"This is an Orvyn native view-tree description target.",
|
|
252
|
-
"Real IPA/APK generation is intentionally not implemented in this architecture phase."
|
|
253
|
-
]
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function ensureDir(dir) {
|
|
258
|
-
mkdirSync(dir, { recursive: true })
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
function writeNativeFile(base, filePath, content) {
|
|
262
|
-
const full = join(base, filePath)
|
|
263
|
-
ensureDir(join(full, ".."))
|
|
264
|
-
writeFileSync(full, content)
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
async function buildNativeProject(target) {
|
|
268
|
-
const outDir = join(cwd, "dist", target)
|
|
269
|
-
ensureDir(outDir)
|
|
270
|
-
|
|
271
|
-
logRenderer(target)
|
|
272
|
-
log("")
|
|
273
|
-
log(`[Orvyn Native Build] Target: ${target}`)
|
|
274
|
-
log("Extracting VNode tree and generating native project structure...")
|
|
275
|
-
log("")
|
|
276
|
-
|
|
277
|
-
const { createServer } = await import("vite")
|
|
278
|
-
const server = await createServer({
|
|
279
|
-
server: { middlewareMode: true },
|
|
280
|
-
appType: "custom",
|
|
281
|
-
root: cwd
|
|
282
|
-
})
|
|
283
|
-
|
|
284
|
-
try {
|
|
285
|
-
let orvynConfig = {}
|
|
286
|
-
if (existsSync(join(cwd, "orvyn.config.ts"))) {
|
|
287
|
-
const mod = await server.ssrLoadModule("/orvyn.config.ts")
|
|
288
|
-
orvynConfig = mod.default || {}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
const config = {
|
|
292
|
-
appId: "com.orvyn.app",
|
|
293
|
-
appName: "OrvynApp",
|
|
294
|
-
version: "1.0.0",
|
|
295
|
-
entry: "/src/main.tsx",
|
|
296
|
-
...(orvynConfig.native || {})
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
const mainMod = await server.ssrLoadModule(config.entry)
|
|
300
|
-
const rootComponent = mainMod[Object.keys(mainMod)[0]] || mainMod.default
|
|
301
|
-
if (!rootComponent) {
|
|
302
|
-
throw new Error(`Could not find exported root component in ${config.entry}`)
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
const vnode = rootComponent()
|
|
306
|
-
|
|
307
|
-
const buildMod = await server.ssrLoadModule("orvyn/build")
|
|
308
|
-
|
|
309
|
-
if (target === "ios") {
|
|
310
|
-
const result = buildMod.buildIOS(vnode, config)
|
|
311
|
-
result.files.forEach(file => {
|
|
312
|
-
writeNativeFile(outDir, file.path, file.content)
|
|
313
|
-
log(` ✓ dist/ios/${file.path}`)
|
|
314
|
-
})
|
|
315
|
-
log("")
|
|
316
|
-
log(`[Orvyn] iOS project generated → dist/ios/ (${result.files.length} files)`)
|
|
317
|
-
compileIOS(outDir)
|
|
318
|
-
} else {
|
|
319
|
-
const result = buildMod.buildAndroid(vnode, config)
|
|
320
|
-
result.files.forEach(file => {
|
|
321
|
-
writeNativeFile(outDir, file.path, file.content)
|
|
322
|
-
log(` ✓ dist/android/${file.path}`)
|
|
323
|
-
})
|
|
324
|
-
log("")
|
|
325
|
-
log(`[Orvyn] Android project generated → dist/android/ (${result.files.length} files)`)
|
|
326
|
-
compileAndroid(outDir)
|
|
327
|
-
}
|
|
328
|
-
} catch (err) {
|
|
329
|
-
log(`[Orvyn Native Build Error] ${err.message}`)
|
|
330
|
-
console.error(err)
|
|
331
|
-
process.exit(1)
|
|
332
|
-
} finally {
|
|
333
|
-
await server.close()
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// Legacy generators removed in favor of proper module architecture
|
|
338
|
-
|
|
339
|
-
function compileIOS(outDir) {
|
|
340
|
-
log("\\n[Orvyn Compile] Attempting to compile iOS App...")
|
|
341
|
-
try {
|
|
342
|
-
const res = spawnSync("xcodebuild", ["-version"], { encoding: "utf-8" })
|
|
343
|
-
if (res.status !== 0 || res.error) throw new Error("xcodebuild not found")
|
|
344
|
-
spawnSync("xcodebuild", ["-project", "OrvynApp.xcodeproj", "build"], { cwd: outDir, stdio: "inherit" })
|
|
345
|
-
log("\\n[Orvyn] ✅ iOS Compilation Successful!")
|
|
346
|
-
} catch (err) {
|
|
347
|
-
log("\\n[Orvyn Warning] Automatic iOS compilation failed.")
|
|
348
|
-
log("Please ensure Xcode and iOS SDK are installed.")
|
|
349
|
-
log("To build manually, open your .xcodeproj in Xcode inside dist/ios/.")
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
function compileAndroid(outDir) {
|
|
354
|
-
log("\\n[Orvyn Compile] Attempting to compile Android APK...")
|
|
355
|
-
try {
|
|
356
|
-
const gradlewPath = join(outDir, "gradlew")
|
|
357
|
-
writeFileSync(gradlewPath, "#!/usr/bin/env sh\\nexec gradle \\\"$@\\\"\\n")
|
|
358
|
-
|
|
359
|
-
const chmodResult = spawnSync("chmod", ["+x", "gradlew"], { cwd: outDir })
|
|
360
|
-
if (chmodResult.error || chmodResult.status !== 0) {
|
|
361
|
-
throw chmodResult.error || new Error("chmod failed")
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
const buildResult = spawnSync("./gradlew", ["assembleDebug"], { cwd: outDir, stdio: "inherit" })
|
|
365
|
-
if (buildResult.error || buildResult.status !== 0) {
|
|
366
|
-
throw buildResult.error || new Error(`gradlew exited with status ${buildResult.status}`)
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
log("\\n[Orvyn] ✅ Android Compilation Successful!")
|
|
370
|
-
log("Installable APK: dist/android/app/build/outputs/apk/debug/app-debug.apk")
|
|
371
|
-
} catch (err) {
|
|
372
|
-
log("\\n[Orvyn Warning] Automatic Android compilation failed.")
|
|
373
|
-
log("Please ensure Java and Gradle are installed.")
|
|
374
|
-
log("To build manually, open dist/android/ in Android Studio, or run `gradle assembleDebug` in dist/android/.")
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
function buildNative(target) {
|
|
379
|
-
buildNativeProject(target)
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
function buildWeb(commandArgs = []) {
|
|
383
|
-
logRenderer("web")
|
|
384
|
-
|
|
385
|
-
runSync(
|
|
386
|
-
viteBinary(),
|
|
387
|
-
[
|
|
388
|
-
"build",
|
|
389
|
-
"--outDir",
|
|
390
|
-
"dist/web",
|
|
391
|
-
...commandArgs
|
|
392
|
-
],
|
|
393
|
-
{
|
|
394
|
-
env: {
|
|
395
|
-
ORVYN_TARGET: "web"
|
|
396
|
-
}
|
|
397
|
-
}
|
|
398
|
-
)
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
function buildTarget(
|
|
402
|
-
target,
|
|
403
|
-
commandArgs = []
|
|
404
|
-
) {
|
|
405
|
-
if (target === "universal") {
|
|
406
|
-
buildWeb(commandArgs)
|
|
407
|
-
buildNativeProject("ios")
|
|
408
|
-
buildNativeProject("android")
|
|
409
|
-
|
|
410
|
-
return
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
if (target === "web") {
|
|
414
|
-
buildWeb(commandArgs)
|
|
415
|
-
|
|
416
|
-
return
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
if (nativeTargets.has(target)) {
|
|
420
|
-
buildNativeProject(target)
|
|
421
|
-
|
|
422
|
-
return
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
log(`Unknown build target: ${target}`)
|
|
426
|
-
process.exit(1)
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
function analyze() {
|
|
430
|
-
const pkg =
|
|
431
|
-
readJson(join(cwd, "package.json"))
|
|
432
|
-
|
|
433
|
-
const sourceFiles =
|
|
434
|
-
walk(join(cwd, "src"))
|
|
435
|
-
|
|
436
|
-
const systems = [
|
|
437
|
-
["Signals", "src/core/signal.ts"],
|
|
438
|
-
["Scheduler", "src/core/scheduler.ts"],
|
|
439
|
-
["VNode runtime", "src/runtime/vnode.ts"],
|
|
440
|
-
["Mount engine", "src/runtime/mount.ts"],
|
|
441
|
-
["Patch engine", "src/runtime/patch.ts"],
|
|
442
|
-
["SSR", "src/runtime/renderToString.ts"],
|
|
443
|
-
["Streaming SSR", "src/runtime/renderToStream.ts"],
|
|
444
|
-
["Hydration", "src/runtime/hydrate.ts"],
|
|
445
|
-
["Partial hydration", "src/runtime/partialHydration.ts"],
|
|
446
|
-
["Resumability", "src/runtime/resume.ts"],
|
|
447
|
-
["Compiler optimizer", "src/compiler/optimizer.ts"],
|
|
448
|
-
["Target compiler", "src/compiler/compile.ts"],
|
|
449
|
-
["Renderer abstraction", "src/runtime/createRenderer.ts"],
|
|
450
|
-
["Platform context", "src/runtime/platform.ts"],
|
|
451
|
-
["Web renderer", "src/platforms/web/index.ts"],
|
|
452
|
-
["iOS renderer", "src/platforms/ios/index.ts"],
|
|
453
|
-
["Android renderer", "src/platforms/android/index.ts"],
|
|
454
|
-
["Device preview", "src/devtools/devicePreview/PreviewFrame.ts"],
|
|
455
|
-
["Build targets", "src/build/index.ts"],
|
|
456
|
-
["DevTools", "src/devtools/runtime.ts"],
|
|
457
|
-
["Playground", "src/playground/Playground.tsx"],
|
|
458
|
-
["Native runtime", "src/native/runtime.ts"],
|
|
459
|
-
["Native types", "src/native/types.ts"],
|
|
460
|
-
["iOS bridge", "src/native/ios/bridge.ts"],
|
|
461
|
-
["iOS native renderer", "src/native/ios/renderer.ts"],
|
|
462
|
-
["Android bridge", "src/native/android/bridge.ts"],
|
|
463
|
-
["Android native renderer", "src/native/android/renderer.ts"],
|
|
464
|
-
["Native events", "src/native/events/events.ts"],
|
|
465
|
-
["Native gestures", "src/native/events/gestures.ts"],
|
|
466
|
-
["Native styling", "src/native/styling/interpreter.ts"],
|
|
467
|
-
["iOS styles", "src/native/styling/ios-styles.ts"],
|
|
468
|
-
["Android styles", "src/native/styling/android-styles.ts"],
|
|
469
|
-
["iOS build pipeline", "src/build/ios/pipeline.ts"],
|
|
470
|
-
["iOS code generator", "src/build/ios/generator.ts"],
|
|
471
|
-
["iOS project structure", "src/build/ios/project.ts"],
|
|
472
|
-
["Android build pipeline", "src/build/android/pipeline.ts"],
|
|
473
|
-
["Android code generator", "src/build/android/generator.ts"],
|
|
474
|
-
["Android project structure", "src/build/android/project.ts"],
|
|
475
|
-
["App signing", "src/build/signing/signing.ts"]
|
|
476
|
-
]
|
|
477
|
-
|
|
478
|
-
const distFiles =
|
|
479
|
-
walk(join(cwd, "dist"))
|
|
480
|
-
|
|
481
|
-
const distSize =
|
|
482
|
-
distFiles.reduce((total, file) =>
|
|
483
|
-
total + statSync(file).size,
|
|
484
|
-
0
|
|
485
|
-
)
|
|
486
|
-
|
|
487
|
-
log("Orvyn Analyze")
|
|
488
|
-
log("=============")
|
|
489
|
-
log(`Project: ${pkg?.name || "unknown"}`)
|
|
490
|
-
log(`Version: ${pkg?.version || "unknown"}`)
|
|
491
|
-
log(`Source files: ${sourceFiles.length}`)
|
|
492
|
-
log(`Build output: ${distFiles.length > 0 ? formatBytes(distSize) : "not built"}`)
|
|
493
|
-
log("")
|
|
494
|
-
|
|
495
|
-
log("Systems")
|
|
496
|
-
log("-------")
|
|
497
|
-
|
|
498
|
-
systems.forEach(([name, path]) => {
|
|
499
|
-
log(`${existsSync(join(cwd, path)) ? "✓" : "·"} ${name} (${path})`)
|
|
500
|
-
})
|
|
501
|
-
|
|
502
|
-
log("")
|
|
503
|
-
log("Source Breakdown")
|
|
504
|
-
log("----------------")
|
|
505
|
-
|
|
506
|
-
const groups =
|
|
507
|
-
sourceFiles.reduce((counts, file) => {
|
|
508
|
-
const group =
|
|
509
|
-
relative(join(cwd, "src"), file)
|
|
510
|
-
.split(/[\\/]/)[0]
|
|
511
|
-
|
|
512
|
-
counts[group] =
|
|
513
|
-
(counts[group] || 0) + 1
|
|
514
|
-
|
|
515
|
-
return counts
|
|
516
|
-
}, {})
|
|
517
|
-
|
|
518
|
-
Object
|
|
519
|
-
.entries(groups)
|
|
520
|
-
.sort(([a], [b]) => a.localeCompare(b))
|
|
521
|
-
.forEach(([group, count]) => {
|
|
522
|
-
log(`${group}: ${count}`)
|
|
523
|
-
})
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
function help() {
|
|
527
|
-
log("Orvyn — one language for web, iPhone and Android")
|
|
528
|
-
log("")
|
|
529
|
-
log("Start:")
|
|
530
|
-
log(" orvyn new my-app Create a new app (and install it)")
|
|
531
|
-
log("")
|
|
532
|
-
log("Inside your app folder:")
|
|
533
|
-
log(" orvyn dev Web, with live reload")
|
|
534
|
-
log(" orvyn ios iPhone simulator, with live reload")
|
|
535
|
-
log(" orvyn android Android emulator or phone")
|
|
536
|
-
log(" orvyn check Find mistakes in your code")
|
|
537
|
-
log(" orvyn build Website → dist/web/")
|
|
538
|
-
log(" orvyn build ios Xcode project → dist/ios/ (for real iPhones / App Store)")
|
|
539
|
-
log(" orvyn build android Android Studio project → dist/android/")
|
|
540
|
-
log("")
|
|
541
|
-
log("Advanced (JSX framework projects):")
|
|
542
|
-
log(" orvyn dev [web|ios|android] [vite args]")
|
|
543
|
-
log(" orvyn build [web|ios|android|universal] [vite args]")
|
|
544
|
-
log(" orvyn preview [web] [vite args]")
|
|
545
|
-
log(" orvyn analyze")
|
|
546
|
-
log(" orvyn help")
|
|
547
|
-
log("")
|
|
548
|
-
log("Advanced (any .orv file):")
|
|
549
|
-
log(" orvyn compile app.orv Compile .orv to JavaScript (prints it)")
|
|
550
|
-
log(" orvyn compile app.orv -o x.js Write the JavaScript to a file")
|
|
551
|
-
log(" orvyn check app.orv Check a .orv file for errors")
|
|
552
|
-
log(" orvyn build ios app.orv Build a native iPhone app (SwiftUI)")
|
|
553
|
-
log(" orvyn build android app.orv Build a native Android app")
|
|
554
|
-
log(" orvyn dev ios app.orv iPhone simulator with live reload (save = reload)")
|
|
555
|
-
log(" orvyn run ios app.orv Build and open it in the iPhone simulator")
|
|
556
|
-
log(" orvyn run android app.orv Build and install on an emulator/phone")
|
|
557
|
-
log("")
|
|
558
|
-
log("Native Build:")
|
|
559
|
-
log(" orvyn build ios Generate iOS Xcode project → dist/ios/")
|
|
560
|
-
log(" orvyn build android Generate Android Gradle project → dist/android/")
|
|
561
|
-
log(" orvyn build universal Generate web + iOS + Android")
|
|
562
|
-
}
|
|
563
|
-
|
|
564
154
|
async function compileOrv(mode, commandArgs) {
|
|
565
155
|
const file = commandArgs.find(arg => arg.endsWith(".orv"))
|
|
566
156
|
const outIndex = commandArgs.indexOf("-o")
|
|
@@ -581,11 +171,25 @@ async function compileOrv(mode, commandArgs) {
|
|
|
581
171
|
|
|
582
172
|
const source = readFileSync(file, "utf-8")
|
|
583
173
|
|
|
174
|
+
let env
|
|
175
|
+
try {
|
|
176
|
+
const { loadEnv } = await import("../lang/env.js")
|
|
177
|
+
env = await loadEnv(cwd, "dev")
|
|
178
|
+
} catch (error) {
|
|
179
|
+
log(error.message)
|
|
180
|
+
process.exit(1)
|
|
181
|
+
}
|
|
182
|
+
|
|
584
183
|
try {
|
|
585
|
-
const
|
|
184
|
+
const { readImportFrom } = await import("../lang/read-import.js")
|
|
185
|
+
const code = compile(source, { env, tests: mode === "check", resolveImport: readImportFrom(file) })
|
|
586
186
|
|
|
587
187
|
if (mode === "check") {
|
|
588
|
-
|
|
188
|
+
const { parse } = await import("../lang/parser.js")
|
|
189
|
+
const { checkAccessibility } = await import("../lang/a11y.js")
|
|
190
|
+
const warnings = checkAccessibility(parse(source))
|
|
191
|
+
for (const warning of warnings) log(`⚠ ${file}:${warning.line}:${warning.col} ${warning.message}`)
|
|
192
|
+
log(`✓ ${file} has no errors${warnings.length ? `, ${warnings.length} warning(s)` : ""}`)
|
|
589
193
|
} else if (outFile) {
|
|
590
194
|
writeFileSync(outFile, code)
|
|
591
195
|
log(`✓ Compiled ${file} → ${outFile}`)
|
|
@@ -606,6 +210,85 @@ async function compileOrv(mode, commandArgs) {
|
|
|
606
210
|
}
|
|
607
211
|
}
|
|
608
212
|
|
|
213
|
+
async function testOrv(commandArgs) {
|
|
214
|
+
const files = commandArgs.filter(arg => arg.endsWith(".orv"))
|
|
215
|
+
if (!files.length && orvEntry) files.push(orvEntry)
|
|
216
|
+
if (!files.length) {
|
|
217
|
+
log("Usage: orvyn test <file.orv>")
|
|
218
|
+
process.exit(1)
|
|
219
|
+
}
|
|
220
|
+
const { runTests } = await import("../lang/test-runner.js")
|
|
221
|
+
const { loadEnv } = await import("../lang/env.js")
|
|
222
|
+
let failed = 0
|
|
223
|
+
let total = 0
|
|
224
|
+
for (const file of files) {
|
|
225
|
+
try {
|
|
226
|
+
for (const result of await runTests(file, await loadEnv(cwd, "dev"))) {
|
|
227
|
+
total++
|
|
228
|
+
log(`${result.ok ? "✓" : "✗"} ${file}: ${result.name}`)
|
|
229
|
+
if (!result.ok) {
|
|
230
|
+
failed++
|
|
231
|
+
log(` ${result.error}`)
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
} catch (error) {
|
|
235
|
+
failed++
|
|
236
|
+
log(`✗ ${file}: ${error.message}`)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
log(total || failed ? `\n${total} test(s), ${failed} failed` : `No tests yet. Add: test "opens" { expect(text("Hello")) }`)
|
|
240
|
+
process.exit(failed ? 1 : 0)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// orvyn serve [server.orv] [--port 3000] [--host 0.0.0.0]
|
|
244
|
+
// orvyn admin you@example.com [server.orv]
|
|
245
|
+
async function serverOrv(mode, commandArgs) {
|
|
246
|
+
const option = (name, fallback) => {
|
|
247
|
+
const at = commandArgs.indexOf(name)
|
|
248
|
+
return at >= 0 ? commandArgs.splice(at, 2)[1] : fallback
|
|
249
|
+
}
|
|
250
|
+
const port = Number(option("--port", process.env.PORT || 3000))
|
|
251
|
+
const host = option("--host", process.env.HOST || "127.0.0.1")
|
|
252
|
+
const file = commandArgs.find(arg => arg.endsWith(".orv")) ||
|
|
253
|
+
["src/server.orv", "server.orv"].find(path => existsSync(join(cwd, path)))
|
|
254
|
+
if (!file || !existsSync(file)) {
|
|
255
|
+
log("No server file. Create server.orv, like:\n\n table notes {\n text: text required\n }")
|
|
256
|
+
process.exit(1)
|
|
257
|
+
}
|
|
258
|
+
try {
|
|
259
|
+
const { parseServer, openDatabase, createApi, makeAdmin } = await import("../lang/server.js")
|
|
260
|
+
const tables = parseServer(readFileSync(file, "utf-8"))
|
|
261
|
+
const { loadLibraries } = await import("../lang/server-libs.js")
|
|
262
|
+
tables.libraries = await loadLibraries(tables.uses ?? [], file)
|
|
263
|
+
const db = openDatabase(process.env.ORVYN_DB || join(cwd, "orvyn.db"), tables)
|
|
264
|
+
if (mode === "admin") {
|
|
265
|
+
const email = commandArgs.find(arg => arg.includes("@"))
|
|
266
|
+
if (!email || !makeAdmin(db, email)) {
|
|
267
|
+
log("Usage: orvyn admin you@example.com (sign up with that email first)")
|
|
268
|
+
process.exit(1)
|
|
269
|
+
}
|
|
270
|
+
log(`✓ ${email} is now an admin`)
|
|
271
|
+
process.exit(0)
|
|
272
|
+
}
|
|
273
|
+
const origins = (process.env.ORVYN_ORIGINS || "").split(",").map(s => s.trim()).filter(Boolean)
|
|
274
|
+
const server = createApi(tables, db, { origins })
|
|
275
|
+
server.on("error", error => {
|
|
276
|
+
log(`✗ ${error.message}`)
|
|
277
|
+
process.exit(1)
|
|
278
|
+
})
|
|
279
|
+
server.listen(port, host, () => {
|
|
280
|
+
log(`[Orvyn] ✓ Server → http://${host === "0.0.0.0" ? "localhost" : host}:${port}/api`)
|
|
281
|
+
for (const table of tables) {
|
|
282
|
+
log(` /api/${table.name.padEnd(16)} ${table.locked ? "only your server code changes" : table.admin ? "only admins change" : "owners change"}, ${table.public ? "anyone reads" : table.admin ? "admins see their own" : "private to each person"}`)
|
|
283
|
+
}
|
|
284
|
+
for (const api of tables.apis ?? []) log(` ${api.method.padEnd(4)} /api${api.path}${api.requires ? ` (requires ${api.requires})` : ""}`)
|
|
285
|
+
})
|
|
286
|
+
} catch (error) {
|
|
287
|
+
log(`✗ ${file}: ${error.message}`)
|
|
288
|
+
process.exit(1)
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
609
292
|
function newOrvProject(name) {
|
|
610
293
|
if (!name) {
|
|
611
294
|
log("Usage: orvyn new <app-name>")
|
|
@@ -642,6 +325,7 @@ function newOrvProject(name) {
|
|
|
642
325
|
ios: "orvyn ios",
|
|
643
326
|
android: "orvyn android",
|
|
644
327
|
check: "orvyn check",
|
|
328
|
+
test: "orvyn test",
|
|
645
329
|
build: "orvyn build"
|
|
646
330
|
},
|
|
647
331
|
dependencies: { [orvynName]: orvynDep },
|
|
@@ -654,7 +338,19 @@ function newOrvProject(name) {
|
|
|
654
338
|
appId: ${JSON.stringify(`com.example.${id || "app"}`)},
|
|
655
339
|
version: "1.0.0",
|
|
656
340
|
ios: { deploymentTarget: "16.0" },
|
|
657
|
-
|
|
341
|
+
// For the stores, add your own appId and:
|
|
342
|
+
// icon: "assets/icon.png", // 1024 x 1024 PNG, no transparency
|
|
343
|
+
// splash: { color: "#ffffff" },
|
|
344
|
+
// permissions: { camera: "To scan codes" },
|
|
345
|
+
android: { minSdk: 24, targetSdk: 36 } // , keystore: "upload.jks", keyAlias: "upload"
|
|
346
|
+
},
|
|
347
|
+
// your website address, for sitemap.xml: site: "https://example.com",
|
|
348
|
+
// seo: { allowAI: false }, // ask AI crawlers not to read your site
|
|
349
|
+
// read in .orv code as env.API_URL. These values ship inside the app: no secrets.
|
|
350
|
+
env: {
|
|
351
|
+
dev: { API_URL: "http://localhost:3000" },
|
|
352
|
+
staging: { API_URL: "https://staging.example.com" },
|
|
353
|
+
prod: { API_URL: "https://api.example.com" }
|
|
658
354
|
}
|
|
659
355
|
}
|
|
660
356
|
`,
|
|
@@ -690,15 +386,23 @@ export default defineConfig({
|
|
|
690
386
|
state count = 0
|
|
691
387
|
|
|
692
388
|
screen Home {
|
|
389
|
+
page title: "${pretty}", description: "${pretty}, built with Orvyn"
|
|
390
|
+
|
|
693
391
|
Column gap: 16, padding: 24 {
|
|
694
392
|
Heading "${pretty}", size: 32
|
|
695
393
|
Text "You tapped {count} times"
|
|
696
394
|
Button "Tap me", bg: black, color: white, padding: 12, radius: 10, onTap: count += 1
|
|
697
395
|
}
|
|
698
396
|
}
|
|
397
|
+
|
|
398
|
+
// run with: orvyn test
|
|
399
|
+
test "counts taps" {
|
|
400
|
+
tap("Tap me")
|
|
401
|
+
expect(text("You tapped 1 times"))
|
|
402
|
+
}
|
|
699
403
|
`,
|
|
700
404
|
|
|
701
|
-
".gitignore": "node_modules\ndist\n",
|
|
405
|
+
".gitignore": "node_modules\ndist\norvyn.db*\n*.jks\n*.keystore\n",
|
|
702
406
|
|
|
703
407
|
"README.md": `# ${pretty}
|
|
704
408
|
|
|
@@ -707,7 +411,8 @@ Built with the Orvyn language (v${orvynVersion}).
|
|
|
707
411
|
\`\`\`bash
|
|
708
412
|
orvyn dev # web → http://localhost:5173 (live reload)
|
|
709
413
|
orvyn ios # iPhone simulator (live reload, needs Xcode)
|
|
710
|
-
orvyn android # Android emulator or phone
|
|
414
|
+
orvyn android # Android emulator or phone, with live reload
|
|
415
|
+
orvyn doctor # what is missing to build and publish
|
|
711
416
|
orvyn check # find mistakes in src/app.orv
|
|
712
417
|
orvyn build ios # Xcode project for real iPhones / App Store
|
|
713
418
|
\`\`\`
|
|
@@ -765,7 +470,8 @@ async function nativeOrv(mode, commandArgs) {
|
|
|
765
470
|
|
|
766
471
|
try {
|
|
767
472
|
const fn = mode === "run" ? runNativeApp : mode === "dev" ? devNativeApp : buildNativeApp
|
|
768
|
-
|
|
473
|
+
if (release && mode !== "build") throw new Error("--release only works with: orvyn build ios|android")
|
|
474
|
+
await fn(target, entry, { cwd, log, release })
|
|
769
475
|
} catch (error) {
|
|
770
476
|
if (error instanceof OrvynSyntaxError || error?.cause instanceof OrvynSyntaxError) {
|
|
771
477
|
log(`✗ ${entry}: ${error.message}`)
|
|
@@ -777,71 +483,92 @@ async function nativeOrv(mode, commandArgs) {
|
|
|
777
483
|
}
|
|
778
484
|
}
|
|
779
485
|
|
|
780
|
-
|
|
486
|
+
function help() {
|
|
487
|
+
log("Orvyn — one language for web, iPhone and Android")
|
|
488
|
+
log("")
|
|
489
|
+
log("Start:")
|
|
490
|
+
log(" orvyn new my-app Create a new app (and install it)")
|
|
491
|
+
log("")
|
|
492
|
+
log("Inside your app folder:")
|
|
493
|
+
log(" orvyn dev Web, with live reload")
|
|
494
|
+
log(" orvyn ios iPhone simulator, with live reload")
|
|
495
|
+
log(" orvyn android Android emulator or phone, with live reload")
|
|
496
|
+
log(" orvyn doctor Check what is missing to build and publish")
|
|
497
|
+
log(" orvyn build ios --release Signed .ipa for the App Store")
|
|
498
|
+
log(" orvyn build android --release Signed .aab for Google Play")
|
|
499
|
+
log(" orvyn check Find mistakes in your code")
|
|
500
|
+
log(" orvyn test Run the test blocks in your app")
|
|
501
|
+
log(" orvyn serve Backend with database and login (server.orv)")
|
|
502
|
+
log(" orvyn admin EMAIL Let an account change admin tables")
|
|
503
|
+
log(" orvyn build server Folder to upload to your host → dist/server/")
|
|
504
|
+
log(" orvyn build Website → dist/web/")
|
|
505
|
+
log(" orvyn build ios Xcode project → dist/ios/ (for real iPhones / App Store)")
|
|
506
|
+
log(" orvyn build android Android Studio project → dist/android/")
|
|
507
|
+
log(" orvyn preview Preview the built website")
|
|
508
|
+
log(" --env staging Use another environment (dev and run: dev, build: prod)")
|
|
509
|
+
log("")
|
|
510
|
+
log("Any .orv file:")
|
|
511
|
+
log(" orvyn compile app.orv Compile .orv to JavaScript (prints it)")
|
|
512
|
+
log(" orvyn compile app.orv -o x.js Write the JavaScript to a file")
|
|
513
|
+
log(" orvyn check app.orv Check a .orv file for errors")
|
|
514
|
+
log(" orvyn build ios app.orv Build a native iPhone app (SwiftUI)")
|
|
515
|
+
log(" orvyn build android app.orv Build a native Android app")
|
|
516
|
+
log(" orvyn dev ios app.orv iPhone simulator with live reload")
|
|
517
|
+
log(" orvyn dev android app.orv Android with live reload")
|
|
518
|
+
log(" orvyn run ios app.orv Build and open it in the iPhone simulator")
|
|
519
|
+
log(" orvyn run android app.orv Build and install on an emulator/phone")
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
if (command === "build" && args[0] === "server") {
|
|
523
|
+
const file = args.find(arg => arg.endsWith(".orv")) ||
|
|
524
|
+
["src/server.orv", "server.orv"].find(path => existsSync(join(cwd, path)))
|
|
525
|
+
try {
|
|
526
|
+
if (!file) throw new Error("No server.orv here")
|
|
527
|
+
const { exportServer } = await import("../lang/server-export.js")
|
|
528
|
+
const files = exportServer(file, join(cwd, "dist/server"))
|
|
529
|
+
log(`[Orvyn] ✓ Server ready to upload → dist/server/ (${files.join(", ")})`)
|
|
530
|
+
} catch (error) {
|
|
531
|
+
log(`✗ ${error.message}`)
|
|
532
|
+
process.exit(1)
|
|
533
|
+
}
|
|
534
|
+
} else if (release && !(command === "build" && args.some(arg => arg.endsWith(".orv")))) {
|
|
535
|
+
log("--release only works with: orvyn build ios|android")
|
|
536
|
+
process.exit(1)
|
|
537
|
+
} else if (command === "serve" || command === "admin") {
|
|
538
|
+
await serverOrv(command, args)
|
|
539
|
+
} else if (command === "test") {
|
|
540
|
+
await testOrv(args)
|
|
541
|
+
} else if (command === "doctor") {
|
|
542
|
+
const { doctor, formatChecks } = await import("../lang/doctor.js")
|
|
543
|
+
log(formatChecks(await doctor(cwd)))
|
|
544
|
+
} else if (command === "web-dev") {
|
|
781
545
|
run(viteBinary(), args)
|
|
782
546
|
} else if (command === "web-build") {
|
|
783
547
|
// dist/web so it never deletes dist/ios or dist/android
|
|
784
|
-
|
|
548
|
+
runSync(viteBinary(), ["build", "--outDir", "dist/web", "--emptyOutDir", ...args])
|
|
549
|
+
if (orvEntry) {
|
|
550
|
+
try {
|
|
551
|
+
const { prerender } = await import("../lang/prerender.js")
|
|
552
|
+
const { loadEnv } = await import("../lang/env.js")
|
|
553
|
+
const files = await prerender(cwd, orvEntry, join(cwd, "dist/web"), await loadEnv(cwd, "prod"))
|
|
554
|
+
log(`[Orvyn] ✓ Ready-made pages for search engines: ${files.join(", ")}`)
|
|
555
|
+
} catch (error) {
|
|
556
|
+
log(`[Orvyn] ✗ Could not make ready-made pages: ${error.message}`)
|
|
557
|
+
process.exit(1)
|
|
558
|
+
}
|
|
559
|
+
}
|
|
785
560
|
} else if (command === "web-preview") {
|
|
786
561
|
run(viteBinary(), ["preview", "--outDir", "dist/web", ...args])
|
|
787
562
|
} else if ((command === "build" || command === "run" || command === "dev") && args.some(arg => arg.endsWith(".orv"))) {
|
|
788
563
|
await nativeOrv(command, args)
|
|
789
|
-
} else if (command === "dev") {
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
if (target === "universal") {
|
|
794
|
-
log("Use one dev target at a time: web, ios, or android.")
|
|
795
|
-
process.exit(1)
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
logRenderer(target)
|
|
799
|
-
|
|
800
|
-
run(
|
|
801
|
-
viteBinary(),
|
|
802
|
-
rest,
|
|
803
|
-
{
|
|
804
|
-
env: {
|
|
805
|
-
ORVYN_TARGET: target
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
)
|
|
809
|
-
} else if (command === "build") {
|
|
810
|
-
const { target, rest } =
|
|
811
|
-
targetFromArgs("web")
|
|
812
|
-
|
|
813
|
-
buildTarget(target, rest)
|
|
814
|
-
} else if (command === "preview") {
|
|
815
|
-
const { target, rest } =
|
|
816
|
-
targetFromArgs("web")
|
|
817
|
-
|
|
818
|
-
if (target !== "web") {
|
|
819
|
-
log("Preview currently serves the browser-native web target.")
|
|
820
|
-
process.exit(1)
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
logRenderer("web")
|
|
824
|
-
|
|
825
|
-
run(
|
|
826
|
-
viteBinary(),
|
|
827
|
-
[
|
|
828
|
-
"preview",
|
|
829
|
-
"--outDir",
|
|
830
|
-
"dist/web",
|
|
831
|
-
...rest
|
|
832
|
-
],
|
|
833
|
-
{
|
|
834
|
-
env: {
|
|
835
|
-
ORVYN_TARGET: "web"
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
)
|
|
564
|
+
} else if (command === "dev" || command === "build" || command === "preview" || command === "run") {
|
|
565
|
+
log("No Orvyn app here (looked for src/app.orv and app.orv).")
|
|
566
|
+
log("Go into your app folder, or create one with: orvyn new my-app")
|
|
567
|
+
process.exit(1)
|
|
839
568
|
} else if (command === "new") {
|
|
840
569
|
newOrvProject(args[0])
|
|
841
570
|
} else if (command === "compile" || command === "check") {
|
|
842
571
|
await compileOrv(command, args)
|
|
843
|
-
} else if (command === "analyze") {
|
|
844
|
-
analyze()
|
|
845
572
|
} else if (
|
|
846
573
|
command === "help" ||
|
|
847
574
|
command === "--help" ||
|