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

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 (118) hide show
  1. package/LICENSE.md +33 -0
  2. package/README.md +1 -1
  3. package/__assets__/package-og.svg +1 -1
  4. package/dist/bin.mjs +2 -10
  5. package/dist/index.d.mts +1087 -368
  6. package/dist/index.d.ts +1087 -368
  7. package/dist/index.mjs +1 -19
  8. package/dist/packem_chunks/dispatch.mjs +1 -0
  9. package/dist/packem_chunks/handler.mjs +1 -78
  10. package/dist/packem_chunks/handler10.mjs +1 -22
  11. package/dist/packem_chunks/handler11.mjs +2 -192
  12. package/dist/packem_chunks/handler12.mjs +1 -131
  13. package/dist/packem_chunks/handler13.mjs +1 -65
  14. package/dist/packem_chunks/handler14.mjs +1 -58
  15. package/dist/packem_chunks/handler15.mjs +1 -79
  16. package/dist/packem_chunks/handler16.mjs +3 -43
  17. package/dist/packem_chunks/handler17.mjs +1 -105
  18. package/dist/packem_chunks/handler18.mjs +1 -172
  19. package/dist/packem_chunks/handler19.mjs +7 -89
  20. package/dist/packem_chunks/handler2.mjs +1 -114
  21. package/dist/packem_chunks/handler20.mjs +1 -94
  22. package/dist/packem_chunks/handler21.mjs +3 -311
  23. package/dist/packem_chunks/handler22.mjs +3 -0
  24. package/dist/packem_chunks/handler23.mjs +1 -0
  25. package/dist/packem_chunks/handler24.mjs +2 -0
  26. package/dist/packem_chunks/handler25.mjs +99 -0
  27. package/dist/packem_chunks/handler26.mjs +10 -0
  28. package/dist/packem_chunks/handler3.mjs +1 -204
  29. package/dist/packem_chunks/handler4.mjs +1 -33
  30. package/dist/packem_chunks/handler5.mjs +1 -49
  31. package/dist/packem_chunks/handler6.mjs +1 -91
  32. package/dist/packem_chunks/handler7.mjs +3 -42
  33. package/dist/packem_chunks/handler8.mjs +1 -174
  34. package/dist/packem_chunks/handler9.mjs +1 -16
  35. package/dist/packem_chunks/planDevCommand.mjs +7 -543
  36. package/dist/packem_chunks/runCodegenCommand.mjs +4 -52
  37. package/dist/packem_chunks/runDeployCommand.mjs +7 -504
  38. package/dist/packem_chunks/runInitCommand.mjs +1179 -544
  39. package/dist/packem_chunks/runResetCommand.mjs +1 -41
  40. package/dist/packem_chunks/runRpcCommand.mjs +1 -68
  41. package/dist/packem_shared/COMMANDS-DdaAWPtr.mjs +1 -0
  42. package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-BgMPHEoe.mjs +1 -0
  43. package/dist/packem_shared/EXIT_CODE-08cwt3MK.mjs +1 -0
  44. package/dist/packem_shared/admin-token-VdUnvnKW.mjs +1 -0
  45. package/dist/packem_shared/admin-url-BhF5ufg1.mjs +1 -0
  46. package/dist/packem_shared/binding-manifest-file-CQ1eQYy1.mjs +2 -0
  47. package/dist/packem_shared/buildRegistryIndex-DVmy8fHE.mjs +1 -0
  48. package/dist/packem_shared/catalog-Cbzph90w.mjs +1 -0
  49. package/dist/packem_shared/cli-DOpChqUe.mjs +2 -0
  50. package/dist/packem_shared/codegen-error-AmH54ofi.mjs +3 -0
  51. package/dist/packem_shared/command-Mmxzxyr5.mjs +1 -0
  52. package/dist/packem_shared/commands-CdVObzRk.mjs +13 -0
  53. package/dist/packem_shared/createLogger-Cl18I8AX.mjs +2 -0
  54. package/dist/packem_shared/createRecordingSpawner-sS7LEN7x.mjs +1 -0
  55. package/dist/packem_shared/deploy-target-DCWwiuAe.mjs +1 -0
  56. package/dist/packem_shared/diffSnapshots-DtC5Cs4Z.mjs +5 -0
  57. package/dist/packem_shared/docker-DpVxvYpL.mjs +1 -0
  58. package/dist/packem_shared/import-D7qdpSmJ.mjs +12 -0
  59. package/dist/packem_shared/insertSchemaExtension-DuiV6cba.mjs +8 -0
  60. package/dist/packem_shared/lint-ignore-report-DKZagpqk.mjs +2 -0
  61. package/dist/packem_shared/open-url-EnKy--w-.mjs +1 -0
  62. package/dist/packem_shared/parseManifest-CwPTKdtS.mjs +1 -0
  63. package/dist/packem_shared/path-containment-CgxYZggb.mjs +1 -0
  64. package/dist/packem_shared/platform-diagnostics-Cn2g6Jh-.mjs +4 -0
  65. package/dist/packem_shared/prompt-cancelled-BvsNxg_Q.mjs +1 -0
  66. package/dist/packem_shared/render-lunora-error--4tmM6mt.mjs +3 -0
  67. package/dist/packem_shared/resolve-DUCSc7jQ.mjs +5 -0
  68. package/dist/packem_shared/resolve-target-C_ZloTvd.mjs +1 -0
  69. package/dist/packem_shared/runAddCommand-1tGOc-uo.mjs +1 -0
  70. package/dist/packem_shared/runExportCommand-DxsJHYZt.mjs +5 -0
  71. package/dist/packem_shared/runMigrateGenerateCommand-BfBHaTLi.mjs +11 -0
  72. package/dist/packem_shared/schema-drift-gate-BDCkQ1S6.mjs +1 -0
  73. package/dist/packem_shared/schemaIrToSnapshot-irmd5g0Y.mjs +1 -0
  74. package/dist/packem_shared/shared-D-zCOmgY.mjs +1 -0
  75. package/dist/packem_shared/storage-2MQBGhKZ.mjs +1 -0
  76. package/dist/packem_shared/tui-prompts-B3YwUhGw.mjs +4 -0
  77. package/dist/packem_shared/vectorize-metadata-dXpl2_Ar.mjs +1 -0
  78. package/dist/packem_shared/wrangler-name-Dsk5K1f-.mjs +1 -0
  79. package/dist/packem_shared/wrangler-secrets-C9lJnd5N.mjs +1 -0
  80. package/package.json +42 -19
  81. package/skills/README.md +35 -17
  82. package/skills/lunora/SKILL.md +123 -9
  83. package/skills/lunora-create-package/SKILL.md +4 -3
  84. package/skills/lunora-deploy/SKILL.md +42 -11
  85. package/skills/lunora-functions/SKILL.md +120 -15
  86. package/skills/lunora-migration-helper/SKILL.md +74 -21
  87. package/skills/lunora-performance-audit/SKILL.md +78 -9
  88. package/skills/lunora-quickstart/SKILL.md +93 -27
  89. package/skills/lunora-realtime/SKILL.md +73 -39
  90. package/skills/lunora-setup-auth/SKILL.md +33 -6
  91. package/skills/lunora-setup-hyperdrive/SKILL.md +33 -13
  92. package/skills/lunora-setup-hyperdrive-global/SKILL.md +5 -0
  93. package/skills/lunora-setup-mail/SKILL.md +34 -28
  94. package/skills/lunora-setup-scheduler/SKILL.md +18 -14
  95. package/skills/lunora-setup-storage/SKILL.md +189 -28
  96. package/dist/packem_chunks/runMigrateGenerateCommand.mjs +0 -397
  97. package/dist/packem_shared/COMMANDS-CHw4zOZ9.mjs +0 -922
  98. package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-Ck-2bU08.mjs +0 -244
  99. package/dist/packem_shared/admin-url-4UzT-CI4.mjs +0 -19
  100. package/dist/packem_shared/api-spec-CtA6ilu4.mjs +0 -13
  101. package/dist/packem_shared/buildRegistryIndex-BcYe607_.mjs +0 -38
  102. package/dist/packem_shared/command-BDXcJCCJ.mjs +0 -14
  103. package/dist/packem_shared/commands-DIQ3nf0C.mjs +0 -743
  104. package/dist/packem_shared/createLogger-CHPNjFw2.mjs +0 -73
  105. package/dist/packem_shared/defaultSpawner-DxI3mebw.mjs +0 -43
  106. package/dist/packem_shared/diffSnapshots-RR2ZE8Ya.mjs +0 -161
  107. package/dist/packem_shared/docker-hMQ97KSQ.mjs +0 -21
  108. package/dist/packem_shared/features-ocSSpZtS.mjs +0 -24
  109. package/dist/packem_shared/insertSchemaExtension-BuzF6-t2.mjs +0 -59
  110. package/dist/packem_shared/open-url-Dfq6fAyT.mjs +0 -41
  111. package/dist/packem_shared/output-format-7gyGR3h8.mjs +0 -17
  112. package/dist/packem_shared/parseArgs-YXFuKdEk.mjs +0 -56
  113. package/dist/packem_shared/parseManifest--vZf2FY1.mjs +0 -94
  114. package/dist/packem_shared/resolve-target-qbsJ_5sF.mjs +0 -16
  115. package/dist/packem_shared/runAddCommand-3I3JFZUG.mjs +0 -4
  116. package/dist/packem_shared/schema-drift-gate-BtBt0as0.mjs +0 -79
  117. package/dist/packem_shared/schemaIrToSnapshot-aBTo7TM5.mjs +0 -43
  118. package/dist/packem_shared/wrangler-name-cy4yhm9j.mjs +0 -12
@@ -1,17 +1,13 @@
1
- import { existsSync, mkdirSync, writeFileSync, readdirSync, mkdtempSync, rmSync, readFileSync } from 'node:fs';
2
- import { tmpdir } from 'node:os';
3
- import { detectFramework as detectFramework$1, isInteractive, promptSelect, promptMultiSelect } from '@lunora/config';
4
- import { walkSync } from '@visulima/fs';
5
- import { resolve, join as join$1, relative, dirname as dirname$1 } from '@visulima/path';
6
- import { downloadTemplate } from 'giget';
7
- import { join, dirname } from 'node:path';
8
- import { d as defineHandler } from '../packem_shared/command-BDXcJCCJ.mjs';
9
- import MagicString from 'magic-string';
10
- import { Project, SyntaxKind } from 'ts-morph';
11
- import { c as resolveSourceRef, r as runAddCommand } from '../packem_shared/commands-DIQ3nf0C.mjs';
12
- import { p as promptAuthProvider, E as EMAIL_ITEM } from '../packem_shared/features-ocSSpZtS.mjs';
13
-
14
- const GITHUB_CONTENT = `name: Deploy
1
+ import{existsSync as m,mkdirSync as M,writeFileSync as w,readFileSync as k,readdirSync as ce,rmSync as O,lstatSync as de,mkdtempSync as ue,copyFileSync as Ge,renameSync as Ye}from"node:fs";import{tmpdir as pe}from"node:os";import{installArgsFor as he,execArgsFor as Je,detectFramework as Xe,isInteractive as y,LUNA_ART as Qe,LUNA_NAME as Ze,LUNA_SIGNOFF as et,BADGES as v,paintAnswer as tt,detectPackageManager as P,detectInstalledManagers as rt,runScriptCommand as at,detectLintTools as ot,addArgsFor as nt,applyLintIgnores as st}from"@lunora/config";import{walkSync as it}from"@visulima/fs";import{join as p,dirname as A,basename as _,resolve as me,relative as fe}from"@visulima/path";import{downloadTemplate as ge}from"giget";import{modify as lt,applyEdits as ct}from"jsonc-parser";import{join as K,dirname as dt}from"node:path";import{d as ut}from"../packem_shared/command-Mmxzxyr5.mjs";import{EXIT_CODE as f}from"../packem_shared/EXIT_CODE-08cwt3MK.mjs";import pt from"magic-string";import{Project as ht,SyntaxKind as g}from"ts-morph";import{P as q}from"../packem_shared/prompt-cancelled-BvsNxg_Q.mjs";import{m as ve,n as mt,o as we,q as ye,b as ft}from"../packem_shared/resolve-DUCSc7jQ.mjs";import{defaultSpawner as be}from"../packem_shared/createRecordingSpawner-sS7LEN7x.mjs";import{d as gt,e as vt,f as wt,a as xe,t as G,g as ke,h as yt,b as Ce,i as Se,w as bt,j as xt,k as Le,l as kt}from"../packem_shared/tui-prompts-B3YwUhGw.mjs";import{A as Me,E as Ae,p as Ct,w as St,M as Lt,r as Mt,k as At,e as Et,c as Ee,l as Ne,i as Nt,f as _t}from"../packem_shared/storage-2MQBGhKZ.mjs";import{r as It}from"../packem_shared/commands-CdVObzRk.mjs";import{logStep as Q}from"../packem_shared/createLogger-Cl18I8AX.mjs";import{r as $t}from"../packem_shared/lint-ignore-report-DKZagpqk.mjs";import Rt from"node:dns/promises";const Y={bun:{githubCacheKey:void 0,githubSetupStep:` - uses: oven-sh/setup-bun@v2
2
+ `,gitlabImage:"oven/bun:1",gitlabProvisionScript:[],installCmd:"bun install --frozen-lockfile",lockfile:"bun.lockb"},npm:{githubCacheKey:"npm",githubSetupStep:"",gitlabImage:"node:22",gitlabProvisionScript:[],installCmd:"npm ci",lockfile:"package-lock.json"},pnpm:{githubCacheKey:"pnpm",githubSetupStep:` - uses: pnpm/action-setup@v4
3
+ with:
4
+ version: latest
5
+ `,gitlabImage:"node:22",gitlabProvisionScript:["corepack enable"],installCmd:"pnpm install --frozen-lockfile",lockfile:"pnpm-lock.yaml"},yarn:{githubCacheKey:"yarn",githubSetupStep:"",gitlabImage:"node:22",gitlabProvisionScript:["corepack enable"],installCmd:"yarn install --frozen-lockfile",lockfile:"yarn.lock"}},L=(e,t)=>{const r=Je(e,"lunora",t);return[r.command,...r.args].join(" ")},Z=e=>` - uses: actions/checkout@v4
6
+ ${e.githubSetupStep} - uses: actions/setup-node@v4
7
+ with:
8
+ node-version: 22
9
+ ${e.githubCacheKey===void 0?"":` cache: ${e.githubCacheKey}
10
+ `} - run: ${e.installCmd}`,Ot=e=>{const t=Y[e],r=t.githubCacheKey===void 0?`# (below) requires it — run \`${e} install\` locally and`:`# (below) and the ${e} cache both require it — run \`${e} install\` locally and`;return`name: Deploy
15
11
 
16
12
  on:
17
13
  push:
@@ -19,6 +15,10 @@ on:
19
15
  pull_request:
20
16
  workflow_dispatch:
21
17
 
18
+ # Prerequisite: commit your ${t.lockfile}. \`${t.installCmd}\`
19
+ ${r}
20
+ # commit the lockfile before pushing, or the first CI run fails.
21
+ #
22
22
  # Set these repository secrets (Settings → Secrets and variables → Actions):
23
23
  # CLOUDFLARE_API_TOKEN — a Workers-scoped API token
24
24
  # CLOUDFLARE_ACCOUNT_ID — your Cloudflare account id
@@ -34,16 +34,10 @@ jobs:
34
34
  permissions:
35
35
  contents: read
36
36
  steps:
37
- - uses: actions/checkout@v4
38
- - uses: pnpm/action-setup@v4
39
- - uses: actions/setup-node@v4
40
- with:
41
- node-version: 22
42
- cache: pnpm
43
- - run: pnpm install --frozen-lockfile
37
+ ${Z(t)}
44
38
  # Codegen + wrangler validation gate (no deploy) — fails fast on drift.
45
- - run: pnpm exec lunora prepare
46
- - run: pnpm exec lunora deploy
39
+ - run: ${L(e,["prepare"])}
40
+ - run: ${L(e,["deploy"])}
47
41
 
48
42
  # Preview version on every pull request — uploads a versioned preview URL;
49
43
  # production traffic is untouched.
@@ -53,27 +47,24 @@ jobs:
53
47
  permissions:
54
48
  contents: read
55
49
  steps:
56
- - uses: actions/checkout@v4
57
- - uses: pnpm/action-setup@v4
58
- - uses: actions/setup-node@v4
59
- with:
60
- node-version: 22
61
- cache: pnpm
62
- - run: pnpm install --frozen-lockfile
63
- - run: pnpm exec lunora deploy --preview
64
- `;
65
- const GITLAB_CONTENT = `stages:
50
+ ${Z(t)}
51
+ - run: ${L(e,["deploy","--preview"])}
52
+ `},Tt=e=>{const t=Y[e],r=[...t.gitlabProvisionScript,t.installCmd].map(a=>` - ${a}`).join(`
53
+ `);return`stages:
66
54
  - deploy
67
55
 
56
+ # Prerequisite: commit your ${t.lockfile}. \`${t.installCmd}\`
57
+ # (below) requires it — run \`${e} install\` locally and commit the lockfile
58
+ # before pushing, or the first pipeline fails.
59
+ #
68
60
  # Set these as masked CI/CD variables (Settings → CI/CD → Variables):
69
61
  # CLOUDFLARE_API_TOKEN — a Workers-scoped API token
70
62
  # CLOUDFLARE_ACCOUNT_ID — your Cloudflare account id
71
63
  .lunora_base:
72
- image: node:22
64
+ image: ${t.gitlabImage}
73
65
  stage: deploy
74
66
  before_script:
75
- - corepack enable
76
- - pnpm install --frozen-lockfile
67
+ ${r}
77
68
 
78
69
  # Production deploy on the default branch.
79
70
  deploy:
@@ -82,8 +73,8 @@ deploy:
82
73
  - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
83
74
  script:
84
75
  # Codegen + wrangler validation gate (no deploy) — fails fast on drift.
85
- - pnpm exec lunora prepare
86
- - pnpm exec lunora deploy
76
+ - ${L(e,["prepare"])}
77
+ - ${L(e,["deploy"])}
87
78
 
88
79
  # Preview version on every merge request (versioned preview URL; production
89
80
  # traffic is untouched).
@@ -92,537 +83,1181 @@ preview:
92
83
  rules:
93
84
  - if: $CI_PIPELINE_SOURCE == "merge_request_event"
94
85
  script:
95
- - pnpm exec lunora deploy --preview
96
- `;
97
- const WORKFLOWS = {
98
- github: {
99
- content: GITHUB_CONTENT,
100
- file: join(".github", "workflows", "deploy.yml"),
101
- secretsHint: "repository secrets (Settings → Secrets and variables → Actions)"
102
- },
103
- gitlab: {
104
- content: GITLAB_CONTENT,
105
- file: ".gitlab-ci.yml",
106
- secretsHint: "masked CI/CD variables (Settings → CI/CD → Variables)"
107
- }
108
- };
109
- const isCiProvider = (value) => value === "github" || value === "gitlab";
110
- const writeCiWorkflow = (projectRoot, provider, options = {}) => {
111
- const spec = WORKFLOWS[provider];
112
- const path = join(projectRoot, spec.file);
113
- if (existsSync(path) && options.overwrite !== true) {
114
- return { path, skipped: true, written: false };
115
- }
116
- mkdirSync(dirname(path), { recursive: true });
117
- writeFileSync(path, spec.content, "utf8");
118
- return { path, skipped: false, written: true };
119
- };
120
- const scaffoldCiWorkflow = (projectRoot, provider, logger, options = {}) => {
121
- const spec = WORKFLOWS[provider];
122
- try {
123
- const result = writeCiWorkflow(projectRoot, provider, options);
124
- if (result.skipped) {
125
- logger.info(`--ci ${provider}: ${spec.file} already exists — left unchanged (re-run with overwrite to replace).`);
126
- } else {
127
- logger.success(`--ci ${provider}: wrote ${spec.file}`);
128
- logger.info(`--ci ${provider}: set CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID as ${spec.secretsHint} to enable deploys.`);
129
- }
130
- return result;
131
- } catch (error) {
132
- const message = error instanceof Error ? error.message : String(error);
133
- logger.warn(`--ci ${provider}: could not write ${spec.file} (${message})`);
134
- return { path: join(projectRoot, spec.file), skipped: false, written: false };
135
- }
136
- };
86
+ - ${L(e,["deploy","--preview"])}
87
+ `},_e={github:{file:K(".github","workflows","deploy.yml"),secretsHint:"repository secrets (Settings → Secrets and variables → Actions)"},gitlab:{file:".gitlab-ci.yml",secretsHint:"masked CI/CD variables (Settings → CI/CD → Variables)"}},Pt=(e,t)=>e==="github"?Ot(t):Tt(t),Dt=e=>e==="github"||e==="gitlab",Bt=(e,t,r,a={})=>{const o=K(e,_e[t].file);return m(o)&&a.overwrite!==!0?{path:o,skipped:!0,written:!1}:(M(dt(o),{recursive:!0}),w(o,Pt(t,r),"utf8"),{path:o,skipped:!1,written:!0})},jt=(e,t,r,a,o={})=>{const n=_e[t];try{const s=Bt(e,t,r,o);if(s.skipped)a.info(`--ci ${t}: ${n.file} already exists — left unchanged (re-run with overwrite to replace).`);else{const i=he(r),l=[i.command,...i.args].join(" "),{installCmd:c,lockfile:u}=Y[r];a.success(`--ci ${t}: wrote ${n.file}`),a.info(`--ci ${t}: set CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID as ${n.secretsHint} to enable deploys.`),a.info(`--ci ${t}: run \`${l}\` and commit ${u} before pushing — the pipeline runs \`${c}\`.`)}return s}catch(s){const i=s instanceof Error?s.message:String(s);return a.warn(`--ci ${t}: could not write ${n.file} (${i})`),{path:K(e,n.file),skipped:!1,written:!1}}},Ut={astro:"@lunora/react",none:"@lunora/react",nuxt:"@lunora/vue","react-router":"@lunora/react","solid-start":"@lunora/solid",sveltekit:"@lunora/svelte","tanstack-start":"@lunora/react","tanstack-start-solid":"@lunora/solid",vinext:"@lunora/react"},Vt=e=>{const t=Xe(e);return{...t,adapter:Ut[t.framework]}},R="lunora()",ee='import { lunora } from "@lunora/vite";',Ft="@lunora/vite",Wt="lunora",Ht=e=>{for(const t of e.getStatements()){if(t.getKind()!==g.ExportAssignment)continue;const r=t.asKindOrThrow(g.ExportAssignment).getExpression();if(r.getKind()!==g.CallExpression)continue;const a=r.asKindOrThrow(g.CallExpression);if(a.getExpression().getText()!=="defineConfig")continue;const o=a.getArguments()[0];if(o?.getKind()===g.ObjectLiteralExpression)return o.asKindOrThrow(g.ObjectLiteralExpression)}},zt=e=>{for(const t of e.getStatements()){if(t.getKind()!==g.ExportAssignment)continue;const r=t.asKindOrThrow(g.ExportAssignment).getExpression();if(r.getKind()===g.ObjectLiteralExpression)return r.asKindOrThrow(g.ObjectLiteralExpression)}},Kt=e=>e.getDescendantsOfKind(g.CallExpression).some(t=>t.getExpression().getText()===Wt),qt=e=>e.getImportDeclarations().some(t=>t.getModuleSpecifierValue()===Ft),Gt=e=>new ht({compilerOptions:{allowJs:!0},useInMemoryFileSystem:!0}).createSourceFile("vite.config.ts",e,{overwrite:!0}),Yt=(e,t)=>{const r=t.getImportDeclarations().at(-1)?.getEnd()??0;r===0?e.prepend(`${ee}
88
+ `):e.appendLeft(r,`
89
+ ${ee}`)},Jt=(e,t)=>{const r=t.getProperty("plugins");if(r===void 0){const s=t.getProperties(),i=t.getStart()+1;if(s.length===0){e.appendLeft(i,` plugins: [${R}] `);return}const l=s[0];if(l===void 0)return"could not locate the start of the Vite config object's first property";e.appendLeft(l.getStart(),`plugins: [${R}],
90
+ `);return}const a=r.getDescendantsOfKind(g.ArrayLiteralExpression)[0];if(a===void 0)return"the Vite config's `plugins` is not an array literal — add `lunora()` to it by hand";const o=a.getElements();if(o.length===0){e.appendLeft(a.getStart()+1,R);return}const n=o[0];if(n===void 0)return"could not locate the first entry of the Vite config's `plugins` array";e.appendLeft(n.getStart(),`${R}, `)},Ie=e=>{const t=Gt(e);if(Kt(t))return{changed:!1,code:e,reason:"lunora plugin already present"};const r=Ht(t)??zt(t);if(r===void 0)return{changed:!1,code:e,reason:"could not locate a Vite config plugins array to patch"};const a=new pt(e);qt(t)||Yt(a,t);const o=Jt(a,r);return o!==void 0?{changed:!1,code:e,reason:o}:{changed:!0,code:a.toString()}},Xt=/enotfound|eai_again|econnrefused|etimedout|network|fetch failed|getaddrinfo/u,Qt=/404|not found|could not find|no such/u,Zt=(e,t)=>{const r=e instanceof Error?e.message:String(e),a=r.toLowerCase(),o=`failed to download template "${t.templateType}" from ${t.remote}: ${r}`;return Qt.test(a)?{hints:[`Check the template name "${t.templateType}" and the ref "${t.ref}".`,"List/inspect available templates, or target a branch/tag with `--ref <branch>`."],message:`template "${t.templateType}" not found at ${t.remote}: ${r}`}:Xt.test(a)?{hints:["You appear to be offline or unable to reach GitHub.","To scaffold without a network, point at a local template root: `lunora init --from <dir>`."],message:o}:{hints:["If this is a network/offline issue, scaffold from a local root with `lunora init --from <dir>`."],message:o}},T=async(e,t,r)=>{if(y()){await vt(v[e],t,r);return}if(process.stdout.write(`
91
+ `),r===void 0||r===""){Q(e,t);return}const a=r.split(`
92
+ `).map(o=>tt(o)).join(`
93
+ `);Q(e,`${t}
94
+ ${a}`)},er=async e=>{if(y()){await gt();return}e.info(`
95
+ ${Qe}
96
+ ${Ze}: ${et}`)},$e=[{description:"LLMs via Workers AI (summarize, generate, stream)",label:"AI",value:"ai"},{description:"Sign-up / sign-in (asks which provider)",label:"Authentication",value:"auth"},{description:"Copy-in auth screens for your framework (sign in/up, reset, 2FA)",label:"Auth UI",value:"auth-ui"},{description:"Snapshot + restore your Durable Object data",label:"Backups",value:"backup"},{description:"Headless browser screenshots + PDFs",label:"Browser rendering",value:"browser"},{description:"Zero Trust identity via Cloudflare Access",label:"Cloudflare Access",value:"cloudflare-access"},{description:"Scheduled jobs via Cron Triggers (@lunora/scheduler)",label:"Cron jobs",value:"crons"},{description:"Cloudflare Email Workers + a dev mail catcher",label:"Transactional email",value:"email"},{description:"OpenFeature feature flags (ctx.flags)",label:"Feature flags",value:"flags"},{description:"External Postgres/MySQL via Hyperdrive",label:"Hyperdrive",value:"hyperdrive"},{description:"Stripe-first payments (checkout, subscription, webhooks)",label:"Payments",value:"payment"},{description:"Live presence / who's-online over hibernated WebSockets",label:"Presence",value:"presence"},{description:"Async message queues (push/pull consumers)",label:"Queues",value:"queue"},{description:"Typed R2 buckets + signed URLs (@lunora/storage)",label:"File storage",value:"storage"},{description:"Durable long-running workflows (step.do, sleep, branch)",label:"Workflows",value:"workflow"}],te=$e.map(e=>e.value),tr=e=>e==="email"?Ae:e,rr=(e,t)=>{const r=[];for(const a of e.split(",").map(o=>o.trim()).filter(Boolean))te.includes(a)?r.includes(a)||r.push(a):t(`init: unknown --add feature "${a}" — expected ${te.join(" | ")}; skipping.`);return r},Re=e=>e.resolveAuthUiItem===void 0?"auth-ui-react":e.resolveAuthUiItem(),ar=async e=>{const t=await Et(e.select),r=await Ee(e.text,e.projectName);return{label:"auth",names:[t],transformManifest:a=>Ne(a,r)}},or=async e=>{const t=await e.text(Lt,{placeholder:"you@yourdomain.com"}),r=Mt(t,a=>{e.logger.warn(a)});return{label:"email",names:[Ae],transformManifest:r===void 0?void 0:a=>At(a,r)}},nr=async(e,t)=>{const r=Re(e);if(r===void 0){e.logger.error(`init: ${Me}`);return}if(t)return{label:"auth-ui",names:[r]};const a=await Ee(e.text,e.projectName);return{label:"auth-ui",names:[r],transformManifest:o=>Ne(o,a)}},sr=async e=>{const t=await Ct(e.text,e.projectName);return{label:"storage",names:["storage"],transformManifest:r=>St(r,t)}},ir=(e,t)=>{const r=[];let a=!1;for(const o of t){if(o!=="auth-ui"){r.push({label:o,names:[tr(o)]});continue}const n=Re(e);if(n===void 0){e.logger.error(`init: ${Me}`),a=!0;continue}r.push({label:o,names:[n]})}return{plans:r,refused:a}},lr={auth:ar,"auth-ui":async(e,t)=>nr(e,t.includes("auth")),email:or,storage:sr},re=async e=>{if(e.preselected!==void 0&&e.preselected.length>0){const{plans:a,refused:o}=ir(e,e.preselected);return await e.applyAll(a)&&!o}if(!e.interactive)return e.logger.info("tip: add features later with `lunora add <ai|auth|backup|browser|cloudflare-access|crons|email|flags|hyperdrive|payment|presence|queue|storage|workflow>`."),!0;const t=await e.multiSelect("Which features do you want to add?",$e,{defaults:[]});if(t.length===0)return!0;const r=[];for(const a of t){const o=lr[a],n=o?await o(e,t):{label:a,names:[a]};n!==void 0&&r.push(n)}return await e.applyAll(r),!0},cr=[{description:"Adds an ignores entry to eslint.config.js",label:"ESLint",value:"eslint"},{description:"Writes .prettierignore",label:"Prettier",value:"prettier"},{description:"Adds negated patterns to biome.json",label:"Biome",value:"biome"},{description:"Writes ignorePatterns to .oxlintrc.json",label:"oxlint (oxc)",value:"oxlint"}],dr="Which linter/formatter do you use? We'll tell it to skip Lunora's generated files.",ur=async e=>{const t=e.interactive?await e.multiSelect(dr,cr,{defaults:e.detected}):[...e.detected];if(t.length===0)return[];const r=e.apply(t);return $t(r,e.logger),r},I="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",N=`/* The welcome page is a full-bleed starter — reset the browser's default
97
+ body margin/padding so it sits flush; everything else is scoped under
98
+ .lunora-welcome (collision-safe). */
99
+ body {
100
+ margin: 0;
101
+ padding: 0;
102
+ }
137
103
 
138
- const ADAPTER_BY_FRAMEWORK = {
139
- astro: "@lunora/react",
140
- none: "@lunora/react",
141
- nuxt: "@lunora/vue",
142
- "react-router": "@lunora/react",
143
- "solid-start": "@lunora/solid",
144
- sveltekit: "@lunora/svelte",
145
- "tanstack-start": "@lunora/react",
146
- "tanstack-start-solid": "@lunora/solid"
147
- };
148
- const detectFramework = (root) => {
149
- const base = detectFramework$1(root);
150
- return { ...base, adapter: ADAPTER_BY_FRAMEWORK[base.framework] };
151
- };
104
+ .lunora-welcome {
105
+ --cyan: hsl(186 84% 56%); --violet: hsl(256 72% 68%); --rose: hsl(330 80% 64%);
106
+ --ribbon: linear-gradient(115deg, var(--cyan), var(--violet) 52%, var(--rose));
107
+ --sans: "Geist Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
108
+ --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
109
+ /* NIGHT (default) */
110
+ --bg: #0e0e11; --surface: hsl(240 12% 8% / 0.72); --surface-2: hsl(240 11% 11% / 0.82);
111
+ --line: hsl(0 0% 100% / 0.08); --line-2: hsl(0 0% 100% / 0.14);
112
+ --t-display: hsl(228 30% 97%); --t-primary: hsl(228 26% 90%); --t-secondary: hsl(228 12% 62%); --t-faint: hsl(228 10% 44%);
113
+ --logo: hsl(228 30% 97%); --accent: var(--violet); --shot-bg: hsl(240 12% 6%);
114
+ --glow-1: hsl(256 80% 52% / 0.30); --glow-2: hsl(196 84% 52% / 0.13); --arc: hsl(256 60% 70% / 0.11);
152
115
 
153
- const LUNORA_CALL = "lunora()";
154
- const LUNORA_IMPORT = 'import { lunora } from "@lunora/vite";';
155
- const LUNORA_CALL_RE = /\blunora\s*\(/u;
156
- const LUNORA_VITE_DOUBLE = '"@lunora/vite"';
157
- const LUNORA_VITE_SINGLE = "'@lunora/vite'";
158
- const findDefineConfigObject = (sf) => {
159
- for (const statement of sf.getStatements()) {
160
- if (statement.getKind() !== SyntaxKind.ExportAssignment) {
161
- continue;
162
- }
163
- const expr = statement.asKindOrThrow(SyntaxKind.ExportAssignment).getExpression();
164
- if (expr.getKind() !== SyntaxKind.CallExpression) {
165
- continue;
166
- }
167
- const call = expr.asKindOrThrow(SyntaxKind.CallExpression);
168
- if (call.getExpression().getText() !== "defineConfig") {
169
- continue;
170
- }
171
- const argument = call.getArguments()[0];
172
- if (argument?.getKind() === SyntaxKind.ObjectLiteralExpression) {
173
- return argument.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);
174
- }
175
- }
176
- return void 0;
177
- };
178
- const findPlainExportObject = (sf) => {
179
- for (const statement of sf.getStatements()) {
180
- if (statement.getKind() !== SyntaxKind.ExportAssignment) {
181
- continue;
182
- }
183
- const expr = statement.asKindOrThrow(SyntaxKind.ExportAssignment).getExpression();
184
- if (expr.getKind() === SyntaxKind.ObjectLiteralExpression) {
185
- return expr.asKindOrThrow(SyntaxKind.ObjectLiteralExpression);
186
- }
187
- }
188
- return void 0;
189
- };
190
- const findConfigObject = (sourceText) => {
191
- const project = new Project({
192
- compilerOptions: { allowJs: true },
193
- useInMemoryFileSystem: true
194
- });
195
- const sf = project.createSourceFile("vite.config.ts", sourceText, { overwrite: true });
196
- return findDefineConfigObject(sf) ?? findPlainExportObject(sf);
197
- };
198
- const importInsertPosition = (sourceText) => {
199
- const project = new Project({
200
- compilerOptions: { allowJs: true },
201
- useInMemoryFileSystem: true
202
- });
203
- const sf = project.createSourceFile("vite.config.ts", sourceText, { overwrite: true });
204
- const imports = sf.getImportDeclarations();
205
- if (imports.length === 0) {
206
- return 0;
207
- }
208
- const last = imports[imports.length - 1];
209
- if (last === void 0) {
210
- return 0;
211
- }
212
- return last.getEnd();
213
- };
214
- const addImport = (ms, source) => {
215
- const insertAt = importInsertPosition(source);
216
- if (insertAt === 0) {
217
- ms.prepend(`${LUNORA_IMPORT}
218
- `);
219
- } else {
220
- ms.appendLeft(insertAt, `
221
- ${LUNORA_IMPORT}`);
222
- }
223
- };
224
- const patchPluginsArray = (ms, configObject) => {
225
- const pluginsProp = configObject.getProperty("plugins");
226
- if (pluginsProp === void 0) {
227
- const properties = configObject.getProperties();
228
- const openBrace = configObject.getStart() + 1;
229
- if (properties.length === 0) {
230
- ms.appendLeft(openBrace, ` plugins: [${LUNORA_CALL}] `);
231
- } else {
232
- const firstProp = properties[0];
233
- if (firstProp !== void 0) {
234
- ms.appendLeft(firstProp.getStart(), `plugins: [${LUNORA_CALL}],
235
- `);
236
- }
237
- }
238
- return;
239
- }
240
- const arrayLit = pluginsProp.getDescendantsOfKind(SyntaxKind.ArrayLiteralExpression)[0];
241
- if (arrayLit === void 0) {
242
- return;
243
- }
244
- const elements = arrayLit.getElements();
245
- if (elements.length === 0) {
246
- ms.appendLeft(arrayLit.getStart() + 1, LUNORA_CALL);
247
- } else {
248
- const firstElement = elements[0];
249
- if (firstElement !== void 0) {
250
- ms.appendLeft(firstElement.getStart(), `${LUNORA_CALL}, `);
116
+ position: relative; min-height: 100vh; background: var(--bg); color: var(--t-primary);
117
+ font-family: var(--sans); line-height: 1.55; -webkit-font-smoothing: antialiased; overflow-x: hidden;
118
+ transition: background .3s, color .3s;
119
+ }
120
+ .lunora-welcome[data-theme="light"] {
121
+ --bg: hsl(228 32% 97%); --surface: hsl(0 0% 100% / 0.82); --surface-2: hsl(0 0% 100% / 0.95);
122
+ --line: hsl(228 16% 88%); --line-2: hsl(228 14% 80%);
123
+ --t-display: hsl(240 14% 10%); --t-primary: hsl(240 12% 18%); --t-secondary: hsl(235 9% 42%); --t-faint: hsl(235 8% 58%);
124
+ --logo: hsl(240 16% 9%); --accent: hsl(256 58% 56%); --shot-bg: hsl(228 26% 99%);
125
+ --glow-1: hsl(256 80% 60% / 0.14); --glow-2: hsl(196 84% 58% / 0.08); --arc: hsl(256 40% 55% / 0.12);
126
+ }
127
+ .lunora-welcome *, .lunora-welcome *::before, .lunora-welcome *::after { box-sizing: border-box; }
128
+ .lunora-welcome a { color: inherit; text-decoration: none; }
129
+ .lunora-welcome button { font-family: inherit; cursor: pointer; }
130
+ .lunora-welcome ::selection { background: hsl(256 72% 68% / 0.3); }
131
+ .lunora-welcome code { font-family: var(--mono); }
132
+
133
+ /* glow background */
134
+ .lunora-welcome .lw-bg { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
135
+ .lunora-welcome .lw-bg .glow { position: absolute; left: 50%; top: -4%; width: 860px; height: 720px; transform: translateX(-50%);
136
+ border-radius: 50%; background: radial-gradient(circle at 50% 50%, var(--glow-1), var(--glow-2) 40%, transparent 66%); }
137
+ .lunora-welcome .lw-bg .arc { position: absolute; left: 50%; border-radius: 50%; border: 1px solid var(--arc); transform: translateX(-50%); }
138
+ .lunora-welcome .lw-bg .arc.a1 { top: -340px; width: 980px; height: 980px; }
139
+ .lunora-welcome .lw-bg .arc.a2 { top: -240px; width: 720px; height: 720px; opacity: .7; }
140
+
141
+ /* theme toggle */
142
+ .lunora-welcome .lw-toggle { position: fixed; z-index: 5; top: 20px; right: clamp(16px,4vw,36px); display: inline-flex; align-items: center;
143
+ gap: 7px; border: 1px solid var(--line-2); background: var(--surface); backdrop-filter: blur(12px); color: var(--t-secondary);
144
+ font-family: var(--mono); font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; padding: 7px 11px; transition: .15s; }
145
+ .lunora-welcome .lw-toggle:hover { color: var(--t-display); border-color: var(--accent); }
146
+ .lunora-welcome .lw-toggle svg { width: 13px; height: 13px; }
147
+
148
+ .lunora-welcome .lw-wrap { position: relative; z-index: 2; width: 100%; max-width: 1080px; margin: 0 auto;
149
+ padding: clamp(44px,8vh,92px) clamp(20px,5vw,48px); display: flex; flex-direction: column; min-height: 100vh; }
150
+ .lunora-welcome .brand { display: flex; align-items: center; justify-content: center; gap: 15px; margin-bottom: clamp(38px,6vh,68px); color: var(--logo); }
151
+ .lunora-welcome .brand svg { width: 54px; height: auto; display: block; }
152
+ .lunora-welcome .brand .word { font-size: 34px; font-weight: 600; letter-spacing: -0.03em; color: var(--t-display); }
153
+
154
+ .lunora-welcome .grid { display: grid; grid-template-columns: 1.06fr 0.94fr; gap: 16px; align-items: stretch; flex: 1; max-height: 580px; }
155
+ @media (max-width: 820px) { .lunora-welcome .grid { grid-template-columns: 1fr; max-height: none; } }
156
+
157
+ .lunora-welcome .card { border: 1px solid var(--line); background: var(--surface); backdrop-filter: blur(10px); transition: border-color .2s, background .2s; }
158
+ .lunora-welcome .card:hover { border-color: var(--line-2); background: var(--surface-2); }
159
+ .lunora-welcome .card:hover .arrow { color: var(--accent); transform: translateX(3px); }
160
+ .lunora-welcome .arrow { color: var(--t-faint); transition: color .2s, transform .2s; }
161
+ .lunora-welcome .arrow svg { width: 20px; height: 20px; display: block; }
162
+ .lunora-welcome .ic { display: grid; place-items: center; color: var(--accent);
163
+ border: 1px solid color-mix(in oklab, var(--accent) 36%, transparent); background: color-mix(in oklab, var(--accent) 12%, transparent); }
164
+ .lunora-welcome .ic svg { display: block; }
165
+
166
+ /* left feature card — stretches to fill the box height */
167
+ .lunora-welcome .feature { padding: clamp(18px,2vw,24px); display: flex; flex-direction: column; }
168
+ .lunora-welcome .shot { border: 1px solid var(--line); overflow: hidden; background: var(--shot-bg);
169
+ -webkit-mask-image: linear-gradient(to bottom, #000 56%, transparent 100%); mask-image: linear-gradient(to bottom, #000 56%, transparent 100%); }
170
+ .lunora-welcome .shot .top { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
171
+ .lunora-welcome .shot .wm { display: flex; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; color: var(--t-primary); }
172
+ .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%); }
173
+ .lunora-welcome .shot .search { flex: 1; height: 22px; border: 1px solid var(--line); border-radius: 4px; }
174
+ .lunora-welcome .shot .ver { font-family: var(--mono); font-size: 8px; letter-spacing: .08em; color: var(--t-faint); }
175
+ .lunora-welcome .shot .body { display: grid; grid-template-columns: 92px 1fr; min-height: 224px; }
176
+ .lunora-welcome .shot .nav { border-right: 1px solid var(--line); padding: 14px 12px; display: flex; flex-direction: column; gap: 11px; }
177
+ .lunora-welcome .shot .nav i, .lunora-welcome .shot .doc i { height: 5px; border-radius: 2px; background: var(--line); }
178
+ .lunora-welcome .shot .doc { padding: 16px 18px; display: flex; flex-direction: column; gap: 9px; }
179
+ .lunora-welcome .shot .doc .h { height: 8px; width: 46%; border-radius: 2px; background: var(--line-2); margin-bottom: 5px; }
180
+ .lunora-welcome .shot .doc .accent { height: 5px; width: 26%; border-radius: 2px; background: var(--accent); }
181
+ .lunora-welcome .feature .info { margin-top: auto; padding-top: clamp(18px,2.4vh,28px); }
182
+ .lunora-welcome .feature .ic { width: 40px; height: 40px; margin-bottom: 15px; }
183
+ .lunora-welcome .feature .ic svg { width: 19px; height: 19px; }
184
+ .lunora-welcome .feature h2 { margin: 0 0 10px; font-size: 19px; font-weight: 600; letter-spacing: -0.015em; color: var(--t-display); }
185
+ .lunora-welcome .feature .row { display: flex; align-items: flex-end; gap: 16px; }
186
+ .lunora-welcome .feature p { margin: 0; color: var(--t-secondary); font-size: 14px; max-width: 50ch; }
187
+ .lunora-welcome .feature .row .arrow { margin-left: auto; }
188
+
189
+ /* right stack — smaller cards, spread to align bottoms with the feature */
190
+ .lunora-welcome .stack { display: flex; flex-direction: column; gap: 16px; height: 100%; }
191
+ .lunora-welcome .mini { flex: 1; padding: 15px 17px; display: flex; align-items: center; gap: 16px; min-height: 0; }
192
+ .lunora-welcome .mini .mc { flex: 1; }
193
+ .lunora-welcome .mini .ic { width: 32px; height: 32px; margin-bottom: 10px; }
194
+ .lunora-welcome .mini .ic svg { width: 16px; height: 16px; }
195
+ .lunora-welcome .mini h3 { margin: 0 0 5px; font-size: 16px; font-weight: 600; letter-spacing: -0.01em; color: var(--t-display); }
196
+ .lunora-welcome .mini p { margin: 0; color: var(--t-secondary); font-size: 12.5px; line-height: 1.45; }
197
+
198
+ .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); }
199
+
200
+ @media (prefers-reduced-motion: reduce) { .lunora-welcome * { transition: none !important; } }
201
+ `,pr=`import { useEffect, useState } from "react";
202
+
203
+ type Theme = "dark" | "light";
204
+
205
+ export default function App() {
206
+ // Default to "dark" for a stable first paint, then reconcile to the OS
207
+ // preference; the toggle takes over after that.
208
+ const [theme, setTheme] = useState<Theme>("dark");
209
+
210
+ useEffect(() => {
211
+ if (typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: light)").matches) {
212
+ setTheme("light");
213
+ }
214
+ }, []);
215
+
216
+ const isLight = theme === "light";
217
+
218
+ return (
219
+ <div className="lunora-welcome" data-theme={theme}>
220
+ <div className="lw-bg">
221
+ <div className="arc a1" />
222
+ <div className="arc a2" />
223
+ <div className="glow" />
224
+ </div>
225
+
226
+ <button className="lw-toggle" type="button" aria-label="Toggle color theme" onClick={() => setTheme(isLight ? "dark" : "light")}>
227
+ {isLight ? (
228
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8">
229
+ <path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z" />
230
+ </svg>
231
+ ) : (
232
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.8">
233
+ <circle cx="12" cy="12" r="4" />
234
+ <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" />
235
+ </svg>
236
+ )}
237
+ <span>{isLight ? "Ivory" : "Night"}</span>
238
+ </button>
239
+
240
+ <div className="lw-wrap">
241
+ <div className="brand">
242
+ <svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
243
+ <path d="${I}" fill="currentColor" fillRule="evenodd" />
244
+ </svg>
245
+ <span className="word">Lunora</span>
246
+ </div>
247
+
248
+ <div className="grid">
249
+ <a className="card feature" href="https://lunora.sh/docs">
250
+ <div className="shot" aria-hidden="true">
251
+ <div className="top">
252
+ <span className="wm">
253
+ <i /> Lunora
254
+ </span>
255
+ <span className="search" />
256
+ <span className="ver">v0.1</span>
257
+ </div>
258
+ <div className="body">
259
+ <div className="nav">
260
+ <i style={{ width: "80%" }} />
261
+ <i style={{ width: "60%" }} />
262
+ <i style={{ width: "72%" }} />
263
+ <i style={{ width: "50%" }} />
264
+ <i style={{ width: "66%" }} />
265
+ <i style={{ width: "44%" }} />
266
+ <i style={{ width: "58%" }} />
267
+ </div>
268
+ <div className="doc">
269
+ <span className="h" />
270
+ <i style={{ width: "92%" }} />
271
+ <i style={{ width: "88%" }} />
272
+ <span className="accent" />
273
+ <i style={{ width: "80%" }} />
274
+ <i style={{ width: "90%" }} />
275
+ <i style={{ width: "72%" }} />
276
+ <i style={{ width: "84%" }} />
277
+ <i style={{ width: "78%" }} />
278
+ </div>
279
+ </div>
280
+ </div>
281
+ <div className="info">
282
+ <span className="ic">
283
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7">
284
+ <path d="M4 5a2 2 0 0 1 2-2h9l5 5v11a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2z" />
285
+ <path d="M14 3v5h5" />
286
+ </svg>
287
+ </span>
288
+ <h2>Documentation</h2>
289
+ <div className="row">
290
+ <p>
291
+ Schemas, queries, live subscriptions, sharding, and edge deploy — start to finish. New here or coming from Convex or tRPC,
292
+ you'll have a live app fast.
293
+ </p>
294
+ <span className="arrow">
295
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
296
+ <path d="M5 12h14M13 6l6 6-6 6" />
297
+ </svg>
298
+ </span>
299
+ </div>
300
+ </div>
301
+ </a>
302
+
303
+ <div className="stack">
304
+ <a className="card mini" href="https://lunora.sh/blog">
305
+ <div className="mc">
306
+ <span className="ic">
307
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7">
308
+ <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" />
309
+ </svg>
310
+ </span>
311
+ <h3>Blog</h3>
312
+ <p>Product updates, deep dives, and what's new in Lunora.</p>
313
+ </div>
314
+ <span className="arrow">
315
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
316
+ <path d="M5 12h14M13 6l6 6-6 6" />
317
+ </svg>
318
+ </span>
319
+ </a>
320
+ <a className="card mini" href="/_lunora">
321
+ <div className="mc">
322
+ <span className="ic">
323
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7">
324
+ <rect x="3" y="3" width="18" height="18" rx="1" />
325
+ <path d="M3 9h18M9 21V9" />
326
+ </svg>
327
+ </span>
328
+ <h3>Lunora Studio</h3>
329
+ <p>Local admin for schema, data, logs, and advisors.</p>
330
+ </div>
331
+ <span className="arrow">
332
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
333
+ <path d="M5 12h14M13 6l6 6-6 6" />
334
+ </svg>
335
+ </span>
336
+ </a>
337
+ <a className="card mini" href="https://lunora.sh/packages">
338
+ <div className="mc">
339
+ <span className="ic">
340
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.7">
341
+ <path d="M12 2 3 7v10l9 5 9-5V7z" />
342
+ <path d="M3 7l9 5 9-5M12 12v10" />
343
+ </svg>
344
+ </span>
345
+ <h3>Cloudflare ecosystem</h3>
346
+ <p>Auth, mail, storage, AI, payments — one deploy.</p>
347
+ </div>
348
+ <span className="arrow">
349
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2">
350
+ <path d="M5 12h14M13 6l6 6-6 6" />
351
+ </svg>
352
+ </span>
353
+ </a>
354
+ </div>
355
+ </div>
356
+
357
+ <div className="lw-foot">Running on Lunora · Vite + React</div>
358
+ </div>
359
+ </div>
360
+ );
361
+ }
362
+ `,hr=`<script setup lang="ts">
363
+ import { onMounted, ref } from "vue";
364
+
365
+ // Default to "dark" for a stable first paint, then reconcile to the OS
366
+ // preference; the toggle takes over after that.
367
+ const theme = ref<"dark" | "light">("dark");
368
+
369
+ onMounted(() => {
370
+ if (window.matchMedia("(prefers-color-scheme: light)").matches) {
371
+ theme.value = "light";
251
372
  }
252
- }
253
- };
254
- const patchViteConfig = (source) => {
255
- if (LUNORA_CALL_RE.test(source)) {
256
- return { changed: false, code: source, reason: "lunora plugin already present" };
257
- }
258
- const configObject = findConfigObject(source);
259
- if (configObject === void 0) {
260
- return { changed: false, code: source, reason: "could not locate a Vite config plugins array to patch" };
261
- }
262
- const ms = new MagicString(source);
263
- const alreadyImported = source.includes(LUNORA_VITE_DOUBLE) || source.includes(LUNORA_VITE_SINGLE);
264
- if (alreadyImported) {
265
- patchPluginsArray(ms, configObject);
266
- } else {
267
- addImport(ms, source);
268
- patchPluginsArray(ms, configObject);
269
- }
270
- return { changed: true, code: ms.toString() };
373
+ });
374
+
375
+ const toggle = (): void => {
376
+ theme.value = theme.value === "light" ? "dark" : "light";
271
377
  };
378
+ <\/script>
272
379
 
273
- const STACK_FEATURE_OPTIONS = [
274
- { description: "Sign-up / sign-in (asks which provider)", label: "Authentication", value: "auth" },
275
- { description: "Cloudflare Email Workers + a dev mail catcher", label: "Transactional email", value: "email" }
276
- ];
277
- const offerRegistryExtras = async (deps) => {
278
- if (!deps.interactive) {
279
- deps.logger.info("tip: add authentication or email later with `lunora add auth` / `lunora add email`.");
280
- return;
281
- }
282
- const picked = await deps.multiSelect("Which features do you want to add?", STACK_FEATURE_OPTIONS, { defaults: [] });
283
- for (const feature of picked) {
284
- if (feature === "auth") {
285
- const provider = await promptAuthProvider(deps.select);
286
- await deps.apply([provider]);
287
- } else {
288
- await deps.apply([EMAIL_ITEM]);
289
- }
290
- }
380
+ <template>
381
+ <div class="lunora-welcome" :data-theme="theme">
382
+ <div class="lw-bg">
383
+ <div class="arc a1" />
384
+ <div class="arc a2" />
385
+ <div class="glow" />
386
+ </div>
387
+
388
+ <button class="lw-toggle" type="button" aria-label="Toggle color theme" @click="toggle">
389
+ <svg v-if="theme === 'light'" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
390
+ <path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z" />
391
+ </svg>
392
+ <svg v-else viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
393
+ <circle cx="12" cy="12" r="4" />
394
+ <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" />
395
+ </svg>
396
+ <span>{{ theme === "light" ? "Ivory" : "Night" }}</span>
397
+ </button>
398
+
399
+ <div class="lw-wrap">
400
+ <div class="brand">
401
+ <svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
402
+ <path d="${I}" fill="currentColor" fill-rule="evenodd" />
403
+ </svg>
404
+ <span class="word">Lunora</span>
405
+ </div>
406
+
407
+ <div class="grid">
408
+ <a class="card feature" href="https://lunora.sh/docs">
409
+ <div class="shot" aria-hidden="true">
410
+ <div class="top">
411
+ <span class="wm"><i /> Lunora</span>
412
+ <span class="search" />
413
+ <span class="ver">v0.1</span>
414
+ </div>
415
+ <div class="body">
416
+ <div class="nav">
417
+ <i style="width: 80%" />
418
+ <i style="width: 60%" />
419
+ <i style="width: 72%" />
420
+ <i style="width: 50%" />
421
+ <i style="width: 66%" />
422
+ <i style="width: 44%" />
423
+ <i style="width: 58%" />
424
+ </div>
425
+ <div class="doc">
426
+ <span class="h" />
427
+ <i style="width: 92%" />
428
+ <i style="width: 88%" />
429
+ <span class="accent" />
430
+ <i style="width: 80%" />
431
+ <i style="width: 90%" />
432
+ <i style="width: 72%" />
433
+ <i style="width: 84%" />
434
+ <i style="width: 78%" />
435
+ </div>
436
+ </div>
437
+ </div>
438
+ <div class="info">
439
+ <span class="ic">
440
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
441
+ <path d="M4 5a2 2 0 0 1 2-2h9l5 5v11a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2z" />
442
+ <path d="M14 3v5h5" />
443
+ </svg>
444
+ </span>
445
+ <h2>Documentation</h2>
446
+ <div class="row">
447
+ <p>
448
+ Schemas, queries, live subscriptions, sharding, and edge deploy — start to finish. New here or coming from Convex or tRPC,
449
+ you'll have a live app fast.
450
+ </p>
451
+ <span class="arrow">
452
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
453
+ <path d="M5 12h14M13 6l6 6-6 6" />
454
+ </svg>
455
+ </span>
456
+ </div>
457
+ </div>
458
+ </a>
459
+
460
+ <div class="stack">
461
+ <a class="card mini" href="https://lunora.sh/blog">
462
+ <div class="mc">
463
+ <span class="ic">
464
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
465
+ <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" />
466
+ </svg>
467
+ </span>
468
+ <h3>Blog</h3>
469
+ <p>Product updates, deep dives, and what's new in Lunora.</p>
470
+ </div>
471
+ <span class="arrow">
472
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
473
+ <path d="M5 12h14M13 6l6 6-6 6" />
474
+ </svg>
475
+ </span>
476
+ </a>
477
+ <a class="card mini" href="/_lunora">
478
+ <div class="mc">
479
+ <span class="ic">
480
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
481
+ <rect x="3" y="3" width="18" height="18" rx="1" />
482
+ <path d="M3 9h18M9 21V9" />
483
+ </svg>
484
+ </span>
485
+ <h3>Lunora Studio</h3>
486
+ <p>Local admin for schema, data, logs, and advisors.</p>
487
+ </div>
488
+ <span class="arrow">
489
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
490
+ <path d="M5 12h14M13 6l6 6-6 6" />
491
+ </svg>
492
+ </span>
493
+ </a>
494
+ <a class="card mini" href="https://lunora.sh/packages">
495
+ <div class="mc">
496
+ <span class="ic">
497
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
498
+ <path d="M12 2 3 7v10l9 5 9-5V7z" />
499
+ <path d="M3 7l9 5 9-5M12 12v10" />
500
+ </svg>
501
+ </span>
502
+ <h3>Cloudflare ecosystem</h3>
503
+ <p>Auth, mail, storage, AI, payments — one deploy.</p>
504
+ </div>
505
+ <span class="arrow">
506
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
507
+ <path d="M5 12h14M13 6l6 6-6 6" />
508
+ </svg>
509
+ </span>
510
+ </a>
511
+ </div>
512
+ </div>
513
+
514
+ <div class="lw-foot">Running on Lunora · Vite + Vue</div>
515
+ </div>
516
+ </div>
517
+ </template>
518
+ `,mr=`import { createSignal, onMount } from "solid-js";
519
+
520
+ export default function App() {
521
+ // Default to "dark" for a stable first paint, then reconcile to the OS
522
+ // preference; the toggle takes over after that.
523
+ const [theme, setTheme] = createSignal<"dark" | "light">("dark");
524
+
525
+ onMount(() => {
526
+ if (window.matchMedia("(prefers-color-scheme: light)").matches) {
527
+ setTheme("light");
528
+ }
529
+ });
530
+
531
+ const isLight = () => theme() === "light";
532
+
533
+ return (
534
+ <div class="lunora-welcome" data-theme={theme()}>
535
+ <div class="lw-bg">
536
+ <div class="arc a1" />
537
+ <div class="arc a2" />
538
+ <div class="glow" />
539
+ </div>
540
+
541
+ <button class="lw-toggle" type="button" aria-label="Toggle color theme" onClick={() => setTheme(isLight() ? "dark" : "light")}>
542
+ {isLight() ? (
543
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
544
+ <path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z" />
545
+ </svg>
546
+ ) : (
547
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
548
+ <circle cx="12" cy="12" r="4" />
549
+ <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" />
550
+ </svg>
551
+ )}
552
+ <span>{isLight() ? "Ivory" : "Night"}</span>
553
+ </button>
554
+
555
+ <div class="lw-wrap">
556
+ <div class="brand">
557
+ <svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
558
+ <path d="${I}" fill="currentColor" fill-rule="evenodd" />
559
+ </svg>
560
+ <span class="word">Lunora</span>
561
+ </div>
562
+
563
+ <div class="grid">
564
+ <a class="card feature" href="https://lunora.sh/docs">
565
+ <div class="shot" aria-hidden="true">
566
+ <div class="top">
567
+ <span class="wm">
568
+ <i /> Lunora
569
+ </span>
570
+ <span class="search" />
571
+ <span class="ver">v0.1</span>
572
+ </div>
573
+ <div class="body">
574
+ <div class="nav">
575
+ <i style={{ width: "80%" }} />
576
+ <i style={{ width: "60%" }} />
577
+ <i style={{ width: "72%" }} />
578
+ <i style={{ width: "50%" }} />
579
+ <i style={{ width: "66%" }} />
580
+ <i style={{ width: "44%" }} />
581
+ <i style={{ width: "58%" }} />
582
+ </div>
583
+ <div class="doc">
584
+ <span class="h" />
585
+ <i style={{ width: "92%" }} />
586
+ <i style={{ width: "88%" }} />
587
+ <span class="accent" />
588
+ <i style={{ width: "80%" }} />
589
+ <i style={{ width: "90%" }} />
590
+ <i style={{ width: "72%" }} />
591
+ <i style={{ width: "84%" }} />
592
+ <i style={{ width: "78%" }} />
593
+ </div>
594
+ </div>
595
+ </div>
596
+ <div class="info">
597
+ <span class="ic">
598
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
599
+ <path d="M4 5a2 2 0 0 1 2-2h9l5 5v11a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2z" />
600
+ <path d="M14 3v5h5" />
601
+ </svg>
602
+ </span>
603
+ <h2>Documentation</h2>
604
+ <div class="row">
605
+ <p>
606
+ Schemas, queries, live subscriptions, sharding, and edge deploy — start to finish. New here or coming from Convex or tRPC,
607
+ you'll have a live app fast.
608
+ </p>
609
+ <span class="arrow">
610
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
611
+ <path d="M5 12h14M13 6l6 6-6 6" />
612
+ </svg>
613
+ </span>
614
+ </div>
615
+ </div>
616
+ </a>
617
+
618
+ <div class="stack">
619
+ <a class="card mini" href="https://lunora.sh/blog">
620
+ <div class="mc">
621
+ <span class="ic">
622
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
623
+ <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" />
624
+ </svg>
625
+ </span>
626
+ <h3>Blog</h3>
627
+ <p>Product updates, deep dives, and what's new in Lunora.</p>
628
+ </div>
629
+ <span class="arrow">
630
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
631
+ <path d="M5 12h14M13 6l6 6-6 6" />
632
+ </svg>
633
+ </span>
634
+ </a>
635
+ <a class="card mini" href="/_lunora">
636
+ <div class="mc">
637
+ <span class="ic">
638
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
639
+ <rect x="3" y="3" width="18" height="18" rx="1" />
640
+ <path d="M3 9h18M9 21V9" />
641
+ </svg>
642
+ </span>
643
+ <h3>Lunora Studio</h3>
644
+ <p>Local admin for schema, data, logs, and advisors.</p>
645
+ </div>
646
+ <span class="arrow">
647
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
648
+ <path d="M5 12h14M13 6l6 6-6 6" />
649
+ </svg>
650
+ </span>
651
+ </a>
652
+ <a class="card mini" href="https://lunora.sh/packages">
653
+ <div class="mc">
654
+ <span class="ic">
655
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
656
+ <path d="M12 2 3 7v10l9 5 9-5V7z" />
657
+ <path d="M3 7l9 5 9-5M12 12v10" />
658
+ </svg>
659
+ </span>
660
+ <h3>Cloudflare ecosystem</h3>
661
+ <p>Auth, mail, storage, AI, payments — one deploy.</p>
662
+ </div>
663
+ <span class="arrow">
664
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
665
+ <path d="M5 12h14M13 6l6 6-6 6" />
666
+ </svg>
667
+ </span>
668
+ </a>
669
+ </div>
670
+ </div>
671
+
672
+ <div class="lw-foot">Running on Lunora · Vite + Solid</div>
673
+ </div>
674
+ </div>
675
+ );
676
+ }
677
+ `,fr=`<script lang="ts">
678
+ import { onMount } from "svelte";
679
+
680
+ // Default to "dark" for a stable first paint, then reconcile to the OS
681
+ // preference; the toggle takes over after that.
682
+ let theme = $state<"dark" | "light">("dark");
683
+ const isLight = $derived(theme === "light");
684
+
685
+ onMount(() => {
686
+ if (window.matchMedia("(prefers-color-scheme: light)").matches) {
687
+ theme = "light";
688
+ }
689
+ });
690
+
691
+ const toggle = (): void => {
692
+ theme = theme === "light" ? "dark" : "light";
693
+ };
694
+ <\/script>
695
+
696
+ <div class="lunora-welcome" data-theme={theme}>
697
+ <div class="lw-bg">
698
+ <div class="arc a1"></div>
699
+ <div class="arc a2"></div>
700
+ <div class="glow"></div>
701
+ </div>
702
+
703
+ <button class="lw-toggle" type="button" aria-label="Toggle color theme" onclick={toggle}>
704
+ {#if isLight}
705
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
706
+ <path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z" />
707
+ </svg>
708
+ {:else}
709
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8">
710
+ <circle cx="12" cy="12" r="4" />
711
+ <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" />
712
+ </svg>
713
+ {/if}
714
+ <span>{isLight ? "Ivory" : "Night"}</span>
715
+ </button>
716
+
717
+ <div class="lw-wrap">
718
+ <div class="brand">
719
+ <svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
720
+ <path d="${I}" fill="currentColor" fill-rule="evenodd" />
721
+ </svg>
722
+ <span class="word">Lunora</span>
723
+ </div>
724
+
725
+ <div class="grid">
726
+ <a class="card feature" href="https://lunora.sh/docs">
727
+ <div class="shot" aria-hidden="true">
728
+ <div class="top">
729
+ <span class="wm"><i></i> Lunora</span>
730
+ <span class="search"></span>
731
+ <span class="ver">v0.1</span>
732
+ </div>
733
+ <div class="body">
734
+ <div class="nav">
735
+ <i style="width: 80%"></i>
736
+ <i style="width: 60%"></i>
737
+ <i style="width: 72%"></i>
738
+ <i style="width: 50%"></i>
739
+ <i style="width: 66%"></i>
740
+ <i style="width: 44%"></i>
741
+ <i style="width: 58%"></i>
742
+ </div>
743
+ <div class="doc">
744
+ <span class="h"></span>
745
+ <i style="width: 92%"></i>
746
+ <i style="width: 88%"></i>
747
+ <span class="accent"></span>
748
+ <i style="width: 80%"></i>
749
+ <i style="width: 90%"></i>
750
+ <i style="width: 72%"></i>
751
+ <i style="width: 84%"></i>
752
+ <i style="width: 78%"></i>
753
+ </div>
754
+ </div>
755
+ </div>
756
+ <div class="info">
757
+ <span class="ic">
758
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
759
+ <path d="M4 5a2 2 0 0 1 2-2h9l5 5v11a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2z" />
760
+ <path d="M14 3v5h5" />
761
+ </svg>
762
+ </span>
763
+ <h2>Documentation</h2>
764
+ <div class="row">
765
+ <p>
766
+ Schemas, queries, live subscriptions, sharding, and edge deploy — start to finish. New here or coming from Convex or tRPC,
767
+ you'll have a live app fast.
768
+ </p>
769
+ <span class="arrow">
770
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
771
+ <path d="M5 12h14M13 6l6 6-6 6" />
772
+ </svg>
773
+ </span>
774
+ </div>
775
+ </div>
776
+ </a>
777
+
778
+ <div class="stack">
779
+ <a class="card mini" href="https://lunora.sh/blog">
780
+ <div class="mc">
781
+ <span class="ic">
782
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
783
+ <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" />
784
+ </svg>
785
+ </span>
786
+ <h3>Blog</h3>
787
+ <p>Product updates, deep dives, and what's new in Lunora.</p>
788
+ </div>
789
+ <span class="arrow">
790
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
791
+ <path d="M5 12h14M13 6l6 6-6 6" />
792
+ </svg>
793
+ </span>
794
+ </a>
795
+ <a class="card mini" href="/_lunora">
796
+ <div class="mc">
797
+ <span class="ic">
798
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
799
+ <rect x="3" y="3" width="18" height="18" rx="1" />
800
+ <path d="M3 9h18M9 21V9" />
801
+ </svg>
802
+ </span>
803
+ <h3>Lunora Studio</h3>
804
+ <p>Local admin for schema, data, logs, and advisors.</p>
805
+ </div>
806
+ <span class="arrow">
807
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
808
+ <path d="M5 12h14M13 6l6 6-6 6" />
809
+ </svg>
810
+ </span>
811
+ </a>
812
+ <a class="card mini" href="https://lunora.sh/packages">
813
+ <div class="mc">
814
+ <span class="ic">
815
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
816
+ <path d="M12 2 3 7v10l9 5 9-5V7z" />
817
+ <path d="M3 7l9 5 9-5M12 12v10" />
818
+ </svg>
819
+ </span>
820
+ <h3>Cloudflare ecosystem</h3>
821
+ <p>Auth, mail, storage, AI, payments — one deploy.</p>
822
+ </div>
823
+ <span class="arrow">
824
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
825
+ <path d="M5 12h14M13 6l6 6-6 6" />
826
+ </svg>
827
+ </span>
828
+ </a>
829
+ </div>
830
+ </div>
831
+
832
+ <div class="lw-foot">Running on Lunora · Vite + Svelte</div>
833
+ </div>
834
+ </div>
835
+ `,gr=`import "./style.css";
836
+
837
+ import { LunoraClient } from "lunorash/client";
838
+
839
+ import { api } from "#lunora/_generated/api.js";
840
+
841
+ // \`@lunora/vite\` runs the Worker on the same origin as Vite, so default to
842
+ // \`location.origin\`. Point \`VITE_LUNORA_URL\` at a deployed Worker to develop
843
+ // the client against production data.
844
+ const url = (import.meta.env.VITE_LUNORA_URL as string | undefined) ?? globalThis.location.origin;
845
+ const client = new LunoraClient({ url });
846
+
847
+ 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>';
848
+ const SUN_ICON =
849
+ '<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>';
850
+
851
+ const welcomeHtml = \`
852
+ <div class="lw-bg">
853
+ <div class="arc a1"></div>
854
+ <div class="arc a2"></div>
855
+ <div class="glow"></div>
856
+ </div>
857
+
858
+ <button class="lw-toggle" type="button" aria-label="Toggle color theme"></button>
859
+
860
+ <div class="lw-wrap">
861
+ <div class="brand">
862
+ <svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
863
+ <path d="${I}" fill="currentColor" fill-rule="evenodd" />
864
+ </svg>
865
+ <span class="word">Lunora</span>
866
+ </div>
867
+
868
+ <div class="grid">
869
+ <a class="card feature" href="https://lunora.sh/docs">
870
+ <div class="shot" aria-hidden="true">
871
+ <div class="top">
872
+ <span class="wm"><i></i> Lunora</span>
873
+ <span class="search"></span>
874
+ <span class="ver">v0.1</span>
875
+ </div>
876
+ <div class="body">
877
+ <div class="nav">
878
+ <i style="width: 80%"></i>
879
+ <i style="width: 60%"></i>
880
+ <i style="width: 72%"></i>
881
+ <i style="width: 50%"></i>
882
+ <i style="width: 66%"></i>
883
+ <i style="width: 44%"></i>
884
+ <i style="width: 58%"></i>
885
+ </div>
886
+ <div class="doc">
887
+ <span class="h"></span>
888
+ <i style="width: 92%"></i>
889
+ <i style="width: 88%"></i>
890
+ <span class="accent"></span>
891
+ <i style="width: 80%"></i>
892
+ <i style="width: 90%"></i>
893
+ <i style="width: 72%"></i>
894
+ <i style="width: 84%"></i>
895
+ <i style="width: 78%"></i>
896
+ </div>
897
+ </div>
898
+ </div>
899
+ <div class="info">
900
+ <span class="ic">
901
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
902
+ <path d="M4 5a2 2 0 0 1 2-2h9l5 5v11a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2z" />
903
+ <path d="M14 3v5h5" />
904
+ </svg>
905
+ </span>
906
+ <h2>Documentation</h2>
907
+ <div class="row">
908
+ <p>
909
+ Schemas, queries, live subscriptions, sharding, and edge deploy — start to finish. New here or coming from Convex or tRPC,
910
+ you'll have a live app fast.
911
+ </p>
912
+ <span class="arrow">
913
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
914
+ <path d="M5 12h14M13 6l6 6-6 6" />
915
+ </svg>
916
+ </span>
917
+ </div>
918
+ </div>
919
+ </a>
920
+
921
+ <div class="stack">
922
+ <a class="card mini" href="https://lunora.sh/blog">
923
+ <div class="mc">
924
+ <span class="ic">
925
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
926
+ <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" />
927
+ </svg>
928
+ </span>
929
+ <h3>Blog</h3>
930
+ <p>Product updates, deep dives, and what's new in Lunora.</p>
931
+ </div>
932
+ <span class="arrow">
933
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
934
+ <path d="M5 12h14M13 6l6 6-6 6" />
935
+ </svg>
936
+ </span>
937
+ </a>
938
+ <a class="card mini" href="/_lunora">
939
+ <div class="mc">
940
+ <span class="ic">
941
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
942
+ <rect x="3" y="3" width="18" height="18" rx="1" />
943
+ <path d="M3 9h18M9 21V9" />
944
+ </svg>
945
+ </span>
946
+ <h3>Lunora Studio</h3>
947
+ <p>Local admin for schema, data, logs, and advisors.</p>
948
+ </div>
949
+ <span class="arrow">
950
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
951
+ <path d="M5 12h14M13 6l6 6-6 6" />
952
+ </svg>
953
+ </span>
954
+ </a>
955
+ <a class="card mini" href="https://lunora.sh/packages">
956
+ <div class="mc">
957
+ <span class="ic">
958
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7">
959
+ <path d="M12 2 3 7v10l9 5 9-5V7z" />
960
+ <path d="M3 7l9 5 9-5M12 12v10" />
961
+ </svg>
962
+ </span>
963
+ <h3>Cloudflare ecosystem</h3>
964
+ <p>Auth, mail, storage, AI, payments — one deploy.</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
+ </div>
973
+ </div>
974
+
975
+ <div class="lw-foot">Running on Lunora · Vite + Vanilla · <span id="lw-count">0</span> messages</div>
976
+ </div>
977
+ \`;
978
+
979
+ const root = document.querySelector<HTMLDivElement>("#app")!;
980
+ root.classList.add("lunora-welcome");
981
+ root.innerHTML = welcomeHtml;
982
+
983
+ // Theme toggle: flip the root's data-theme + swap the button's icon/label.
984
+ const toggleButton = root.querySelector<HTMLButtonElement>(".lw-toggle")!;
985
+
986
+ const paintToggle = (theme: "dark" | "light"): void => {
987
+ root.dataset.theme = theme;
988
+ toggleButton.innerHTML = \`\${theme === "light" ? MOON_ICON : SUN_ICON}<span>\${theme === "light" ? "Ivory" : "Night"}</span>\`;
291
989
  };
292
990
 
293
- const TEXT_EXTENSIONS = /* @__PURE__ */ new Set([".gitignore", ".html", ".js", ".json", ".jsonc", ".md", ".mjs", ".ts", ".tsx"]);
294
- const VITE_CONFIG_CANDIDATES = ["vite.config.ts", "vite.config.mts", "vite.config.js", "vite.config.mjs"];
295
- const MINIMAL_VITE_CONFIG = `import { defineConfig } from "vite";
991
+ paintToggle(window.matchMedia("(prefers-color-scheme: light)").matches ? "light" : "dark");
992
+ toggleButton.addEventListener("click", () => {
993
+ paintToggle(root.dataset.theme === "light" ? "dark" : "light");
994
+ });
995
+
996
+ // Live demo: the message count of a demo channel re-renders on every delta.
997
+ const count = document.querySelector<HTMLSpanElement>("#lw-count")!;
998
+
999
+ client.subscribe(api.messages.list, { channelId: "channel:demo" }, (result) => {
1000
+ count.textContent = String(result.messages.length);
1001
+ });
1002
+ `,D="const url = (import.meta.env.VITE_LUNORA_URL as string | undefined) ?? globalThis.location.origin;",vr=`import "./index.css";
1003
+
1004
+ import { LunoraProvider } from "@lunora/react";
1005
+ import { LunoraClient } from "lunorash/client";
1006
+ import { StrictMode } from "react";
1007
+ import { createRoot } from "react-dom/client";
1008
+
1009
+ import App from "./App.tsx";
1010
+
1011
+ // \`@lunora/vite\` runs the Worker on the same origin as Vite, so default to
1012
+ // \`location.origin\`. Point \`VITE_LUNORA_URL\` at a deployed Worker to develop
1013
+ // the client against production data.
1014
+ ${D}
1015
+ const client = new LunoraClient({ url });
1016
+
1017
+ const root = document.getElementById("root");
1018
+
1019
+ if (!root) {
1020
+ throw new Error("missing #root mount node");
1021
+ }
1022
+
1023
+ createRoot(root).render(
1024
+ <StrictMode>
1025
+ <LunoraProvider client={client}>
1026
+ <App />
1027
+ </LunoraProvider>
1028
+ </StrictMode>,
1029
+ );
1030
+ `,wr=`import "./style.css";
1031
+
1032
+ import { createLunora } from "@lunora/vue";
1033
+ import { LunoraClient } from "lunorash/client";
1034
+ import { createApp } from "vue";
1035
+
1036
+ import App from "./App.vue";
1037
+
1038
+ // Provide one LunoraClient at the app root via the Vue plugin form.
1039
+ ${D}
1040
+ createApp(App).use(createLunora(new LunoraClient({ url }))).mount("#app");
1041
+ `,yr=`import "./index.css";
1042
+
1043
+ import { LunoraProvider } from "@lunora/solid";
1044
+ import { LunoraClient } from "lunorash/client";
1045
+ import { render } from "solid-js/web";
1046
+
1047
+ import App from "./App";
1048
+
1049
+ ${D}
1050
+ const client = new LunoraClient({ url });
1051
+ const root = document.getElementById("root");
1052
+
1053
+ render(
1054
+ () => (
1055
+ <LunoraProvider client={client}>
1056
+ <App />
1057
+ </LunoraProvider>
1058
+ ),
1059
+ root!,
1060
+ );
1061
+ `,br=`<script lang="ts">
1062
+ import { setLunoraClient } from "@lunora/svelte";
1063
+ import { LunoraClient } from "lunorash/client";
1064
+
1065
+ import App from "./App.svelte";
1066
+
1067
+ ${D}
1068
+ setLunoraClient(new LunoraClient({ url }));
1069
+ <\/script>
1070
+
1071
+ <App />
1072
+ `,xr=`import "./app.css";
1073
+
1074
+ import { mount } from "svelte";
1075
+
1076
+ import Root from "./Root.svelte";
1077
+
1078
+ // Mount \`Root\` (it sets the ambient LunoraClient) rather than \`App\` directly.
1079
+ const app = mount(Root, { target: document.getElementById("app")! });
1080
+
1081
+ export default app;
1082
+ `,B={react:{adapter:"@lunora/react",createViteTemplate:"react-ts",files:[{contents:vr,path:"src/main.tsx"},{contents:pr,path:"src/App.tsx"},{contents:N,path:"src/index.css"}],label:"React"},solid:{adapter:"@lunora/solid",createViteTemplate:"solid-ts",files:[{contents:yr,path:"src/index.tsx"},{contents:mr,path:"src/App.tsx"},{contents:N,path:"src/index.css"}],label:"Solid"},svelte:{adapter:"@lunora/svelte",createViteTemplate:"svelte-ts",files:[{contents:br,path:"src/Root.svelte"},{contents:xr,path:"src/main.ts"},{contents:fr,path:"src/App.svelte"},{contents:N,path:"src/app.css"}],label:"Svelte"},vanilla:{adapter:"lunorash/client",createViteTemplate:"vanilla-ts",files:[{contents:gr,path:"src/main.ts"},{contents:N,path:"src/style.css"}],label:"Vanilla"},vue:{adapter:"@lunora/vue",createViteTemplate:"vue-ts",files:[{contents:wr,path:"src/main.ts"},{contents:hr,path:"src/App.vue"},{contents:N,path:"src/style.css"}],label:"Vue"}},j=e=>Object.hasOwn(B,e),kr=`/**
1083
+ * Rate-limit schema extension + plugin.
1084
+ *
1085
+ * Defines the \`ratelimit_buckets\` table used by \`createDbStore\` for durable,
1086
+ * DO-backed rate limiting. Included automatically in every Lunora project.
1087
+ */
1088
+ import type { Middleware } from "lunorash/server";
1089
+ import { defineSchemaExtension, defineTable, definePlugin, v } from "lunorash/server";
1090
+ import { createDbStore, RateLimiter } from "lunorash/ratelimit";
1091
+ import type { RateLimitConfigMap } from "lunorash/ratelimit";
1092
+
1093
+ /**
1094
+ * Named limits this app enforces. This is the one place they live — add your own
1095
+ * and reference them by name from \`rateLimit(limiter, "<name>", …)\` (see
1096
+ * \`lunora/messages.ts\`).
1097
+ */
1098
+ export const limits = {
1099
+ /** Chat writes: 30 per caller per minute, refilling continuously over 60s. */
1100
+ send: { kind: "token bucket", period: 60_000, rate: 30 },
1101
+ } as const satisfies RateLimitConfigMap;
1102
+
1103
+ export type LimitName = keyof typeof limits;
1104
+
1105
+ export const makeRateLimiter = (ctx: { db: unknown }): RateLimiter<LimitName> =>
1106
+ new RateLimiter<LimitName>({
1107
+ config: limits,
1108
+ store: createDbStore({ db: ctx.db as never, table: "ratelimit_buckets" }),
1109
+ });
1110
+
1111
+ const middleware: Middleware<{ api?: Record<string, unknown>; db: unknown }, { api: Record<string, unknown>; db: unknown }> = ({ ctx, next }) =>
1112
+ next({
1113
+ ctx: {
1114
+ ...ctx,
1115
+ api: { ...ctx.api, ratelimit: makeRateLimiter(ctx) },
1116
+ },
1117
+ });
1118
+
1119
+ export const ratelimit = definePlugin("ratelimit", {
1120
+ extension: defineSchemaExtension("ratelimit", {
1121
+ tables: {
1122
+ buckets: defineTable({
1123
+ key: v.string(),
1124
+ value: v.number(),
1125
+ ts: v.number(),
1126
+ prev: v.optional(v.number()),
1127
+ })
1128
+ .index("by_key", ["key"])
1129
+ .externallyManaged(),
1130
+ },
1131
+ }),
1132
+ middleware,
1133
+ });
1134
+ `,Cr=`import { ratelimit } from "./ratelimit/schema.js";
1135
+ import { defineSchema, defineTable, v } from "lunorash/server";
1136
+
1137
+ export default defineSchema({
1138
+ messages: defineTable({
1139
+ channelId: v.string(),
1140
+ text: v.string(),
1141
+ })
1142
+ .shardBy("channelId")
1143
+ .index("by_channel", ["channelId"]),
1144
+ }).extend(ratelimit.extension);
1145
+ `,Sr=`import { rateLimit } from "lunorash/ratelimit";
1146
+
1147
+ import { makeRateLimiter } from "./ratelimit/schema.js";
1148
+ import type { MutationCtx } from "#lunora/_generated/server.js";
1149
+ import { mutation, query, v } from "#lunora/_generated/server.js";
1150
+
1151
+ /**
1152
+ * The limiter comes from \`lunora/ratelimit/schema.ts\` — that file owns the named
1153
+ * limits and the durable store, so tuning \`send\` there is what changes this
1154
+ * procedure's budget. Build it from the generated \`MutationCtx\` so
1155
+ * \`rateLimit(limiter, …)\` infers the full procedure context: \`ctx.auth\`/\`ctx.ip\`
1156
+ * in the key callback and a typed \`ctx.db\` in the handler both depend on it.
1157
+ */
1158
+ const limiter = (ctx: MutationCtx) => makeRateLimiter(ctx);
1159
+
1160
+ /**
1161
+ * One bucket per caller, not one bucket for the whole app.
1162
+ *
1163
+ * \`ctx.auth.userId\` is \`null\` until you wire auth (\`lunora registry add auth\`),
1164
+ * so the \`ctx.ip\` fallback is what actually keys the limit in a fresh project.
1165
+ * Keying on \`"anon"\` alone would let one script exhaust the budget for every user.
1166
+ *
1167
+ * \`ctx.ip\` is Cloudflare's server-side \`CF-Connecting-IP\` and is populated ONLY
1168
+ * when the app runs on Cloudflare, where the edge stamps that header over
1169
+ * anything the client sent. Deploy this to another target and \`ctx.ip\` is
1170
+ * \`undefined\` by design — the runtime will not pass on a header the caller can
1171
+ * type — so every anonymous caller falls back to the shared \`"anon"\` bucket.
1172
+ * Off Cloudflare, key on something the caller cannot choose (an API key, a
1173
+ * signed session) before relying on this limit.
1174
+ */
1175
+ const byCaller = { key: (ctx: { auth: { userId?: null | string }; ip?: string }): string => ctx.auth.userId ?? ctx.ip ?? "anon" };
1176
+
1177
+ export const list = query.input({ channelId: v.string().max(256), limit: v.optional(v.number()) }).query(async ({ args, ctx }) => {
1178
+ const messages = await ctx.db
1179
+ .query("messages")
1180
+ .withIndex("by_channel", (q) => q.eq("channelId", args.channelId))
1181
+ .take(args.limit ?? 50);
1182
+
1183
+ return { channelId: args.channelId, messages };
1184
+ });
1185
+
1186
+ export const send = mutation
1187
+ .input({ channelId: v.string().max(256), text: v.string().max(4096) })
1188
+ .use(rateLimit(limiter, "send", byCaller))
1189
+ .mutation(async ({ args, ctx }) => {
1190
+ const id = await ctx.db.insert("messages", { channelId: args.channelId, text: args.text });
1191
+
1192
+ return { channelId: args.channelId, id, text: args.text };
1193
+ });
1194
+ `,Lr=`import type { ShardNamespaceLike } from "lunorash/runtime";
1195
+
1196
+ import { defineApp } from "../lunora/_generated/app.js";
1197
+
1198
+ interface Env extends Record<string, unknown> {
1199
+ SHARD: ShardNamespaceLike;
1200
+ }
1201
+
1202
+ const app = defineApp<Env>()
1203
+ .shard((env) => env.SHARD)
1204
+ .build();
1205
+
1206
+ export const ShardDO = app.ShardDO;
1207
+ export default app;
1208
+ `,Mr=`{
1209
+ "$schema": "node_modules/wrangler/config-schema.json",
1210
+ "name": "__NAME__",
1211
+ "main": "src/server.ts",
1212
+ "compatibility_date": "2026-06-10",
1213
+ "compatibility_flags": ["nodejs_compat"],
1214
+ "durable_objects": {
1215
+ "bindings": [{ "name": "SHARD", "class_name": "ShardDO" }],
1216
+ },
1217
+ "migrations": [{ "tag": "v1", "new_sqlite_classes": ["ShardDO"] }],
1218
+ "observability": { "enabled": true, "head_sampling_rate": 1 },
1219
+ }
1220
+ `,ae=[".wrangler",".env",".env.*","!.env.example",".dev.vars",".dev.vars.*","!.dev.vars.example",".lunora/",".lunora-cache","lunora/_generated"],Ar=`# Lunora endpoint for the browser client.
1221
+ # Vite statically replaces \`import.meta.env.VITE_LUNORA_URL\` at \`vite dev\` / build.
1222
+ # Leave it unset to use the page origin; set it to point at a deployed Worker:
1223
+ #
1224
+ # VITE_LUNORA_URL=https://my-app.example.workers.dev
1225
+ `,Er={"@cloudflare/workers-types":"^4.20260611.1",wrangler:"^4.100.0"},C=(e,t,r,a)=>{const o=p(e,t);M(A(o),{recursive:!0}),w(o,r,"utf8"),a.push(o)},Nr=/\r?\n/,_r=e=>{const t=p(e,".gitignore"),r=m(t)?k(t,"utf8"):"",a=new Set(r.split(Nr)),o=ae.filter(i=>!a.has(i));if(o.length===0)return;const n=o.some(i=>!i.startsWith("!"))?[...o.filter(i=>!i.startsWith("!")),...ae.filter(i=>i.startsWith("!"))]:o,s=r.length>0&&!r.endsWith(`
1226
+ `)?`
1227
+ `:"";w(t,`${r}${s}
1228
+ # Lunora
1229
+ ${n.join(`
1230
+ `)}
1231
+ `,"utf8")},U=e=>e==="lunorash"||e.startsWith("@lunora/"),Ir=(e,t,r,a)=>U(e)?a.get(e)??r:t,S=(e,t,r)=>({...e,[t]:r}),oe=(e,t,r)=>Object.fromEntries(Object.entries(e).map(([a,o])=>[a,Ir(a,o,t,r)])),$r=async(e,t,r,a)=>{const o=p(e,"package.json"),n=JSON.parse(k(o,"utf8"));let s=S(n.dependencies??{},"lunorash",a);s=S(s,"@lunora/ratelimit",a),r.adapter.startsWith("@lunora/")&&(s=S(s,r.adapter,a));for(const[u,h]of Object.entries(r.extraDependencies??{}))s=S(s,u,h);let i=S(n.devDependencies??{},"@lunora/vite",a);i=S(i,"@lunora/studio",a);for(const[u,h]of Object.entries(Er))i=S(i,u,h);const l=[...Object.keys(s),...Object.keys(i)].filter(u=>U(u)),c=await ve(l,a);n.name=t,n.imports={...n.imports,"#lunora/*":"./lunora/*"},n.dependencies=oe(s,a,c),n.devDependencies=oe(i,a,c),n.scripts={...n.scripts,codegen:"lunora codegen",deploy:"vite build && lunora deploy"},w(o,`${JSON.stringify(n,void 0,4)}
1232
+ `,"utf8")},Rr=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],Oe=e=>Rr.map(t=>p(e,t)).find(t=>m(t)),Or=(e,t)=>{const r=Oe(e);if(r===void 0){t.warn("overlay: no vite.config found in the create-vite base — add `lunora()` to your Vite plugins manually.");return}const a=Ie(k(r,"utf8"));a.changed&&w(r,a.code,"utf8")},Tr=async e=>{const{adapter:t,distTag:r,logger:a,name:o,target:n}=e,s=[];C(n,p("lunora","ratelimit","schema.ts"),kr,s),C(n,p("lunora","schema.ts"),Cr,s),C(n,p("lunora","messages.ts"),Sr,s),C(n,p("src","server.ts"),Lr,s),C(n,"wrangler.jsonc",Mr.replaceAll("__NAME__",o),s),C(n,".env.example",Ar,s);for(const i of t.files)C(n,i.path,i.contents,s);return Or(n,a),await $r(n,o,t,r),_r(n),s},Pr=["lunar","silver","silent","waning","waxing","crescent","cosmic","stellar","orbital","gibbous","twilight","midnight","shimmering","drifting","weightless"],Dr=["moon","tide","crater","comet","eclipse","halo","orbit","nebula","voyager","lander","rover","beacon","harbor","meadow","fox"],ne=e=>e[Math.floor(Math.random()*e.length)],Br=()=>`${ne(Pr)}-${ne(Dr)}`,jr=async()=>Rt.lookup("github.com").then(()=>!0,()=>!1),Ur=/^(?:gh|github):([^/]+)\/([^#/]+)(?:\/[^#]*)?(?:#(.+))?$/,Te=e=>{const t=Ur.exec(e);if(t===null)return;const[,r,a,o]=t;if(!(r===void 0||a===void 0))return{owner:r,ref:o??"HEAD",repo:a}},Vr=async e=>{const t=Te(e);if(t===void 0)return;const r=`https://codeload.github.com/${t.owner}/${t.repo}/tar.gz/${t.ref}`;try{const a=await fetch(r,{method:"HEAD"});return a.status===404?!1:a.ok?!0:void 0}catch{return}},Pe=async e=>e.isLocal||!(e.source===void 0||Te(e.source)!==void 0)?!0:await jr()?e.source!==void 0&&await Vr(e.source)===!1?(e.logger.error(`template source not found: ${e.source} — double-check --ref / --source, or browse the templates at https://lunora.sh/docs.`),!1):!0:(e.logger.error("you appear to be offline — connect to the internet and try again, or scaffold from a local template with `--from <dir>`."),!1),x={extras:"Let's finish setting up your app.",framework:"Which framework should we launch?",git:"Initialize a new git repository? (optional)",install:"Install dependencies now?",name:"Where should we land your project?",nextHeader:"Liftoff confirmed — explore your project!",packageManager:"Which package manager?"},Fr=new Set([".gitignore",".html",".js",".json",".jsonc",".md",".mjs",".ts",".tsx"]),Wr=`import { defineConfig } from "vite";
296
1233
  import { lunora } from "@lunora/vite";
297
1234
 
298
1235
  export default defineConfig({ plugins: [lunora()] });
299
- `;
300
- const SAMPLE_SCHEMA = `import { defineSchema, defineTable, v } from "@lunora/server";
1236
+ `,Hr=`import { defineSchema, defineTable, v } from "@lunora/server";
301
1237
 
302
1238
  export default defineSchema({
303
1239
  messages: defineTable({
304
- channelId: v.id("channels"),
1240
+ channelId: v.string(),
305
1241
  text: v.string(),
306
1242
  })
307
1243
  .shardBy("channelId")
308
1244
  .index("by_channel", ["channelId"]),
309
1245
  });
310
- `;
311
- const SAMPLE_FUNCTION = `import { mutation, query, v } from "./_generated/server";
1246
+ `,zr=`import { mutation, query, v } from "./_generated/server";
312
1247
 
313
1248
  export const list = query
314
- .input({ channelId: v.id("channels"), limit: v.optional(v.number()) })
1249
+ .input({ channelId: v.string(), limit: v.optional(v.number()) })
315
1250
  .query(async ({ args }) => {
316
1251
  return { channelId: args.channelId, limit: args.limit ?? 50, messages: [] };
317
1252
  });
318
1253
 
319
1254
  export const send = mutation
320
- .input({ channelId: v.id("channels"), text: v.string() })
1255
+ .input({ channelId: v.string(), text: v.string() })
321
1256
  .mutation(async ({ args }) => {
322
1257
  return { channelId: args.channelId, text: args.text };
323
1258
  });
324
- `;
325
- const DEFAULT_SOURCE_BASE = "gh:anolilab/lunora/templates";
326
- const isTextFile = (filePath) => {
327
- const lastDot = filePath.lastIndexOf(".");
328
- if (lastDot === -1) {
329
- return false;
330
- }
331
- return TEXT_EXTENSIONS.has(filePath.slice(lastDot));
332
- };
333
- const substitute = (content, name) => content.replaceAll("{{name}}", name);
334
- const collectFiles = (directory) => {
335
- const out = [];
336
- for (const entry of walkSync(directory, { includeDirs: false, includeFiles: true })) {
337
- out.push(entry.path);
338
- }
339
- return out;
340
- };
341
- const copyTemplate = (sourceDirectory, target, name) => {
342
- const files = collectFiles(sourceDirectory);
343
- const written = [];
344
- for (const source of files) {
345
- const relativePath = relative(sourceDirectory, source);
346
- const destination = join$1(target, relativePath);
347
- mkdirSync(dirname$1(destination), { recursive: true });
348
- const raw = readFileSync(source);
349
- const text = isTextFile(source) ? substitute(raw.toString("utf8"), name) : void 0;
350
- if (text === void 0) {
351
- writeFileSync(destination, raw);
352
- } else {
353
- writeFileSync(destination, text, "utf8");
354
- }
355
- written.push(destination);
356
- }
357
- return written;
358
- };
359
- const resolveTemplateSource = (templateType, source, ref) => {
360
- if (source !== void 0 && source.length > 0) {
361
- return source;
362
- }
363
- return `${DEFAULT_SOURCE_BASE}/${templateType}#${resolveSourceRef(ref)}`;
364
- };
365
- const isSafeSource = (source) => {
366
- if (source.includes("..")) {
367
- return false;
368
- }
369
- return source.startsWith("gh:") || source.startsWith("github:") || source.startsWith("https://");
370
- };
371
- const logScaffoldSuccess = (logger, written, target, name) => {
372
- logger.success(`scaffolded ${String(written.length)} files into ${target}`);
373
- logger.info("next steps:");
374
- logger.info(` cd ${name}`);
375
- logger.info(" pnpm install");
376
- logger.info(" pnpm dev");
377
- };
378
- const scaffoldFromLocal = (fromRoot, templateType, target, name, logger) => {
379
- const templateDirectory = join$1(fromRoot, templateType);
380
- if (!existsSync(templateDirectory)) {
381
- logger.error(`template not found in local source: ${templateDirectory}`);
382
- return { code: 1, files: [], target };
383
- }
384
- const written = copyTemplate(templateDirectory, target, name);
385
- logScaffoldSuccess(logger, written, target, name);
386
- return { code: 0, files: written, target };
387
- };
388
- const scaffoldFromRemote = async (options) => {
389
- const { logger, name, ref, source, target, templateType } = options;
390
- const stagingRoot = mkdtempSync(join$1(tmpdir(), "lunora-init-fetch-"));
391
- const stagingDirectory = join$1(stagingRoot, "template");
392
- try {
393
- const remote = resolveTemplateSource(templateType, source, ref);
394
- logger.info(`fetching template from ${remote}`);
395
- const downloaded = await downloadTemplate(remote, {
396
- cwd: stagingRoot,
397
- dir: stagingDirectory,
398
- force: true,
399
- install: false,
400
- silent: true
401
- });
402
- const staged = collectFiles(stagingDirectory);
403
- if (downloaded.commit) {
404
- logger.info(`resolved ${downloaded.source} @ ${downloaded.commit} (${String(staged.length)} file(s))`);
405
- } else {
406
- logger.info(`resolved ${downloaded.source} (${String(staged.length)} file(s))`);
407
- }
408
- const written = copyTemplate(stagingDirectory, target, name);
409
- logScaffoldSuccess(logger, written, target, name);
410
- return { code: 0, files: written, target };
411
- } catch (error) {
412
- const message = error instanceof Error ? error.message : String(error);
413
- logger.error(`failed to download template: ${message}`);
414
- return { code: 1, files: [], target };
415
- } finally {
416
- rmSync(stagingRoot, { force: true, recursive: true });
417
- }
418
- };
419
- const createMinimalViteConfig = (cwd, logger) => {
420
- const target = join$1(cwd, "vite.config.ts");
421
- try {
422
- writeFileSync(target, MINIMAL_VITE_CONFIG, "utf8");
423
- } catch (error) {
424
- const message = error instanceof Error ? error.message : String(error);
425
- logger.error(`init --in-place: could not write ${target}: ${message}`);
426
- return { code: 1, files: [], target: cwd };
427
- }
428
- logger.success(`created ${target} with lunora() plugin`);
429
- return { code: 0, files: [target], target: cwd };
430
- };
431
- const patchExistingViteConfig = (viteConfigPath, cwd, logger) => {
432
- let source;
433
- try {
434
- source = readFileSync(viteConfigPath, "utf8");
435
- } catch (error) {
436
- const message = error instanceof Error ? error.message : String(error);
437
- logger.error(`init --in-place: could not read ${viteConfigPath}: ${message}`);
438
- return { code: 1, files: [], target: cwd };
439
- }
440
- const result = patchViteConfig(source);
441
- if (!result.changed) {
442
- logger.info(`${viteConfigPath}: ${result.reason ?? "no changes needed"}`);
443
- return { code: 0, files: [], target: cwd };
444
- }
445
- try {
446
- writeFileSync(viteConfigPath, result.code, "utf8");
447
- } catch (error) {
448
- const message = error instanceof Error ? error.message : String(error);
449
- logger.error(`init --in-place: could not write ${viteConfigPath}: ${message}`);
450
- return { code: 1, files: [], target: cwd };
451
- }
452
- logger.success(`patched ${viteConfigPath} — added lunora() plugin`);
453
- return { code: 0, files: [viteConfigPath], target: cwd };
454
- };
455
- const scaffoldLunoraDirectory = (cwd, logger) => {
456
- const lunoraDirectory = join$1(cwd, "lunora");
457
- const schemaPath = join$1(lunoraDirectory, "schema.ts");
458
- if (existsSync(schemaPath)) {
459
- logger.info(`lunora/ already present — left ${schemaPath} untouched`);
460
- return [];
461
- }
462
- const written = [];
463
- try {
464
- mkdirSync(lunoraDirectory, { recursive: true });
465
- writeFileSync(schemaPath, SAMPLE_SCHEMA, "utf8");
466
- written.push(schemaPath);
467
- const functionPath = join$1(lunoraDirectory, "messages.ts");
468
- if (!existsSync(functionPath)) {
469
- writeFileSync(functionPath, SAMPLE_FUNCTION, "utf8");
470
- written.push(functionPath);
471
- }
472
- logger.success(`scaffolded lunora/ (${String(written.length)} file(s))`);
473
- } catch (error) {
474
- const message = error instanceof Error ? error.message : String(error);
475
- logger.error(`init --here: could not scaffold lunora/: ${message}`);
476
- }
477
- return written;
478
- };
479
- const printFrameworkNextSteps = (detection, logger) => {
480
- const { adapter, class: frameworkClass, framework } = detection;
481
- logger.info("");
482
- logger.info(`detected framework: ${framework} (class ${frameworkClass})`);
483
- logger.info("next steps:");
484
- logger.info(` 1. install the adapter: pnpm add ${adapter} @lunora/client @lunora/runtime @lunora/server`);
485
- logger.info(" 2. run codegen: lunora codegen");
486
- if (frameworkClass === "A") {
487
- logger.info(" 3. compose one worker: wrap your worker entry with");
488
- logger.info(" createWorker({ httpRouter: <your framework SSR handler>, shardDO: ShardDO, ... })");
489
- logger.info(` 4. add the provider: mount the ${adapter} provider in your root layout/route`);
490
- logger.info(" 5. make a loader live: preloadQuery() in a loader, usePreloadedQuery() in the component");
491
- logger.info(" see https://lunora.sh/docs/frameworks/reactive-loaders");
492
- } else if (frameworkClass === "B") {
493
- logger.info(" 3. inject Lunora: mount Lunora realtime under /_lunora/* in your server hook");
494
- logger.info(` (${framework} owns its Cloudflare adapter — Lunora composes into its server entry)`);
495
- logger.info(` 4. add the provider: mount the ${adapter} provider in your root layout`);
496
- logger.info(" 5. read the guide: https://lunora.sh/docs/frameworks/deploy");
497
- } else {
498
- logger.info(" 3. add the provider: wrap your app with the LunoraProvider from @lunora/react");
499
- logger.info(" 4. read the guide: https://lunora.sh/docs/frameworks/bring-your-framework");
500
- }
501
- logger.info("");
502
- };
503
- const findExistingViteConfig = (cwd) => {
504
- for (const candidate of VITE_CONFIG_CANDIDATES) {
505
- const full = join$1(cwd, candidate);
506
- if (existsSync(full)) {
507
- return full;
508
- }
509
- }
510
- return void 0;
511
- };
512
- const patchOrCreateViteConfig = (cwd, framework, logger) => {
513
- const viteConfigPath = findExistingViteConfig(cwd);
514
- if (viteConfigPath === void 0) {
515
- if (framework === "sveltekit" || framework === "nuxt" || framework === "astro") {
516
- logger.info(`no Vite config found — ${framework} wires Lunora through its server entry (see next steps)`);
517
- return { code: 0, files: [], target: cwd };
518
- }
519
- return createMinimalViteConfig(cwd, logger);
520
- }
521
- return patchExistingViteConfig(viteConfigPath, cwd, logger);
522
- };
523
- const runInPlaceInit = (cwd, logger) => {
524
- const detection = detectFramework(cwd);
525
- const viteResult = patchOrCreateViteConfig(cwd, detection.framework, logger);
526
- if (viteResult.code !== 0) {
527
- return viteResult;
528
- }
529
- const scaffolded = scaffoldLunoraDirectory(cwd, logger);
530
- printFrameworkNextSteps(detection, logger);
531
- return { code: 0, files: [...viteResult.files, ...scaffolded], target: cwd };
532
- };
533
- const offerIsInteractive = (options) => options.yes !== true && (options.prompt !== void 0 || (options.interactive ?? isInteractive()));
534
- const maybeOfferExtras = async (options, projectDirectory) => {
535
- const interactive = offerIsInteractive(options);
536
- const apply = async (names) => {
537
- const result = await runAddCommand({
538
- allowUnsafeSource: options.allowUnsafeSource,
539
- cwd: projectDirectory,
540
- from: options.registryFrom,
541
- logger: options.logger,
542
- names: [...names],
543
- ref: options.ref,
544
- source: options.registrySource,
545
- yes: true
546
- });
547
- return result.code === 0;
548
- };
549
- await offerRegistryExtras({
550
- apply,
551
- interactive,
552
- logger: options.logger,
553
- multiSelect: options.prompt?.multiSelect ?? ((message, choices, settings) => promptMultiSelect(message, choices, settings)),
554
- select: options.prompt?.select ?? ((message, choices, settings) => promptSelect(message, choices, settings))
555
- });
556
- };
557
- const scaffoldNewProject = async (options, cwd) => {
558
- const name = options.name ?? "lunora-app";
559
- const templateType = options.templateType ?? "vite";
560
- if (templateType === "next") {
561
- options.logger.warn('template "next" is not yet available — re-run with `-t vite` or `-t standalone`.');
562
- return { code: 1, files: [], target: "" };
563
- }
564
- if (name.includes("/") || name.includes("\\") || name === ".." || name === ".") {
565
- options.logger.error(`init: refusing project name "${name}" — must not contain path separators or be "." / "..".`);
566
- return { code: 1, files: [], target: "" };
567
- }
568
- const target = resolve(cwd, name);
569
- if (existsSync(target)) {
570
- const entries = readdirSync(target);
571
- if (entries.length > 0) {
572
- options.logger.error(`target directory not empty: ${target}`);
573
- return { code: 1, files: [], target };
574
- }
575
- }
576
- if (options.from !== void 0) {
577
- return scaffoldFromLocal(options.from, templateType, target, name, options.logger);
578
- }
579
- if (options.source !== void 0 && options.source.length > 0 && !options.allowUnsafeSource && !isSafeSource(options.source)) {
580
- options.logger.error(
581
- `init: refusing --source ${options.source} — only gh:, github:, or https:// sources are allowed (and may not contain ".."). Re-run with --allow-unsafe-source if you really want this.`
582
- );
583
- return { code: 1, files: [], target };
584
- }
585
- return scaffoldFromRemote({ logger: options.logger, name, ref: options.ref, source: options.source, target, templateType });
586
- };
587
- const runInitCommand = async (options) => {
588
- const cwd = options.cwd ?? process.cwd();
589
- const result = options.inPlace === true ? runInPlaceInit(cwd, options.logger) : await scaffoldNewProject(options, cwd);
590
- if (result.code === 0 && result.target !== "") {
591
- await maybeOfferExtras(options, result.target);
592
- }
593
- if (result.code === 0 && options.ci !== void 0) {
594
- scaffoldCiWorkflow(options.inPlace === true ? cwd : result.target, options.ci, options.logger);
595
- }
596
- return result;
597
- };
598
- const isTemplate = (value) => value === "astro" || value === "next" || value === "nuxt" || value === "standalone" || value === "sveltekit" || value === "tanstack-start-react" || value === "tanstack-start-solid" || value === "vite";
599
- const resolveCiProvider = (raw, logger) => {
600
- if (raw === void 0) {
601
- return void 0;
602
- }
603
- if (isCiProvider(raw)) {
604
- return raw;
605
- }
606
- logger.warn(`init: unknown --ci "${raw}" — expected github | gitlab; skipping CI scaffold.`);
607
- return void 0;
608
- };
609
- const execute = defineHandler(({ argument, cwd, logger, options }) => {
610
- const templateRaw = options.template ?? "vite";
611
- const template = isTemplate(templateRaw) ? templateRaw : "vite";
612
- return runInitCommand({
613
- allowUnsafeSource: options.allowUnsafeSource === true,
614
- cwd,
615
- ci: resolveCiProvider(options.ci, logger),
616
- from: options.from,
617
- inPlace: options.here === true,
618
- interactive: options.interactive === true ? true : void 0,
619
- logger,
620
- name: argument[0],
621
- ref: options.ref,
622
- source: options.source,
623
- templateType: template,
624
- yes: options.yes === true
625
- });
626
- });
627
-
628
- export { execute, isTemplate, resolveTemplateSource, runInitCommand };
1259
+ `,Kr="gh:anolilab/lunora/templates",qr=e=>{const t=e.lastIndexOf(".");return t===-1?!1:Fr.has(e.slice(t))},Gr=/^[a-z0-9_][a-z0-9\-_]*$/u,Yr=/([a-z0-9])([A-Z])/gu,Jr=/[^a-z0-9_]/gu,Xr=e=>{const t=e.replaceAll(Yr,"$1-$2").toLowerCase().replaceAll(Jr,"-").split("-").filter(r=>r.length>0);return t.length>0?t.join("-"):"my-app"},Qr=(e,t)=>e.replaceAll("{{name}}",t),Zr=async(e,t)=>{const r=new Set;for(const a of e)if(_(a)==="package.json")try{const o=JSON.parse(k(a,"utf8"));for(const n of["dependencies","devDependencies"])for(const s of Object.keys(o[n]??{}))U(s)&&r.add(s)}catch{}return ve(r,t)},ea=(e,t,r)=>{let a;try{a=JSON.parse(e)}catch{return e}let o=e;for(const n of["dependencies","devDependencies"])for(const s of Object.keys(a[n]??{})){if(!U(s))continue;const i=r.get(s)??t,l=lt(o,[n,s],i,{formattingOptions:{insertSpaces:!0,tabSize:4}});o=ct(o,l)}return o},ta=["@parcel/watcher","esbuild","lmdb","msgpackr-extract","rs-module-lexer","sharp","unrs-resolver","vue-demi","workerd"],ra=["cpu-features","protobufjs","ssh2"],De="pnpm-workspace.yaml",aa=()=>["# pnpm reads its settings from here (the package.json `pnpm` field is no longer read).","# Pre-approve the toolchain's native build scripts so `pnpm install` runs them","# without the interactive `pnpm approve-builds` step; deny the optional native","# builds a scaffold doesn't need (so no C/C++ toolchain is required).","allowBuilds:",...ta.map(e=>` '${e}': true`),...ra.map(e=>` '${e}': false`),""].join(`
1260
+ `),Be=e=>{const t=p(e,De);m(t)||w(t,aa(),"utf8")},V=e=>{const t=[];for(const r of it(e,{includeDirs:!1,includeFiles:!0}))de(r.path).isSymbolicLink()||t.push(r.path);return t},se="vitejs/vite",ie=(e,t)=>{for(const r of V(e)){const a=p(t,fe(e,r));M(A(a),{recursive:!0}),Ge(r,a)}},je=async(e,t,r)=>{const a=V(e),o=[],n=we(),s=await Zr(a,n);for(const i of a){const l=fe(e,i),c=p(t,l);M(A(c),{recursive:!0});const u=k(i);let h=qr(i)?Qr(u.toString("utf8"),r):void 0;h!==void 0&&_(i)==="package.json"&&(h=ea(h,n,s)),h===void 0?w(c,u):w(c,h,"utf8"),o.push(c)}return o},H=(e,t,r)=>t!==void 0&&t.length>0?t:`${Kr}/${e}#${ye(r)}`,oa=e=>e.includes("..")?!1:e.startsWith("gh:")||e.startsWith("github:")||e.startsWith("https://"),E=(e,t)=>{e.info(`[dry-run] would ${t}`)},Ue=(e,t,r)=>(e.error(`init: the template at ${r} contains no files — nothing was scaffolded. Check the template name, \`--source\` layout and \`--ref\`.`),{code:f.NOT_FOUND,files:[],target:t}),Ve="Template files copied.",J=(e,t,r)=>{y()&&process.stdout.write(`
1261
+ `),e.success(`scaffolded ${String(t.length)} files into ${r}`)},na=(e,t)=>{const{args:r,command:a}=nt(e,t);return`${a} ${r.join(" ")}`},Fe=(e,t)=>{let r=me(e);for(;;){if(t(r))return!0;const a=A(r);if(a===r)return!1;r=a}},sa=e=>{if(m(p(e,De)))return!0;const t=p(e,"package.json");if(!m(t))return!1;try{return JSON.parse(k(t,"utf8")).workspaces!==void 0}catch{return!1}},X=e=>Fe(e,sa),ia=e=>Fe(e,t=>m(p(t,".git"))),la=async(e,t)=>{if(e.yes===!0||!y()||ia(A(t)))return;if(!await Ce(x.git,{badge:v.git,defaultYes:!1})){await Se("Sounds good! You can always run git init manually.");return}if(e.dryRun===!0){E(e.logger,"initialize a git repository");return}const r=e.spawner??be;(await bt("Initializing a git repository…",()=>r({args:["init"],command:"git",cwd:t}))).code===0?await T("git","Initialized an empty git repository."):e.logger.warn("`git init` failed — initialize it yourself later with `git init`.")},ca=async(e,t,r,a)=>{const o=[{code:`cd ./${e}`,lead:"Enter your project directory using"}];t===void 0&&o.push({code:`${r} install`,lead:"Install dependencies with",tail:a?" from the workspace root":void 0}),o.push({code:at(r,"dev"),lead:"Run",tail:" to start the dev server."},{code:"lunora add",lead:"Add features like auth or storage using"});const n=[{code:"https://lunora.sh/docs",lead:"Read the docs at"},{code:"https://lunora.sh/chat",lead:"Stuck? Join the chat at"}];if(y()){await xt(v.next,x.nextHeader,o,n);return}const s=o.map(i=>`${i.lead} ${i.code}${i.tail??""}`);s.push("",...n.map(i=>`${i.lead} ${i.code}${i.tail??""}`)),await T("next",x.nextHeader,s.join(`
1262
+ `))},da=e=>e.yes!==!0&&(e.installPrompt!==void 0||y()),ua=async(e,t)=>{if(!da(e)||X(A(t)))return;const r=rt(e.packageManagerProbe),[a]=r;if(a===void 0)return;if(!await(e.installPrompt?.confirmInstall??(async()=>Ce(x.install,{badge:v.deps,defaultYes:!0})))()){await Se("No problem! Remember to install dependencies after setup.");return}let n=a;if(r.length>1&&(n=e.installPrompt?await e.installPrompt.selectManager(r):await G(x.packageManager,r.map(u=>({label:u,value:u})),{badge:v.deps,default:a})??a),e.dryRun===!0){E(e.logger,`install dependencies with ${n}`);return}n==="pnpm"&&Be(t);const s=e.spawner??be,{args:i,command:l}=he(n);await T("deps",`Installing dependencies with ${n}…`);const c=await s({args:i,command:l,cwd:t});if(c.code!==0){e.logger.warn(`\`${l} install\` exited with code ${String(c.code)} — run it yourself in ${_(t)}/.`);return}return await T("deps",`Dependencies installed with ${n}.`),n},pa=async(e,t,r,a,o,n)=>{const s=p(e,t);if(!m(s))return o.error(`template not found in local source: ${s}`),{code:f.NOT_FOUND,files:[],target:r};const i=await je(s,r,a);return i.length===0?Ue(o,r,s):(n(),J(o,i,r),{code:0,files:i,target:r})},ha=async e=>{const{logger:t,markComplete:r,name:a,ref:o,source:n,target:s,templateType:i}=e,l=ue(p(pe(),"lunora-init-fetch-")),c=p(l,"template");try{const u=n!==void 0&&n.length>0?o:await ft(o,t),h=H(i,n,u);let d,b=[];if(await Le([{label:`${i} template fetched`,run:async()=>{d=await ge(h,{cwd:l,dir:c,force:!0,install:!1,silent:!0})}},{label:`files copied into ${a}/`,run:async()=>{b=await je(c,s,a)}}],{end:Ve,start:"Project initializing…"}),b.length===0)return Ue(t,s,d?.source??h);r();const $=V(c);return y()&&process.stdout.write(`
1263
+ `),t.info(d?.commit?`template: ${d.source} @ ${d.commit} (${String($.length)} files)`:`template: ${d?.source??h} (${String($.length)} files)`),J(t,b,s),{code:0,files:b,target:s}}catch(u){if(u instanceof q)throw u;const{hints:h,message:d}=Zt(u,{ref:ye(o),remote:H(i,n,o),templateType:i});t.error(d);for(const b of h)t.warn(b);return{code:1,files:[],target:s}}finally{O(l,{force:!0,recursive:!0})}},ma=e=>{for(const t of["_gitignore","_npmrc","_gitattributes"]){const r=p(e,t);m(r)&&Ye(r,p(e,`.${t.slice(1)}`))}},fa=async e=>{const{framework:t,logger:r,markComplete:a,name:o,overlayBaseFrom:n,target:s}=e,i=B[t],l=ue(p(pe(),"lunora-vite-base-"));try{let c;if(n!==void 0&&(c=p(n,`template-${i.createViteTemplate}`),!m(c)))return r.error(`create-vite base not found on disk: ${c}`),{code:f.NOT_FOUND,files:[],target:s};const u=async()=>{if(c!==void 0){ie(c,s);return}const d=p(l,"base"),b=await mt(se,"main",r),$=`github:${se}/packages/create-vite/template-${i.createViteTemplate}#${b}`;await ge($,{cwd:l,dir:d,force:!0,install:!1,silent:!0}),ma(d),ie(d,s)};let h=[];return await Le([{label:`create-vite (${i.label}) base ready`,run:u},{label:`Lunora overlay applied (${i.label})`,run:async()=>{h=await Tr({adapter:i,distTag:we(),logger:r,name:o,target:s})}}],{end:Ve,start:"Project initializing…"}),a(),J(r,h,s),{code:0,files:[...V(s)],target:s}}catch(c){if(c instanceof q)throw c;const u=c instanceof Error?c.message:String(c);return r.error(`failed to scaffold the ${i.label} base: ${u}`),{code:1,files:[],target:s}}finally{O(l,{force:!0,recursive:!0})}},z=(e,t,r,a,o)=>(o.error(`init --in-place: could not ${e} ${t}: ${r instanceof Error?r.message:String(r)}`),{code:1,files:[],target:a}),ga=(e,t)=>{const r=p(e,"vite.config.ts");try{w(r,Wr,"utf8")}catch(a){return z("write",r,a,e,t)}return t.success(`created ${r} with lunora() plugin`),{code:0,files:[r],target:e}},va=(e,t,r)=>{let a;try{a=k(e,"utf8")}catch(n){return z("read",e,n,t,r)}const o=Ie(a);if(!o.changed)return r.info(`${e}: ${o.reason??"no changes needed"}`),{code:0,files:[],target:t};try{w(e,o.code,"utf8")}catch(n){return z("write",e,n,t,r)}return r.success(`patched ${e} — added lunora() plugin`),{code:0,files:[e],target:t}},wa=(e,t)=>{const r=p(e,"lunora"),a=p(r,"schema.ts");if(m(a))return t.info(`lunora/ already present — left ${a} untouched`),[];const o=[];try{M(r,{recursive:!0}),w(a,Hr,"utf8"),o.push(a);const n=p(r,"messages.ts");m(n)||(w(n,zr,"utf8"),o.push(n)),t.success(`scaffolded lunora/ (${String(o.length)} file(s))`)}catch(n){const s=n instanceof Error?n.message:String(n);t.error(`init --here: could not scaffold lunora/: ${s}`)}return o},We=e=>e==="sveltekit"||e==="nuxt"||e==="astro",ya=(e,t,r)=>{const{adapter:a,class:o,framework:n}=e;r.info(""),r.info(`detected framework: ${n} (class ${o})`),r.info("next steps:");const s=[a,"@lunora/client","@lunora/runtime","@lunora/server"];We(n)||s.push("@lunora/vite"),r.info(` 1. install the adapter: ${na(t,s)}`),r.info(" 2. run codegen: lunora codegen"),o==="A"?(r.info(" 3. compose one worker: wrap your worker entry with"),r.info(" createWorker({ httpRouter: <your framework SSR handler>, shardDO: ShardDO, ... })"),r.info(` 4. add the provider: mount the ${a} provider in your root layout/route`),r.info(" 5. make a loader live: preloadQuery() in a loader, usePreloadedQuery() in the component"),r.info(" see https://lunora.sh/docs/frameworks/reactive-loaders")):o==="B"?(r.info(" 3. inject Lunora: mount Lunora realtime under /_lunora/* in your server hook"),r.info(` (${n} owns its Cloudflare adapter — Lunora composes into its server entry)`),r.info(` 4. add the provider: mount the ${a} provider in your root layout`),r.info(" 5. read the guide: https://lunora.sh/docs/frameworks/deploy")):(r.info(" 3. add the provider: wrap your app with the LunoraProvider from @lunora/react"),r.info(" 4. read the guide: https://lunora.sh/docs/frameworks/bring-your-framework")),r.info("")},ba=(e,t,r)=>{if(We(t))return r.info(`${t} wires Lunora through its server entry, not a lunora() Vite plugin — leaving the Vite config alone (see next steps)`),{code:0,files:[],target:e};const a=Oe(e);return a===void 0?ga(e,r):va(a,e,r)},xa=(e,t)=>{const r=Vt(e),a=ba(e,r.framework,t);if(a.code!==0)return a;const o=wa(e,t);return ya(r,P(e),t),{code:0,files:[...a.files,...o],target:e}},ka=e=>e.yes!==!0&&(e.prompt!==void 0||(e.interactive??y())),le=async(e,t,r)=>{r.dryRun!==!0&&await ur({apply:a=>st(e,a),detected:ot(e),interactive:t,logger:r.logger,multiSelect:r.lintPrompt??((a,o,n)=>ke(a,o,{...n,badge:v.add}))})},Ca=async(e,t)=>{const r=ka(e),a=e.add===void 0?[]:rr(e.add,s=>{e.logger.warn(s)}),n={applyAll:async s=>{if(s.length===0)return!0;if(e.dryRun===!0)return E(e.logger,`add ${s.map(d=>d.label).join(", ")}`),!0;const i=[],l=y()?{error:d=>{i.push({level:"error",message:d})},info:()=>{},success:()=>{},warn:d=>{i.push({level:"warn",message:d})}}:e.logger,c=s.map(d=>({running:`adding ${d.label}…`,task:()=>It({allowUnsafeSource:e.allowUnsafeSource,cwd:t,from:e.registryFrom,logger:l,names:[...d.names],ref:e.ref,source:e.registrySource,transformManifest:d.transformManifest,yes:!0})})),u=`added ${s.map(d=>d.label).join(", ")}`,h=await kt(v.add,c,u);for(const{level:d,message:b}of i)e.logger[d](b);return h.every(d=>d.code===0)},interactive:r,logger:e.logger,multiSelect:e.prompt?.multiSelect??((s,i,l)=>ke(s,i,{...l,badge:v.add})),preselected:a.length>0?a:void 0,projectName:_(t),resolveAuthUiItem:()=>{let s;try{const i=JSON.parse(k(p(t,"package.json"),"utf8"));s={...i.dependencies,...i.devDependencies}}catch{return"auth-ui-react"}if(!Nt(s))return _t(s)??"auth-ui-react"},select:e.prompt?.select??((s,i,l)=>G(s,i,{...l,badge:v.add})),text:e.prompt?.text??((s,i)=>xe(s,{...i,badge:v.add}))};if(a.length>0){const s=await re(n);return await le(t,r,e),s}return y()&&await yt(x.extras),await re(n),await le(t,r,e),!0},F="react",He=[{description:"React SPA — official create-vite base + the Lunora layer (the default)",label:"React",value:"react"},{description:"Vue SPA — create-vite base + Lunora",label:"Vue",value:"vue"},{description:"Solid SPA — create-vite base + Lunora",label:"Solid",value:"solid"},{description:"Solid 2.0 SPA — the Solid 2 line (@solidjs/web, vite-plugin-solid 3)",label:"Solid 2",value:"solid-v2"},{description:"Svelte SPA — create-vite base + Lunora",label:"Svelte",value:"svelte"},{description:"Next.js (App Router) — OpenNext on Cloudflare + a standalone Lunora worker",label:"Next.js",value:"next"},{description:"TanStack Start (React) — SSR with live-loader routes",label:"TanStack Start · React",value:"tanstack-start-react"},{description:"TanStack Start (Solid)",label:"TanStack Start · Solid",value:"tanstack-start-solid"},{description:"Next.js App Router on Vite (vinext) — composed into the Lunora worker (experimental)",label:"vinext · App Router",value:"vinext"},{description:"Next.js Pages Router on Vite (vinext) — composed into one worker (experimental)",label:"vinext · Pages Router",value:"vinext-pages"},{description:"React Router (v7, framework mode) — SSR composed into the Lunora worker",label:"React Router",value:"react-router"},{description:"Astro (islands) — single-worker, Lunora composed into the adapter worker",label:"Astro",value:"astro"},{description:"AnalogJS (Angular) — single-worker, Lunora mounted in Nitro",label:"Analog",value:"analog"},{description:"Nuxt (Vue) — single-worker, Lunora mounted in Nitro",label:"Nuxt",value:"nuxt"},{description:"SvelteKit — single-worker, Lunora composed into the adapter worker",label:"SvelteKit",value:"sveltekit"},{description:"React Native (Expo) — an iOS/Android/web app + a Lunora worker backend",label:"React Native · Expo",value:"expo"},{description:"Worker only — no frontend",label:"Standalone",value:"standalone"}],ze=Object.keys(B).join("|"),Ke=He.filter(e=>!j(e.value)).map(e=>e.value),qe=Ke.join("|"),Sa=e=>j(e)?{framework:e,kind:"overlay"}:{kind:"template",templateType:e},La=async e=>e.vite!==void 0?{framework:e.vite,kind:"overlay"}:e.templateType!==void 0?{kind:"template",templateType:e.templateType}:!y()||e.yes===!0?{framework:F,kind:"overlay"}:Sa(await G(x.framework,He,{badge:v.tmpl,default:F})??F),Ma=e=>{if(y()||e.yes===!0)return;const t=[];if(e.name===void 0&&t.push("a project name (`lunora init <name>`)"),e.templateType===void 0&&e.vite===void 0&&t.push(`a framework — \`--vite <${ze}>\` for an SPA, or \`-t <${qe}>\` for a bespoke template`),t.length!==0)return`lunora init can't prompt in a non-interactive terminal — provide ${t.join(" and ")}, or pass --yes to accept the defaults.`},Aa=async(e,t,r,a,o)=>j(t)?await Pe({isLocal:e.overlayBaseFrom!==void 0,logger:e.logger})?(M(a,{recursive:!0}),fa({framework:t,logger:e.logger,markComplete:o,name:r,overlayBaseFrom:e.overlayBaseFrom,target:a})):{code:1,files:[],target:a}:(e.logger.error(`init: unknown framework "${t}". Supported overlays: ${Object.keys(B).join(", ")}.`),{code:f.USAGE,files:[],target:a}),Ea=async(e,t,r,a,o)=>e.from!==void 0?await pa(e.from,t,a,r,e.logger,o):e.source!==void 0&&e.source.length>0&&!e.allowUnsafeSource&&!oa(e.source)?(e.logger.error(`init: refusing --source ${e.source} — only gh:, github:, or https:// sources are allowed (and may not contain ".."). Re-run with --allow-unsafe-source if you really want this.`),{code:f.USAGE,files:[],target:a}):await Pe({isLocal:!1,logger:e.logger,source:H(t,e.source,e.ref)})?ha({logger:e.logger,markComplete:o,name:r,ref:e.ref,source:e.source,target:a,templateType:t}):{code:1,files:[],target:a},Na=(e,t)=>{if(X(t))return;let r;try{r=P(e)}catch{return}r==="pnpm"&&Be(e)},_a=async(e,t,r)=>{await wt("realtime backend on Cloudflare Workers + Durable Objects");const a=Ma(e);if(a!==void 0)return e.logger.error(a),{code:f.USAGE,files:[],target:""};const o=Br(),n=e.name??await xe(x.name,{badge:v.dir,default:o,placeholder:o}),s=await La(e),i=n.trim();if(i.length===0)return e.logger.error("init: refusing an empty project name — pass a directory name (e.g. `lunora init my-app`)."),{code:f.USAGE,files:[],target:""};if(i.includes("/")||i.includes("\\")||i===".."||i===".")return e.logger.error(`init: refusing project name "${i}" — must not contain path separators or be "." / "..".`),{code:f.USAGE,files:[],target:""};if(!Gr.test(i))return e.logger.error(`init: refusing project name "${i}" — a Cloudflare Worker name must be lowercase letters, digits, "-" or "_" (starting with a letter, digit or "_"), and wrangler rejects anything else. Try \`${Xr(i)}\`.`),{code:f.USAGE,files:[],target:""};const l=me(t,i),c=de(l,{throwIfNoEntry:!1});if(c?.isSymbolicLink()===!0)return e.logger.error(`init: refusing to scaffold into "${l}" — it is a symlink. Remove it, or scaffold into a different directory name.`),{code:f.CONFLICT,files:[],target:l};const u=c!==void 0;if(u&&ce(l).length>0)return e.logger.error(`target directory not empty: ${l}`),{code:f.CONFLICT,files:[],target:l};if(e.dryRun===!0){const d=s.kind==="overlay"?`the ${s.framework} create-vite overlay`:`the ${s.templateType} template`;return E(e.logger,`scaffold ${d} into ${l}`),{code:0,files:[],target:l}}r.record(l,u);const h=s.kind==="overlay"?await Aa(e,s.framework,i,l,r.complete):await Ea(e,s.templateType,i,l,r.complete);return h.code===0&&Na(l,t),h},W=(e,t)=>{const{target:r,targetPreExisted:a}=e;if(!(r===void 0||!m(r))){if(a===!0)for(const o of ce(r))O(p(r,o),{force:!0,recursive:!0});else O(r,{force:!0,recursive:!0});t.info(`removed the partially-created project at ${r}`)}},Ia=async(e,t,r)=>e.inPlace!==!0?_a(e,t,r):e.dryRun===!0?(E(e.logger,`configure Lunora into ${t}`),{code:0,files:[],target:t}):xa(t,e.logger),$a=async(e,t,r)=>{const a=await Ca(e,t.target),o=e.inPlace===!0?void 0:await ua(e,t.target);if(e.inPlace!==!0){await la(e,t.target);const n=o??P(t.target);await ca(_(t.target),o,n,X(r)),await er(e.logger)}return a},Ra=(e,t,r)=>{if(t.code!==0||e.ci===void 0)return;if(e.dryRun===!0){E(e.logger,`scaffold a ${e.ci} CI deploy pipeline`);return}const a=e.inPlace===!0?r:t.target;try{const o=P(a);jt(a,e.ci,o,e.logger)}catch{e.logger.warn(`--ci ${e.ci}: could not detect a package manager for this project — skipped the CI pipeline.`)}},Oa=async e=>{const t=e.cwd??process.cwd(),r={};let a;try{a=await Ia(e,t,{complete:()=>{r.target=void 0},record:(o,n)=>{r.target=o,r.targetPreExisted=n}}),a.code===0&&a.target!==""?(r.target=void 0,await $a(e,a,t)||(a={...a,code:1})):a.code!==0&&W(r,e.logger)}catch(o){if(o instanceof q)return W(r,e.logger),process.stdout.write("\n ✖ Setup cancelled — run `lunora init` again whenever you're ready. 🌙\n"),{code:130,files:[],target:""};throw W(r,e.logger),o}return Ra(e,a,t),a},Ta=e=>typeof e=="string"&&Ke.includes(e),Pa=(e,t)=>{if(e!==void 0){if(Dt(e))return e;t.warn(`init: unknown --ci "${e}" — expected github | gitlab; skipping CI scaffold.`)}},Da=e=>e===void 0?{}:Ta(e)?{templateType:e}:j(e)?{vite:e}:{error:`init: unknown --template "${e}" — expected a bespoke template (${qe}) or an overlay framework (${ze}).`},no=ut(({argument:e,cwd:t,logger:r,options:a})=>{const o=Da(a.template);return"error"in o?(r.error(o.error),{code:f.USAGE}):Oa({add:a.add,allowUnsafeSource:a.allowUnsafeSource===!0,cwd:t,ci:Pa(a.ci,r),dryRun:a.dryRun===!0,from:a.from,inPlace:a.here===!0,interactive:a.interactive===!0?!0:void 0,logger:r,name:e[0],ref:a.ref,source:a.source,templateType:o.templateType,vite:a.vite??o.vite,yes:a.yes===!0})});export{He as FRAMEWORK_CHOICES,no as execute,Ta as isTemplate,Da as resolveTemplateFlag,H as resolveTemplateSource,Oa as runInitCommand};