@lunora/cli 1.0.0-alpha.9 → 1.0.0-alpha.91

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 (59) 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 +358 -300
  5. package/dist/index.d.ts +358 -300
  6. package/dist/index.mjs +8 -9
  7. package/dist/packem_chunks/handler.mjs +15 -5
  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 +48 -67
  14. package/dist/packem_chunks/handler16.mjs +94 -37
  15. package/dist/packem_chunks/handler17.mjs +39 -100
  16. package/dist/packem_chunks/handler18.mjs +87 -152
  17. package/dist/packem_chunks/handler19.mjs +148 -67
  18. package/dist/packem_chunks/handler2.mjs +6 -4
  19. package/dist/packem_chunks/handler20.mjs +77 -75
  20. package/dist/packem_chunks/handler21.mjs +71 -288
  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 +762 -81
  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 +1648 -188
  32. package/dist/packem_chunks/runMigrateGenerateCommand.mjs +94 -47
  33. package/dist/packem_chunks/runResetCommand.mjs +2 -2
  34. package/dist/packem_chunks/runRpcCommand.mjs +3 -2
  35. package/dist/packem_shared/{COMMANDS-Dh0bSERi.mjs → COMMANDS-DZ0NnuqI.mjs} +103 -27
  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/{commands-CkkATMMx.mjs → commands-D5Yxt9VY.mjs} +199 -20
  42. package/dist/packem_shared/{createLogger-CHPNjFw2.mjs → createLogger-CIWSHrTL.mjs} +40 -8
  43. package/dist/packem_shared/{createRecordingSpawner-DxI3mebw.mjs → createRecordingSpawner-WuSn20kb.mjs} +23 -2
  44. package/dist/packem_shared/detect-package-manager-v4hHpQd0.mjs +62 -0
  45. package/dist/packem_shared/{insertSchemaExtension-BuzF6-t2.mjs → insertSchemaExtension-DAqbfr9Z.mjs} +15 -10
  46. package/dist/packem_shared/{open-url-Dfq6fAyT.mjs → open-url-4PBLY9X0.mjs} +3 -2
  47. package/dist/packem_shared/{output-format-7gyGR3h8.mjs → output-format-B4642rjE.mjs} +1 -1
  48. package/dist/packem_shared/{parseManifest--vZf2FY1.mjs → parseManifest-Dbp-Q2q3.mjs} +36 -9
  49. package/dist/packem_shared/prompt-cancelled-APzX1Im-.mjs +9 -0
  50. package/dist/packem_shared/runAddCommand-D1hgfqFQ.mjs +4 -0
  51. package/dist/packem_shared/{storage-Bjo35hPa.mjs → storage-BXU4ax4O.mjs} +1 -1
  52. package/dist/packem_shared/tui-prompts-BjEN8XgP.mjs +658 -0
  53. package/dist/packem_shared/wrangler-secrets-Coni-mER.mjs +49 -0
  54. package/package.json +17 -14
  55. package/skills/lunora-quickstart/SKILL.md +26 -5
  56. package/dist/packem_shared/detect-package-manager-DYp7n3mJ.mjs +0 -61
  57. package/dist/packem_shared/parseArgs-YXFuKdEk.mjs +0 -56
  58. package/dist/packem_shared/runAddCommand-DepS9W9W.mjs +0 -4
  59. package/dist/packem_shared/tui-prompts-CA9lngSS.mjs +0 -269
@@ -1,19 +1,22 @@
1
- import { existsSync, mkdirSync, writeFileSync, readFileSync, readdirSync, mkdtempSync, cpSync, rmSync, renameSync } 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 { detectFramework as detectFramework$1, isInteractive } from '@lunora/config';
3
+ import { detectFramework as detectFramework$1, isInteractive, LUNA_ART, LUNA_NAME, LUNA_SIGNOFF, paintAnswer, BADGES } from '@lunora/config';
4
4
  import { walkSync } from '@visulima/fs';
5
5
  import { join as join$1, dirname as dirname$1, basename, resolve, relative } from '@visulima/path';
6
6
  import { downloadTemplate } from 'giget';
7
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';
10
- import { a as detectInstalledManagers, i as installArgsFor } from '../packem_shared/detect-package-manager-DYp7n3mJ.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';
11
11
  import MagicString from 'magic-string';
12
12
  import { Project, SyntaxKind } from 'ts-morph';
13
- import { c as resolveDistTag, d as resolveSourceRef, r as runAddCommand } from '../packem_shared/commands-CkkATMMx.mjs';
14
- import { defaultSpawner } from '../packem_shared/createRecordingSpawner-DxI3mebw.mjs';
15
- import { d as tuiOutro, e as tuiBanner, t as tuiText, f as tuiIntro, a as tuiSelect, w as withTuiSpinner, b as tuiConfirm, g as tuiMultiSelect } from '../packem_shared/tui-prompts-CA9lngSS.mjs';
16
- import { p as promptBucketName, w as withStorageBucketName, M as MAIL_DESTINATION_PROMPT, r as resolveTypedDestination, E as EMAIL_ITEM, f as withMailDestination, e as promptAuthProvider, c as promptDatabaseName, g as withAuthDatabaseName } from '../packem_shared/storage-Bjo35hPa.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';
17
20
 
18
21
  const GITHUB_CONTENT = `name: Deploy
19
22
 
@@ -285,47 +288,1057 @@ const patchViteConfig = (source) => {
285
288
  return { changed: true, code: ms.toString() };
286
289
  };
287
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
+
288
345
  const STACK_FEATURE_OPTIONS = [
346
+ { description: "LLMs via Workers AI (summarize, generate, stream)", label: "AI", value: "ai" },
289
347
  { description: "Sign-up / sign-in (asks which provider)", label: "Authentication", value: "auth" },
290
- { description: "Cloudflare Email Workers + a dev mail catcher", label: "Transactional email", value: "email" },
291
- { description: "Typed R2 buckets + signed URLs (@lunora/storage)", label: "File storage", value: "storage" },
292
- { description: "Token-bucket / sliding-window limits (@lunora/ratelimit)", label: "Rate limiting", value: "ratelimit" },
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" },
293
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" },
294
356
  { description: "Live presence / who's-online over hibernated WebSockets", label: "Presence", value: "presence" },
295
- { description: "Snapshot + restore your Durable Object data", label: "Backups", value: "backup" }
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" }
296
360
  ];
297
- const applyAuthFeature = async (deps) => {
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) => {
298
377
  const provider = await promptAuthProvider(deps.select);
299
378
  const databaseName = await promptDatabaseName(deps.text, deps.projectName);
300
- await deps.apply([provider], { transformManifest: (manifest) => withAuthDatabaseName(manifest, databaseName) });
379
+ return { label: "auth", names: [provider], transformManifest: (manifest) => withAuthDatabaseName(manifest, databaseName) };
301
380
  };
302
- const applyEmailFeature = async (deps) => {
381
+ const collectEmailFeature = async (deps) => {
303
382
  const answer = await deps.text(MAIL_DESTINATION_PROMPT, { placeholder: "you@yourdomain.com" });
304
383
  const destination = resolveTypedDestination(answer, (message) => {
305
384
  deps.logger.warn(message);
306
385
  });
307
- await deps.apply([EMAIL_ITEM], destination === void 0 ? void 0 : { transformManifest: (manifest) => withMailDestination(manifest, destination) });
386
+ return {
387
+ label: "email",
388
+ names: [EMAIL_ITEM],
389
+ transformManifest: destination === void 0 ? void 0 : (manifest) => withMailDestination(manifest, destination)
390
+ };
308
391
  };
309
- const applyStorageFeature = async (deps) => {
392
+ const collectStorageFeature = async (deps) => {
310
393
  const bucketName = await promptBucketName(deps.text, deps.projectName);
311
- await deps.apply(["storage"], { transformManifest: (manifest) => withStorageBucketName(manifest, bucketName) });
394
+ return { label: "storage", names: ["storage"], transformManifest: (manifest) => withStorageBucketName(manifest, bucketName) };
312
395
  };
313
- const FEATURE_HANDLERS = {
314
- auth: applyAuthFeature,
315
- email: applyEmailFeature,
316
- storage: applyStorageFeature
396
+ const FEATURE_COLLECTORS = {
397
+ auth: collectAuthFeature,
398
+ email: collectEmailFeature,
399
+ storage: collectStorageFeature
317
400
  };
318
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
+ }
319
410
  if (!deps.interactive) {
320
- deps.logger.info("tip: add features later with `lunora add <auth|email|storage|ratelimit|crons|presence|backup>`.");
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
+ );
321
415
  return;
322
416
  }
323
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 = [];
324
422
  for (const feature of picked) {
325
- const handler = FEATURE_HANDLERS[feature];
326
- await (handler ? handler(deps) : deps.apply([feature]));
423
+ const collect = FEATURE_COLLECTORS[feature];
424
+ plans.push(collect ? await collect(deps) : { label: feature, names: [feature] });
327
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";
708
+ }
709
+ });
710
+
711
+ const toggle = (): void => {
712
+ theme.value = theme.value === "light" ? "dark" : "light";
328
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
+ `;
329
1342
 
330
1343
  const READ_URL = `const url = (import.meta.env.VITE_LUNORA_URL as string | undefined) ?? globalThis.location.origin;`;
331
1344
  const REACT_MAIN = `import "./index.css";
@@ -413,51 +1426,103 @@ const app = mount(Root, { target: document.getElementById("app")! });
413
1426
 
414
1427
  export default app;
415
1428
  `;
416
- const VANILLA_MAIN = `import "./style.css";
417
-
418
- import { LunoraClient } from "lunorash/client";
419
-
420
- import { api } from "../lunora/_generated/api";
421
-
422
- // Vanilla starter: no framework provider — talk to Lunora through the client
423
- // directly. \`@lunora/vite\` runs the Worker on the same origin as Vite.
424
- ${READ_URL}
425
- const client = new LunoraClient({ url });
426
-
427
- const root = document.querySelector<HTMLDivElement>("#app")!;
428
-
429
- const heading = document.createElement("h1");
430
- heading.textContent = "Vite + Lunora";
431
-
432
- const output = document.createElement("pre");
433
- root.replaceChildren(heading, output);
434
-
435
- const render = (messages: unknown): void => {
436
- // textContent (not innerHTML) — never inject server data as markup.
437
- output.textContent = JSON.stringify(messages, null, 2);
438
- };
439
-
440
- // Live subscription: the list re-renders on every server delta.
441
- client.onUpdate(api.messages.list, { channelId: "channel:demo" }, render);
442
- `;
443
1429
  const ADAPTERS = {
444
- react: { adapter: "@lunora/react", createViteTemplate: "react-ts", files: [{ contents: REACT_MAIN, path: "src/main.tsx" }], label: "React" },
445
- solid: { adapter: "@lunora/solid", createViteTemplate: "solid", files: [{ contents: SOLID_INDEX, path: "src/index.tsx" }], label: "Solid" },
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
+ },
446
1450
  svelte: {
447
1451
  adapter: "@lunora/svelte",
448
1452
  createViteTemplate: "svelte-ts",
449
1453
  files: [
450
1454
  { contents: SVELTE_ROOT, path: "src/Root.svelte" },
451
- { contents: SVELTE_MAIN, path: "src/main.ts" }
1455
+ { contents: SVELTE_MAIN, path: "src/main.ts" },
1456
+ { contents: SVELTE_APP, path: "src/App.svelte" },
1457
+ { contents: WELCOME_CSS, path: "src/app.css" }
452
1458
  ],
453
1459
  label: "Svelte"
454
1460
  },
455
- vanilla: { adapter: "lunorash/client", createViteTemplate: "vanilla-ts", files: [{ contents: VANILLA_MAIN, path: "src/main.ts" }], label: "Vanilla" },
456
- vue: { adapter: "@lunora/vue", createViteTemplate: "vue-ts", files: [{ contents: VUE_MAIN, path: "src/main.ts" }], label: "Vue" }
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"
1479
+ }
457
1480
  };
458
1481
  const isOverlayFramework = (value) => Object.hasOwn(ADAPTERS, value);
459
1482
 
460
- const LUNORA_SCHEMA = `import { defineSchema, defineTable, v } from "lunorash/server";
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";
461
1526
 
462
1527
  export default defineSchema({
463
1528
  messages: defineTable({
@@ -466,17 +1531,36 @@ export default defineSchema({
466
1531
  })
467
1532
  .shardBy("channelId")
468
1533
  .index("by_channel", ["channelId"]),
469
- });
1534
+ }).extend(ratelimit.extension);
470
1535
  `;
471
- const LUNORA_MESSAGES = `import { mutation, query, v } from "./_generated/server.js";
1536
+ const LUNORA_MESSAGES = `import { RateLimiter, rateLimit, createDbStore } from "lunorash/ratelimit";
1537
+
1538
+ import { mutation, query, v } from "#lunora/_generated/server.js";
472
1539
 
473
- export const list = query.input({ channelId: v.string(), limit: v.optional(v.number()) }).query(async ({ args }) => {
474
- return { channelId: args.channelId, limit: args.limit ?? 50, messages: [] };
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" }),
475
1545
  });
476
1546
 
477
- export const send = mutation.input({ channelId: v.string(), text: v.string() }).mutation(async ({ args }) => {
478
- return { channelId: args.channelId, text: args.text };
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 };
479
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
+ });
480
1564
  `;
481
1565
  const SERVER_ENTRY = `import type { ShardNamespaceLike } from "lunorash/runtime";
482
1566
 
@@ -537,15 +1621,17 @@ const ensureGitignore = (target) => {
537
1621
  ${missing.join("\n")}
538
1622
  `, "utf8");
539
1623
  };
540
- const stampRange = (name, range, distTag) => name === "lunorash" || name.startsWith("@lunora/") ? distTag : range;
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;
541
1626
  const withDependency = (map, name, range, distTag) => {
542
1627
  return { ...map, [name]: stampRange(name, range, distTag) };
543
1628
  };
544
- const restampLunora = (map, distTag) => Object.fromEntries(Object.entries(map).map(([name, range]) => [name, stampRange(name, range, distTag)]));
545
- const patchPackageJson = (target, name, adapter, distTag) => {
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) => {
546
1631
  const path = join$1(target, "package.json");
547
1632
  const parsed = JSON.parse(readFileSync(path, "utf8"));
548
1633
  let dependencies = withDependency(parsed.dependencies ?? {}, "lunorash", distTag, distTag);
1634
+ dependencies = withDependency(dependencies, "@lunora/ratelimit", distTag, distTag);
549
1635
  if (adapter.adapter.startsWith("@lunora/")) {
550
1636
  dependencies = withDependency(dependencies, adapter.adapter, distTag, distTag);
551
1637
  }
@@ -553,12 +1639,16 @@ const patchPackageJson = (target, name, adapter, distTag) => {
553
1639
  dependencies = withDependency(dependencies, depName, range, distTag);
554
1640
  }
555
1641
  let devDependencies = withDependency(parsed.devDependencies ?? {}, "@lunora/vite", distTag, distTag);
1642
+ devDependencies = withDependency(devDependencies, "@lunora/studio", distTag, distTag);
556
1643
  for (const [depName, range] of Object.entries(COMMON_DEV_DEPENDENCIES)) {
557
1644
  devDependencies = withDependency(devDependencies, depName, range, distTag);
558
1645
  }
1646
+ const lunoraNames = [...Object.keys(dependencies), ...Object.keys(devDependencies)].filter((depName) => isLunoraDep$1(depName));
1647
+ const versions = await resolveTagVersions(lunoraNames, distTag);
559
1648
  parsed.name = name;
560
- parsed.dependencies = restampLunora(dependencies, distTag);
561
- parsed.devDependencies = restampLunora(devDependencies, distTag);
1649
+ parsed.imports = { ...parsed.imports, "#lunora/*": "./lunora/*" };
1650
+ parsed.dependencies = restampLunora(dependencies, distTag, versions);
1651
+ parsed.devDependencies = restampLunora(devDependencies, distTag, versions);
562
1652
  parsed.scripts = { ...parsed.scripts, codegen: "lunora codegen", deploy: "vite build && lunora deploy" };
563
1653
  writeFileSync(path, `${JSON.stringify(parsed, void 0, 4)}
564
1654
  `, "utf8");
@@ -574,9 +1664,10 @@ const patchBaseViteConfig = (target, logger) => {
574
1664
  writeFileSync(candidate, result.code, "utf8");
575
1665
  }
576
1666
  };
577
- const applyLunoraOverlay = (options) => {
1667
+ const applyLunoraOverlay = async (options) => {
578
1668
  const { adapter, distTag, logger, name, target } = options;
579
1669
  const written = [];
1670
+ writeFile(target, join$1("lunora", "ratelimit", "schema.ts"), RATELIMIT_SCHEMA, written);
580
1671
  writeFile(target, join$1("lunora", "schema.ts"), LUNORA_SCHEMA, written);
581
1672
  writeFile(target, join$1("lunora", "messages.ts"), LUNORA_MESSAGES, written);
582
1673
  writeFile(target, join$1("src", "server.ts"), SERVER_ENTRY, written);
@@ -586,11 +1677,111 @@ const applyLunoraOverlay = (options) => {
586
1677
  writeFile(target, file.path, file.contents, written);
587
1678
  }
588
1679
  patchBaseViteConfig(target, logger);
589
- patchPackageJson(target, name, adapter, distTag);
1680
+ await patchPackageJson(target, name, adapter, distTag);
590
1681
  ensureGitignore(target);
591
1682
  return written;
592
1683
  };
593
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
+ };
594
1785
  const TEXT_EXTENSIONS = /* @__PURE__ */ new Set([".gitignore", ".html", ".js", ".json", ".jsonc", ".md", ".mjs", ".ts", ".tsx"]);
595
1786
  const VITE_CONFIG_CANDIDATES = ["vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"];
596
1787
  const MINIMAL_VITE_CONFIG = `import { defineConfig } from "vite";
@@ -633,7 +1824,27 @@ const isTextFile = (filePath) => {
633
1824
  };
634
1825
  const substitute = (content, name) => content.replaceAll("{{name}}", name);
635
1826
  const isLunoraDep = (name) => name === "lunorash" || name.startsWith("@lunora/");
636
- const stampLunoraDeps = (packageJsonText, distTag) => {
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) => {
637
1848
  let parsed;
638
1849
  try {
639
1850
  parsed = JSON.parse(packageJsonText);
@@ -646,23 +1857,50 @@ const stampLunoraDeps = (packageJsonText, distTag) => {
646
1857
  if (!isLunoraDep(name)) {
647
1858
  continue;
648
1859
  }
649
- const edits = modify(text, [section, name], distTag, { formattingOptions: { insertSpaces: true, tabSize: 4 } });
1860
+ const pin = versions.get(name) ?? distTag;
1861
+ const edits = modify(text, [section, name], pin, { formattingOptions: { insertSpaces: true, tabSize: 4 } });
650
1862
  text = applyEdits(text, edits);
651
1863
  }
652
1864
  }
653
1865
  return text;
654
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");
655
1889
  const collectFiles = (directory) => {
656
1890
  const out = [];
657
1891
  for (const entry of walkSync(directory, { includeDirs: false, includeFiles: true })) {
1892
+ if (lstatSync(entry.path).isSymbolicLink()) {
1893
+ continue;
1894
+ }
658
1895
  out.push(entry.path);
659
1896
  }
660
1897
  return out;
661
1898
  };
662
- const copyTemplate = (sourceDirectory, target, name) => {
1899
+ const copyTemplate = async (sourceDirectory, target, name) => {
663
1900
  const files = collectFiles(sourceDirectory);
664
1901
  const written = [];
665
1902
  const distTag = resolveDistTag();
1903
+ const versions = await resolveLunoraVersions(files, distTag);
666
1904
  for (const source of files) {
667
1905
  const relativePath = relative(sourceDirectory, source);
668
1906
  const destination = join$1(target, relativePath);
@@ -670,7 +1908,7 @@ const copyTemplate = (sourceDirectory, target, name) => {
670
1908
  const raw = readFileSync(source);
671
1909
  let text = isTextFile(source) ? substitute(raw.toString("utf8"), name) : void 0;
672
1910
  if (text !== void 0 && basename(source) === "package.json") {
673
- text = stampLunoraDeps(text, distTag);
1911
+ text = stampLunoraDeps(text, distTag, versions);
674
1912
  }
675
1913
  if (text === void 0) {
676
1914
  writeFileSync(destination, raw);
@@ -693,68 +1931,152 @@ const isSafeSource = (source) => {
693
1931
  }
694
1932
  return source.startsWith("gh:") || source.startsWith("github:") || source.startsWith("https://");
695
1933
  };
1934
+ const logWould = (logger, action) => {
1935
+ logger.info(`[dry-run] would ${action}`);
1936
+ };
696
1937
  const logScaffoldSuccess = (logger, written, target) => {
1938
+ if (isInteractive()) {
1939
+ process.stdout.write("\n");
1940
+ }
697
1941
  logger.success(`scaffolded ${String(written.length)} files into ${target}`);
698
1942
  };
699
- const runScriptCommand = (manager, script) => {
700
- if (manager === "npm") {
701
- return `npm run ${script}`;
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;
702
1986
  }
703
- if (manager === "bun") {
704
- return `bun run ${script}`;
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`.");
705
2001
  }
706
- return `${manager} ${script}`;
707
2002
  };
708
- const printNextSteps = (logger, name, installed) => {
709
- const manager = installed ?? "pnpm";
710
- logger.info("next steps:");
711
- logger.info(` cd ${name}`);
2003
+ const printNextSteps = async (name, installed, manager, insideMonorepo) => {
2004
+ const steps = [{ code: `cd ./${name}`, lead: "Enter your project directory using" }];
712
2005
  if (installed === void 0) {
713
- logger.info(` ${manager} install`);
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;
714
2019
  }
715
- logger.info(` ${runScriptCommand(manager, "dev")}`);
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"));
716
2023
  };
717
2024
  const offerInstallIsInteractive = (options) => options.yes !== true && (options.installPrompt !== void 0 || isInteractive());
718
2025
  const maybeOfferInstall = async (options, target) => {
719
2026
  if (!offerInstallIsInteractive(options)) {
720
2027
  return void 0;
721
2028
  }
2029
+ if (isInsideMonorepo(dirname$1(target))) {
2030
+ return void 0;
2031
+ }
722
2032
  const managers = detectInstalledManagers(options.packageManagerProbe);
723
2033
  const [defaultManager] = managers;
724
2034
  if (defaultManager === void 0) {
725
2035
  return void 0;
726
2036
  }
727
- const confirm = options.installPrompt?.confirmInstall ?? (async () => tuiConfirm("Install dependencies now?", { defaultYes: true }));
2037
+ const confirm = options.installPrompt?.confirmInstall ?? (async () => tuiConfirm(COPY.install, { badge: BADGES.deps, defaultYes: true }));
728
2038
  if (!await confirm()) {
2039
+ await tuiInfo("No problem! Remember to install dependencies after setup.");
729
2040
  return void 0;
730
2041
  }
731
2042
  let manager = defaultManager;
732
2043
  if (managers.length > 1) {
733
2044
  manager = options.installPrompt ? await options.installPrompt.selectManager(managers) : await tuiSelect(
734
- "Which package manager?",
2045
+ COPY.packageManager,
735
2046
  managers.map((candidate) => {
736
2047
  return { label: candidate, value: candidate };
737
2048
  }),
738
- { default: defaultManager }
2049
+ { badge: BADGES.deps, default: defaultManager }
739
2050
  ) ?? defaultManager;
740
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
+ }
741
2062
  const spawner = options.spawner ?? defaultSpawner;
742
2063
  const { args, command } = installArgsFor(manager);
743
- const result = await withTuiSpinner(`Installing dependencies with ${manager}…`, () => spawner({ args, command, cwd: target }));
2064
+ await emitStep("deps", `Installing dependencies with ${manager}…`);
2065
+ const result = await spawner({ args, command, cwd: target });
744
2066
  if (result.code !== 0) {
745
2067
  options.logger.warn(`\`${command} install\` exited with code ${String(result.code)} — run it yourself in ${basename(target)}/.`);
746
2068
  return void 0;
747
2069
  }
748
- options.logger.success(`installed dependencies with ${manager}`);
2070
+ await emitStep("deps", `Dependencies installed with ${manager}.`);
749
2071
  return manager;
750
2072
  };
751
- const scaffoldFromLocal = (fromRoot, templateType, target, name, logger) => {
2073
+ const scaffoldFromLocal = async (fromRoot, templateType, target, name, logger) => {
752
2074
  const templateDirectory = join$1(fromRoot, templateType);
753
2075
  if (!existsSync(templateDirectory)) {
754
2076
  logger.error(`template not found in local source: ${templateDirectory}`);
755
2077
  return { code: 1, files: [], target };
756
2078
  }
757
- const written = copyTemplate(templateDirectory, target, name);
2079
+ const written = await copyTemplate(templateDirectory, target, name);
758
2080
  logScaffoldSuccess(logger, written, target);
759
2081
  return { code: 0, files: written, target };
760
2082
  };
@@ -763,30 +2085,55 @@ const scaffoldFromRemote = async (options) => {
763
2085
  const stagingRoot = mkdtempSync(join$1(tmpdir(), "lunora-init-fetch-"));
764
2086
  const stagingDirectory = join$1(stagingRoot, "template");
765
2087
  try {
766
- const remote = resolveTemplateSource(templateType, source, ref);
767
- const downloaded = await withTuiSpinner(
768
- `Fetching the ${templateType} template…`,
769
- () => downloadTemplate(remote, {
770
- cwd: stagingRoot,
771
- dir: stagingDirectory,
772
- force: true,
773
- install: false,
774
- silent: true
775
- })
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…" }
776
2114
  );
777
2115
  const staged = collectFiles(stagingDirectory);
2116
+ if (isInteractive()) {
2117
+ process.stdout.write("\n");
2118
+ }
778
2119
  logger.info(
779
- downloaded.commit ? `template: ${downloaded.source} @ ${downloaded.commit} (${String(staged.length)} files)` : `template: ${downloaded.source} (${String(staged.length)} files)`
780
- );
781
- const written = await withTuiSpinner(
782
- `Scaffolding ${String(staged.length)} files into ${name}/…`,
783
- () => Promise.resolve(copyTemplate(stagingDirectory, target, name))
2120
+ downloaded?.commit ? `template: ${downloaded.source} @ ${downloaded.commit} (${String(staged.length)} files)` : `template: ${downloaded?.source ?? remote} (${String(staged.length)} files)`
784
2121
  );
785
2122
  logScaffoldSuccess(logger, written, target);
786
2123
  return { code: 0, files: written, target };
787
2124
  } catch (error) {
788
- const message = error instanceof Error ? error.message : String(error);
789
- logger.error(`failed to download template: ${message}`);
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
+ }
790
2137
  return { code: 1, files: [], target };
791
2138
  } finally {
792
2139
  rmSync(stagingRoot, { force: true, recursive: true });
@@ -805,30 +2152,44 @@ const scaffoldViteOverlay = async (options) => {
805
2152
  const adapter = ADAPTERS[framework];
806
2153
  const stagingRoot = mkdtempSync(join$1(tmpdir(), "lunora-vite-base-"));
807
2154
  try {
808
- if (overlayBaseFrom === void 0) {
809
- const stagingDirectory = join$1(stagingRoot, "base");
810
- const remote = `github:vitejs/vite/packages/create-vite/template-${adapter.createViteTemplate}#main`;
811
- await withTuiSpinner(
812
- `Fetching the ${adapter.label} (create-vite) base…`,
813
- () => downloadTemplate(remote, { cwd: stagingRoot, dir: stagingDirectory, force: true, install: false, silent: true })
814
- );
815
- renameCreateViteDotfiles(stagingDirectory);
816
- cpSync(stagingDirectory, target, { recursive: true });
817
- } else {
818
- const localBase = join$1(overlayBaseFrom, `template-${adapter.createViteTemplate}`);
2155
+ let localBase;
2156
+ if (overlayBaseFrom !== void 0) {
2157
+ localBase = join$1(overlayBaseFrom, `template-${adapter.createViteTemplate}`);
819
2158
  if (!existsSync(localBase)) {
820
2159
  logger.error(`create-vite base not found on disk: ${localBase}`);
821
2160
  return { code: 1, files: [], target };
822
2161
  }
823
- cpSync(localBase, target, { recursive: true });
824
2162
  }
825
- const written = await withTuiSpinner(
826
- `Applying the Lunora overlay (${adapter.label})…`,
827
- () => Promise.resolve(applyLunoraOverlay({ adapter, distTag: resolveDistTag(), logger, name, target }))
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…" }
828
2186
  );
829
2187
  logScaffoldSuccess(logger, written, target);
830
2188
  return { code: 0, files: [...collectFiles(target)], target };
831
2189
  } catch (error) {
2190
+ if (error instanceof PromptCancelledError) {
2191
+ throw error;
2192
+ }
832
2193
  const message = error instanceof Error ? error.message : String(error);
833
2194
  logger.error(`failed to scaffold the ${adapter.label} base: ${message}`);
834
2195
  return { code: 1, files: [], target };
@@ -896,12 +2257,12 @@ const scaffoldLunoraDirectory = (cwd, logger) => {
896
2257
  }
897
2258
  return written;
898
2259
  };
899
- const printFrameworkNextSteps = (detection, logger) => {
2260
+ const printFrameworkNextSteps = (detection, manager, logger) => {
900
2261
  const { adapter, class: frameworkClass, framework } = detection;
901
2262
  logger.info("");
902
2263
  logger.info(`detected framework: ${framework} (class ${frameworkClass})`);
903
2264
  logger.info("next steps:");
904
- 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"])}`);
905
2266
  logger.info(" 2. run codegen: lunora codegen");
906
2267
  if (frameworkClass === "A") {
907
2268
  logger.info(" 3. compose one worker: wrap your worker entry with");
@@ -947,51 +2308,77 @@ const runInPlaceInit = (cwd, logger) => {
947
2308
  return viteResult;
948
2309
  }
949
2310
  const scaffolded = scaffoldLunoraDirectory(cwd, logger);
950
- printFrameworkNextSteps(detection, logger);
2311
+ printFrameworkNextSteps(detection, detectPackageManager(cwd), logger);
951
2312
  return { code: 0, files: [...viteResult.files, ...scaffolded], target: cwd };
952
2313
  };
953
2314
  const offerIsInteractive = (options) => options.yes !== true && (options.prompt !== void 0 || (options.interactive ?? isInteractive()));
954
2315
  const maybeOfferExtras = async (options, projectDirectory) => {
955
2316
  const interactive = offerIsInteractive(options);
956
- const apply = async (names, applyOptions) => {
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 = [];
957
2329
  const applyLogger = isInteractive() ? {
958
2330
  error: (message) => {
959
- options.logger.error(message);
2331
+ buffered.push({ level: "error", message });
960
2332
  },
961
2333
  info: () => {
962
2334
  },
963
2335
  success: () => {
964
2336
  },
965
2337
  warn: (message) => {
966
- options.logger.warn(message);
2338
+ buffered.push({ level: "warn", message });
967
2339
  }
968
2340
  } : options.logger;
969
- const result = await withTuiSpinner(
970
- `adding ${names.join(", ")}…`,
971
- () => runAddCommand({
972
- allowUnsafeSource: options.allowUnsafeSource,
973
- cwd: projectDirectory,
974
- from: options.registryFrom,
975
- logger: applyLogger,
976
- names: [...names],
977
- ref: options.ref,
978
- source: options.registrySource,
979
- transformManifest: applyOptions?.transformManifest,
980
- yes: true
981
- })
982
- );
983
- return result.code === 0;
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
+ };
2356
+ });
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);
984
2363
  };
985
- await tuiIntro("let's finish setting up your app");
986
- await offerRegistryExtras({
987
- apply,
2364
+ const deps = {
2365
+ applyAll,
988
2366
  interactive,
989
2367
  logger: options.logger,
990
- multiSelect: options.prompt?.multiSelect ?? ((message, choices, settings) => tuiMultiSelect(message, choices, settings)),
2368
+ multiSelect: options.prompt?.multiSelect ?? ((message, choices, settings) => tuiMultiSelect(message, choices, { ...settings, badge: BADGES.add })),
2369
+ preselected: preselected.length > 0 ? preselected : void 0,
991
2370
  projectName: basename(projectDirectory),
992
- select: options.prompt?.select ?? ((message, choices, settings) => tuiSelect(message, choices, settings)),
993
- text: options.prompt?.text ?? ((message, settings) => tuiText(message, settings))
994
- });
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);
995
2382
  };
996
2383
  const DEFAULT_FRAMEWORK = "react";
997
2384
  const FRAMEWORK_CHOICES = [
@@ -999,6 +2386,7 @@ const FRAMEWORK_CHOICES = [
999
2386
  { description: "Vue SPA — create-vite base + Lunora", label: "Vue", value: "vue" },
1000
2387
  { description: "Solid SPA — create-vite base + Lunora", label: "Solid", value: "solid" },
1001
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" },
1002
2390
  { description: "TanStack Start (React) — SSR with live-loader routes", label: "TanStack Start · React", value: "tanstack-start-react" },
1003
2391
  { description: "TanStack Start (Solid)", label: "TanStack Start · Solid", value: "tanstack-start-solid" },
1004
2392
  { description: "React Router (v7, framework mode) — SSR composed into the Lunora worker", label: "React Router", value: "react-router" },
@@ -1006,6 +2394,7 @@ const FRAMEWORK_CHOICES = [
1006
2394
  { description: "AnalogJS (Angular) — single-worker, Lunora mounted in Nitro", label: "Analog", value: "analog" },
1007
2395
  { description: "Nuxt (Vue) — single-worker, Lunora mounted in Nitro", label: "Nuxt", value: "nuxt" },
1008
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" },
1009
2398
  { description: "Worker only — no frontend", label: "Standalone", value: "standalone" }
1010
2399
  ];
1011
2400
  const OVERLAY_VALUES = Object.keys(ADAPTERS).join("|");
@@ -1021,7 +2410,7 @@ const resolveScaffoldChoice = async (options) => {
1021
2410
  if (!isInteractive() || options.yes === true) {
1022
2411
  return { framework: DEFAULT_FRAMEWORK, kind: "overlay" };
1023
2412
  }
1024
- return toScaffoldChoice(await tuiSelect("Which framework would you like?", FRAMEWORK_CHOICES, { default: DEFAULT_FRAMEWORK }) ?? DEFAULT_FRAMEWORK);
2413
+ return toScaffoldChoice(await tuiSelect(COPY.framework, FRAMEWORK_CHOICES, { badge: BADGES.tmpl, default: DEFAULT_FRAMEWORK }) ?? DEFAULT_FRAMEWORK);
1025
2414
  };
1026
2415
  const nonInteractiveInitError = (options) => {
1027
2416
  if (isInteractive() || options.yes === true) {
@@ -1039,68 +2428,137 @@ const nonInteractiveInitError = (options) => {
1039
2428
  }
1040
2429
  return `lunora init can't prompt in a non-interactive terminal — provide ${missing.join(" and ")}, or pass --yes to accept the defaults.`;
1041
2430
  };
1042
- const scaffoldNewProject = async (options, cwd) => {
1043
- await tuiBanner("realtime backend on Cloudflare Workers + Durable Objects");
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");
1044
2459
  const blocked = nonInteractiveInitError(options);
1045
2460
  if (blocked !== void 0) {
1046
2461
  options.logger.error(blocked);
1047
2462
  return { code: 1, files: [], target: "" };
1048
2463
  }
1049
- const name = options.name ?? await tuiText("What should we call your project?", { default: "lunora-app", placeholder: "lunora-app" });
2464
+ const suggestedName = generateProjectName();
2465
+ const rawName = options.name ?? await tuiText(COPY.name, { badge: BADGES.dir, default: suggestedName, placeholder: suggestedName });
1050
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\`).`);
2470
+ return { code: 1, files: [], target: "" };
2471
+ }
1051
2472
  if (name.includes("/") || name.includes("\\") || name === ".." || name === ".") {
1052
2473
  options.logger.error(`init: refusing project name "${name}" — must not contain path separators or be "." / "..".`);
1053
2474
  return { code: 1, files: [], target: "" };
1054
2475
  }
1055
2476
  const target = resolve(cwd, name);
1056
- if (existsSync(target)) {
2477
+ const targetPreExisted = existsSync(target);
2478
+ if (targetPreExisted) {
1057
2479
  const entries = readdirSync(target);
1058
2480
  if (entries.length > 0) {
1059
2481
  options.logger.error(`target directory not empty: ${target}`);
1060
2482
  return { code: 1, files: [], target };
1061
2483
  }
1062
2484
  }
1063
- if (choice.kind === "overlay") {
1064
- if (!isOverlayFramework(choice.framework)) {
1065
- options.logger.error(`init: unknown framework "${choice.framework}". Supported overlays: ${Object.keys(ADAPTERS).join(", ")}.`);
1066
- return { code: 1, files: [], target };
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 };
2489
+ }
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 });
1067
2501
  }
1068
- mkdirSync(target, { recursive: true });
1069
- return scaffoldViteOverlay({ framework: choice.framework, logger: options.logger, name, overlayBaseFrom: options.overlayBaseFrom, target });
2502
+ } else {
2503
+ rmSync(target, { force: true, recursive: true });
1070
2504
  }
1071
- const { templateType } = choice;
1072
- if (templateType === "next") {
1073
- options.logger.warn('template "next" is not yet available re-run with `--vite react` or `-t standalone`.');
1074
- return { code: 1, files: [], target };
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);
1075
2510
  }
1076
- if (options.from !== void 0) {
1077
- return scaffoldFromLocal(options.from, templateType, target, name, options.logger);
2511
+ if (options.dryRun === true) {
2512
+ logWould(options.logger, `configure Lunora into ${cwd}`);
2513
+ return { code: 0, files: [], target: cwd };
1078
2514
  }
1079
- if (options.source !== void 0 && options.source.length > 0 && !options.allowUnsafeSource && !isSafeSource(options.source)) {
1080
- options.logger.error(
1081
- `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.`
1082
- );
1083
- return { code: 1, files: [], target };
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);
1084
2525
  }
1085
- return scaffoldFromRemote({ logger: options.logger, name, ref: options.ref, source: options.source, target, templateType });
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;
2534
+ }
2535
+ scaffoldCiWorkflow(options.inPlace === true ? cwd : result.target, options.ci, options.logger);
1086
2536
  };
1087
2537
  const runInitCommand = async (options) => {
1088
2538
  const cwd = options.cwd ?? process.cwd();
1089
- const result = options.inPlace === true ? runInPlaceInit(cwd, options.logger) : await scaffoldNewProject(options, cwd);
1090
- if (result.code === 0 && result.target !== "") {
1091
- await maybeOfferExtras(options, result.target);
1092
- const installedManager = options.inPlace === true ? void 0 : await maybeOfferInstall(options, result.target);
1093
- if (options.inPlace !== true) {
1094
- await tuiOutro("you're all set 🎉");
1095
- printNextSteps(options.logger, basename(result.target), installedManager);
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);
1096
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;
1097
2557
  }
1098
- if (result.code === 0 && options.ci !== void 0) {
1099
- scaffoldCiWorkflow(options.inPlace === true ? cwd : result.target, options.ci, options.logger);
1100
- }
2558
+ scaffoldCiPipeline(options, result, cwd);
1101
2559
  return result;
1102
2560
  };
1103
- const isTemplate = (value) => value === "analog" || value === "astro" || value === "next" || value === "nuxt" || value === "react-router" || value === "standalone" || value === "sveltekit" || value === "tanstack-start-react" || value === "tanstack-start-solid";
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";
1104
2562
  const resolveCiProvider = (raw, logger) => {
1105
2563
  if (raw === void 0) {
1106
2564
  return void 0;
@@ -1114,9 +2572,11 @@ const resolveCiProvider = (raw, logger) => {
1114
2572
  const execute = defineHandler(({ argument, cwd, logger, options }) => {
1115
2573
  const templateType = options.template !== void 0 && isTemplate(options.template) ? options.template : void 0;
1116
2574
  return runInitCommand({
2575
+ add: options.add,
1117
2576
  allowUnsafeSource: options.allowUnsafeSource === true,
1118
2577
  cwd,
1119
2578
  ci: resolveCiProvider(options.ci, logger),
2579
+ dryRun: options.dryRun === true,
1120
2580
  from: options.from,
1121
2581
  inPlace: options.here === true,
1122
2582
  interactive: options.interactive === true ? true : void 0,