@lunora/cli 1.0.0-alpha.3 → 1.0.0-alpha.31

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 (53) hide show
  1. package/__assets__/package-og.svg +1 -1
  2. package/dist/bin.mjs +1 -1
  3. package/dist/index.d.mts +243 -114
  4. package/dist/index.d.ts +243 -114
  5. package/dist/index.mjs +7 -7
  6. package/dist/packem_chunks/handler.mjs +89 -7
  7. package/dist/packem_chunks/handler10.mjs +8 -14
  8. package/dist/packem_chunks/handler11.mjs +19 -189
  9. package/dist/packem_chunks/handler12.mjs +176 -115
  10. package/dist/packem_chunks/handler13.mjs +118 -52
  11. package/dist/packem_chunks/handler14.mjs +50 -43
  12. package/dist/packem_chunks/handler15.mjs +46 -67
  13. package/dist/packem_chunks/handler16.mjs +74 -37
  14. package/dist/packem_chunks/handler17.mjs +38 -100
  15. package/dist/packem_chunks/handler18.mjs +87 -154
  16. package/dist/packem_chunks/handler19.mjs +148 -67
  17. package/dist/packem_chunks/handler2.mjs +2 -2
  18. package/dist/packem_chunks/handler20.mjs +75 -75
  19. package/dist/packem_chunks/handler21.mjs +71 -288
  20. package/dist/packem_chunks/handler3.mjs +1 -1
  21. package/dist/packem_chunks/handler4.mjs +1 -1
  22. package/dist/packem_chunks/handler5.mjs +2 -2
  23. package/dist/packem_chunks/handler6.mjs +2 -2
  24. package/dist/packem_chunks/handler7.mjs +1 -1
  25. package/dist/packem_chunks/handler8.mjs +1 -1
  26. package/dist/packem_chunks/handler9.mjs +311 -12
  27. package/dist/packem_chunks/planDevCommand.mjs +48 -50
  28. package/dist/packem_chunks/runCodegenCommand.mjs +2 -2
  29. package/dist/packem_chunks/runDeployCommand.mjs +105 -15
  30. package/dist/packem_chunks/runInitCommand.mjs +1980 -77
  31. package/dist/packem_chunks/runMigrateGenerateCommand.mjs +5 -5
  32. package/dist/packem_chunks/runResetCommand.mjs +4 -4
  33. package/dist/packem_chunks/runRpcCommand.mjs +1 -1
  34. package/dist/packem_shared/{COMMANDS-CHw4zOZ9.mjs → COMMANDS-B0ftFD_3.mjs} +47 -21
  35. package/dist/packem_shared/codegen-error-DJG-ghs_.mjs +31 -0
  36. package/dist/packem_shared/{command-BDXcJCCJ.mjs → command-D3lB_4Az.mjs} +6 -1
  37. package/dist/packem_shared/{commands-DIQ3nf0C.mjs → commands-B-gR09Z_.mjs} +124 -22
  38. package/dist/packem_shared/{createLogger-CHPNjFw2.mjs → createLogger-B40gPzQo.mjs} +9 -4
  39. package/dist/packem_shared/detect-package-manager-DYp7n3mJ.mjs +61 -0
  40. package/dist/packem_shared/{diffSnapshots-RR2ZE8Ya.mjs → diffSnapshots-BeDvvNiF.mjs} +1 -1
  41. package/dist/packem_shared/{insertSchemaExtension-BuzF6-t2.mjs → insertSchemaExtension-DAqbfr9Z.mjs} +15 -10
  42. package/dist/packem_shared/{output-format-7gyGR3h8.mjs → output-format-wUvAN6AL.mjs} +1 -1
  43. package/dist/packem_shared/prompt-cancelled-APzX1Im-.mjs +9 -0
  44. package/dist/packem_shared/runAddCommand-bnY6-HKb.mjs +4 -0
  45. package/dist/packem_shared/{schemaIrToSnapshot-aBTo7TM5.mjs → schemaIrToSnapshot-DdsljJT-.mjs} +1 -1
  46. package/dist/packem_shared/storage-BIsph-Vk.mjs +84 -0
  47. package/dist/packem_shared/tui-prompts-BjEN8XgP.mjs +658 -0
  48. package/dist/packem_shared/wrangler-secrets-P2_ZUR-k.mjs +47 -0
  49. package/package.json +13 -11
  50. package/skills/lunora-setup-storage/SKILL.md +7 -3
  51. package/dist/packem_shared/features-ocSSpZtS.mjs +0 -24
  52. package/dist/packem_shared/runAddCommand-3I3JFZUG.mjs +0 -4
  53. /package/dist/packem_shared/{defaultSpawner-DxI3mebw.mjs → createRecordingSpawner-DxI3mebw.mjs} +0 -0
@@ -1,15 +1,22 @@
1
- import { existsSync, mkdirSync, writeFileSync, readdirSync, mkdtempSync, rmSync, readFileSync } from 'node:fs';
1
+ import { existsSync, mkdirSync, writeFileSync, readFileSync, readdirSync, rmSync, mkdtempSync, cpSync, renameSync } from 'node:fs';
2
2
  import { tmpdir } from 'node:os';
3
- import { detectFramework as detectFramework$1, isInteractive, promptSelect, promptMultiSelect } from '@lunora/config';
3
+ import { detectFramework as detectFramework$1, isInteractive, LUNA_ART, LUNA_NAME, LUNA_SIGNOFF, paintAnswer, BADGES } from '@lunora/config';
4
4
  import { walkSync } from '@visulima/fs';
5
- import { resolve, join as join$1, relative, dirname as dirname$1 } from '@visulima/path';
5
+ import { join as join$1, dirname as dirname$1, basename, resolve, relative } from '@visulima/path';
6
6
  import { downloadTemplate } from 'giget';
7
+ import { modify, applyEdits } from 'jsonc-parser';
7
8
  import { join, dirname } from 'node:path';
8
- import { d as defineHandler } from '../packem_shared/command-BDXcJCCJ.mjs';
9
+ import { d as defineHandler } from '../packem_shared/command-D3lB_4Az.mjs';
10
+ import { a as detectInstalledManagers, i as installArgsFor } from '../packem_shared/detect-package-manager-DYp7n3mJ.mjs';
9
11
  import MagicString from 'magic-string';
10
12
  import { Project, SyntaxKind } from 'ts-morph';
11
- import { c as resolveSourceRef, r as runAddCommand } from '../packem_shared/commands-DIQ3nf0C.mjs';
12
- import { p as promptAuthProvider, E as EMAIL_ITEM } from '../packem_shared/features-ocSSpZtS.mjs';
13
+ import { P as PromptCancelledError } from '../packem_shared/prompt-cancelled-APzX1Im-.mjs';
14
+ import { c as resolveTagVersions, d as resolveSourceRef, e as resolveDistTag, r as runAddCommand } from '../packem_shared/commands-B-gR09Z_.mjs';
15
+ import { defaultSpawner } from '../packem_shared/createRecordingSpawner-DxI3mebw.mjs';
16
+ import { d as tuiMascot, e as tuiStep, f as tuiMoonrise, t as tuiText, g as tuiHeadline, h as tuiInfo, a as tuiSelect, b as tuiConfirm, w as withTuiSpinner, i as tuiNextSteps, j as tuiTasks, k as tuiMultiSelect, l as withTuiBadgeProgress } from '../packem_shared/tui-prompts-BjEN8XgP.mjs';
17
+ import { logStep } from '../packem_shared/createLogger-B40gPzQo.mjs';
18
+ import { E as EMAIL_ITEM, p as promptBucketName, w as withStorageBucketName, M as MAIL_DESTINATION_PROMPT, r as resolveTypedDestination, f as withMailDestination, e as promptAuthProvider, c as promptDatabaseName, g as withAuthDatabaseName } from '../packem_shared/storage-BIsph-Vk.mjs';
19
+ import dns from 'node:dns/promises';
13
20
 
14
21
  const GITHUB_CONTENT = `name: Deploy
15
22
 
@@ -19,6 +26,10 @@ on:
19
26
  pull_request:
20
27
  workflow_dispatch:
21
28
 
29
+ # Prerequisite: commit your pnpm-lock.yaml. \`pnpm install --frozen-lockfile\`
30
+ # (below) and the pnpm cache both require it — run \`pnpm install\` locally and
31
+ # commit the lockfile before pushing, or the first CI run fails.
32
+ #
22
33
  # Set these repository secrets (Settings → Secrets and variables → Actions):
23
34
  # CLOUDFLARE_API_TOKEN — a Workers-scoped API token
24
35
  # CLOUDFLARE_ACCOUNT_ID — your Cloudflare account id
@@ -65,6 +76,10 @@ jobs:
65
76
  const GITLAB_CONTENT = `stages:
66
77
  - deploy
67
78
 
79
+ # Prerequisite: commit your pnpm-lock.yaml. \`pnpm install --frozen-lockfile\`
80
+ # (below) requires it — run \`pnpm install\` locally and commit the lockfile
81
+ # before pushing, or the first pipeline fails.
82
+ #
68
83
  # Set these as masked CI/CD variables (Settings → CI/CD → Variables):
69
84
  # CLOUDFLARE_API_TOKEN — a Workers-scoped API token
70
85
  # CLOUDFLARE_ACCOUNT_ID — your Cloudflare account id
@@ -126,6 +141,9 @@ const scaffoldCiWorkflow = (projectRoot, provider, logger, options = {}) => {
126
141
  } else {
127
142
  logger.success(`--ci ${provider}: wrote ${spec.file}`);
128
143
  logger.info(`--ci ${provider}: set CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID as ${spec.secretsHint} to enable deploys.`);
144
+ logger.info(
145
+ `--ci ${provider}: run \`pnpm install\` and commit pnpm-lock.yaml before pushing — the pipeline runs \`pnpm install --frozen-lockfile\`.`
146
+ );
129
147
  }
130
148
  return result;
131
149
  } catch (error) {
@@ -270,26 +288,1452 @@ const patchViteConfig = (source) => {
270
288
  return { changed: true, code: ms.toString() };
271
289
  };
272
290
 
291
+ const NETWORK_ERROR_PATTERN = /enotfound|eai_again|econnrefused|etimedout|network|fetch failed|getaddrinfo/u;
292
+ const NOT_FOUND_ERROR_PATTERN = /404|not found|could not find|no such/u;
293
+ const describeDownloadFailure = (error, context) => {
294
+ const raw = error instanceof Error ? error.message : String(error);
295
+ const lower = raw.toLowerCase();
296
+ const genericMessage = `failed to download template "${context.templateType}" from ${context.remote}: ${raw}`;
297
+ if (NOT_FOUND_ERROR_PATTERN.test(lower)) {
298
+ return {
299
+ hints: [
300
+ `Check the template name "${context.templateType}" and the ref "${context.ref}".`,
301
+ "List/inspect available templates, or target a branch/tag with `--ref <branch>`."
302
+ ],
303
+ message: `template "${context.templateType}" not found at ${context.remote}: ${raw}`
304
+ };
305
+ }
306
+ if (NETWORK_ERROR_PATTERN.test(lower)) {
307
+ return {
308
+ hints: [
309
+ "You appear to be offline or unable to reach GitHub.",
310
+ "To scaffold without a network, point at a local template root: `lunora init --from <dir>`."
311
+ ],
312
+ message: genericMessage
313
+ };
314
+ }
315
+ return {
316
+ hints: ["If this is a network/offline issue, scaffold from a local root with `lunora init --from <dir>`."],
317
+ message: genericMessage
318
+ };
319
+ };
320
+
321
+ const emitStep = async (type, message, answer) => {
322
+ if (isInteractive()) {
323
+ await tuiStep(BADGES[type], message, answer);
324
+ return;
325
+ }
326
+ process.stdout.write("\n");
327
+ if (answer === void 0 || answer === "") {
328
+ logStep(type, message);
329
+ return;
330
+ }
331
+ const dimmed = answer.split("\n").map((line) => paintAnswer(line)).join("\n");
332
+ logStep(type, `${message}
333
+ ${dimmed}`);
334
+ };
335
+ const emitMascot = async (logger) => {
336
+ if (isInteractive()) {
337
+ await tuiMascot();
338
+ return;
339
+ }
340
+ logger.info(`
341
+ ${LUNA_ART}
342
+ ${LUNA_NAME}: ${LUNA_SIGNOFF}`);
343
+ };
344
+
273
345
  const STACK_FEATURE_OPTIONS = [
274
346
  { description: "Sign-up / sign-in (asks which provider)", label: "Authentication", value: "auth" },
275
- { description: "Cloudflare Email Workers + a dev mail catcher", label: "Transactional email", value: "email" }
347
+ { description: "Cloudflare Email Workers + a dev mail catcher", label: "Transactional email", value: "email" },
348
+ { description: "Typed R2 buckets + signed URLs (@lunora/storage)", label: "File storage", value: "storage" },
349
+ { description: "Token-bucket / sliding-window limits (@lunora/ratelimit)", label: "Rate limiting", value: "ratelimit" },
350
+ { description: "Scheduled jobs via Cron Triggers (@lunora/scheduler)", label: "Cron jobs", value: "crons" },
351
+ { description: "Live presence / who's-online over hibernated WebSockets", label: "Presence", value: "presence" },
352
+ { description: "Snapshot + restore your Durable Object data", label: "Backups", value: "backup" }
276
353
  ];
354
+ const STACK_FEATURE_VALUES = STACK_FEATURE_OPTIONS.map((option) => option.value);
355
+ const featureItem = (feature) => feature === "email" ? EMAIL_ITEM : feature;
356
+ const parseFeatureList = (raw, warn) => {
357
+ const features = [];
358
+ for (const part of raw.split(",").map((entry) => entry.trim()).filter(Boolean)) {
359
+ if (STACK_FEATURE_VALUES.includes(part)) {
360
+ if (!features.includes(part)) {
361
+ features.push(part);
362
+ }
363
+ } else {
364
+ warn(`init: unknown --add feature "${part}" — expected ${STACK_FEATURE_VALUES.join(" | ")}; skipping.`);
365
+ }
366
+ }
367
+ return features;
368
+ };
369
+ const collectAuthFeature = async (deps) => {
370
+ const provider = await promptAuthProvider(deps.select);
371
+ const databaseName = await promptDatabaseName(deps.text, deps.projectName);
372
+ return { label: "auth", names: [provider], transformManifest: (manifest) => withAuthDatabaseName(manifest, databaseName) };
373
+ };
374
+ const collectEmailFeature = async (deps) => {
375
+ const answer = await deps.text(MAIL_DESTINATION_PROMPT, { placeholder: "you@yourdomain.com" });
376
+ const destination = resolveTypedDestination(answer, (message) => {
377
+ deps.logger.warn(message);
378
+ });
379
+ return {
380
+ label: "email",
381
+ names: [EMAIL_ITEM],
382
+ transformManifest: destination === void 0 ? void 0 : (manifest) => withMailDestination(manifest, destination)
383
+ };
384
+ };
385
+ const collectStorageFeature = async (deps) => {
386
+ const bucketName = await promptBucketName(deps.text, deps.projectName);
387
+ return { label: "storage", names: ["storage"], transformManifest: (manifest) => withStorageBucketName(manifest, bucketName) };
388
+ };
389
+ const FEATURE_COLLECTORS = {
390
+ auth: collectAuthFeature,
391
+ email: collectEmailFeature,
392
+ storage: collectStorageFeature
393
+ };
277
394
  const offerRegistryExtras = async (deps) => {
395
+ if (deps.preselected !== void 0 && deps.preselected.length > 0) {
396
+ await deps.applyAll(
397
+ deps.preselected.map((feature) => {
398
+ return { label: feature, names: [featureItem(feature)] };
399
+ })
400
+ );
401
+ return;
402
+ }
278
403
  if (!deps.interactive) {
279
- deps.logger.info("tip: add authentication or email later with `lunora add auth` / `lunora add email`.");
404
+ deps.logger.info("tip: add features later with `lunora add <auth|email|storage|ratelimit|crons|presence|backup>`.");
280
405
  return;
281
406
  }
282
407
  const picked = await deps.multiSelect("Which features do you want to add?", STACK_FEATURE_OPTIONS, { defaults: [] });
408
+ if (picked.length === 0) {
409
+ return;
410
+ }
411
+ const plans = [];
283
412
  for (const feature of picked) {
284
- if (feature === "auth") {
285
- const provider = await promptAuthProvider(deps.select);
286
- await deps.apply([provider]);
287
- } else {
288
- await deps.apply([EMAIL_ITEM]);
413
+ const collect = FEATURE_COLLECTORS[feature];
414
+ plans.push(collect ? await collect(deps) : { label: feature, names: [feature] });
415
+ }
416
+ await deps.applyAll(plans);
417
+ };
418
+
419
+ const LOGO_PATH = "M 259.500 10.552 C 220.080 15.859, 182.424 32.566, 152.500 58.025 C 110.179 94.031, 85.380 137.183, 77.518 188.500 C 75.410 202.255, 74.569 225.677, 75.796 236.466 C 76.757 244.917, 76.683 245.692, 74.518 249.966 C 63.118 272.466, 53.141 303.876, 51.382 322.799 L 50.718 329.943 71.960 320.471 C 83.643 315.262, 93.326 311, 93.478 311 C 93.630 311, 96.547 316.063, 99.959 322.250 C 103.371 328.438, 107.249 334.850, 108.577 336.500 L 110.990 339.500 110.981 336 C 110.977 334.075, 111.499 324.991, 112.143 315.813 L 113.312 299.127 121.406 293.336 C 132.495 285.403, 149.593 271.554, 161 261.268 C 171.556 251.748, 189.116 235, 188.540 235 C 188.337 235, 183.069 238.648, 176.835 243.106 C 142.318 267.789, 68.537 314, 63.646 314 C 61.843 314, 72.791 281.179, 80.905 262.259 C 92.233 235.845, 107.473 212.389, 132.106 183.453 L 138.451 176 148.268 176 C 176.192 176, 197.512 187.154, 212.868 209.797 C 216.470 215.108, 217.035 216.595, 216.477 219.297 C 211.386 243.968, 202.359 274.496, 193.797 296 C 183.898 320.861, 167.147 352.101, 152.395 373.215 L 147.004 380.930 152.891 385.830 C 161.400 392.911, 165.563 396, 166.594 395.998 C 167.092 395.998, 168.772 391.641, 170.327 386.317 C 176.279 365.934, 188.422 338.749, 200.942 317.778 C 223.060 280.731, 256.432 244.369, 294.500 215.836 C 309.956 204.252, 313.937 201.603, 314.719 202.385 C 315.116 202.783, 315.449 213.096, 315.460 225.304 C 315.474 241.855, 315.021 250.405, 313.680 258.924 C 307.009 301.272, 291.175 336.677, 263.112 372 C 255.259 381.883, 227.182 410.673, 218.516 417.727 L 213.532 421.783 223.439 424.880 C 281.705 443.093, 349.165 436.018, 398.616 406.508 C 446.728 377.797, 483.322 331.466, 497.366 281.481 C 503.381 260.075, 504.480 250.741, 504.491 221 C 504.501 191.997, 503.598 184.047, 497.987 163.732 C 484.768 115.871, 452.505 72.708, 407.718 42.964 C 381.051 25.254, 352.818 14.828, 319.695 10.460 C 305.932 8.645, 273.298 8.695, 259.500 10.552";
420
+ const WELCOME_CSS = `/* The welcome page is a full-bleed starter — reset the browser's default
421
+ body margin/padding so it sits flush; everything else is scoped under
422
+ .lunora-welcome (collision-safe). */
423
+ body {
424
+ margin: 0;
425
+ padding: 0;
426
+ }
427
+
428
+ .lunora-welcome {
429
+ --cyan: hsl(186 84% 56%); --violet: hsl(256 72% 68%); --rose: hsl(330 80% 64%);
430
+ --ribbon: linear-gradient(115deg, var(--cyan), var(--violet) 52%, var(--rose));
431
+ --sans: "Geist Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
432
+ --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
433
+ /* NIGHT (default) */
434
+ --bg: #0e0e11; --surface: hsl(240 12% 8% / 0.72); --surface-2: hsl(240 11% 11% / 0.82);
435
+ --line: hsl(0 0% 100% / 0.08); --line-2: hsl(0 0% 100% / 0.14);
436
+ --t-display: hsl(228 30% 97%); --t-primary: hsl(228 26% 90%); --t-secondary: hsl(228 12% 62%); --t-faint: hsl(228 10% 44%);
437
+ --logo: hsl(228 30% 97%); --accent: var(--violet); --shot-bg: hsl(240 12% 6%);
438
+ --glow-1: hsl(256 80% 52% / 0.30); --glow-2: hsl(196 84% 52% / 0.13); --arc: hsl(256 60% 70% / 0.11);
439
+
440
+ position: relative; min-height: 100vh; background: var(--bg); color: var(--t-primary);
441
+ font-family: var(--sans); line-height: 1.55; -webkit-font-smoothing: antialiased; overflow-x: hidden;
442
+ transition: background .3s, color .3s;
443
+ }
444
+ .lunora-welcome[data-theme="light"] {
445
+ --bg: hsl(228 32% 97%); --surface: hsl(0 0% 100% / 0.82); --surface-2: hsl(0 0% 100% / 0.95);
446
+ --line: hsl(228 16% 88%); --line-2: hsl(228 14% 80%);
447
+ --t-display: hsl(240 14% 10%); --t-primary: hsl(240 12% 18%); --t-secondary: hsl(235 9% 42%); --t-faint: hsl(235 8% 58%);
448
+ --logo: hsl(240 16% 9%); --accent: hsl(256 58% 56%); --shot-bg: hsl(228 26% 99%);
449
+ --glow-1: hsl(256 80% 60% / 0.14); --glow-2: hsl(196 84% 58% / 0.08); --arc: hsl(256 40% 55% / 0.12);
450
+ }
451
+ .lunora-welcome *, .lunora-welcome *::before, .lunora-welcome *::after { box-sizing: border-box; }
452
+ .lunora-welcome a { color: inherit; text-decoration: none; }
453
+ .lunora-welcome button { font-family: inherit; cursor: pointer; }
454
+ .lunora-welcome ::selection { background: hsl(256 72% 68% / 0.3); }
455
+ .lunora-welcome code { font-family: var(--mono); }
456
+
457
+ /* glow background */
458
+ .lunora-welcome .lw-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
459
+ .lunora-welcome .lw-bg .glow { position: absolute; left: 50%; top: -4%; width: 860px; height: 720px; transform: translateX(-50%);
460
+ border-radius: 50%; background: radial-gradient(circle at 50% 50%, var(--glow-1), var(--glow-2) 40%, transparent 66%); }
461
+ .lunora-welcome .lw-bg .arc { position: absolute; left: 50%; border-radius: 50%; border: 1px solid var(--arc); transform: translateX(-50%); }
462
+ .lunora-welcome .lw-bg .arc.a1 { top: -340px; width: 980px; height: 980px; }
463
+ .lunora-welcome .lw-bg .arc.a2 { top: -240px; width: 720px; height: 720px; opacity: .7; }
464
+
465
+ /* theme toggle */
466
+ .lunora-welcome .lw-toggle { position: fixed; z-index: 5; top: 20px; right: clamp(16px,4vw,36px); display: inline-flex; align-items: center;
467
+ gap: 7px; border: 1px solid var(--line-2); background: var(--surface); backdrop-filter: blur(12px); color: var(--t-secondary);
468
+ font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; padding: 7px 11px; transition: .15s; }
469
+ .lunora-welcome .lw-toggle:hover { color: var(--t-display); border-color: var(--accent); }
470
+ .lunora-welcome .lw-toggle svg { width: 13px; height: 13px; }
471
+
472
+ .lunora-welcome .lw-wrap { position: relative; z-index: 2; width: 100%; max-width: 1080px; margin: 0 auto;
473
+ padding: clamp(44px,8vh,92px) clamp(20px,5vw,48px); display: flex; flex-direction: column; min-height: 100vh; }
474
+ .lunora-welcome .brand { display: flex; align-items: center; justify-content: center; gap: 15px; margin-bottom: clamp(38px,6vh,68px); color: var(--logo); }
475
+ .lunora-welcome .brand svg { width: 54px; height: auto; display: block; }
476
+ .lunora-welcome .brand .word { font-size: 34px; font-weight: 600; letter-spacing: -0.03em; color: var(--t-display); }
477
+
478
+ .lunora-welcome .grid { display: grid; grid-template-columns: 1.06fr 0.94fr; gap: 16px; align-items: stretch; flex: 1; max-height: 580px; }
479
+ @media (max-width: 820px) { .lunora-welcome .grid { grid-template-columns: 1fr; max-height: none; } }
480
+
481
+ .lunora-welcome .card { border: 1px solid var(--line); background: var(--surface); backdrop-filter: blur(10px); transition: border-color .2s, background .2s; }
482
+ .lunora-welcome .card:hover { border-color: var(--line-2); background: var(--surface-2); }
483
+ .lunora-welcome .card:hover .arrow { color: var(--accent); transform: translateX(3px); }
484
+ .lunora-welcome .arrow { color: var(--t-faint); transition: color .2s, transform .2s; }
485
+ .lunora-welcome .arrow svg { width: 20px; height: 20px; display: block; }
486
+ .lunora-welcome .ic { display: grid; place-items: center; color: var(--accent);
487
+ border: 1px solid color-mix(in oklab, var(--accent) 36%, transparent); background: color-mix(in oklab, var(--accent) 12%, transparent); }
488
+ .lunora-welcome .ic svg { display: block; }
489
+
490
+ /* left feature card — stretches to fill the box height */
491
+ .lunora-welcome .feature { padding: clamp(18px,2vw,24px); display: flex; flex-direction: column; }
492
+ .lunora-welcome .shot { border: 1px solid var(--line); overflow: hidden; background: var(--shot-bg);
493
+ -webkit-mask-image: linear-gradient(to bottom, #000 56%, transparent 100%); mask-image: linear-gradient(to bottom, #000 56%, transparent 100%); }
494
+ .lunora-welcome .shot .top { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
495
+ .lunora-welcome .shot .wm { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--t-primary); }
496
+ .lunora-welcome .shot .wm i { width: 11px; height: 11px; background: var(--ribbon); -webkit-mask: radial-gradient(circle,#000 60%,transparent 62%); mask: radial-gradient(circle,#000 60%,transparent 62%); }
497
+ .lunora-welcome .shot .search { flex: 1; height: 22px; border: 1px solid var(--line); border-radius: 4px; }
498
+ .lunora-welcome .shot .ver { font-family: var(--mono); font-size: 8px; letter-spacing: .08em; color: var(--t-faint); }
499
+ .lunora-welcome .shot .body { display: grid; grid-template-columns: 92px 1fr; min-height: 224px; }
500
+ .lunora-welcome .shot .nav { border-right: 1px solid var(--line); padding: 14px 12px; display: flex; flex-direction: column; gap: 11px; }
501
+ .lunora-welcome .shot .nav i, .lunora-welcome .shot .doc i { height: 5px; border-radius: 2px; background: var(--line); }
502
+ .lunora-welcome .shot .doc { padding: 16px 18px; display: flex; flex-direction: column; gap: 9px; }
503
+ .lunora-welcome .shot .doc .h { height: 8px; width: 46%; border-radius: 2px; background: var(--line-2); margin-bottom: 5px; }
504
+ .lunora-welcome .shot .doc .accent { height: 5px; width: 26%; border-radius: 2px; background: var(--accent); }
505
+ .lunora-welcome .feature .info { margin-top: auto; padding-top: clamp(18px,2.4vh,28px); }
506
+ .lunora-welcome .feature .ic { width: 40px; height: 40px; margin-bottom: 15px; }
507
+ .lunora-welcome .feature .ic svg { width: 19px; height: 19px; }
508
+ .lunora-welcome .feature h2 { margin: 0 0 10px; font-size: 19px; font-weight: 600; letter-spacing: -0.015em; color: var(--t-display); }
509
+ .lunora-welcome .feature .row { display: flex; align-items: flex-end; gap: 16px; }
510
+ .lunora-welcome .feature p { margin: 0; color: var(--t-secondary); font-size: 14px; max-width: 50ch; }
511
+ .lunora-welcome .feature .row .arrow { margin-left: auto; }
512
+
513
+ /* right stack — smaller cards, spread to align bottoms with the feature */
514
+ .lunora-welcome .stack { display: flex; flex-direction: column; gap: 16px; height: 100%; }
515
+ .lunora-welcome .mini { flex: 1; padding: 15px 17px; display: flex; align-items: center; gap: 16px; min-height: 0; }
516
+ .lunora-welcome .mini .mc { flex: 1; }
517
+ .lunora-welcome .mini .ic { width: 32px; height: 32px; margin-bottom: 10px; }
518
+ .lunora-welcome .mini .ic svg { width: 16px; height: 16px; }
519
+ .lunora-welcome .mini h3 { margin: 0 0 5px; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; color: var(--t-display); }
520
+ .lunora-welcome .mini p { margin: 0; color: var(--t-secondary); font-size: 12.5px; line-height: 1.45; }
521
+
522
+ .lunora-welcome .lw-foot { text-align: center; padding-top: 26px; font-family: var(--mono); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--t-faint); }
523
+
524
+ @media (prefers-reduced-motion: reduce) { .lunora-welcome * { transition: none !important; } }
525
+ `;
526
+ const REACT_APP = `import { useEffect, useState } from "react";
527
+
528
+ type Theme = "dark" | "light";
529
+
530
+ export default function App() {
531
+ // Default to "dark" for a stable first paint, then reconcile to the OS
532
+ // preference; the toggle takes over after that.
533
+ const [theme, setTheme] = useState<Theme>("dark");
534
+
535
+ useEffect(() => {
536
+ if (typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: light)").matches) {
537
+ setTheme("light");
538
+ }
539
+ }, []);
540
+
541
+ const isLight = theme === "light";
542
+
543
+ return (
544
+ <div className="lunora-welcome" data-theme={theme}>
545
+ <div className="lw-bg">
546
+ <div className="arc a1" />
547
+ <div className="arc a2" />
548
+ <div className="glow" />
549
+ </div>
550
+
551
+ <button className="lw-toggle" type="button" aria-label="Toggle color theme" onClick={() => setTheme(isLight ? "dark" : "light")}>
552
+ {isLight ? (
553
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8">
554
+ <path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z" />
555
+ </svg>
556
+ ) : (
557
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8">
558
+ <circle cx="12" cy="12" r="4" />
559
+ <path d="M12 2v2M12 20v2M4 12H2M22 12h-2M5 5l1.5 1.5M17.5 17.5 19 19M19 5l-1.5 1.5M6.5 17.5 5 19" />
560
+ </svg>
561
+ )}
562
+ <span>{isLight ? "Ivory" : "Night"}</span>
563
+ </button>
564
+
565
+ <div className="lw-wrap">
566
+ <div className="brand">
567
+ <svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
568
+ <path d="${LOGO_PATH}" fill="currentColor" fillRule="evenodd" />
569
+ </svg>
570
+ <span className="word">Lunora</span>
571
+ </div>
572
+
573
+ <div className="grid">
574
+ <a className="card feature" href="https://lunora.sh/docs">
575
+ <div className="shot" aria-hidden="true">
576
+ <div className="top">
577
+ <span className="wm">
578
+ <i /> Lunora
579
+ </span>
580
+ <span className="search" />
581
+ <span className="ver">v0.1</span>
582
+ </div>
583
+ <div className="body">
584
+ <div className="nav">
585
+ <i style={{ width: "80%" }} />
586
+ <i style={{ width: "60%" }} />
587
+ <i style={{ width: "72%" }} />
588
+ <i style={{ width: "50%" }} />
589
+ <i style={{ width: "66%" }} />
590
+ <i style={{ width: "44%" }} />
591
+ <i style={{ width: "58%" }} />
592
+ </div>
593
+ <div className="doc">
594
+ <span className="h" />
595
+ <i style={{ width: "92%" }} />
596
+ <i style={{ width: "88%" }} />
597
+ <span className="accent" />
598
+ <i style={{ width: "80%" }} />
599
+ <i style={{ width: "90%" }} />
600
+ <i style={{ width: "72%" }} />
601
+ <i style={{ width: "84%" }} />
602
+ <i style={{ width: "78%" }} />
603
+ </div>
604
+ </div>
605
+ </div>
606
+ <div className="info">
607
+ <span className="ic">
608
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7">
609
+ <path d="M4 5a2 2 0 0 1 2-2h9l5 5v11a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2z" />
610
+ <path d="M14 3v5h5" />
611
+ </svg>
612
+ </span>
613
+ <h2>Documentation</h2>
614
+ <div className="row">
615
+ <p>
616
+ Schemas, queries, live subscriptions, sharding, and edge deploy — start to finish. New here or coming from Convex or tRPC,
617
+ you'll have a live app fast.
618
+ </p>
619
+ <span className="arrow">
620
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
621
+ <path d="M5 12h14M13 6l6 6-6 6" />
622
+ </svg>
623
+ </span>
624
+ </div>
625
+ </div>
626
+ </a>
627
+
628
+ <div className="stack">
629
+ <a className="card mini" href="https://lunora.sh/blog">
630
+ <div className="mc">
631
+ <span className="ic">
632
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7">
633
+ <path d="M5 4h11a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H6a2 2 0 0 1-2-2V5a1 1 0 0 1 1-1zM8 8h7M8 12h7M8 16h4" />
634
+ </svg>
635
+ </span>
636
+ <h3>Blog</h3>
637
+ <p>Product updates, deep dives, and what's new in Lunora.</p>
638
+ </div>
639
+ <span className="arrow">
640
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
641
+ <path d="M5 12h14M13 6l6 6-6 6" />
642
+ </svg>
643
+ </span>
644
+ </a>
645
+ <a className="card mini" href="/_lunora">
646
+ <div className="mc">
647
+ <span className="ic">
648
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7">
649
+ <rect x="3" y="3" width="18" height="18" rx="1" />
650
+ <path d="M3 9h18M9 21V9" />
651
+ </svg>
652
+ </span>
653
+ <h3>Lunora Studio</h3>
654
+ <p>Local admin for schema, data, logs, and advisors.</p>
655
+ </div>
656
+ <span className="arrow">
657
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
658
+ <path d="M5 12h14M13 6l6 6-6 6" />
659
+ </svg>
660
+ </span>
661
+ </a>
662
+ <a className="card mini" href="https://lunora.sh/packages">
663
+ <div className="mc">
664
+ <span className="ic">
665
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7">
666
+ <path d="M12 2 3 7v10l9 5 9-5V7z" />
667
+ <path d="M3 7l9 5 9-5M12 12v10" />
668
+ </svg>
669
+ </span>
670
+ <h3>Cloudflare ecosystem</h3>
671
+ <p>Auth, mail, storage, AI, payments — one deploy.</p>
672
+ </div>
673
+ <span className="arrow">
674
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
675
+ <path d="M5 12h14M13 6l6 6-6 6" />
676
+ </svg>
677
+ </span>
678
+ </a>
679
+ </div>
680
+ </div>
681
+
682
+ <div className="lw-foot">Running on Lunora · Vite + React</div>
683
+ </div>
684
+ </div>
685
+ );
686
+ }
687
+ `;
688
+ const VUE_APP = `<script setup lang="ts">
689
+ import { onMounted, ref } from "vue";
690
+
691
+ // Default to "dark" for a stable first paint, then reconcile to the OS
692
+ // preference; the toggle takes over after that.
693
+ const theme = ref<"dark" | "light">("dark");
694
+
695
+ onMounted(() => {
696
+ if (window.matchMedia("(prefers-color-scheme: light)").matches) {
697
+ theme.value = "light";
289
698
  }
699
+ });
700
+
701
+ const toggle = (): void => {
702
+ theme.value = theme.value === "light" ? "dark" : "light";
703
+ };
704
+ <\/script>
705
+
706
+ <template>
707
+ <div class="lunora-welcome" :data-theme="theme">
708
+ <div class="lw-bg">
709
+ <div class="arc a1" />
710
+ <div class="arc a2" />
711
+ <div class="glow" />
712
+ </div>
713
+
714
+ <button class="lw-toggle" type="button" aria-label="Toggle color theme" @click="toggle">
715
+ <svg v-if="theme === 'light'" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
716
+ <path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z" />
717
+ </svg>
718
+ <svg v-else viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
719
+ <circle cx="12" cy="12" r="4" />
720
+ <path d="M12 2v2M12 20v2M4 12H2M22 12h-2M5 5l1.5 1.5M17.5 17.5 19 19M19 5l-1.5 1.5M6.5 17.5 5 19" />
721
+ </svg>
722
+ <span>{{ theme === "light" ? "Ivory" : "Night" }}</span>
723
+ </button>
724
+
725
+ <div class="lw-wrap">
726
+ <div class="brand">
727
+ <svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
728
+ <path d="${LOGO_PATH}" fill="currentColor" fill-rule="evenodd" />
729
+ </svg>
730
+ <span class="word">Lunora</span>
731
+ </div>
732
+
733
+ <div class="grid">
734
+ <a class="card feature" href="https://lunora.sh/docs">
735
+ <div class="shot" aria-hidden="true">
736
+ <div class="top">
737
+ <span class="wm"><i /> Lunora</span>
738
+ <span class="search" />
739
+ <span class="ver">v0.1</span>
740
+ </div>
741
+ <div class="body">
742
+ <div class="nav">
743
+ <i style="width: 80%" />
744
+ <i style="width: 60%" />
745
+ <i style="width: 72%" />
746
+ <i style="width: 50%" />
747
+ <i style="width: 66%" />
748
+ <i style="width: 44%" />
749
+ <i style="width: 58%" />
750
+ </div>
751
+ <div class="doc">
752
+ <span class="h" />
753
+ <i style="width: 92%" />
754
+ <i style="width: 88%" />
755
+ <span class="accent" />
756
+ <i style="width: 80%" />
757
+ <i style="width: 90%" />
758
+ <i style="width: 72%" />
759
+ <i style="width: 84%" />
760
+ <i style="width: 78%" />
761
+ </div>
762
+ </div>
763
+ </div>
764
+ <div class="info">
765
+ <span class="ic">
766
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
767
+ <path d="M4 5a2 2 0 0 1 2-2h9l5 5v11a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2z" />
768
+ <path d="M14 3v5h5" />
769
+ </svg>
770
+ </span>
771
+ <h2>Documentation</h2>
772
+ <div class="row">
773
+ <p>
774
+ Schemas, queries, live subscriptions, sharding, and edge deploy — start to finish. New here or coming from Convex or tRPC,
775
+ you'll have a live app fast.
776
+ </p>
777
+ <span class="arrow">
778
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
779
+ <path d="M5 12h14M13 6l6 6-6 6" />
780
+ </svg>
781
+ </span>
782
+ </div>
783
+ </div>
784
+ </a>
785
+
786
+ <div class="stack">
787
+ <a class="card mini" href="https://lunora.sh/blog">
788
+ <div class="mc">
789
+ <span class="ic">
790
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
791
+ <path d="M5 4h11a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H6a2 2 0 0 1-2-2V5a1 1 0 0 1 1-1zM8 8h7M8 12h7M8 16h4" />
792
+ </svg>
793
+ </span>
794
+ <h3>Blog</h3>
795
+ <p>Product updates, deep dives, and what's new in Lunora.</p>
796
+ </div>
797
+ <span class="arrow">
798
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
799
+ <path d="M5 12h14M13 6l6 6-6 6" />
800
+ </svg>
801
+ </span>
802
+ </a>
803
+ <a class="card mini" href="/_lunora">
804
+ <div class="mc">
805
+ <span class="ic">
806
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
807
+ <rect x="3" y="3" width="18" height="18" rx="1" />
808
+ <path d="M3 9h18M9 21V9" />
809
+ </svg>
810
+ </span>
811
+ <h3>Lunora Studio</h3>
812
+ <p>Local admin for schema, data, logs, and advisors.</p>
813
+ </div>
814
+ <span class="arrow">
815
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
816
+ <path d="M5 12h14M13 6l6 6-6 6" />
817
+ </svg>
818
+ </span>
819
+ </a>
820
+ <a class="card mini" href="https://lunora.sh/packages">
821
+ <div class="mc">
822
+ <span class="ic">
823
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
824
+ <path d="M12 2 3 7v10l9 5 9-5V7z" />
825
+ <path d="M3 7l9 5 9-5M12 12v10" />
826
+ </svg>
827
+ </span>
828
+ <h3>Cloudflare ecosystem</h3>
829
+ <p>Auth, mail, storage, AI, payments — one deploy.</p>
830
+ </div>
831
+ <span class="arrow">
832
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
833
+ <path d="M5 12h14M13 6l6 6-6 6" />
834
+ </svg>
835
+ </span>
836
+ </a>
837
+ </div>
838
+ </div>
839
+
840
+ <div class="lw-foot">Running on Lunora · Vite + Vue</div>
841
+ </div>
842
+ </div>
843
+ </template>
844
+ `;
845
+ const SOLID_APP = `import { createSignal, onMount } from "solid-js";
846
+
847
+ export default function App() {
848
+ // Default to "dark" for a stable first paint, then reconcile to the OS
849
+ // preference; the toggle takes over after that.
850
+ const [theme, setTheme] = createSignal<"dark" | "light">("dark");
851
+
852
+ onMount(() => {
853
+ if (window.matchMedia("(prefers-color-scheme: light)").matches) {
854
+ setTheme("light");
855
+ }
856
+ });
857
+
858
+ const isLight = () => theme() === "light";
859
+
860
+ return (
861
+ <div class="lunora-welcome" data-theme={theme()}>
862
+ <div class="lw-bg">
863
+ <div class="arc a1" />
864
+ <div class="arc a2" />
865
+ <div class="glow" />
866
+ </div>
867
+
868
+ <button class="lw-toggle" type="button" aria-label="Toggle color theme" onClick={() => setTheme(isLight() ? "dark" : "light")}>
869
+ {isLight() ? (
870
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
871
+ <path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z" />
872
+ </svg>
873
+ ) : (
874
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
875
+ <circle cx="12" cy="12" r="4" />
876
+ <path d="M12 2v2M12 20v2M4 12H2M22 12h-2M5 5l1.5 1.5M17.5 17.5 19 19M19 5l-1.5 1.5M6.5 17.5 5 19" />
877
+ </svg>
878
+ )}
879
+ <span>{isLight() ? "Ivory" : "Night"}</span>
880
+ </button>
881
+
882
+ <div class="lw-wrap">
883
+ <div class="brand">
884
+ <svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
885
+ <path d="${LOGO_PATH}" fill="currentColor" fill-rule="evenodd" />
886
+ </svg>
887
+ <span class="word">Lunora</span>
888
+ </div>
889
+
890
+ <div class="grid">
891
+ <a class="card feature" href="https://lunora.sh/docs">
892
+ <div class="shot" aria-hidden="true">
893
+ <div class="top">
894
+ <span class="wm">
895
+ <i /> Lunora
896
+ </span>
897
+ <span class="search" />
898
+ <span class="ver">v0.1</span>
899
+ </div>
900
+ <div class="body">
901
+ <div class="nav">
902
+ <i style={{ width: "80%" }} />
903
+ <i style={{ width: "60%" }} />
904
+ <i style={{ width: "72%" }} />
905
+ <i style={{ width: "50%" }} />
906
+ <i style={{ width: "66%" }} />
907
+ <i style={{ width: "44%" }} />
908
+ <i style={{ width: "58%" }} />
909
+ </div>
910
+ <div class="doc">
911
+ <span class="h" />
912
+ <i style={{ width: "92%" }} />
913
+ <i style={{ width: "88%" }} />
914
+ <span class="accent" />
915
+ <i style={{ width: "80%" }} />
916
+ <i style={{ width: "90%" }} />
917
+ <i style={{ width: "72%" }} />
918
+ <i style={{ width: "84%" }} />
919
+ <i style={{ width: "78%" }} />
920
+ </div>
921
+ </div>
922
+ </div>
923
+ <div class="info">
924
+ <span class="ic">
925
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
926
+ <path d="M4 5a2 2 0 0 1 2-2h9l5 5v11a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2z" />
927
+ <path d="M14 3v5h5" />
928
+ </svg>
929
+ </span>
930
+ <h2>Documentation</h2>
931
+ <div class="row">
932
+ <p>
933
+ Schemas, queries, live subscriptions, sharding, and edge deploy — start to finish. New here or coming from Convex or tRPC,
934
+ you'll have a live app fast.
935
+ </p>
936
+ <span class="arrow">
937
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
938
+ <path d="M5 12h14M13 6l6 6-6 6" />
939
+ </svg>
940
+ </span>
941
+ </div>
942
+ </div>
943
+ </a>
944
+
945
+ <div class="stack">
946
+ <a class="card mini" href="https://lunora.sh/blog">
947
+ <div class="mc">
948
+ <span class="ic">
949
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
950
+ <path d="M5 4h11a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H6a2 2 0 0 1-2-2V5a1 1 0 0 1 1-1zM8 8h7M8 12h7M8 16h4" />
951
+ </svg>
952
+ </span>
953
+ <h3>Blog</h3>
954
+ <p>Product updates, deep dives, and what's new in Lunora.</p>
955
+ </div>
956
+ <span class="arrow">
957
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
958
+ <path d="M5 12h14M13 6l6 6-6 6" />
959
+ </svg>
960
+ </span>
961
+ </a>
962
+ <a class="card mini" href="/_lunora">
963
+ <div class="mc">
964
+ <span class="ic">
965
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
966
+ <rect x="3" y="3" width="18" height="18" rx="1" />
967
+ <path d="M3 9h18M9 21V9" />
968
+ </svg>
969
+ </span>
970
+ <h3>Lunora Studio</h3>
971
+ <p>Local admin for schema, data, logs, and advisors.</p>
972
+ </div>
973
+ <span class="arrow">
974
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
975
+ <path d="M5 12h14M13 6l6 6-6 6" />
976
+ </svg>
977
+ </span>
978
+ </a>
979
+ <a class="card mini" href="https://lunora.sh/packages">
980
+ <div class="mc">
981
+ <span class="ic">
982
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
983
+ <path d="M12 2 3 7v10l9 5 9-5V7z" />
984
+ <path d="M3 7l9 5 9-5M12 12v10" />
985
+ </svg>
986
+ </span>
987
+ <h3>Cloudflare ecosystem</h3>
988
+ <p>Auth, mail, storage, AI, payments — one deploy.</p>
989
+ </div>
990
+ <span class="arrow">
991
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
992
+ <path d="M5 12h14M13 6l6 6-6 6" />
993
+ </svg>
994
+ </span>
995
+ </a>
996
+ </div>
997
+ </div>
998
+
999
+ <div class="lw-foot">Running on Lunora · Vite + Solid</div>
1000
+ </div>
1001
+ </div>
1002
+ );
1003
+ }
1004
+ `;
1005
+ const SVELTE_APP = `<script lang="ts">
1006
+ import { onMount } from "svelte";
1007
+
1008
+ // Default to "dark" for a stable first paint, then reconcile to the OS
1009
+ // preference; the toggle takes over after that.
1010
+ let theme = $state<"dark" | "light">("dark");
1011
+ const isLight = $derived(theme === "light");
1012
+
1013
+ onMount(() => {
1014
+ if (window.matchMedia("(prefers-color-scheme: light)").matches) {
1015
+ theme = "light";
1016
+ }
1017
+ });
1018
+
1019
+ const toggle = (): void => {
1020
+ theme = theme === "light" ? "dark" : "light";
1021
+ };
1022
+ <\/script>
1023
+
1024
+ <div class="lunora-welcome" data-theme={theme}>
1025
+ <div class="lw-bg">
1026
+ <div class="arc a1"></div>
1027
+ <div class="arc a2"></div>
1028
+ <div class="glow"></div>
1029
+ </div>
1030
+
1031
+ <button class="lw-toggle" type="button" aria-label="Toggle color theme" onclick={toggle}>
1032
+ {#if isLight}
1033
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
1034
+ <path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z" />
1035
+ </svg>
1036
+ {:else}
1037
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
1038
+ <circle cx="12" cy="12" r="4" />
1039
+ <path d="M12 2v2M12 20v2M4 12H2M22 12h-2M5 5l1.5 1.5M17.5 17.5 19 19M19 5l-1.5 1.5M6.5 17.5 5 19" />
1040
+ </svg>
1041
+ {/if}
1042
+ <span>{isLight ? "Ivory" : "Night"}</span>
1043
+ </button>
1044
+
1045
+ <div class="lw-wrap">
1046
+ <div class="brand">
1047
+ <svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
1048
+ <path d="${LOGO_PATH}" fill="currentColor" fill-rule="evenodd" />
1049
+ </svg>
1050
+ <span class="word">Lunora</span>
1051
+ </div>
1052
+
1053
+ <div class="grid">
1054
+ <a class="card feature" href="https://lunora.sh/docs">
1055
+ <div class="shot" aria-hidden="true">
1056
+ <div class="top">
1057
+ <span class="wm"><i></i> Lunora</span>
1058
+ <span class="search"></span>
1059
+ <span class="ver">v0.1</span>
1060
+ </div>
1061
+ <div class="body">
1062
+ <div class="nav">
1063
+ <i style="width: 80%"></i>
1064
+ <i style="width: 60%"></i>
1065
+ <i style="width: 72%"></i>
1066
+ <i style="width: 50%"></i>
1067
+ <i style="width: 66%"></i>
1068
+ <i style="width: 44%"></i>
1069
+ <i style="width: 58%"></i>
1070
+ </div>
1071
+ <div class="doc">
1072
+ <span class="h"></span>
1073
+ <i style="width: 92%"></i>
1074
+ <i style="width: 88%"></i>
1075
+ <span class="accent"></span>
1076
+ <i style="width: 80%"></i>
1077
+ <i style="width: 90%"></i>
1078
+ <i style="width: 72%"></i>
1079
+ <i style="width: 84%"></i>
1080
+ <i style="width: 78%"></i>
1081
+ </div>
1082
+ </div>
1083
+ </div>
1084
+ <div class="info">
1085
+ <span class="ic">
1086
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
1087
+ <path d="M4 5a2 2 0 0 1 2-2h9l5 5v11a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2z" />
1088
+ <path d="M14 3v5h5" />
1089
+ </svg>
1090
+ </span>
1091
+ <h2>Documentation</h2>
1092
+ <div class="row">
1093
+ <p>
1094
+ Schemas, queries, live subscriptions, sharding, and edge deploy — start to finish. New here or coming from Convex or tRPC,
1095
+ you'll have a live app fast.
1096
+ </p>
1097
+ <span class="arrow">
1098
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1099
+ <path d="M5 12h14M13 6l6 6-6 6" />
1100
+ </svg>
1101
+ </span>
1102
+ </div>
1103
+ </div>
1104
+ </a>
1105
+
1106
+ <div class="stack">
1107
+ <a class="card mini" href="https://lunora.sh/blog">
1108
+ <div class="mc">
1109
+ <span class="ic">
1110
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
1111
+ <path d="M5 4h11a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H6a2 2 0 0 1-2-2V5a1 1 0 0 1 1-1zM8 8h7M8 12h7M8 16h4" />
1112
+ </svg>
1113
+ </span>
1114
+ <h3>Blog</h3>
1115
+ <p>Product updates, deep dives, and what's new in Lunora.</p>
1116
+ </div>
1117
+ <span class="arrow">
1118
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1119
+ <path d="M5 12h14M13 6l6 6-6 6" />
1120
+ </svg>
1121
+ </span>
1122
+ </a>
1123
+ <a class="card mini" href="/_lunora">
1124
+ <div class="mc">
1125
+ <span class="ic">
1126
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
1127
+ <rect x="3" y="3" width="18" height="18" rx="1" />
1128
+ <path d="M3 9h18M9 21V9" />
1129
+ </svg>
1130
+ </span>
1131
+ <h3>Lunora Studio</h3>
1132
+ <p>Local admin for schema, data, logs, and advisors.</p>
1133
+ </div>
1134
+ <span class="arrow">
1135
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1136
+ <path d="M5 12h14M13 6l6 6-6 6" />
1137
+ </svg>
1138
+ </span>
1139
+ </a>
1140
+ <a class="card mini" href="https://lunora.sh/packages">
1141
+ <div class="mc">
1142
+ <span class="ic">
1143
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
1144
+ <path d="M12 2 3 7v10l9 5 9-5V7z" />
1145
+ <path d="M3 7l9 5 9-5M12 12v10" />
1146
+ </svg>
1147
+ </span>
1148
+ <h3>Cloudflare ecosystem</h3>
1149
+ <p>Auth, mail, storage, AI, payments — one deploy.</p>
1150
+ </div>
1151
+ <span class="arrow">
1152
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1153
+ <path d="M5 12h14M13 6l6 6-6 6" />
1154
+ </svg>
1155
+ </span>
1156
+ </a>
1157
+ </div>
1158
+ </div>
1159
+
1160
+ <div class="lw-foot">Running on Lunora · Vite + Svelte</div>
1161
+ </div>
1162
+ </div>
1163
+ `;
1164
+ const VANILLA_MAIN = `import "./style.css";
1165
+
1166
+ import { LunoraClient } from "lunorash/client";
1167
+
1168
+ import { api } from "#lunora/_generated/api.js";
1169
+
1170
+ // \`@lunora/vite\` runs the Worker on the same origin as Vite, so default to
1171
+ // \`location.origin\`. Point \`VITE_LUNORA_URL\` at a deployed Worker to develop
1172
+ // the client against production data.
1173
+ const url = (import.meta.env.VITE_LUNORA_URL as string | undefined) ?? globalThis.location.origin;
1174
+ const client = new LunoraClient({ url });
1175
+
1176
+ const MOON_ICON = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"><path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z" /></svg>';
1177
+ const SUN_ICON =
1178
+ '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"><circle cx="12" cy="12" r="4" /><path d="M12 2v2M12 20v2M4 12H2M22 12h-2M5 5l1.5 1.5M17.5 17.5 19 19M19 5l-1.5 1.5M6.5 17.5 5 19" /></svg>';
1179
+
1180
+ const welcomeHtml = \`
1181
+ <div class="lw-bg">
1182
+ <div class="arc a1"></div>
1183
+ <div class="arc a2"></div>
1184
+ <div class="glow"></div>
1185
+ </div>
1186
+
1187
+ <button class="lw-toggle" type="button" aria-label="Toggle color theme"></button>
1188
+
1189
+ <div class="lw-wrap">
1190
+ <div class="brand">
1191
+ <svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
1192
+ <path d="${LOGO_PATH}" fill="currentColor" fill-rule="evenodd" />
1193
+ </svg>
1194
+ <span class="word">Lunora</span>
1195
+ </div>
1196
+
1197
+ <div class="grid">
1198
+ <a class="card feature" href="https://lunora.sh/docs">
1199
+ <div class="shot" aria-hidden="true">
1200
+ <div class="top">
1201
+ <span class="wm"><i></i> Lunora</span>
1202
+ <span class="search"></span>
1203
+ <span class="ver">v0.1</span>
1204
+ </div>
1205
+ <div class="body">
1206
+ <div class="nav">
1207
+ <i style="width: 80%"></i>
1208
+ <i style="width: 60%"></i>
1209
+ <i style="width: 72%"></i>
1210
+ <i style="width: 50%"></i>
1211
+ <i style="width: 66%"></i>
1212
+ <i style="width: 44%"></i>
1213
+ <i style="width: 58%"></i>
1214
+ </div>
1215
+ <div class="doc">
1216
+ <span class="h"></span>
1217
+ <i style="width: 92%"></i>
1218
+ <i style="width: 88%"></i>
1219
+ <span class="accent"></span>
1220
+ <i style="width: 80%"></i>
1221
+ <i style="width: 90%"></i>
1222
+ <i style="width: 72%"></i>
1223
+ <i style="width: 84%"></i>
1224
+ <i style="width: 78%"></i>
1225
+ </div>
1226
+ </div>
1227
+ </div>
1228
+ <div class="info">
1229
+ <span class="ic">
1230
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
1231
+ <path d="M4 5a2 2 0 0 1 2-2h9l5 5v11a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2z" />
1232
+ <path d="M14 3v5h5" />
1233
+ </svg>
1234
+ </span>
1235
+ <h2>Documentation</h2>
1236
+ <div class="row">
1237
+ <p>
1238
+ Schemas, queries, live subscriptions, sharding, and edge deploy — start to finish. New here or coming from Convex or tRPC,
1239
+ you'll have a live app fast.
1240
+ </p>
1241
+ <span class="arrow">
1242
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1243
+ <path d="M5 12h14M13 6l6 6-6 6" />
1244
+ </svg>
1245
+ </span>
1246
+ </div>
1247
+ </div>
1248
+ </a>
1249
+
1250
+ <div class="stack">
1251
+ <a class="card mini" href="https://lunora.sh/blog">
1252
+ <div class="mc">
1253
+ <span class="ic">
1254
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
1255
+ <path d="M5 4h11a1 1 0 0 1 1 1v14a1 1 0 0 1-1 1H6a2 2 0 0 1-2-2V5a1 1 0 0 1 1-1zM8 8h7M8 12h7M8 16h4" />
1256
+ </svg>
1257
+ </span>
1258
+ <h3>Blog</h3>
1259
+ <p>Product updates, deep dives, and what's new in Lunora.</p>
1260
+ </div>
1261
+ <span class="arrow">
1262
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1263
+ <path d="M5 12h14M13 6l6 6-6 6" />
1264
+ </svg>
1265
+ </span>
1266
+ </a>
1267
+ <a class="card mini" href="/_lunora">
1268
+ <div class="mc">
1269
+ <span class="ic">
1270
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
1271
+ <rect x="3" y="3" width="18" height="18" rx="1" />
1272
+ <path d="M3 9h18M9 21V9" />
1273
+ </svg>
1274
+ </span>
1275
+ <h3>Lunora Studio</h3>
1276
+ <p>Local admin for schema, data, logs, and advisors.</p>
1277
+ </div>
1278
+ <span class="arrow">
1279
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1280
+ <path d="M5 12h14M13 6l6 6-6 6" />
1281
+ </svg>
1282
+ </span>
1283
+ </a>
1284
+ <a class="card mini" href="https://lunora.sh/packages">
1285
+ <div class="mc">
1286
+ <span class="ic">
1287
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
1288
+ <path d="M12 2 3 7v10l9 5 9-5V7z" />
1289
+ <path d="M3 7l9 5 9-5M12 12v10" />
1290
+ </svg>
1291
+ </span>
1292
+ <h3>Cloudflare ecosystem</h3>
1293
+ <p>Auth, mail, storage, AI, payments — one deploy.</p>
1294
+ </div>
1295
+ <span class="arrow">
1296
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
1297
+ <path d="M5 12h14M13 6l6 6-6 6" />
1298
+ </svg>
1299
+ </span>
1300
+ </a>
1301
+ </div>
1302
+ </div>
1303
+
1304
+ <div class="lw-foot">Running on Lunora · Vite + Vanilla · <span id="lw-count">0</span> messages</div>
1305
+ </div>
1306
+ \`;
1307
+
1308
+ const root = document.querySelector<HTMLDivElement>("#app")!;
1309
+ root.classList.add("lunora-welcome");
1310
+ root.innerHTML = welcomeHtml;
1311
+
1312
+ // Theme toggle: flip the root's data-theme + swap the button's icon/label.
1313
+ const toggleButton = root.querySelector<HTMLButtonElement>(".lw-toggle")!;
1314
+
1315
+ const paintToggle = (theme: "dark" | "light"): void => {
1316
+ root.dataset.theme = theme;
1317
+ toggleButton.innerHTML = \`\${theme === "light" ? MOON_ICON : SUN_ICON}<span>\${theme === "light" ? "Ivory" : "Night"}</span>\`;
1318
+ };
1319
+
1320
+ paintToggle(window.matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark");
1321
+ toggleButton.addEventListener("click", () => {
1322
+ paintToggle(root.dataset.theme === "light" ? "dark" : "light");
1323
+ });
1324
+
1325
+ // Live demo: the message count of a demo channel re-renders on every delta.
1326
+ const count = document.querySelector<HTMLSpanElement>("#lw-count")!;
1327
+
1328
+ client.onUpdate(api.messages.list, { channelId: "channel:demo" }, (result) => {
1329
+ count.textContent = String(result.messages.length);
1330
+ });
1331
+ `;
1332
+
1333
+ const READ_URL = `const url = (import.meta.env.VITE_LUNORA_URL as string | undefined) ?? globalThis.location.origin;`;
1334
+ const REACT_MAIN = `import "./index.css";
1335
+
1336
+ import { LunoraProvider } from "@lunora/react";
1337
+ import { LunoraClient } from "lunorash/client";
1338
+ import { StrictMode } from "react";
1339
+ import { createRoot } from "react-dom/client";
1340
+
1341
+ import App from "./App.tsx";
1342
+
1343
+ // \`@lunora/vite\` runs the Worker on the same origin as Vite, so default to
1344
+ // \`location.origin\`. Point \`VITE_LUNORA_URL\` at a deployed Worker to develop
1345
+ // the client against production data.
1346
+ ${READ_URL}
1347
+ const client = new LunoraClient({ url });
1348
+
1349
+ const root = document.getElementById("root");
1350
+
1351
+ if (!root) {
1352
+ throw new Error("missing #root mount node");
1353
+ }
1354
+
1355
+ createRoot(root).render(
1356
+ <StrictMode>
1357
+ <LunoraProvider client={client}>
1358
+ <App />
1359
+ </LunoraProvider>
1360
+ </StrictMode>,
1361
+ );
1362
+ `;
1363
+ const VUE_MAIN = `import "./style.css";
1364
+
1365
+ import { createLunora } from "@lunora/vue";
1366
+ import { LunoraClient } from "lunorash/client";
1367
+ import { createApp } from "vue";
1368
+
1369
+ import App from "./App.vue";
1370
+
1371
+ // Provide one LunoraClient at the app root via the Vue plugin form.
1372
+ ${READ_URL}
1373
+ createApp(App).use(createLunora(new LunoraClient({ url }))).mount("#app");
1374
+ `;
1375
+ const SOLID_INDEX = `import "./index.css";
1376
+
1377
+ import { LunoraContext } from "@lunora/solid";
1378
+ import { LunoraClient } from "lunorash/client";
1379
+ import { render } from "solid-js/web";
1380
+
1381
+ import App from "./App";
1382
+
1383
+ ${READ_URL}
1384
+ const client = new LunoraClient({ url });
1385
+ const root = document.getElementById("root");
1386
+
1387
+ render(
1388
+ () => (
1389
+ <LunoraContext.Provider value={client}>
1390
+ <App />
1391
+ </LunoraContext.Provider>
1392
+ ),
1393
+ root!,
1394
+ );
1395
+ `;
1396
+ const SVELTE_ROOT = `<script lang="ts">
1397
+ import { setLunoraClient } from "@lunora/svelte";
1398
+ import { LunoraClient } from "lunorash/client";
1399
+
1400
+ import App from "./App.svelte";
1401
+
1402
+ ${READ_URL}
1403
+ setLunoraClient(new LunoraClient({ url }));
1404
+ <\/script>
1405
+
1406
+ <App />
1407
+ `;
1408
+ const SVELTE_MAIN = `import "./app.css";
1409
+
1410
+ import { mount } from "svelte";
1411
+
1412
+ import Root from "./Root.svelte";
1413
+
1414
+ // Mount \`Root\` (it sets the ambient LunoraClient) rather than \`App\` directly.
1415
+ const app = mount(Root, { target: document.getElementById("app")! });
1416
+
1417
+ export default app;
1418
+ `;
1419
+ const ADAPTERS = {
1420
+ react: {
1421
+ adapter: "@lunora/react",
1422
+ createViteTemplate: "react-ts",
1423
+ files: [
1424
+ { contents: REACT_MAIN, path: "src/main.tsx" },
1425
+ { contents: REACT_APP, path: "src/App.tsx" },
1426
+ { contents: WELCOME_CSS, path: "src/index.css" }
1427
+ ],
1428
+ label: "React"
1429
+ },
1430
+ solid: {
1431
+ adapter: "@lunora/solid",
1432
+ createViteTemplate: "solid",
1433
+ files: [
1434
+ { contents: SOLID_INDEX, path: "src/index.tsx" },
1435
+ { contents: SOLID_APP, path: "src/App.tsx" },
1436
+ { contents: WELCOME_CSS, path: "src/index.css" }
1437
+ ],
1438
+ label: "Solid"
1439
+ },
1440
+ svelte: {
1441
+ adapter: "@lunora/svelte",
1442
+ createViteTemplate: "svelte-ts",
1443
+ files: [
1444
+ { contents: SVELTE_ROOT, path: "src/Root.svelte" },
1445
+ { contents: SVELTE_MAIN, path: "src/main.ts" },
1446
+ { contents: SVELTE_APP, path: "src/App.svelte" },
1447
+ { contents: WELCOME_CSS, path: "src/app.css" }
1448
+ ],
1449
+ label: "Svelte"
1450
+ },
1451
+ vanilla: {
1452
+ adapter: "lunorash/client",
1453
+ createViteTemplate: "vanilla-ts",
1454
+ files: [
1455
+ { contents: VANILLA_MAIN, path: "src/main.ts" },
1456
+ { contents: WELCOME_CSS, path: "src/style.css" }
1457
+ ],
1458
+ label: "Vanilla"
1459
+ },
1460
+ vue: {
1461
+ adapter: "@lunora/vue",
1462
+ createViteTemplate: "vue-ts",
1463
+ files: [
1464
+ { contents: VUE_MAIN, path: "src/main.ts" },
1465
+ { contents: VUE_APP, path: "src/App.vue" },
1466
+ { contents: WELCOME_CSS, path: "src/style.css" }
1467
+ ],
1468
+ label: "Vue"
290
1469
  }
291
1470
  };
1471
+ const isOverlayFramework = (value) => Object.hasOwn(ADAPTERS, value);
292
1472
 
1473
+ const LUNORA_SCHEMA = `import { defineSchema, defineTable, v } from "lunorash/server";
1474
+
1475
+ export default defineSchema({
1476
+ messages: defineTable({
1477
+ channelId: v.string(),
1478
+ text: v.string(),
1479
+ })
1480
+ .shardBy("channelId")
1481
+ .index("by_channel", ["channelId"]),
1482
+ });
1483
+ `;
1484
+ const LUNORA_MESSAGES = `import { RateLimiter, rateLimit } from "@lunora/ratelimit";
1485
+
1486
+ import { mutation, query, v } from "#lunora/_generated/server.js";
1487
+
1488
+ /**
1489
+ * One in-memory limiter so the public \`send\` mutation isn't an open flood target
1490
+ * out of the box. The default store is in-memory (per-isolate, resets on
1491
+ * eviction) — fine for a starter; run \`lunora add ratelimit\` for the durable,
1492
+ * \`ctx.db\`-backed store when you ship to production.
1493
+ */
1494
+ const limiter = new RateLimiter({
1495
+ config: {
1496
+ send: { kind: "token bucket", period: 60_000, rate: 30 },
1497
+ },
1498
+ });
1499
+
1500
+ export const list = query.input({ channelId: v.string().meta({ schema: { maxLength: 256 } }), limit: v.optional(v.number()) }).query(async ({ args, ctx }) => {
1501
+ const messages = await ctx.db
1502
+ .query("messages")
1503
+ .withIndex("by_channel", (q) => q.eq("channelId", args.channelId))
1504
+ .take(args.limit ?? 50);
1505
+
1506
+ return { channelId: args.channelId, messages };
1507
+ });
1508
+
1509
+ export const send = mutation
1510
+ .input({ channelId: v.string().meta({ schema: { maxLength: 256 } }), text: v.string().meta({ schema: { maxLength: 4096 } }) })
1511
+ .use(rateLimit(limiter, "send", { key: (ctx) => ctx.auth.userId ?? "anon" }))
1512
+ .mutation(async ({ args, ctx }) => {
1513
+ const id = await ctx.db.insert("messages", { channelId: args.channelId, text: args.text });
1514
+
1515
+ return { channelId: args.channelId, id, text: args.text };
1516
+ });
1517
+ `;
1518
+ const SERVER_ENTRY = `import type { ShardNamespaceLike } from "lunorash/runtime";
1519
+
1520
+ import { defineApp } from "../lunora/_generated/app.js";
1521
+
1522
+ interface Env extends Record<string, unknown> {
1523
+ SHARD: ShardNamespaceLike;
1524
+ }
1525
+
1526
+ const app = defineApp<Env>()
1527
+ .shard((env) => env.SHARD)
1528
+ .build();
1529
+
1530
+ export const ShardDO = app.ShardDO;
1531
+ export default app;
1532
+ `;
1533
+ const WRANGLER = `{
1534
+ "$schema": "node_modules/wrangler/config-schema.json",
1535
+ "name": "__NAME__",
1536
+ "main": "src/server.ts",
1537
+ "compatibility_date": "2026-06-10",
1538
+ "compatibility_flags": ["nodejs_compat"],
1539
+ "durable_objects": {
1540
+ "bindings": [{ "name": "SHARD", "class_name": "ShardDO" }],
1541
+ },
1542
+ "migrations": [{ "tag": "v1", "new_sqlite_classes": ["ShardDO"] }],
1543
+ "observability": { "enabled": true, "head_sampling_rate": 1 },
1544
+ }
1545
+ `;
1546
+ const GITIGNORE_ADDITIONS = [".wrangler", ".env", ".env.*", "!.env.example", ".lunora/", ".lunora-cache", "lunora/_generated"];
1547
+ const ENV_EXAMPLE = `# Lunora endpoint for the browser client.
1548
+ # Vite statically replaces \`import.meta.env.VITE_LUNORA_URL\` at \`vite dev\` / build.
1549
+ # Leave it unset to use the page origin; set it to point at a deployed Worker:
1550
+ #
1551
+ # VITE_LUNORA_URL=https://my-app.example.workers.dev
1552
+ `;
1553
+ const COMMON_DEV_DEPENDENCIES = {
1554
+ "@cloudflare/workers-types": "^4.20260611.1",
1555
+ wrangler: "^4.100.0"
1556
+ };
1557
+ const writeFile = (target, relativePath, contents, written) => {
1558
+ const destination = join$1(target, relativePath);
1559
+ mkdirSync(dirname$1(destination), { recursive: true });
1560
+ writeFileSync(destination, contents, "utf8");
1561
+ written.push(destination);
1562
+ };
1563
+ const NEWLINE = /\r?\n/;
1564
+ const ensureGitignore = (target) => {
1565
+ const path = join$1(target, ".gitignore");
1566
+ const existing = existsSync(path) ? readFileSync(path, "utf8") : "";
1567
+ const missing = GITIGNORE_ADDITIONS.filter((entry) => !existing.split(NEWLINE).includes(entry));
1568
+ if (missing.length === 0) {
1569
+ return;
1570
+ }
1571
+ const prefix = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
1572
+ writeFileSync(path, `${existing}${prefix}
1573
+ # Lunora
1574
+ ${missing.join("\n")}
1575
+ `, "utf8");
1576
+ };
1577
+ const isLunoraDep$1 = (name) => name === "lunorash" || name.startsWith("@lunora/");
1578
+ const stampRange = (name, range, distTag, versions) => isLunoraDep$1(name) ? versions?.get(name) ?? distTag : range;
1579
+ const withDependency = (map, name, range, distTag) => {
1580
+ return { ...map, [name]: stampRange(name, range, distTag) };
1581
+ };
1582
+ const restampLunora = (map, distTag, versions) => Object.fromEntries(Object.entries(map).map(([name, range]) => [name, stampRange(name, range, distTag, versions)]));
1583
+ const patchPackageJson = async (target, name, adapter, distTag) => {
1584
+ const path = join$1(target, "package.json");
1585
+ const parsed = JSON.parse(readFileSync(path, "utf8"));
1586
+ let dependencies = withDependency(parsed.dependencies ?? {}, "lunorash", distTag, distTag);
1587
+ dependencies = withDependency(dependencies, "@lunora/ratelimit", distTag, distTag);
1588
+ if (adapter.adapter.startsWith("@lunora/")) {
1589
+ dependencies = withDependency(dependencies, adapter.adapter, distTag, distTag);
1590
+ }
1591
+ for (const [depName, range] of Object.entries(adapter.extraDependencies ?? {})) {
1592
+ dependencies = withDependency(dependencies, depName, range, distTag);
1593
+ }
1594
+ let devDependencies = withDependency(parsed.devDependencies ?? {}, "@lunora/vite", distTag, distTag);
1595
+ devDependencies = withDependency(devDependencies, "@lunora/studio", distTag, distTag);
1596
+ for (const [depName, range] of Object.entries(COMMON_DEV_DEPENDENCIES)) {
1597
+ devDependencies = withDependency(devDependencies, depName, range, distTag);
1598
+ }
1599
+ const lunoraNames = [...Object.keys(dependencies), ...Object.keys(devDependencies)].filter((depName) => isLunoraDep$1(depName));
1600
+ const versions = await resolveTagVersions(lunoraNames, distTag);
1601
+ parsed.name = name;
1602
+ parsed.imports = { ...parsed.imports, "#lunora/*": "./lunora/*" };
1603
+ parsed.dependencies = restampLunora(dependencies, distTag, versions);
1604
+ parsed.devDependencies = restampLunora(devDependencies, distTag, versions);
1605
+ parsed.scripts = { ...parsed.scripts, codegen: "lunora codegen", deploy: "vite build && lunora deploy" };
1606
+ writeFileSync(path, `${JSON.stringify(parsed, void 0, 4)}
1607
+ `, "utf8");
1608
+ };
1609
+ const patchBaseViteConfig = (target, logger) => {
1610
+ const candidate = ["vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"].map((file) => join$1(target, file)).find((path) => existsSync(path));
1611
+ if (candidate === void 0) {
1612
+ logger.warn("overlay: no vite.config found in the create-vite base — add `lunora()` to your Vite plugins manually.");
1613
+ return;
1614
+ }
1615
+ const result = patchViteConfig(readFileSync(candidate, "utf8"));
1616
+ if (result.changed) {
1617
+ writeFileSync(candidate, result.code, "utf8");
1618
+ }
1619
+ };
1620
+ const applyLunoraOverlay = async (options) => {
1621
+ const { adapter, distTag, logger, name, target } = options;
1622
+ const written = [];
1623
+ writeFile(target, join$1("lunora", "schema.ts"), LUNORA_SCHEMA, written);
1624
+ writeFile(target, join$1("lunora", "messages.ts"), LUNORA_MESSAGES, written);
1625
+ writeFile(target, join$1("src", "server.ts"), SERVER_ENTRY, written);
1626
+ writeFile(target, "wrangler.jsonc", WRANGLER.replaceAll("__NAME__", name), written);
1627
+ writeFile(target, ".env.example", ENV_EXAMPLE, written);
1628
+ for (const file of adapter.files) {
1629
+ writeFile(target, file.path, file.contents, written);
1630
+ }
1631
+ patchBaseViteConfig(target, logger);
1632
+ await patchPackageJson(target, name, adapter, distTag);
1633
+ ensureGitignore(target);
1634
+ return written;
1635
+ };
1636
+
1637
+ const ADJECTIVES = [
1638
+ "lunar",
1639
+ "silver",
1640
+ "silent",
1641
+ "waning",
1642
+ "waxing",
1643
+ "crescent",
1644
+ "cosmic",
1645
+ "stellar",
1646
+ "orbital",
1647
+ "gibbous",
1648
+ "twilight",
1649
+ "midnight",
1650
+ "shimmering",
1651
+ "drifting",
1652
+ "weightless"
1653
+ ];
1654
+ const NOUNS = [
1655
+ "moon",
1656
+ "tide",
1657
+ "crater",
1658
+ "comet",
1659
+ "eclipse",
1660
+ "halo",
1661
+ "orbit",
1662
+ "nebula",
1663
+ "voyager",
1664
+ "lander",
1665
+ "rover",
1666
+ "beacon",
1667
+ "harbor",
1668
+ "meadow",
1669
+ "fox"
1670
+ ];
1671
+ const pick = (items) => (
1672
+ // eslint-disable-next-line sonarjs/pseudo-random -- cosmetic default project name, not a security decision.
1673
+ items[Math.floor(Math.random() * items.length)]
1674
+ );
1675
+ const generateProjectName = () => `${pick(ADJECTIVES)}-${pick(NOUNS)}`;
1676
+
1677
+ const isOnline = async () => dns.lookup("github.com").then(
1678
+ () => true,
1679
+ () => false
1680
+ );
1681
+ const GITHUB_SOURCE = /^(?:gh|github):([^/]+)\/([^#/]+)(?:\/[^#]*)?(?:#(.+))?$/;
1682
+ const parseGitHubSource = (source) => {
1683
+ const match = GITHUB_SOURCE.exec(source);
1684
+ if (match === null) {
1685
+ return void 0;
1686
+ }
1687
+ const [, owner, repo, ref] = match;
1688
+ if (owner === void 0 || repo === void 0) {
1689
+ return void 0;
1690
+ }
1691
+ return { owner, ref: ref ?? "HEAD", repo };
1692
+ };
1693
+ const templateRefExists = async (source) => {
1694
+ const parsed = parseGitHubSource(source);
1695
+ if (parsed === void 0) {
1696
+ return void 0;
1697
+ }
1698
+ const url = `https://codeload.github.com/${parsed.owner}/${parsed.repo}/tar.gz/${parsed.ref}`;
1699
+ try {
1700
+ const response = await fetch(url, { method: "HEAD" });
1701
+ if (response.status === 404) {
1702
+ return false;
1703
+ }
1704
+ return response.ok ? true : void 0;
1705
+ } catch {
1706
+ return void 0;
1707
+ }
1708
+ };
1709
+ const verifyRemoteTemplate = async (params) => {
1710
+ if (params.isLocal) {
1711
+ return true;
1712
+ }
1713
+ const isGitHubBacked = params.source === void 0 || parseGitHubSource(params.source) !== void 0;
1714
+ if (!isGitHubBacked) {
1715
+ return true;
1716
+ }
1717
+ if (!await isOnline()) {
1718
+ params.logger.error("you appear to be offline — connect to the internet and try again, or scaffold from a local template with `--from <dir>`.");
1719
+ return false;
1720
+ }
1721
+ if (params.source !== void 0 && await templateRefExists(params.source) === false) {
1722
+ params.logger.error(`template source not found: ${params.source} — double-check --ref / --source, or browse the templates at https://lunora.sh/docs.`);
1723
+ return false;
1724
+ }
1725
+ return true;
1726
+ };
1727
+
1728
+ const COPY = {
1729
+ extras: "Let's finish setting up your app.",
1730
+ framework: "Which framework should we launch?",
1731
+ git: "Initialize a new git repository? (optional)",
1732
+ install: "Install dependencies now?",
1733
+ name: "Where should we land your project?",
1734
+ nextHeader: "Liftoff confirmed — explore your project!",
1735
+ packageManager: "Which package manager?"
1736
+ };
293
1737
  const TEXT_EXTENSIONS = /* @__PURE__ */ new Set([".gitignore", ".html", ".js", ".json", ".jsonc", ".md", ".mjs", ".ts", ".tsx"]);
294
1738
  const VITE_CONFIG_CANDIDATES = ["vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"];
295
1739
  const MINIMAL_VITE_CONFIG = `import { defineConfig } from "vite";
@@ -331,6 +1775,57 @@ const isTextFile = (filePath) => {
331
1775
  return TEXT_EXTENSIONS.has(filePath.slice(lastDot));
332
1776
  };
333
1777
  const substitute = (content, name) => content.replaceAll("{{name}}", name);
1778
+ const isLunoraDep = (name) => name === "lunorash" || name.startsWith("@lunora/");
1779
+ const resolveLunoraVersions = async (files, distTag) => {
1780
+ const names = /* @__PURE__ */ new Set();
1781
+ for (const file of files) {
1782
+ if (basename(file) !== "package.json") {
1783
+ continue;
1784
+ }
1785
+ try {
1786
+ const parsed = JSON.parse(readFileSync(file, "utf8"));
1787
+ for (const section of ["dependencies", "devDependencies"]) {
1788
+ for (const name of Object.keys(parsed[section] ?? {})) {
1789
+ if (isLunoraDep(name)) {
1790
+ names.add(name);
1791
+ }
1792
+ }
1793
+ }
1794
+ } catch {
1795
+ }
1796
+ }
1797
+ return resolveTagVersions(names, distTag);
1798
+ };
1799
+ const stampLunoraDeps = (packageJsonText, distTag, versions) => {
1800
+ let parsed;
1801
+ try {
1802
+ parsed = JSON.parse(packageJsonText);
1803
+ } catch {
1804
+ return packageJsonText;
1805
+ }
1806
+ let text = packageJsonText;
1807
+ for (const section of ["dependencies", "devDependencies"]) {
1808
+ for (const name of Object.keys(parsed[section] ?? {})) {
1809
+ if (!isLunoraDep(name)) {
1810
+ continue;
1811
+ }
1812
+ const pin = versions.get(name) ?? distTag;
1813
+ const edits = modify(text, [section, name], pin, { formattingOptions: { insertSpaces: true, tabSize: 4 } });
1814
+ text = applyEdits(text, edits);
1815
+ }
1816
+ }
1817
+ return text;
1818
+ };
1819
+ const PNPM_BUILT_DEPENDENCIES = ["esbuild", "sharp", "workerd"];
1820
+ const PNPM_WORKSPACE_FILENAME = "pnpm-workspace.yaml";
1821
+ const pnpmWorkspaceYaml = () => [
1822
+ "# pnpm reads its settings from here (the package.json `pnpm` field is no longer read).",
1823
+ "# Pre-approve the toolchain's native build scripts so `pnpm install` runs them",
1824
+ "# without the interactive `pnpm approve-builds` step.",
1825
+ "allowBuilds:",
1826
+ ...PNPM_BUILT_DEPENDENCIES.map((name) => ` ${name}: true`),
1827
+ ""
1828
+ ].join("\n");
334
1829
  const collectFiles = (directory) => {
335
1830
  const out = [];
336
1831
  for (const entry of walkSync(directory, { includeDirs: false, includeFiles: true })) {
@@ -338,15 +1833,20 @@ const collectFiles = (directory) => {
338
1833
  }
339
1834
  return out;
340
1835
  };
341
- const copyTemplate = (sourceDirectory, target, name) => {
1836
+ const copyTemplate = async (sourceDirectory, target, name) => {
342
1837
  const files = collectFiles(sourceDirectory);
343
1838
  const written = [];
1839
+ const distTag = resolveDistTag();
1840
+ const versions = await resolveLunoraVersions(files, distTag);
344
1841
  for (const source of files) {
345
1842
  const relativePath = relative(sourceDirectory, source);
346
1843
  const destination = join$1(target, relativePath);
347
1844
  mkdirSync(dirname$1(destination), { recursive: true });
348
1845
  const raw = readFileSync(source);
349
- const text = isTextFile(source) ? substitute(raw.toString("utf8"), name) : void 0;
1846
+ let text = isTextFile(source) ? substitute(raw.toString("utf8"), name) : void 0;
1847
+ if (text !== void 0 && basename(source) === "package.json") {
1848
+ text = stampLunoraDeps(text, distTag, versions);
1849
+ }
350
1850
  if (text === void 0) {
351
1851
  writeFileSync(destination, raw);
352
1852
  } else {
@@ -368,21 +1868,159 @@ const isSafeSource = (source) => {
368
1868
  }
369
1869
  return source.startsWith("gh:") || source.startsWith("github:") || source.startsWith("https://");
370
1870
  };
371
- const logScaffoldSuccess = (logger, written, target, name) => {
1871
+ const logWould = (logger, action) => {
1872
+ logger.info(`[dry-run] would ${action}`);
1873
+ };
1874
+ const logScaffoldSuccess = (logger, written, target) => {
1875
+ if (isInteractive()) {
1876
+ process.stdout.write("\n");
1877
+ }
372
1878
  logger.success(`scaffolded ${String(written.length)} files into ${target}`);
373
- logger.info("next steps:");
374
- logger.info(` cd ${name}`);
375
- logger.info(" pnpm install");
376
- logger.info(" pnpm dev");
377
1879
  };
378
- const scaffoldFromLocal = (fromRoot, templateType, target, name, logger) => {
1880
+ const runScriptCommand = (manager, script) => {
1881
+ if (manager === "npm") {
1882
+ return `npm run ${script}`;
1883
+ }
1884
+ if (manager === "bun") {
1885
+ return `bun run ${script}`;
1886
+ }
1887
+ return `${manager} ${script}`;
1888
+ };
1889
+ const isInsideMonorepo = (startDirectory) => {
1890
+ let directory = resolve(startDirectory);
1891
+ for (; ; ) {
1892
+ if (existsSync(join$1(directory, "pnpm-workspace.yaml"))) {
1893
+ return true;
1894
+ }
1895
+ const packagePath = join$1(directory, "package.json");
1896
+ if (existsSync(packagePath)) {
1897
+ try {
1898
+ const parsed = JSON.parse(readFileSync(packagePath, "utf8"));
1899
+ if (parsed.workspaces !== void 0) {
1900
+ return true;
1901
+ }
1902
+ } catch {
1903
+ }
1904
+ }
1905
+ const parent = dirname$1(directory);
1906
+ if (parent === directory) {
1907
+ return false;
1908
+ }
1909
+ directory = parent;
1910
+ }
1911
+ };
1912
+ const isInsideGitRepo = (startDirectory) => {
1913
+ let directory = resolve(startDirectory);
1914
+ for (; ; ) {
1915
+ if (existsSync(join$1(directory, ".git"))) {
1916
+ return true;
1917
+ }
1918
+ const parent = dirname$1(directory);
1919
+ if (parent === directory) {
1920
+ return false;
1921
+ }
1922
+ directory = parent;
1923
+ }
1924
+ };
1925
+ const maybeOfferGit = async (options, target) => {
1926
+ if (options.yes === true || !isInteractive() || isInsideGitRepo(dirname$1(target))) {
1927
+ return;
1928
+ }
1929
+ if (!await tuiConfirm(COPY.git, { badge: BADGES.git, defaultYes: false })) {
1930
+ await tuiInfo("Sounds good! You can always run git init manually.");
1931
+ return;
1932
+ }
1933
+ if (options.dryRun === true) {
1934
+ logWould(options.logger, "initialize a git repository");
1935
+ return;
1936
+ }
1937
+ const spawner = options.spawner ?? defaultSpawner;
1938
+ const result = await withTuiSpinner("Initializing a git repository…", () => spawner({ args: ["init"], command: "git", cwd: target }));
1939
+ if (result.code === 0) {
1940
+ await emitStep("git", "Initialized an empty git repository.");
1941
+ } else {
1942
+ options.logger.warn("`git init` failed — initialize it yourself later with `git init`.");
1943
+ }
1944
+ };
1945
+ const printNextSteps = async (name, installed, insideMonorepo) => {
1946
+ const manager = installed ?? "pnpm";
1947
+ const steps = [{ code: `cd ./${name}`, lead: "Enter your project directory using" }];
1948
+ if (installed === void 0) {
1949
+ steps.push({ code: `${manager} install`, lead: "Install dependencies with", tail: insideMonorepo ? " from the workspace root" : void 0 });
1950
+ }
1951
+ steps.push(
1952
+ { code: runScriptCommand(manager, "dev"), lead: "Run", tail: " to start the dev server." },
1953
+ { code: "lunora add", lead: "Add features like auth or storage using" }
1954
+ );
1955
+ const help = [
1956
+ { code: "https://lunora.sh/docs", lead: "Read the docs at" },
1957
+ { code: "https://lunora.sh/chat", lead: "Stuck? Join the chat at" }
1958
+ ];
1959
+ if (isInteractive()) {
1960
+ await tuiNextSteps(BADGES.next, COPY.nextHeader, steps, help);
1961
+ return;
1962
+ }
1963
+ const lines = steps.map((step) => `${step.lead} ${step.code}${step.tail ?? ""}`);
1964
+ lines.push("", ...help.map((line) => `${line.lead} ${line.code}${line.tail ?? ""}`));
1965
+ await emitStep("next", COPY.nextHeader, lines.join("\n"));
1966
+ };
1967
+ const offerInstallIsInteractive = (options) => options.yes !== true && (options.installPrompt !== void 0 || isInteractive());
1968
+ const maybeOfferInstall = async (options, target) => {
1969
+ if (!offerInstallIsInteractive(options)) {
1970
+ return void 0;
1971
+ }
1972
+ if (isInsideMonorepo(dirname$1(target))) {
1973
+ return void 0;
1974
+ }
1975
+ const managers = detectInstalledManagers(options.packageManagerProbe);
1976
+ const [defaultManager] = managers;
1977
+ if (defaultManager === void 0) {
1978
+ return void 0;
1979
+ }
1980
+ const confirm = options.installPrompt?.confirmInstall ?? (async () => tuiConfirm(COPY.install, { badge: BADGES.deps, defaultYes: true }));
1981
+ if (!await confirm()) {
1982
+ await tuiInfo("No problem! Remember to install dependencies after setup.");
1983
+ return void 0;
1984
+ }
1985
+ let manager = defaultManager;
1986
+ if (managers.length > 1) {
1987
+ manager = options.installPrompt ? await options.installPrompt.selectManager(managers) : await tuiSelect(
1988
+ COPY.packageManager,
1989
+ managers.map((candidate) => {
1990
+ return { label: candidate, value: candidate };
1991
+ }),
1992
+ { badge: BADGES.deps, default: defaultManager }
1993
+ ) ?? defaultManager;
1994
+ }
1995
+ if (options.dryRun === true) {
1996
+ logWould(options.logger, `install dependencies with ${manager}`);
1997
+ return void 0;
1998
+ }
1999
+ if (manager === "pnpm") {
2000
+ const workspacePath = join$1(target, PNPM_WORKSPACE_FILENAME);
2001
+ if (!existsSync(workspacePath)) {
2002
+ writeFileSync(workspacePath, pnpmWorkspaceYaml(), "utf8");
2003
+ }
2004
+ }
2005
+ const spawner = options.spawner ?? defaultSpawner;
2006
+ const { args, command } = installArgsFor(manager);
2007
+ await emitStep("deps", `Installing dependencies with ${manager}…`);
2008
+ const result = await spawner({ args, command, cwd: target });
2009
+ if (result.code !== 0) {
2010
+ options.logger.warn(`\`${command} install\` exited with code ${String(result.code)} — run it yourself in ${basename(target)}/.`);
2011
+ return void 0;
2012
+ }
2013
+ await emitStep("deps", `Dependencies installed with ${manager}.`);
2014
+ return manager;
2015
+ };
2016
+ const scaffoldFromLocal = async (fromRoot, templateType, target, name, logger) => {
379
2017
  const templateDirectory = join$1(fromRoot, templateType);
380
2018
  if (!existsSync(templateDirectory)) {
381
2019
  logger.error(`template not found in local source: ${templateDirectory}`);
382
2020
  return { code: 1, files: [], target };
383
2021
  }
384
- const written = copyTemplate(templateDirectory, target, name);
385
- logScaffoldSuccess(logger, written, target, name);
2022
+ const written = await copyTemplate(templateDirectory, target, name);
2023
+ logScaffoldSuccess(logger, written, target);
386
2024
  return { code: 0, files: written, target };
387
2025
  };
388
2026
  const scaffoldFromRemote = async (options) => {
@@ -391,26 +2029,111 @@ const scaffoldFromRemote = async (options) => {
391
2029
  const stagingDirectory = join$1(stagingRoot, "template");
392
2030
  try {
393
2031
  const remote = resolveTemplateSource(templateType, source, ref);
394
- logger.info(`fetching template from ${remote}`);
395
- const downloaded = await downloadTemplate(remote, {
396
- cwd: stagingRoot,
397
- dir: stagingDirectory,
398
- force: true,
399
- install: false,
400
- silent: true
401
- });
2032
+ let downloaded;
2033
+ let written = [];
2034
+ await tuiTasks(
2035
+ [
2036
+ {
2037
+ label: `${templateType} template fetched`,
2038
+ run: async () => {
2039
+ downloaded = await downloadTemplate(remote, {
2040
+ cwd: stagingRoot,
2041
+ dir: stagingDirectory,
2042
+ force: true,
2043
+ install: false,
2044
+ silent: true
2045
+ });
2046
+ }
2047
+ },
2048
+ {
2049
+ label: `files copied into ${name}/`,
2050
+ run: async () => {
2051
+ written = await copyTemplate(stagingDirectory, target, name);
2052
+ }
2053
+ }
2054
+ ],
2055
+ { end: "Project initialized!", start: "Project initializing…" }
2056
+ );
402
2057
  const staged = collectFiles(stagingDirectory);
403
- if (downloaded.commit) {
404
- logger.info(`resolved ${downloaded.source} @ ${downloaded.commit} (${String(staged.length)} file(s))`);
405
- } else {
406
- logger.info(`resolved ${downloaded.source} (${String(staged.length)} file(s))`);
2058
+ if (isInteractive()) {
2059
+ process.stdout.write("\n");
407
2060
  }
408
- const written = copyTemplate(stagingDirectory, target, name);
409
- logScaffoldSuccess(logger, written, target, name);
2061
+ logger.info(
2062
+ downloaded?.commit ? `template: ${downloaded.source} @ ${downloaded.commit} (${String(staged.length)} files)` : `template: ${downloaded?.source ?? remote} (${String(staged.length)} files)`
2063
+ );
2064
+ logScaffoldSuccess(logger, written, target);
410
2065
  return { code: 0, files: written, target };
411
2066
  } catch (error) {
2067
+ if (error instanceof PromptCancelledError) {
2068
+ throw error;
2069
+ }
2070
+ const { hints, message } = describeDownloadFailure(error, {
2071
+ ref: resolveSourceRef(ref),
2072
+ remote: resolveTemplateSource(templateType, source, ref),
2073
+ templateType
2074
+ });
2075
+ logger.error(message);
2076
+ for (const hint of hints) {
2077
+ logger.warn(hint);
2078
+ }
2079
+ return { code: 1, files: [], target };
2080
+ } finally {
2081
+ rmSync(stagingRoot, { force: true, recursive: true });
2082
+ }
2083
+ };
2084
+ const renameCreateViteDotfiles = (directory) => {
2085
+ for (const file of ["_gitignore", "_npmrc", "_gitattributes"]) {
2086
+ const from = join$1(directory, file);
2087
+ if (existsSync(from)) {
2088
+ renameSync(from, join$1(directory, `.${file.slice(1)}`));
2089
+ }
2090
+ }
2091
+ };
2092
+ const scaffoldViteOverlay = async (options) => {
2093
+ const { framework, logger, name, overlayBaseFrom, target } = options;
2094
+ const adapter = ADAPTERS[framework];
2095
+ const stagingRoot = mkdtempSync(join$1(tmpdir(), "lunora-vite-base-"));
2096
+ try {
2097
+ let localBase;
2098
+ if (overlayBaseFrom !== void 0) {
2099
+ localBase = join$1(overlayBaseFrom, `template-${adapter.createViteTemplate}`);
2100
+ if (!existsSync(localBase)) {
2101
+ logger.error(`create-vite base not found on disk: ${localBase}`);
2102
+ return { code: 1, files: [], target };
2103
+ }
2104
+ }
2105
+ const copyBase = async () => {
2106
+ if (localBase !== void 0) {
2107
+ cpSync(localBase, target, { recursive: true });
2108
+ return;
2109
+ }
2110
+ const stagingDirectory = join$1(stagingRoot, "base");
2111
+ const remote = `github:vitejs/vite/packages/create-vite/template-${adapter.createViteTemplate}#main`;
2112
+ await downloadTemplate(remote, { cwd: stagingRoot, dir: stagingDirectory, force: true, install: false, silent: true });
2113
+ renameCreateViteDotfiles(stagingDirectory);
2114
+ cpSync(stagingDirectory, target, { recursive: true });
2115
+ };
2116
+ let written = [];
2117
+ await tuiTasks(
2118
+ [
2119
+ { label: `create-vite (${adapter.label}) base ready`, run: copyBase },
2120
+ {
2121
+ label: `Lunora overlay applied (${adapter.label})`,
2122
+ run: async () => {
2123
+ written = await applyLunoraOverlay({ adapter, distTag: resolveDistTag(), logger, name, target });
2124
+ }
2125
+ }
2126
+ ],
2127
+ { end: "Project initialized!", start: "Project initializing…" }
2128
+ );
2129
+ logScaffoldSuccess(logger, written, target);
2130
+ return { code: 0, files: [...collectFiles(target)], target };
2131
+ } catch (error) {
2132
+ if (error instanceof PromptCancelledError) {
2133
+ throw error;
2134
+ }
412
2135
  const message = error instanceof Error ? error.message : String(error);
413
- logger.error(`failed to download template: ${message}`);
2136
+ logger.error(`failed to scaffold the ${adapter.label} base: ${message}`);
414
2137
  return { code: 1, files: [], target };
415
2138
  } finally {
416
2139
  rmSync(stagingRoot, { force: true, recursive: true });
@@ -533,69 +2256,247 @@ const runInPlaceInit = (cwd, logger) => {
533
2256
  const offerIsInteractive = (options) => options.yes !== true && (options.prompt !== void 0 || (options.interactive ?? isInteractive()));
534
2257
  const maybeOfferExtras = async (options, projectDirectory) => {
535
2258
  const interactive = offerIsInteractive(options);
536
- const apply = async (names) => {
537
- const result = await runAddCommand({
538
- allowUnsafeSource: options.allowUnsafeSource,
539
- cwd: projectDirectory,
540
- from: options.registryFrom,
541
- logger: options.logger,
542
- names: [...names],
543
- ref: options.ref,
544
- source: options.registrySource,
545
- yes: true
2259
+ const preselected = options.add === void 0 ? [] : parseFeatureList(options.add, (message) => {
2260
+ options.logger.warn(message);
2261
+ });
2262
+ const applyAll = async (plans) => {
2263
+ if (plans.length === 0) {
2264
+ return true;
2265
+ }
2266
+ if (options.dryRun === true) {
2267
+ logWould(options.logger, `add ${plans.map((plan) => plan.label).join(", ")}`);
2268
+ return true;
2269
+ }
2270
+ const buffered = [];
2271
+ const applyLogger = isInteractive() ? {
2272
+ error: (message) => {
2273
+ buffered.push({ level: "error", message });
2274
+ },
2275
+ info: () => {
2276
+ },
2277
+ success: () => {
2278
+ },
2279
+ warn: (message) => {
2280
+ buffered.push({ level: "warn", message });
2281
+ }
2282
+ } : options.logger;
2283
+ const steps = plans.map((plan) => {
2284
+ return {
2285
+ running: `adding ${plan.label}…`,
2286
+ task: () => runAddCommand({
2287
+ allowUnsafeSource: options.allowUnsafeSource,
2288
+ cwd: projectDirectory,
2289
+ from: options.registryFrom,
2290
+ logger: applyLogger,
2291
+ names: [...plan.names],
2292
+ ref: options.ref,
2293
+ source: options.registrySource,
2294
+ transformManifest: plan.transformManifest,
2295
+ yes: true
2296
+ })
2297
+ };
546
2298
  });
547
- return result.code === 0;
2299
+ const done = `added ${plans.map((plan) => plan.label).join(", ")}`;
2300
+ const results = await withTuiBadgeProgress(BADGES.add, steps, done);
2301
+ for (const { level, message } of buffered) {
2302
+ options.logger[level](message);
2303
+ }
2304
+ return results.every((result) => result.code === 0);
548
2305
  };
549
- await offerRegistryExtras({
550
- apply,
2306
+ const deps = {
2307
+ applyAll,
551
2308
  interactive,
552
2309
  logger: options.logger,
553
- multiSelect: options.prompt?.multiSelect ?? ((message, choices, settings) => promptMultiSelect(message, choices, settings)),
554
- select: options.prompt?.select ?? ((message, choices, settings) => promptSelect(message, choices, settings))
555
- });
2310
+ multiSelect: options.prompt?.multiSelect ?? ((message, choices, settings) => tuiMultiSelect(message, choices, { ...settings, badge: BADGES.add })),
2311
+ preselected: preselected.length > 0 ? preselected : void 0,
2312
+ projectName: basename(projectDirectory),
2313
+ select: options.prompt?.select ?? ((message, choices, settings) => tuiSelect(message, choices, { ...settings, badge: BADGES.add })),
2314
+ text: options.prompt?.text ?? ((message, settings) => tuiText(message, { ...settings, badge: BADGES.add }))
2315
+ };
2316
+ if (preselected.length > 0) {
2317
+ await offerRegistryExtras(deps);
2318
+ return;
2319
+ }
2320
+ if (isInteractive()) {
2321
+ await tuiHeadline(COPY.extras);
2322
+ }
2323
+ await offerRegistryExtras(deps);
2324
+ };
2325
+ const DEFAULT_FRAMEWORK = "react";
2326
+ const FRAMEWORK_CHOICES = [
2327
+ { description: "React SPA — official create-vite base + the Lunora layer (the default)", label: "React", value: "react" },
2328
+ { description: "Vue SPA — create-vite base + Lunora", label: "Vue", value: "vue" },
2329
+ { description: "Solid SPA — create-vite base + Lunora", label: "Solid", value: "solid" },
2330
+ { description: "Svelte SPA — create-vite base + Lunora", label: "Svelte", value: "svelte" },
2331
+ { description: "TanStack Start (React) — SSR with live-loader routes", label: "TanStack Start · React", value: "tanstack-start-react" },
2332
+ { description: "TanStack Start (Solid)", label: "TanStack Start · Solid", value: "tanstack-start-solid" },
2333
+ { description: "React Router (v7, framework mode) — SSR composed into the Lunora worker", label: "React Router", value: "react-router" },
2334
+ { description: "Astro + a standalone Lunora worker", label: "Astro", value: "astro" },
2335
+ { description: "AnalogJS (Angular) — single-worker, Lunora mounted in Nitro", label: "Analog", value: "analog" },
2336
+ { description: "Nuxt (Vue) — single-worker, Lunora mounted in Nitro", label: "Nuxt", value: "nuxt" },
2337
+ { description: "SvelteKit + a standalone Lunora worker", label: "SvelteKit", value: "sveltekit" },
2338
+ { description: "Worker only — no frontend", label: "Standalone", value: "standalone" }
2339
+ ];
2340
+ const OVERLAY_VALUES = Object.keys(ADAPTERS).join("|");
2341
+ const TEMPLATE_VALUES = FRAMEWORK_CHOICES.filter((choice) => !isOverlayFramework(choice.value)).map((choice) => choice.value).join("|");
2342
+ const toScaffoldChoice = (value) => isOverlayFramework(value) ? { framework: value, kind: "overlay" } : { kind: "template", templateType: value };
2343
+ const resolveScaffoldChoice = async (options) => {
2344
+ if (options.vite !== void 0) {
2345
+ return { framework: options.vite, kind: "overlay" };
2346
+ }
2347
+ if (options.templateType !== void 0) {
2348
+ return { kind: "template", templateType: options.templateType };
2349
+ }
2350
+ if (!isInteractive() || options.yes === true) {
2351
+ return { framework: DEFAULT_FRAMEWORK, kind: "overlay" };
2352
+ }
2353
+ return toScaffoldChoice(await tuiSelect(COPY.framework, FRAMEWORK_CHOICES, { badge: BADGES.tmpl, default: DEFAULT_FRAMEWORK }) ?? DEFAULT_FRAMEWORK);
2354
+ };
2355
+ const nonInteractiveInitError = (options) => {
2356
+ if (isInteractive() || options.yes === true) {
2357
+ return void 0;
2358
+ }
2359
+ const missing = [];
2360
+ if (options.name === void 0) {
2361
+ missing.push("a project name (`lunora init <name>`)");
2362
+ }
2363
+ if (options.templateType === void 0 && options.vite === void 0) {
2364
+ missing.push(`a framework — \`--vite <${OVERLAY_VALUES}>\` for an SPA, or \`-t <${TEMPLATE_VALUES}>\` for a bespoke template`);
2365
+ }
2366
+ if (missing.length === 0) {
2367
+ return void 0;
2368
+ }
2369
+ return `lunora init can't prompt in a non-interactive terminal — provide ${missing.join(" and ")}, or pass --yes to accept the defaults.`;
2370
+ };
2371
+ const scaffoldOverlayPath = async (options, framework, name, target) => {
2372
+ if (!isOverlayFramework(framework)) {
2373
+ options.logger.error(`init: unknown framework "${framework}". Supported overlays: ${Object.keys(ADAPTERS).join(", ")}.`);
2374
+ return { code: 1, files: [], target };
2375
+ }
2376
+ if (!await verifyRemoteTemplate({ isLocal: options.overlayBaseFrom !== void 0, logger: options.logger })) {
2377
+ return { code: 1, files: [], target };
2378
+ }
2379
+ mkdirSync(target, { recursive: true });
2380
+ return scaffoldViteOverlay({ framework, logger: options.logger, name, overlayBaseFrom: options.overlayBaseFrom, target });
556
2381
  };
557
- const scaffoldNewProject = async (options, cwd) => {
558
- const name = options.name ?? "lunora-app";
559
- const templateType = options.templateType ?? "vite";
2382
+ const scaffoldTemplatePath = async (options, templateType, name, target) => {
560
2383
  if (templateType === "next") {
561
- options.logger.warn('template "next" is not yet available — re-run with `-t vite` or `-t standalone`.');
2384
+ options.logger.warn('template "next" is not yet available — re-run with `--vite react` or `-t standalone`.');
2385
+ return { code: 1, files: [], target };
2386
+ }
2387
+ if (options.from !== void 0) {
2388
+ return await scaffoldFromLocal(options.from, templateType, target, name, options.logger);
2389
+ }
2390
+ if (options.source !== void 0 && options.source.length > 0 && !options.allowUnsafeSource && !isSafeSource(options.source)) {
2391
+ options.logger.error(
2392
+ `init: refusing --source ${options.source} — only gh:, github:, or https:// sources are allowed (and may not contain ".."). Re-run with --allow-unsafe-source if you really want this.`
2393
+ );
2394
+ return { code: 1, files: [], target };
2395
+ }
2396
+ if (!await verifyRemoteTemplate({ isLocal: false, logger: options.logger, source: resolveTemplateSource(templateType, options.source, options.ref) })) {
2397
+ return { code: 1, files: [], target };
2398
+ }
2399
+ return scaffoldFromRemote({ logger: options.logger, name, ref: options.ref, source: options.source, target, templateType });
2400
+ };
2401
+ const scaffoldNewProject = async (options, cwd, recordTarget) => {
2402
+ await tuiMoonrise("realtime backend on Cloudflare Workers + Durable Objects");
2403
+ const blocked = nonInteractiveInitError(options);
2404
+ if (blocked !== void 0) {
2405
+ options.logger.error(blocked);
562
2406
  return { code: 1, files: [], target: "" };
563
2407
  }
2408
+ const suggestedName = generateProjectName();
2409
+ const name = options.name ?? await tuiText(COPY.name, { badge: BADGES.dir, default: suggestedName, placeholder: suggestedName });
2410
+ const choice = await resolveScaffoldChoice(options);
564
2411
  if (name.includes("/") || name.includes("\\") || name === ".." || name === ".") {
565
2412
  options.logger.error(`init: refusing project name "${name}" — must not contain path separators or be "." / "..".`);
566
2413
  return { code: 1, files: [], target: "" };
567
2414
  }
568
2415
  const target = resolve(cwd, name);
569
- if (existsSync(target)) {
2416
+ const targetPreExisted = existsSync(target);
2417
+ if (targetPreExisted) {
570
2418
  const entries = readdirSync(target);
571
2419
  if (entries.length > 0) {
572
2420
  options.logger.error(`target directory not empty: ${target}`);
573
2421
  return { code: 1, files: [], target };
574
2422
  }
575
2423
  }
576
- if (options.from !== void 0) {
577
- return scaffoldFromLocal(options.from, templateType, target, name, options.logger);
2424
+ if (options.dryRun === true) {
2425
+ const what = choice.kind === "overlay" ? `the ${choice.framework} create-vite overlay` : `the ${choice.templateType} template`;
2426
+ logWould(options.logger, `scaffold ${what} into ${target}`);
2427
+ return { code: 0, files: [], target };
578
2428
  }
579
- if (options.source !== void 0 && options.source.length > 0 && !options.allowUnsafeSource && !isSafeSource(options.source)) {
580
- options.logger.error(
581
- `init: refusing --source ${options.source} — only gh:, github:, or https:// sources are allowed (and may not contain ".."). Re-run with --allow-unsafe-source if you really want this.`
582
- );
583
- return { code: 1, files: [], target };
2429
+ recordTarget(target, targetPreExisted);
2430
+ return choice.kind === "overlay" ? scaffoldOverlayPath(options, choice.framework, name, target) : scaffoldTemplatePath(options, choice.templateType, name, target);
2431
+ };
2432
+ const resetScaffoldOnCancel = (cleanup, logger) => {
2433
+ const { target, targetPreExisted } = cleanup;
2434
+ if (target === void 0 || !existsSync(target)) {
2435
+ return;
2436
+ }
2437
+ if (targetPreExisted === true) {
2438
+ for (const entry of readdirSync(target)) {
2439
+ rmSync(join$1(target, entry), { force: true, recursive: true });
2440
+ }
2441
+ } else {
2442
+ rmSync(target, { force: true, recursive: true });
2443
+ }
2444
+ logger.info(`removed the partially-created project at ${target}`);
2445
+ };
2446
+ const runScaffoldStep = async (options, cwd, recordTarget) => {
2447
+ if (options.inPlace !== true) {
2448
+ return scaffoldNewProject(options, cwd, recordTarget);
2449
+ }
2450
+ if (options.dryRun === true) {
2451
+ logWould(options.logger, `configure Lunora into ${cwd}`);
2452
+ return { code: 0, files: [], target: cwd };
2453
+ }
2454
+ return runInPlaceInit(cwd, options.logger);
2455
+ };
2456
+ const runPostScaffold = async (options, result, cwd) => {
2457
+ await maybeOfferExtras(options, result.target);
2458
+ const installedManager = options.inPlace === true ? void 0 : await maybeOfferInstall(options, result.target);
2459
+ if (options.inPlace !== true) {
2460
+ await maybeOfferGit(options, result.target);
2461
+ await printNextSteps(basename(result.target), installedManager, isInsideMonorepo(cwd));
2462
+ await emitMascot(options.logger);
584
2463
  }
585
- return scaffoldFromRemote({ logger: options.logger, name, ref: options.ref, source: options.source, target, templateType });
2464
+ };
2465
+ const scaffoldCiPipeline = (options, result, cwd) => {
2466
+ if (result.code !== 0 || options.ci === void 0) {
2467
+ return;
2468
+ }
2469
+ if (options.dryRun === true) {
2470
+ logWould(options.logger, `scaffold a ${options.ci} CI deploy pipeline`);
2471
+ return;
2472
+ }
2473
+ scaffoldCiWorkflow(options.inPlace === true ? cwd : result.target, options.ci, options.logger);
586
2474
  };
587
2475
  const runInitCommand = async (options) => {
588
2476
  const cwd = options.cwd ?? process.cwd();
589
- const result = options.inPlace === true ? runInPlaceInit(cwd, options.logger) : await scaffoldNewProject(options, cwd);
590
- if (result.code === 0 && result.target !== "") {
591
- await maybeOfferExtras(options, result.target);
592
- }
593
- if (result.code === 0 && options.ci !== void 0) {
594
- scaffoldCiWorkflow(options.inPlace === true ? cwd : result.target, options.ci, options.logger);
2477
+ const cleanup = {};
2478
+ let result;
2479
+ try {
2480
+ result = await runScaffoldStep(options, cwd, (target, preExisted) => {
2481
+ cleanup.target = target;
2482
+ cleanup.targetPreExisted = preExisted;
2483
+ });
2484
+ if (result.code === 0 && result.target !== "") {
2485
+ cleanup.target = void 0;
2486
+ await runPostScaffold(options, result, cwd);
2487
+ }
2488
+ } catch (error) {
2489
+ if (error instanceof PromptCancelledError) {
2490
+ resetScaffoldOnCancel(cleanup, options.logger);
2491
+ process.stdout.write("\n ✖ Setup cancelled — run `lunora init` again whenever you're ready. 🌙\n");
2492
+ return { code: 130, files: [], target: "" };
2493
+ }
2494
+ throw error;
595
2495
  }
2496
+ scaffoldCiPipeline(options, result, cwd);
596
2497
  return result;
597
2498
  };
598
- const isTemplate = (value) => value === "astro" || value === "next" || value === "nuxt" || value === "standalone" || value === "sveltekit" || value === "tanstack-start-react" || value === "tanstack-start-solid" || value === "vite";
2499
+ const isTemplate = (value) => value === "analog" || value === "astro" || value === "next" || value === "nuxt" || value === "react-router" || value === "standalone" || value === "sveltekit" || value === "tanstack-start-react" || value === "tanstack-start-solid";
599
2500
  const resolveCiProvider = (raw, logger) => {
600
2501
  if (raw === void 0) {
601
2502
  return void 0;
@@ -607,12 +2508,13 @@ const resolveCiProvider = (raw, logger) => {
607
2508
  return void 0;
608
2509
  };
609
2510
  const execute = defineHandler(({ argument, cwd, logger, options }) => {
610
- const templateRaw = options.template ?? "vite";
611
- const template = isTemplate(templateRaw) ? templateRaw : "vite";
2511
+ const templateType = options.template !== void 0 && isTemplate(options.template) ? options.template : void 0;
612
2512
  return runInitCommand({
2513
+ add: options.add,
613
2514
  allowUnsafeSource: options.allowUnsafeSource === true,
614
2515
  cwd,
615
2516
  ci: resolveCiProvider(options.ci, logger),
2517
+ dryRun: options.dryRun === true,
616
2518
  from: options.from,
617
2519
  inPlace: options.here === true,
618
2520
  interactive: options.interactive === true ? true : void 0,
@@ -620,7 +2522,8 @@ const execute = defineHandler(({ argument, cwd, logger, options }) => {
620
2522
  name: argument[0],
621
2523
  ref: options.ref,
622
2524
  source: options.source,
623
- templateType: template,
2525
+ templateType,
2526
+ vite: options.vite,
624
2527
  yes: options.yes === true
625
2528
  });
626
2529
  });