@lunora/cli 1.0.0-alpha.1 → 1.0.0-alpha.100

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