@lunora/cli 1.0.0-alpha.225 → 1.0.0-alpha.227
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.mjs +1 -1
- package/dist/index.d.mts +20 -1
- package/dist/index.d.ts +20 -1
- package/dist/index.mjs +1 -1
- package/dist/packem_chunks/handler.mjs +1 -1
- package/dist/packem_chunks/handler10.mjs +3 -4
- package/dist/packem_chunks/handler14.mjs +1 -1
- package/dist/packem_chunks/handler15.mjs +1 -1
- package/dist/packem_chunks/handler16.mjs +1 -1
- package/dist/packem_chunks/handler17.mjs +1 -1
- package/dist/packem_chunks/handler19.mjs +1 -1
- package/dist/packem_chunks/handler20.mjs +1 -1
- package/dist/packem_chunks/handler22.mjs +3 -3
- package/dist/packem_chunks/handler26.mjs +1 -1
- package/dist/packem_chunks/handler6.mjs +1 -1
- package/dist/packem_chunks/handler9.mjs +1 -1
- package/dist/packem_chunks/planDevCommand.mjs +5 -5
- package/dist/packem_chunks/runCodegenCommand.mjs +2 -2
- package/dist/packem_chunks/runDeployCommand.mjs +2 -2
- package/dist/packem_chunks/runInitCommand.mjs +47 -45
- package/dist/packem_chunks/runMigrateGenerateCommand.mjs +7 -7
- package/dist/packem_chunks/runResetCommand.mjs +1 -1
- package/dist/packem_shared/{COMMANDS-BbQ3-hLn.mjs → COMMANDS-rRB9TbDL.mjs} +1 -1
- package/dist/packem_shared/{DEFAULT_IMPORT_BATCH_SIZE-BPQYMEmV.mjs → DEFAULT_IMPORT_BATCH_SIZE-BMH-ZXl5.mjs} +1 -1
- package/dist/packem_shared/cli-DIb5Ay4K.mjs +3 -0
- package/dist/packem_shared/{commands-BadIgWaM.mjs → commands-I18aR_DJ.mjs} +1 -1
- package/dist/packem_shared/{import-DuHtoh4_.mjs → import-Dqd1MOOv.mjs} +10 -10
- package/dist/packem_shared/insertSchemaExtension-DuiV6cba.mjs +8 -0
- package/dist/packem_shared/platform-diagnostics-Cn2g6Jh-.mjs +4 -0
- package/dist/packem_shared/{runAddCommand-DE1b920I.mjs → runAddCommand-BXea8slz.mjs} +1 -1
- package/dist/packem_shared/{storage-B08EcdWm.mjs → storage-B0ixDDxG.mjs} +1 -1
- package/package.json +11 -11
- package/dist/packem_shared/advisory-gate-Cl8IEFIj.mjs +0 -1
- package/dist/packem_shared/cli-DOBnG22n.mjs +0 -3
- package/dist/packem_shared/insertSchemaExtension-DY4pA8wE.mjs +0 -8
- package/dist/packem_shared/platform-diagnostics-D0YzAdXm.mjs +0 -4
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import{existsSync as m,mkdirSync as L,writeFileSync as g,readFileSync as x,readdirSync as ie,rmSync as R,lstatSync as le,mkdtempSync as ce,copyFileSync as
|
|
1
|
+
import{existsSync as m,mkdirSync as L,writeFileSync as g,readFileSync as x,readdirSync as ie,rmSync as R,lstatSync as le,mkdtempSync as ce,copyFileSync as Ke,renameSync as qe}from"node:fs";import{tmpdir as de}from"node:os";import{installArgsFor as ue,execArgsFor as Ge,detectFramework as Ye,isInteractive as v,LUNA_ART as Je,LUNA_NAME as Xe,LUNA_SIGNOFF as Qe,BADGES as f,paintAnswer as Ze,detectPackageManager as H,detectInstalledManagers as et,runScriptCommand as tt,detectLintTools as rt,addArgsFor as at,applyLintIgnores as ot}from"@lunora/config";import{walkSync as nt}from"@visulima/fs";import{join as p,dirname as M,basename as N,resolve as pe,relative as he}from"@visulima/path";import{downloadTemplate as me}from"giget";import{modify as st,applyEdits as it}from"jsonc-parser";import{join as z,dirname as lt}from"node:path";import{d as ct}from"../packem_shared/command-DwC11Cwe.mjs";import dt from"magic-string";import{Project as ut,SyntaxKind as w}from"ts-morph";import{P as K}from"../packem_shared/prompt-cancelled-C8Sj7OqI.mjs";import{l as fe,m as pt,n as ge,o as ve,b as ht}from"../packem_shared/resolve-B9ReA3FV.mjs";import{defaultSpawner as we}from"../packem_shared/createRecordingSpawner-DJlNacZ6.mjs";import{d as mt,e as ft,f as gt,a as ye,t as q,g as be,h as vt,b as xe,i as ke,w as wt,j as yt,k as Ce,l as bt}from"../packem_shared/tui-prompts-DzYd2fL3.mjs";import{A as Se,E as Le,p as xt,w as kt,M as Ct,r as St,k as Lt,e as Mt,c as Me,l as Ae,i as At,f as Et}from"../packem_shared/storage-B0ixDDxG.mjs";import{logStep as J}from"../packem_shared/createLogger-hGafwf-3.mjs";import{r as Nt}from"../packem_shared/lint-ignore-report-DKZagpqk.mjs";import _t from"node:dns/promises";import{r as It}from"../packem_shared/commands-I18aR_DJ.mjs";const G={bun:{githubCacheKey:void 0,githubSetupStep:` - uses: oven-sh/setup-bun@v2
|
|
2
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
|
-
|
|
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"}},S=(e,t)=>{const r=Ge(e,"lunora",t);return[r.command,...r.args].join(" ")},X=e=>` - uses: actions/checkout@v4
|
|
4
6
|
${e.githubSetupStep} - uses: actions/setup-node@v4
|
|
5
7
|
with:
|
|
6
8
|
node-version: 22
|
|
7
9
|
${e.githubCacheKey===void 0?"":` cache: ${e.githubCacheKey}
|
|
8
|
-
`} - run: ${e.installCmd}
|
|
10
|
+
`} - run: ${e.installCmd}`,$t=e=>{const t=G[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
|
|
9
11
|
|
|
10
12
|
on:
|
|
11
13
|
push:
|
|
@@ -47,7 +49,7 @@ ${X(t)}
|
|
|
47
49
|
steps:
|
|
48
50
|
${X(t)}
|
|
49
51
|
- run: ${S(e,["deploy","--preview"])}
|
|
50
|
-
`},
|
|
52
|
+
`},Rt=e=>{const t=G[e],r=[...t.gitlabProvisionScript,t.installCmd].map(a=>` - ${a}`).join(`
|
|
51
53
|
`);return`stages:
|
|
52
54
|
- deploy
|
|
53
55
|
|
|
@@ -82,16 +84,16 @@ preview:
|
|
|
82
84
|
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
83
85
|
script:
|
|
84
86
|
- ${S(e,["deploy","--preview"])}
|
|
85
|
-
`},
|
|
87
|
+
`},Ee={github:{file:z(".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)"}},Tt=(e,t)=>e==="github"?$t(t):Rt(t),Ot=e=>e==="github"||e==="gitlab",Pt=(e,t,r,a={})=>{const o=z(e,Ee[t].file);return m(o)&&a.overwrite!==!0?{path:o,skipped:!0,written:!1}:(L(lt(o),{recursive:!0}),g(o,Tt(t,r),"utf8"),{path:o,skipped:!1,written:!0})},Dt=(e,t,r,a,o={})=>{const n=Ee[t];try{const s=Pt(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=ue(r),l=[i.command,...i.args].join(" "),{installCmd:c,lockfile:d}=G[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 ${d} 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:z(e,n.file),skipped:!1,written:!1}}},Bt={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"},jt=e=>{const t=Ye(e);return{...t,adapter:Bt[t.framework]}},$="lunora()",Q='import { lunora } from "@lunora/vite";',Vt=/\blunora\s*\(/u,Ut='"@lunora/vite"',Ft="'@lunora/vite'",Wt=e=>{for(const t of e.getStatements()){if(t.getKind()!==w.ExportAssignment)continue;const r=t.asKindOrThrow(w.ExportAssignment).getExpression();if(r.getKind()!==w.CallExpression)continue;const a=r.asKindOrThrow(w.CallExpression);if(a.getExpression().getText()!=="defineConfig")continue;const o=a.getArguments()[0];if(o?.getKind()===w.ObjectLiteralExpression)return o.asKindOrThrow(w.ObjectLiteralExpression)}},Ht=e=>{for(const t of e.getStatements()){if(t.getKind()!==w.ExportAssignment)continue;const r=t.asKindOrThrow(w.ExportAssignment).getExpression();if(r.getKind()===w.ObjectLiteralExpression)return r.asKindOrThrow(w.ObjectLiteralExpression)}},zt=e=>new ut({compilerOptions:{allowJs:!0},useInMemoryFileSystem:!0}).createSourceFile("vite.config.ts",e,{overwrite:!0}),Kt=(e,t)=>{const r=t.getImportDeclarations().at(-1)?.getEnd()??0;r===0?e.prepend(`${Q}
|
|
86
88
|
`):e.appendLeft(r,`
|
|
87
|
-
${Q}`)},
|
|
88
|
-
`)
|
|
89
|
+
${Q}`)},qt=(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: [${$}] `);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: [${$}],
|
|
90
|
+
`);return}const a=r.getDescendantsOfKind(w.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,$);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(),`${$}, `)},Ne=e=>{if(Vt.test(e))return{changed:!1,code:e,reason:"lunora plugin already present"};const t=zt(e),r=Wt(t)??Ht(t);if(r===void 0)return{changed:!1,code:e,reason:"could not locate a Vite config plugins array to patch"};const a=new dt(e);!e.includes(Ut)&&!e.includes(Ft)&&Kt(a,t);const o=qt(a,r);return o!==void 0?{changed:!1,code:e,reason:o}:{changed:!0,code:a.toString()}},Gt=/enotfound|eai_again|econnrefused|etimedout|network|fetch failed|getaddrinfo/u,Yt=/404|not found|could not find|no such/u,Jt=(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 Yt.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}`}:Gt.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(v()){await ft(f[e],t,r);return}if(process.stdout.write(`
|
|
89
91
|
`),r===void 0||r===""){J(e,t);return}const a=r.split(`
|
|
90
|
-
`).map(o=>
|
|
92
|
+
`).map(o=>Ze(o)).join(`
|
|
91
93
|
`);J(e,`${t}
|
|
92
|
-
${a}`)},
|
|
93
|
-
${
|
|
94
|
-
${
|
|
94
|
+
${a}`)},Xt=async e=>{if(v()){await mt();return}e.info(`
|
|
95
|
+
${Je}
|
|
96
|
+
${Xe}: ${Qe}`)},_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"}],Z=_e.map(e=>e.value),Qt=e=>e==="email"?Le:e,Zt=(e,t)=>{const r=[];for(const a of e.split(",").map(o=>o.trim()).filter(Boolean))Z.includes(a)?r.includes(a)||r.push(a):t(`init: unknown --add feature "${a}" — expected ${Z.join(" | ")}; skipping.`);return r},Ie=e=>e.resolveAuthUiItem===void 0?"auth-ui-react":e.resolveAuthUiItem(),er=async e=>{const t=await Mt(e.select),r=await Me(e.text,e.projectName);return{label:"auth",names:[t],transformManifest:a=>Ae(a,r)}},tr=async e=>{const t=await e.text(Ct,{placeholder:"you@yourdomain.com"}),r=St(t,a=>{e.logger.warn(a)});return{label:"email",names:[Le],transformManifest:r===void 0?void 0:a=>Lt(a,r)}},rr=async(e,t)=>{const r=Ie(e);if(r===void 0){e.logger.error(`init: ${Se}`);return}if(t)return{label:"auth-ui",names:[r]};const a=await Me(e.text,e.projectName);return{label:"auth-ui",names:[r],transformManifest:o=>Ae(o,a)}},ar=async e=>{const t=await xt(e.text,e.projectName);return{label:"storage",names:["storage"],transformManifest:r=>kt(r,t)}},or=(e,t)=>{const r=[];let a=!1;for(const o of t){if(o!=="auth-ui"){r.push({label:o,names:[Qt(o)]});continue}const n=Ie(e);if(n===void 0){e.logger.error(`init: ${Se}`),a=!0;continue}r.push({label:o,names:[n]})}return{plans:r,refused:a}},nr={auth:er,"auth-ui":async(e,t)=>rr(e,t.includes("auth")),email:tr,storage:ar},ee=async e=>{if(e.preselected!==void 0&&e.preselected.length>0){const{plans:a,refused:o}=or(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=nr[a],n=o?await o(e,t):{label:a,names:[a]};n!==void 0&&r.push(n)}return await e.applyAll(r),!0},sr=[{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"}],ir="Which linter/formatter do you use? We'll tell it to skip Lunora's generated files.",lr=async e=>{const t=e.interactive?await e.multiSelect(ir,sr,{defaults:e.detected}):[...e.detected];if(t.length===0)return[];const r=e.apply(t);return Nt(r,e.logger),r},_="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",E=`/* The welcome page is a full-bleed starter — reset the browser's default
|
|
95
97
|
body margin/padding so it sits flush; everything else is scoped under
|
|
96
98
|
.lunora-welcome (collision-safe). */
|
|
97
99
|
body {
|
|
@@ -196,7 +198,7 @@ body {
|
|
|
196
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); }
|
|
197
199
|
|
|
198
200
|
@media (prefers-reduced-motion: reduce) { .lunora-welcome * { transition: none !important; } }
|
|
199
|
-
`,
|
|
201
|
+
`,cr=`import { useEffect, useState } from "react";
|
|
200
202
|
|
|
201
203
|
type Theme = "dark" | "light";
|
|
202
204
|
|
|
@@ -357,7 +359,7 @@ export default function App() {
|
|
|
357
359
|
</div>
|
|
358
360
|
);
|
|
359
361
|
}
|
|
360
|
-
`,
|
|
362
|
+
`,dr=`<script setup lang="ts">
|
|
361
363
|
import { onMounted, ref } from "vue";
|
|
362
364
|
|
|
363
365
|
// Default to "dark" for a stable first paint, then reconcile to the OS
|
|
@@ -513,7 +515,7 @@ const toggle = (): void => {
|
|
|
513
515
|
</div>
|
|
514
516
|
</div>
|
|
515
517
|
</template>
|
|
516
|
-
`,
|
|
518
|
+
`,ur=`import { createSignal, onMount } from "solid-js";
|
|
517
519
|
|
|
518
520
|
export default function App() {
|
|
519
521
|
// Default to "dark" for a stable first paint, then reconcile to the OS
|
|
@@ -672,7 +674,7 @@ export default function App() {
|
|
|
672
674
|
</div>
|
|
673
675
|
);
|
|
674
676
|
}
|
|
675
|
-
`,
|
|
677
|
+
`,pr=`<script lang="ts">
|
|
676
678
|
import { onMount } from "svelte";
|
|
677
679
|
|
|
678
680
|
// Default to "dark" for a stable first paint, then reconcile to the OS
|
|
@@ -830,7 +832,7 @@ export default function App() {
|
|
|
830
832
|
<div class="lw-foot">Running on Lunora · Vite + Svelte</div>
|
|
831
833
|
</div>
|
|
832
834
|
</div>
|
|
833
|
-
`,
|
|
835
|
+
`,hr=`import "./style.css";
|
|
834
836
|
|
|
835
837
|
import { LunoraClient } from "lunorash/client";
|
|
836
838
|
|
|
@@ -994,10 +996,10 @@ toggleButton.addEventListener("click", () => {
|
|
|
994
996
|
// Live demo: the message count of a demo channel re-renders on every delta.
|
|
995
997
|
const count = document.querySelector<HTMLSpanElement>("#lw-count")!;
|
|
996
998
|
|
|
997
|
-
client.
|
|
999
|
+
client.subscribe(api.messages.list, { channelId: "channel:demo" }, (result) => {
|
|
998
1000
|
count.textContent = String(result.messages.length);
|
|
999
1001
|
});
|
|
1000
|
-
`,
|
|
1002
|
+
`,O="const url = (import.meta.env.VITE_LUNORA_URL as string | undefined) ?? globalThis.location.origin;",mr=`import "./index.css";
|
|
1001
1003
|
|
|
1002
1004
|
import { LunoraProvider } from "@lunora/react";
|
|
1003
1005
|
import { LunoraClient } from "lunorash/client";
|
|
@@ -1009,7 +1011,7 @@ import App from "./App.tsx";
|
|
|
1009
1011
|
// \`@lunora/vite\` runs the Worker on the same origin as Vite, so default to
|
|
1010
1012
|
// \`location.origin\`. Point \`VITE_LUNORA_URL\` at a deployed Worker to develop
|
|
1011
1013
|
// the client against production data.
|
|
1012
|
-
${
|
|
1014
|
+
${O}
|
|
1013
1015
|
const client = new LunoraClient({ url });
|
|
1014
1016
|
|
|
1015
1017
|
const root = document.getElementById("root");
|
|
@@ -1025,7 +1027,7 @@ createRoot(root).render(
|
|
|
1025
1027
|
</LunoraProvider>
|
|
1026
1028
|
</StrictMode>,
|
|
1027
1029
|
);
|
|
1028
|
-
`,
|
|
1030
|
+
`,fr=`import "./style.css";
|
|
1029
1031
|
|
|
1030
1032
|
import { createLunora } from "@lunora/vue";
|
|
1031
1033
|
import { LunoraClient } from "lunorash/client";
|
|
@@ -1034,9 +1036,9 @@ import { createApp } from "vue";
|
|
|
1034
1036
|
import App from "./App.vue";
|
|
1035
1037
|
|
|
1036
1038
|
// Provide one LunoraClient at the app root via the Vue plugin form.
|
|
1037
|
-
${
|
|
1039
|
+
${O}
|
|
1038
1040
|
createApp(App).use(createLunora(new LunoraClient({ url }))).mount("#app");
|
|
1039
|
-
`,
|
|
1041
|
+
`,gr=`import "./index.css";
|
|
1040
1042
|
|
|
1041
1043
|
import { LunoraProvider } from "@lunora/solid";
|
|
1042
1044
|
import { LunoraClient } from "lunorash/client";
|
|
@@ -1044,7 +1046,7 @@ import { render } from "solid-js/web";
|
|
|
1044
1046
|
|
|
1045
1047
|
import App from "./App";
|
|
1046
1048
|
|
|
1047
|
-
${
|
|
1049
|
+
${O}
|
|
1048
1050
|
const client = new LunoraClient({ url });
|
|
1049
1051
|
const root = document.getElementById("root");
|
|
1050
1052
|
|
|
@@ -1056,18 +1058,18 @@ render(
|
|
|
1056
1058
|
),
|
|
1057
1059
|
root!,
|
|
1058
1060
|
);
|
|
1059
|
-
`,
|
|
1061
|
+
`,vr=`<script lang="ts">
|
|
1060
1062
|
import { setLunoraClient } from "@lunora/svelte";
|
|
1061
1063
|
import { LunoraClient } from "lunorash/client";
|
|
1062
1064
|
|
|
1063
1065
|
import App from "./App.svelte";
|
|
1064
1066
|
|
|
1065
|
-
${
|
|
1067
|
+
${O}
|
|
1066
1068
|
setLunoraClient(new LunoraClient({ url }));
|
|
1067
1069
|
<\/script>
|
|
1068
1070
|
|
|
1069
1071
|
<App />
|
|
1070
|
-
`,
|
|
1072
|
+
`,wr=`import "./app.css";
|
|
1071
1073
|
|
|
1072
1074
|
import { mount } from "svelte";
|
|
1073
1075
|
|
|
@@ -1077,7 +1079,7 @@ import Root from "./Root.svelte";
|
|
|
1077
1079
|
const app = mount(Root, { target: document.getElementById("app")! });
|
|
1078
1080
|
|
|
1079
1081
|
export default app;
|
|
1080
|
-
`,P={react:{adapter:"@lunora/react",createViteTemplate:"react-ts",files:[{contents:
|
|
1082
|
+
`,P={react:{adapter:"@lunora/react",createViteTemplate:"react-ts",files:[{contents:mr,path:"src/main.tsx"},{contents:cr,path:"src/App.tsx"},{contents:E,path:"src/index.css"}],label:"React"},solid:{adapter:"@lunora/solid",createViteTemplate:"solid-ts",files:[{contents:gr,path:"src/index.tsx"},{contents:ur,path:"src/App.tsx"},{contents:E,path:"src/index.css"}],label:"Solid"},svelte:{adapter:"@lunora/svelte",createViteTemplate:"svelte-ts",files:[{contents:vr,path:"src/Root.svelte"},{contents:wr,path:"src/main.ts"},{contents:pr,path:"src/App.svelte"},{contents:E,path:"src/app.css"}],label:"Svelte"},vanilla:{adapter:"lunorash/client",createViteTemplate:"vanilla-ts",files:[{contents:hr,path:"src/main.ts"},{contents:E,path:"src/style.css"}],label:"Vanilla"},vue:{adapter:"@lunora/vue",createViteTemplate:"vue-ts",files:[{contents:fr,path:"src/main.ts"},{contents:dr,path:"src/App.vue"},{contents:E,path:"src/style.css"}],label:"Vue"}},D=e=>Object.hasOwn(P,e),yr=`/**
|
|
1081
1083
|
* Rate-limit schema extension + plugin.
|
|
1082
1084
|
*
|
|
1083
1085
|
* Defines the \`ratelimit_buckets\` table used by \`createDbStore\` for durable,
|
|
@@ -1129,7 +1131,7 @@ export const ratelimit = definePlugin("ratelimit", {
|
|
|
1129
1131
|
}),
|
|
1130
1132
|
middleware,
|
|
1131
1133
|
});
|
|
1132
|
-
`,
|
|
1134
|
+
`,br=`import { ratelimit } from "./ratelimit/schema.js";
|
|
1133
1135
|
import { defineSchema, defineTable, v } from "lunorash/server";
|
|
1134
1136
|
|
|
1135
1137
|
export default defineSchema({
|
|
@@ -1140,7 +1142,7 @@ export default defineSchema({
|
|
|
1140
1142
|
.shardBy("channelId")
|
|
1141
1143
|
.index("by_channel", ["channelId"]),
|
|
1142
1144
|
}).extend(ratelimit.extension);
|
|
1143
|
-
`,
|
|
1145
|
+
`,xr=`import { rateLimit } from "lunorash/ratelimit";
|
|
1144
1146
|
|
|
1145
1147
|
import { makeRateLimiter } from "./ratelimit/schema.js";
|
|
1146
1148
|
import type { MutationCtx } from "#lunora/_generated/server.js";
|
|
@@ -1182,7 +1184,7 @@ export const send = mutation
|
|
|
1182
1184
|
|
|
1183
1185
|
return { channelId: args.channelId, id, text: args.text };
|
|
1184
1186
|
});
|
|
1185
|
-
`,
|
|
1187
|
+
`,kr=`import type { ShardNamespaceLike } from "lunorash/runtime";
|
|
1186
1188
|
|
|
1187
1189
|
import { defineApp } from "../lunora/_generated/app.js";
|
|
1188
1190
|
|
|
@@ -1196,7 +1198,7 @@ const app = defineApp<Env>()
|
|
|
1196
1198
|
|
|
1197
1199
|
export const ShardDO = app.ShardDO;
|
|
1198
1200
|
export default app;
|
|
1199
|
-
`,
|
|
1201
|
+
`,Cr=`{
|
|
1200
1202
|
"$schema": "node_modules/wrangler/config-schema.json",
|
|
1201
1203
|
"name": "__NAME__",
|
|
1202
1204
|
"main": "src/server.ts",
|
|
@@ -1208,47 +1210,47 @@ export default app;
|
|
|
1208
1210
|
"migrations": [{ "tag": "v1", "new_sqlite_classes": ["ShardDO"] }],
|
|
1209
1211
|
"observability": { "enabled": true, "head_sampling_rate": 1 },
|
|
1210
1212
|
}
|
|
1211
|
-
`,te=[".wrangler",".env",".env.*","!.env.example",".dev.vars",".dev.vars.*","!.dev.vars.example",".lunora/",".lunora-cache","lunora/_generated"],
|
|
1213
|
+
`,te=[".wrangler",".env",".env.*","!.env.example",".dev.vars",".dev.vars.*","!.dev.vars.example",".lunora/",".lunora-cache","lunora/_generated"],Sr=`# Lunora endpoint for the browser client.
|
|
1212
1214
|
# Vite statically replaces \`import.meta.env.VITE_LUNORA_URL\` at \`vite dev\` / build.
|
|
1213
1215
|
# Leave it unset to use the page origin; set it to point at a deployed Worker:
|
|
1214
1216
|
#
|
|
1215
1217
|
# VITE_LUNORA_URL=https://my-app.example.workers.dev
|
|
1216
|
-
`,
|
|
1218
|
+
`,Lr={"@cloudflare/workers-types":"^4.20260611.1",wrangler:"^4.100.0"},k=(e,t,r,a)=>{const o=p(e,t);L(M(o),{recursive:!0}),g(o,r,"utf8"),a.push(o)},Mr=/\r?\n/,Ar=e=>{const t=p(e,".gitignore"),r=m(t)?x(t,"utf8"):"",a=new Set(r.split(Mr)),o=te.filter(i=>!a.has(i));if(o.length===0)return;const n=o.some(i=>!i.startsWith("!"))?[...o.filter(i=>!i.startsWith("!")),...te.filter(i=>i.startsWith("!"))]:o,s=r.length>0&&!r.endsWith(`
|
|
1217
1219
|
`)?`
|
|
1218
1220
|
`:"";g(t,`${r}${s}
|
|
1219
1221
|
# Lunora
|
|
1220
1222
|
${n.join(`
|
|
1221
1223
|
`)}
|
|
1222
|
-
`,"utf8")},B=e=>e==="lunorash"||e.startsWith("@lunora/"),
|
|
1223
|
-
`,"utf8")},
|
|
1224
|
+
`,"utf8")},B=e=>e==="lunorash"||e.startsWith("@lunora/"),Er=(e,t,r,a)=>B(e)?a.get(e)??r:t,C=(e,t,r)=>({...e,[t]:r}),re=(e,t,r)=>Object.fromEntries(Object.entries(e).map(([a,o])=>[a,Er(a,o,t,r)])),Nr=async(e,t,r,a)=>{const o=p(e,"package.json"),n=JSON.parse(x(o,"utf8"));let s=C(n.dependencies??{},"lunorash",a);s=C(s,"@lunora/ratelimit",a),r.adapter.startsWith("@lunora/")&&(s=C(s,r.adapter,a));for(const[d,h]of Object.entries(r.extraDependencies??{}))s=C(s,d,h);let i=C(n.devDependencies??{},"@lunora/vite",a);i=C(i,"@lunora/studio",a);for(const[d,h]of Object.entries(Lr))i=C(i,d,h);const l=[...Object.keys(s),...Object.keys(i)].filter(d=>B(d)),c=await fe(l,a);n.name=t,n.imports={...n.imports,"#lunora/*":"./lunora/*"},n.dependencies=re(s,a,c),n.devDependencies=re(i,a,c),n.scripts={...n.scripts,codegen:"lunora codegen",deploy:"vite build && lunora deploy"},g(o,`${JSON.stringify(n,void 0,4)}
|
|
1225
|
+
`,"utf8")},_r=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],$e=e=>_r.map(t=>p(e,t)).find(t=>m(t)),Ir=(e,t)=>{const r=$e(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=Ne(x(r,"utf8"));a.changed&&g(r,a.code,"utf8")},$r=async e=>{const{adapter:t,distTag:r,logger:a,name:o,target:n}=e,s=[];k(n,p("lunora","ratelimit","schema.ts"),yr,s),k(n,p("lunora","schema.ts"),br,s),k(n,p("lunora","messages.ts"),xr,s),k(n,p("src","server.ts"),kr,s),k(n,"wrangler.jsonc",Cr.replaceAll("__NAME__",o),s),k(n,".env.example",Sr,s);for(const i of t.files)k(n,i.path,i.contents,s);return Ir(n,a),await Nr(n,o,t,r),Ar(n),s},Rr=["lunar","silver","silent","waning","waxing","crescent","cosmic","stellar","orbital","gibbous","twilight","midnight","shimmering","drifting","weightless"],Tr=["moon","tide","crater","comet","eclipse","halo","orbit","nebula","voyager","lander","rover","beacon","harbor","meadow","fox"],ae=e=>e[Math.floor(Math.random()*e.length)],Or=()=>`${ae(Rr)}-${ae(Tr)}`,Pr=async()=>_t.lookup("github.com").then(()=>!0,()=>!1),Dr=/^(?:gh|github):([^/]+)\/([^#/]+)(?:\/[^#]*)?(?:#(.+))?$/,Re=e=>{const t=Dr.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}},Br=async e=>{const t=Re(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}},Te=async e=>e.isLocal||!(e.source===void 0||Re(e.source)!==void 0)?!0:await Pr()?e.source!==void 0&&await Br(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),b={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?"},jr=new Set([".gitignore",".html",".js",".json",".jsonc",".md",".mjs",".ts",".tsx"]),Vr=`import { defineConfig } from "vite";
|
|
1224
1226
|
import { lunora } from "@lunora/vite";
|
|
1225
1227
|
|
|
1226
1228
|
export default defineConfig({ plugins: [lunora()] });
|
|
1227
|
-
`,
|
|
1229
|
+
`,Ur=`import { defineSchema, defineTable, v } from "@lunora/server";
|
|
1228
1230
|
|
|
1229
1231
|
export default defineSchema({
|
|
1230
1232
|
messages: defineTable({
|
|
1231
|
-
channelId: v.
|
|
1233
|
+
channelId: v.string(),
|
|
1232
1234
|
text: v.string(),
|
|
1233
1235
|
})
|
|
1234
1236
|
.shardBy("channelId")
|
|
1235
1237
|
.index("by_channel", ["channelId"]),
|
|
1236
1238
|
});
|
|
1237
|
-
`,
|
|
1239
|
+
`,Fr=`import { mutation, query, v } from "./_generated/server";
|
|
1238
1240
|
|
|
1239
1241
|
export const list = query
|
|
1240
|
-
.input({ channelId: v.
|
|
1242
|
+
.input({ channelId: v.string(), limit: v.optional(v.number()) })
|
|
1241
1243
|
.query(async ({ args }) => {
|
|
1242
1244
|
return { channelId: args.channelId, limit: args.limit ?? 50, messages: [] };
|
|
1243
1245
|
});
|
|
1244
1246
|
|
|
1245
1247
|
export const send = mutation
|
|
1246
|
-
.input({ channelId: v.
|
|
1248
|
+
.input({ channelId: v.string(), text: v.string() })
|
|
1247
1249
|
.mutation(async ({ args }) => {
|
|
1248
1250
|
return { channelId: args.channelId, text: args.text };
|
|
1249
1251
|
});
|
|
1250
|
-
`,
|
|
1251
|
-
`),j=e=>{const t=[];for(const r of
|
|
1252
|
-
`),e.success(`scaffolded ${String(t.length)} files into ${r}`)},
|
|
1253
|
-
`))},
|
|
1254
|
-
`),t.info(u?.commit?`template: ${u.source} @ ${u.commit} (${String(I.length)} files)`:`template: ${u?.source??h} (${String(I.length)} files)`),Y(t,y,s),{code:0,files:y,target:s}}catch(d){if(d instanceof K)throw d;const{hints:h,message:u}=Kt(d,{ref:ve(o),remote:F(i,n,o),templateType:i});t.error(u);for(const y of h)t.warn(y);return{code:1,files:[],target:s}}finally{R(l,{force:!0,recursive:!0})}},sa=e=>{for(const t of["_gitignore","_npmrc","_gitattributes"]){const r=p(e,t);m(r)&&He(r,p(e,`.${t.slice(1)}`))}},ia=async e=>{const{framework:t,logger:r,markComplete:a,name:o,overlayBaseFrom:n,target:s}=e,i=P[t],l=ce(p(de(),"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:1,files:[],target:s};const d=async()=>{if(c!==void 0){ne(c,s);return}const u=p(l,"base"),y=await ct(oe,"main",r),I=`github:${oe}/packages/create-vite/template-${i.createViteTemplate}#${y}`;await me(I,{cwd:l,dir:u,force:!0,install:!1,silent:!0}),sa(u),ne(u,s)};let h=[];return await Ce([{label:`create-vite (${i.label}) base ready`,run:d},{label:`Lunora overlay applied (${i.label})`,run:async()=>{h=await Ar({adapter:i,distTag:ge(),logger:r,name:o,target:s})}}],{end:Pe,start:"Project initializing…"}),a(),Y(r,h,s),{code:0,files:[...j(s)],target:s}}catch(c){if(c instanceof K)throw c;const d=c instanceof Error?c.message:String(c);return r.error(`failed to scaffold the ${i.label} base: ${d}`),{code:1,files:[],target:s}}finally{R(l,{force:!0,recursive:!0})}},W=(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}),la=(e,t)=>{const r=p(e,"vite.config.ts");try{g(r,Tr,"utf8")}catch(a){return W("write",r,a,e,t)}return t.success(`created ${r} with lunora() plugin`),{code:0,files:[r],target:e}},ca=(e,t,r)=>{let a;try{a=x(e,"utf8")}catch(n){return W("read",e,n,t,r)}const o=Ee(a);if(!o.changed)return r.info(`${e}: ${o.reason??"no changes needed"}`),{code:0,files:[],target:t};try{g(e,o.code,"utf8")}catch(n){return W("write",e,n,t,r)}return r.success(`patched ${e} — added lunora() plugin`),{code:0,files:[e],target:t}},da=(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{L(r,{recursive:!0}),g(a,Pr,"utf8"),o.push(a);const n=p(r,"messages.ts");m(n)||(g(n,Dr,"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},ua=(e,t,r)=>{const{adapter:a,class:o,framework:n}=e;r.info(""),r.info(`detected framework: ${n} (class ${o})`),r.info("next steps:"),r.info(` 1. install the adapter: ${Xr(t,[a,"@lunora/client","@lunora/runtime","@lunora/server"])}`),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("")},pa=(e,t,r)=>{if(t==="sveltekit"||t==="nuxt"||t==="astro")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=_e(e);return a===void 0?la(e,r):ca(a,e,r)},ha=(e,t)=>{const r=Tt(e),a=pa(e,r.framework,t);if(a.code!==0)return a;const o=da(e,t);return ua(r,H(e),t),{code:0,files:[...a.files,...o],target:e}},ma=e=>e.yes!==!0&&(e.prompt!==void 0||(e.interactive??v())),se=async(e,t,r)=>{r.dryRun!==!0&&await ar({apply:a=>tt(e,a),detected:Ze(e),interactive:t,logger:r.logger,multiSelect:r.lintPrompt??((a,o,n)=>be(a,o,{...n,badge:f.add}))})},fa=async(e,t)=>{const r=ma(e),a=e.add===void 0?[]:Yt(e.add,s=>{e.logger.warn(s)}),n={applyAll:async s=>{if(s.length===0)return!0;if(e.dryRun===!0)return A(e.logger,`add ${s.map(u=>u.label).join(", ")}`),!0;const i=[],l=v()?{error:u=>{i.push({level:"error",message:u})},info:()=>{},success:()=>{},warn:u=>{i.push({level:"warn",message:u})}}:e.logger,c=s.map(u=>({running:`adding ${u.label}…`,task:()=>At({allowUnsafeSource:e.allowUnsafeSource,cwd:t,from:e.registryFrom,logger:l,names:[...u.names],ref:e.ref,source:e.registrySource,transformManifest:u.transformManifest,yes:!0})})),d=`added ${s.map(u=>u.label).join(", ")}`,h=await vt(f.add,c,d);for(const{level:u,message:y}of i)e.logger[u](y);return h.every(u=>u.code===0)},interactive:r,logger:e.logger,multiSelect:e.prompt?.multiSelect??((s,i,l)=>be(s,i,{...l,badge:f.add})),preselected:a.length>0?a:void 0,projectName:N(t),resolveAuthUiItem:()=>{try{const s=JSON.parse(x(p(t,"package.json"),"utf8"));return St({...s.dependencies,...s.devDependencies})??"auth-ui-react"}catch{return"auth-ui-react"}},select:e.prompt?.select??((s,i,l)=>q(s,i,{...l,badge:f.add})),text:e.prompt?.text??((s,i)=>ye(s,{...i,badge:f.add}))};if(a.length>0){const s=await ee(n);return await se(t,r,e),s}return v()&&await mt(b.extras),await ee(n),await se(t,r,e),!0},V="react",je=[{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"}],Ve=Object.keys(P).join("|"),Ue=je.filter(e=>!D(e.value)).map(e=>e.value),Fe=Ue.join("|"),ga=e=>D(e)?{framework:e,kind:"overlay"}:{kind:"template",templateType:e},va=async e=>e.vite!==void 0?{framework:e.vite,kind:"overlay"}:e.templateType!==void 0?{kind:"template",templateType:e.templateType}:!v()||e.yes===!0?{framework:V,kind:"overlay"}:ga(await q(b.framework,je,{badge:f.tmpl,default:V})??V),wa=e=>{if(v()||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 <${Ve}>\` for an SPA, or \`-t <${Fe}>\` 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.`},ya=async(e,t,r,a,o)=>D(t)?await $e({isLocal:e.overlayBaseFrom!==void 0,logger:e.logger})?(L(a,{recursive:!0}),ia({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(P).join(", ")}.`),{code:1,files:[],target:a}),ba=async(e,t,r,a,o)=>e.from!==void 0?await oa(e.from,t,a,r,e.logger,o):e.source!==void 0&&e.source.length>0&&!e.allowUnsafeSource&&!Jr(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:1,files:[],target:a}):await $e({isLocal:!1,logger:e.logger,source:F(t,e.source,e.ref)})?na({logger:e.logger,markComplete:o,name:r,ref:e.ref,source:e.source,target:a,templateType:t}):{code:1,files:[],target:a},xa=async(e,t,r)=>{await ht("realtime backend on Cloudflare Workers + Durable Objects");const a=wa(e);if(a!==void 0)return e.logger.error(a),{code:1,files:[],target:""};const o=_r(),n=e.name??await ye(b.name,{badge:f.dir,default:o,placeholder:o}),s=await va(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:1,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:1,files:[],target:""};if(!Vr.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 \`${Wr(i)}\`.`),{code:1,files:[],target:""};const l=pe(t,i),c=le(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:1,files:[],target:l};const d=c!==void 0;if(d&&ie(l).length>0)return e.logger.error(`target directory not empty: ${l}`),{code:1,files:[],target:l};if(e.dryRun===!0){const h=s.kind==="overlay"?`the ${s.framework} create-vite overlay`:`the ${s.templateType} template`;return A(e.logger,`scaffold ${h} into ${l}`),{code:0,files:[],target:l}}return r.record(l,d),s.kind==="overlay"?ya(e,s.framework,i,l,r.complete):ba(e,s.templateType,i,l,r.complete)},U=(e,t)=>{const{target:r,targetPreExisted:a}=e;if(!(r===void 0||!m(r))){if(a===!0)for(const o of ie(r))R(p(r,o),{force:!0,recursive:!0});else R(r,{force:!0,recursive:!0});t.info(`removed the partially-created project at ${r}`)}},ka=async(e,t,r)=>e.inPlace!==!0?xa(e,t,r):e.dryRun===!0?(A(e.logger,`configure Lunora into ${t}`),{code:0,files:[],target:t}):ha(t,e.logger),Ca=async(e,t,r)=>{const a=await fa(e,t.target),o=e.inPlace===!0?void 0:await aa(e,t.target);if(e.inPlace!==!0){await ea(e,t.target);const n=o??H(t.target);await ta(N(t.target),o,n,Be(r)),await qt(e.logger)}return a},Sa=(e,t,r)=>{if(t.code!==0||e.ci===void 0)return;if(e.dryRun===!0){A(e.logger,`scaffold a ${e.ci} CI deploy pipeline`);return}const a=e.inPlace===!0?r:t.target;try{const o=H(a);Rt(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.`)}},La=async e=>{const t=e.cwd??process.cwd(),r={};let a;try{a=await ka(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 Ca(e,a,t)||(a={...a,code:1})):a.code!==0&&U(r,e.logger)}catch(o){if(o instanceof K)return U(r,e.logger),process.stdout.write("\n ✖ Setup cancelled — run `lunora init` again whenever you're ready. 🌙\n"),{code:130,files:[],target:""};throw U(r,e.logger),o}return Sa(e,a,t),a},Ma=e=>typeof e=="string"&&Ue.includes(e),Aa=(e,t)=>{if(e!==void 0){if(It(e))return e;t.warn(`init: unknown --ci "${e}" — expected github | gitlab; skipping CI scaffold.`)}},Ea=e=>e===void 0?{}:Ma(e)?{templateType:e}:D(e)?{vite:e}:{error:`init: unknown --template "${e}" — expected a bespoke template (${Fe}) or an overlay framework (${Ve}).`},Ya=st(({argument:e,cwd:t,logger:r,options:a})=>{const o=Ea(a.template);return"error"in o?(r.error(o.error),{code:1}):La({add:a.add,allowUnsafeSource:a.allowUnsafeSource===!0,cwd:t,ci:Aa(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{Ya as execute,Ma as isTemplate,Ea as resolveTemplateFlag,F as resolveTemplateSource,La as runInitCommand};
|
|
1252
|
+
`,Wr="gh:anolilab/lunora/templates",Hr=e=>{const t=e.lastIndexOf(".");return t===-1?!1:jr.has(e.slice(t))},zr=/^[a-z0-9_][a-z0-9\-_]*$/u,Kr=/([a-z0-9])([A-Z])/gu,qr=/[^a-z0-9_]/gu,Gr=e=>{const t=e.replaceAll(Kr,"$1-$2").toLowerCase().replaceAll(qr,"-").split("-").filter(r=>r.length>0);return t.length>0?t.join("-"):"my-app"},Yr=(e,t)=>e.replaceAll("{{name}}",t),Jr=async(e,t)=>{const r=new Set;for(const a of e)if(N(a)==="package.json")try{const o=JSON.parse(x(a,"utf8"));for(const n of["dependencies","devDependencies"])for(const s of Object.keys(o[n]??{}))B(s)&&r.add(s)}catch{}return fe(r,t)},Xr=(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(!B(s))continue;const i=r.get(s)??t,l=st(o,[n,s],i,{formattingOptions:{insertSpaces:!0,tabSize:4}});o=it(o,l)}return o},Qr=["@parcel/watcher","esbuild","lmdb","msgpackr-extract","rs-module-lexer","sharp","unrs-resolver","vue-demi","workerd"],Zr=["cpu-features","protobufjs","ssh2"],Oe="pnpm-workspace.yaml",ea=()=>["# 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:",...Qr.map(e=>` '${e}': true`),...Zr.map(e=>` '${e}': false`),""].join(`
|
|
1253
|
+
`),j=e=>{const t=[];for(const r of nt(e,{includeDirs:!1,includeFiles:!0}))le(r.path).isSymbolicLink()||t.push(r.path);return t},oe="vitejs/vite",ne=(e,t)=>{for(const r of j(e)){const a=p(t,he(e,r));L(M(a),{recursive:!0}),Ke(r,a)}},Pe=async(e,t,r)=>{const a=j(e),o=[],n=ge(),s=await Jr(a,n);for(const i of a){const l=he(e,i),c=p(t,l);L(M(c),{recursive:!0});const d=x(i);let h=Hr(i)?Yr(d.toString("utf8"),r):void 0;h!==void 0&&N(i)==="package.json"&&(h=Xr(h,n,s)),h===void 0?g(c,d):g(c,h,"utf8"),o.push(c)}return o},F=(e,t,r)=>t!==void 0&&t.length>0?t:`${Wr}/${e}#${ve(r)}`,ta=e=>e.includes("..")?!1:e.startsWith("gh:")||e.startsWith("github:")||e.startsWith("https://"),A=(e,t)=>{e.info(`[dry-run] would ${t}`)},De=(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:1,files:[],target:t}),Be="Template files copied.",Y=(e,t,r)=>{v()&&process.stdout.write(`
|
|
1254
|
+
`),e.success(`scaffolded ${String(t.length)} files into ${r}`)},ra=(e,t)=>{const{args:r,command:a}=at(e,t);return`${a} ${r.join(" ")}`},je=(e,t)=>{let r=pe(e);for(;;){if(t(r))return!0;const a=M(r);if(a===r)return!1;r=a}},aa=e=>{if(m(p(e,Oe)))return!0;const t=p(e,"package.json");if(!m(t))return!1;try{return JSON.parse(x(t,"utf8")).workspaces!==void 0}catch{return!1}},Ve=e=>je(e,aa),oa=e=>je(e,t=>m(p(t,".git"))),na=async(e,t)=>{if(e.yes===!0||!v()||oa(M(t)))return;if(!await xe(b.git,{badge:f.git,defaultYes:!1})){await ke("Sounds good! You can always run git init manually.");return}if(e.dryRun===!0){A(e.logger,"initialize a git repository");return}const r=e.spawner??we;(await wt("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`.")},sa=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:tt(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(v()){await yt(f.next,b.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",b.nextHeader,s.join(`
|
|
1255
|
+
`))},ia=e=>e.yes!==!0&&(e.installPrompt!==void 0||v()),la=async(e,t)=>{if(!ia(e)||Ve(M(t)))return;const r=et(e.packageManagerProbe),[a]=r;if(a===void 0)return;if(!await(e.installPrompt?.confirmInstall??(async()=>xe(b.install,{badge:f.deps,defaultYes:!0})))()){await ke("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 q(b.packageManager,r.map(d=>({label:d,value:d})),{badge:f.deps,default:a})??a),e.dryRun===!0){A(e.logger,`install dependencies with ${n}`);return}if(n==="pnpm"){const d=p(t,Oe);m(d)||g(d,ea(),"utf8")}const s=e.spawner??we,{args:i,command:l}=ue(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 ${N(t)}/.`);return}return await T("deps",`Dependencies installed with ${n}.`),n},ca=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:1,files:[],target:r};const i=await Pe(s,r,a);return i.length===0?De(o,r,s):(n(),Y(o,i,r),{code:0,files:i,target:r})},da=async e=>{const{logger:t,markComplete:r,name:a,ref:o,source:n,target:s,templateType:i}=e,l=ce(p(de(),"lunora-init-fetch-")),c=p(l,"template");try{const d=n!==void 0&&n.length>0?o:await ht(o,t),h=F(i,n,d);let u,y=[];if(await Ce([{label:`${i} template fetched`,run:async()=>{u=await me(h,{cwd:l,dir:c,force:!0,install:!1,silent:!0})}},{label:`files copied into ${a}/`,run:async()=>{y=await Pe(c,s,a)}}],{end:Be,start:"Project initializing…"}),y.length===0)return De(t,s,u?.source??h);r();const I=j(c);return v()&&process.stdout.write(`
|
|
1256
|
+
`),t.info(u?.commit?`template: ${u.source} @ ${u.commit} (${String(I.length)} files)`:`template: ${u?.source??h} (${String(I.length)} files)`),Y(t,y,s),{code:0,files:y,target:s}}catch(d){if(d instanceof K)throw d;const{hints:h,message:u}=Jt(d,{ref:ve(o),remote:F(i,n,o),templateType:i});t.error(u);for(const y of h)t.warn(y);return{code:1,files:[],target:s}}finally{R(l,{force:!0,recursive:!0})}},ua=e=>{for(const t of["_gitignore","_npmrc","_gitattributes"]){const r=p(e,t);m(r)&&qe(r,p(e,`.${t.slice(1)}`))}},pa=async e=>{const{framework:t,logger:r,markComplete:a,name:o,overlayBaseFrom:n,target:s}=e,i=P[t],l=ce(p(de(),"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:1,files:[],target:s};const d=async()=>{if(c!==void 0){ne(c,s);return}const u=p(l,"base"),y=await pt(oe,"main",r),I=`github:${oe}/packages/create-vite/template-${i.createViteTemplate}#${y}`;await me(I,{cwd:l,dir:u,force:!0,install:!1,silent:!0}),ua(u),ne(u,s)};let h=[];return await Ce([{label:`create-vite (${i.label}) base ready`,run:d},{label:`Lunora overlay applied (${i.label})`,run:async()=>{h=await $r({adapter:i,distTag:ge(),logger:r,name:o,target:s})}}],{end:Be,start:"Project initializing…"}),a(),Y(r,h,s),{code:0,files:[...j(s)],target:s}}catch(c){if(c instanceof K)throw c;const d=c instanceof Error?c.message:String(c);return r.error(`failed to scaffold the ${i.label} base: ${d}`),{code:1,files:[],target:s}}finally{R(l,{force:!0,recursive:!0})}},W=(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}),ha=(e,t)=>{const r=p(e,"vite.config.ts");try{g(r,Vr,"utf8")}catch(a){return W("write",r,a,e,t)}return t.success(`created ${r} with lunora() plugin`),{code:0,files:[r],target:e}},ma=(e,t,r)=>{let a;try{a=x(e,"utf8")}catch(n){return W("read",e,n,t,r)}const o=Ne(a);if(!o.changed)return r.info(`${e}: ${o.reason??"no changes needed"}`),{code:0,files:[],target:t};try{g(e,o.code,"utf8")}catch(n){return W("write",e,n,t,r)}return r.success(`patched ${e} — added lunora() plugin`),{code:0,files:[e],target:t}},fa=(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{L(r,{recursive:!0}),g(a,Ur,"utf8"),o.push(a);const n=p(r,"messages.ts");m(n)||(g(n,Fr,"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},Ue=e=>e==="sveltekit"||e==="nuxt"||e==="astro",ga=(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"];Ue(n)||s.push("@lunora/vite"),r.info(` 1. install the adapter: ${ra(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("")},va=(e,t,r)=>{if(Ue(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=$e(e);return a===void 0?ha(e,r):ma(a,e,r)},wa=(e,t)=>{const r=jt(e),a=va(e,r.framework,t);if(a.code!==0)return a;const o=fa(e,t);return ga(r,H(e),t),{code:0,files:[...a.files,...o],target:e}},ya=e=>e.yes!==!0&&(e.prompt!==void 0||(e.interactive??v())),se=async(e,t,r)=>{r.dryRun!==!0&&await lr({apply:a=>ot(e,a),detected:rt(e),interactive:t,logger:r.logger,multiSelect:r.lintPrompt??((a,o,n)=>be(a,o,{...n,badge:f.add}))})},ba=async(e,t)=>{const r=ya(e),a=e.add===void 0?[]:Zt(e.add,s=>{e.logger.warn(s)}),n={applyAll:async s=>{if(s.length===0)return!0;if(e.dryRun===!0)return A(e.logger,`add ${s.map(u=>u.label).join(", ")}`),!0;const i=[],l=v()?{error:u=>{i.push({level:"error",message:u})},info:()=>{},success:()=>{},warn:u=>{i.push({level:"warn",message:u})}}:e.logger,c=s.map(u=>({running:`adding ${u.label}…`,task:()=>It({allowUnsafeSource:e.allowUnsafeSource,cwd:t,from:e.registryFrom,logger:l,names:[...u.names],ref:e.ref,source:e.registrySource,transformManifest:u.transformManifest,yes:!0})})),d=`added ${s.map(u=>u.label).join(", ")}`,h=await bt(f.add,c,d);for(const{level:u,message:y}of i)e.logger[u](y);return h.every(u=>u.code===0)},interactive:r,logger:e.logger,multiSelect:e.prompt?.multiSelect??((s,i,l)=>be(s,i,{...l,badge:f.add})),preselected:a.length>0?a:void 0,projectName:N(t),resolveAuthUiItem:()=>{let s;try{const i=JSON.parse(x(p(t,"package.json"),"utf8"));s={...i.dependencies,...i.devDependencies}}catch{return"auth-ui-react"}if(!At(s))return Et(s)??"auth-ui-react"},select:e.prompt?.select??((s,i,l)=>q(s,i,{...l,badge:f.add})),text:e.prompt?.text??((s,i)=>ye(s,{...i,badge:f.add}))};if(a.length>0){const s=await ee(n);return await se(t,r,e),s}return v()&&await vt(b.extras),await ee(n),await se(t,r,e),!0},V="react",Fe=[{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"}],We=Object.keys(P).join("|"),He=Fe.filter(e=>!D(e.value)).map(e=>e.value),ze=He.join("|"),xa=e=>D(e)?{framework:e,kind:"overlay"}:{kind:"template",templateType:e},ka=async e=>e.vite!==void 0?{framework:e.vite,kind:"overlay"}:e.templateType!==void 0?{kind:"template",templateType:e.templateType}:!v()||e.yes===!0?{framework:V,kind:"overlay"}:xa(await q(b.framework,Fe,{badge:f.tmpl,default:V})??V),Ca=e=>{if(v()||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 <${We}>\` for an SPA, or \`-t <${ze}>\` 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.`},Sa=async(e,t,r,a,o)=>D(t)?await Te({isLocal:e.overlayBaseFrom!==void 0,logger:e.logger})?(L(a,{recursive:!0}),pa({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(P).join(", ")}.`),{code:1,files:[],target:a}),La=async(e,t,r,a,o)=>e.from!==void 0?await ca(e.from,t,a,r,e.logger,o):e.source!==void 0&&e.source.length>0&&!e.allowUnsafeSource&&!ta(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:1,files:[],target:a}):await Te({isLocal:!1,logger:e.logger,source:F(t,e.source,e.ref)})?da({logger:e.logger,markComplete:o,name:r,ref:e.ref,source:e.source,target:a,templateType:t}):{code:1,files:[],target:a},Ma=async(e,t,r)=>{await gt("realtime backend on Cloudflare Workers + Durable Objects");const a=Ca(e);if(a!==void 0)return e.logger.error(a),{code:1,files:[],target:""};const o=Or(),n=e.name??await ye(b.name,{badge:f.dir,default:o,placeholder:o}),s=await ka(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:1,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:1,files:[],target:""};if(!zr.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 \`${Gr(i)}\`.`),{code:1,files:[],target:""};const l=pe(t,i),c=le(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:1,files:[],target:l};const d=c!==void 0;if(d&&ie(l).length>0)return e.logger.error(`target directory not empty: ${l}`),{code:1,files:[],target:l};if(e.dryRun===!0){const h=s.kind==="overlay"?`the ${s.framework} create-vite overlay`:`the ${s.templateType} template`;return A(e.logger,`scaffold ${h} into ${l}`),{code:0,files:[],target:l}}return r.record(l,d),s.kind==="overlay"?Sa(e,s.framework,i,l,r.complete):La(e,s.templateType,i,l,r.complete)},U=(e,t)=>{const{target:r,targetPreExisted:a}=e;if(!(r===void 0||!m(r))){if(a===!0)for(const o of ie(r))R(p(r,o),{force:!0,recursive:!0});else R(r,{force:!0,recursive:!0});t.info(`removed the partially-created project at ${r}`)}},Aa=async(e,t,r)=>e.inPlace!==!0?Ma(e,t,r):e.dryRun===!0?(A(e.logger,`configure Lunora into ${t}`),{code:0,files:[],target:t}):wa(t,e.logger),Ea=async(e,t,r)=>{const a=await ba(e,t.target),o=e.inPlace===!0?void 0:await la(e,t.target);if(e.inPlace!==!0){await na(e,t.target);const n=o??H(t.target);await sa(N(t.target),o,n,Ve(r)),await Xt(e.logger)}return a},Na=(e,t,r)=>{if(t.code!==0||e.ci===void 0)return;if(e.dryRun===!0){A(e.logger,`scaffold a ${e.ci} CI deploy pipeline`);return}const a=e.inPlace===!0?r:t.target;try{const o=H(a);Dt(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.`)}},_a=async e=>{const t=e.cwd??process.cwd(),r={};let a;try{a=await Aa(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 Ea(e,a,t)||(a={...a,code:1})):a.code!==0&&U(r,e.logger)}catch(o){if(o instanceof K)return U(r,e.logger),process.stdout.write("\n ✖ Setup cancelled — run `lunora init` again whenever you're ready. 🌙\n"),{code:130,files:[],target:""};throw U(r,e.logger),o}return Na(e,a,t),a},Ia=e=>typeof e=="string"&&He.includes(e),$a=(e,t)=>{if(e!==void 0){if(Ot(e))return e;t.warn(`init: unknown --ci "${e}" — expected github | gitlab; skipping CI scaffold.`)}},Ra=e=>e===void 0?{}:Ia(e)?{templateType:e}:D(e)?{vite:e}:{error:`init: unknown --template "${e}" — expected a bespoke template (${ze}) or an overlay framework (${We}).`},eo=ct(({argument:e,cwd:t,logger:r,options:a})=>{const o=Ra(a.template);return"error"in o?(r.error(o.error),{code:1}):_a({add:a.add,allowUnsafeSource:a.allowUnsafeSource===!0,cwd:t,ci:$a(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{eo as execute,Ia as isTemplate,Ra as resolveTemplateFlag,F as resolveTemplateSource,_a as runInitCommand};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import{existsSync as
|
|
2
|
-
`,"utf8"),e.logger.success(`wrote ${
|
|
3
|
-
`:
|
|
4
|
-
${i}`;const
|
|
1
|
+
import{existsSync as f,mkdirSync as _,writeFileSync as b,mkdtempSync as N,rmSync as M,readFileSync as k}from"node:fs";import{tmpdir as x}from"node:os";import{discoverSchema as U,readPackageDependencies as C,discoverMigrations as F}from"@lunora/codegen";import{isInteractive as O,promptSelect as P,promptText as D}from"@lunora/config";import{LunoraError as $}from"@lunora/errors";import{join as c}from"@visulima/path";import{Project as v}from"ts-morph";import{r as z,t as j}from"../packem_shared/admin-token-VdUnvnKW.mjs";import{n as q,r as L}from"../packem_shared/admin-url-BhF5ufg1.mjs";import{d as B}from"../packem_shared/command-DwC11Cwe.mjs";import{diffSnapshots as H,renderMigrationFile as G}from"../packem_shared/diffSnapshots-DtC5Cs4Z.mjs";import{r as W}from"../packem_shared/resolve-target-BRvw8Pf7.mjs";import J from"../packem_shared/schemaIrToSnapshot-VpPguG3W.mjs";import{readAndLogBody as V}from"./runRpcCommand.mjs";import{runExportCommand as Z}from"../packem_shared/runExportCommand-Dq-SpjAe.mjs";import{r as K}from"../packem_shared/import-Dqd1MOOv.mjs";const m="__lunora_reproject__",X=e=>{if(!e.startsWith(m))return;const r=e.slice(m.length);return r===""?void 0:r},Q=".snapshot.json",A=/[^\da-z]+/gu,E=(e,r)=>{let a=0,t=e.length;for(;a<t&&e[a]===r;)a+=1;for(;t>a&&e[t-1]===r;)t-=1;return e.slice(a,t)},Y=e=>{const r=E(e.toLowerCase().replaceAll(A,"_"),"_");return r===""?"auto":r},ee=e=>{const r=(a,t=2)=>a.toString().padStart(t,"0");return`${String(e.getUTCFullYear())}${r(e.getUTCMonth()+1)}${r(e.getUTCDate())}${r(e.getUTCHours())}${r(e.getUTCMinutes())}${r(e.getUTCSeconds())}`},re=e=>{if(f(e))try{const r=k(e,"utf8"),a=JSON.parse(r);if(a.version!==1)throw new $("INTERNAL",`unsupported snapshot version: ${a.version}`);return a}catch(r){const a=r instanceof Error?r.message:String(r);throw new $("INTERNAL",`failed to read ${e}: ${a}`,{cause:r})}},te=e=>{const r=e.cwd??process.cwd(),a=c(r,"lunora","schema.ts");if(!f(a))return e.logger.error(`schema not found: ${a} — run \`vis generate lunora-table --name=<name>\` to create one`),{code:1,empty:!0,migrationFile:""};const t=new v({skipAddingFilesFromTsConfig:!0}),n=U(t,a),s=J(n),o=c(r,"lunora","migrations"),i=c(o,Q);let l;try{l=re(i)}catch(h){return e.logger.error(h instanceof Error?h.message:String(h)),{code:1,empty:!0,migrationFile:""}}const d=H(l,s);if(d.empty)return e.logger.info("no schema changes detected — snapshot is already up to date"),{code:0,empty:!0,migrationFile:""};const p=(e.now??(()=>new Date))(),w=Y(e.name??"auto"),y=`${ee(p)}_${w}.sql`,g=c(o,y);_(o,{recursive:!0});const R=G(w,d,p.toISOString());return b(g,R,"utf8"),b(i,`${JSON.stringify(s,void 0,4)}
|
|
2
|
+
`,"utf8"),e.logger.success(`wrote ${g}`),d.unsupported.length>0&&e.logger.warn(`${String(d.unsupported.length)} unsupported diff(s) — see the comment block in ${y} and write the SQL manually`),{code:0,empty:!1,migrationFile:g}},ae="migrations.ts",S=/^[A-Za-z_]\w*$/u,ne=new Set(["await","break","case","catch","class","const","continue","debugger","default","delete","do","else","enum","export","extends","false","finally","for","function","if","implements","import","in","instanceof","interface","let","new","null","package","private","protected","public","return","static","super","switch","this","throw","true","try","typeof","var","void","while","with","yield"]),T=/^import\s*\{\s*defineMigration\s*\}\s*from\s*["'](?:@lunora\/server|lunorash\/server)["'][^\n]*$/mu,oe=e=>`import { defineMigration } from "${C(e)?.has("lunorash")??!1?"lunorash/server":"@lunora/server"}";`,ie="__lunora_admin__:runMigration",se="__lunora_admin__:migrationStatus",ce="/_lunora/migrate",le=e=>E(e.trim().toLowerCase().replaceAll(A,"-"),"-"),de=e=>e.split("-").filter(r=>r.length>0).map((r,a)=>a===0?r:r.charAt(0).toUpperCase()+r.slice(1)).join(""),ue=e=>{const r=c(e,"lunora","schema.ts");if(!f(r))return[];try{const a=new v({skipAddingFilesFromTsConfig:!0});return U(a,r).tables.map(t=>t.name)}catch{return[]}},me=async e=>e.length>0?P("Which table does this migration iterate?",e.map(r=>({label:r,value:r}))):D("Target table for the migration: "),fe=async(e,r)=>{if(r.table!==void 0)return r.table;const a=r.promptTable??(O()?me:void 0);if(a===void 0){r.logger.error("migrate create requires a target table when not running interactively — re-run with --table <table>");return}const n=(await a(ue(e)))?.trim();if(n===void 0||n===""){r.logger.error("no table selected — re-run with --table <table>");return}return n},ge=async e=>{const r=e.cwd??process.cwd(),a=le(e.name);if(a==="")return e.logger.error(`invalid migration name: "${e.name}" — must contain at least one alphanumeric character`),{code:1,file:""};const t=de(a);if(!S.test(t)||ne.has(t))return e.logger.error(`invalid migration name: "${e.name}" derives the export \`${t}\`, which is not a valid identifier — pick a name that starts with a letter and isn't a reserved word`),{code:1,file:""};const n=await fe(r,e);if(n===void 0)return{code:1,file:""};if(!S.test(n))return e.logger.error(`invalid table: "${n}" — must be a valid identifier ([A-Za-z_][A-Za-z0-9_]*)`),{code:1,file:""};const s=c(r,"lunora"),o=c(s,ae);let i=f(o)?k(o,"utf8"):"";if(i.includes(`id: "${a}"`)||new RegExp(String.raw`\bexport const ${t}\b`,"u").test(i))return e.logger.error(`a migration with id "${a}" (export \`${t}\`) already exists in ${o}`),{code:1,file:""};const l=oe(r);i.trim()===""?i=`${l}
|
|
3
|
+
`:T.test(i)?i=i.replace(T,l):i=`${l}
|
|
4
|
+
${i}`;const d=`export const ${t} = defineMigration({
|
|
5
5
|
id: "${a}",
|
|
6
6
|
table: "${n}",
|
|
7
7
|
up: (document) => document,
|
|
8
|
-
});`;return
|
|
8
|
+
});`;return _(s,{recursive:!0}),b(o,`${i.trimEnd()}
|
|
9
9
|
|
|
10
|
-
${
|
|
11
|
-
`,"utf8"),e.logger.success(`scaffolded migration "${a}" in ${o}`),{code:0,file:o}},
|
|
10
|
+
${d}
|
|
11
|
+
`,"utf8"),e.logger.success(`scaffolded migration "${a}" in ${o}`),{code:0,file:o}},he=(e,r)=>{const a=new v({skipAddingFilesFromTsConfig:!0});return F(a,c(e,"lunora")).find(n=>n.id===r)?.table},be=(e,r)=>{const a=X(r.id);if(a!==void 0)return a;if(r.id.startsWith(m)){r.logger.error(`"${r.id}" names no table — use ${m}<table>`);return}let t;try{t=he(e,r.id)}catch(n){r.logger.error(n instanceof Error?n.message:String(n));return}if(t===void 0){r.logger.error(`migration "${r.id}" not found under lunora/ — declare it with defineMigration({ id: "${r.id}", ... })`);return}if(t===""){r.logger.error(`migration "${r.id}" must declare \`table\` as a static string literal`);return}return t},ve=e=>{const r=e.cwd??process.cwd();if(e.prod&&e.url===void 0){e.logger.error("--prod requires an explicit --url (refusing to migrate the implicit localhost worker)");return}const a=be(r,e);if(a===void 0)return;const t=L(e.url,e.logger,e.cwd);if(t===void 0)return;const{token:n}=z({cwd:r,token:e.token,url:t});if(!n){e.logger.error("admin token required — pass --token, set LUNORA_ADMIN_TOKEN, or add it to .dev.vars (local targets only)");return}if((e.subcommand==="up"||e.subcommand==="down")&&j({prod:e.prod,url:t})&&!e.yes){e.logger.error(`migrate ${e.subcommand} runs the migration against ${t}, which is not local. Re-run with --yes to confirm.`);return}const s=e.fetchImpl??globalThis.fetch;if(typeof s!="function")throw new TypeError("no fetch implementation available — pass fetchImpl or run on Node >= 18");return{fetchImpl:s,requestUrl:`${t}${ce}`,table:a,token:n}},pe=e=>{if(e===null||typeof e!="object")return;const r=e,a=typeof r.failed=="number"&&r.failed>0?r.failed:0;if(a>0)return`${String(a)} shard(s) could not be reached — their rows were NOT migrated (see the per-shard errors above)`;if(r.status==="failed")return"the migration reported `failed` on at least one shard — see the per-shard results above"},we=e=>{const r={id:e.id};return e.subcommand==="status"||(r.direction=e.subcommand,e.dryRun&&(r.dryRun=!0),e.batchSize!==void 0&&(r.batchSize=e.batchSize),e.maxBatches!==void 0&&(r.maxBatches=e.maxBatches)),r},ye=async e=>{const r=ve(e);if(r===void 0)return{body:void 0,code:1,requestUrl:""};const{fetchImpl:a,requestUrl:t,table:n,token:s}=r,o=e.subcommand==="status"?se:ie,i=we(e);e.logger.info(`POST ${t} -> ${e.subcommand} ${e.id} (table "${n}")`);const l=await a(t,{body:JSON.stringify({args:i,functionPath:o,table:n}),headers:{authorization:`Bearer ${s}`,"content-type":"application/json"},method:"POST"}),d=await V(l,e.logger),u=pe(d);return u!==void 0&&e.logger.error(`migrate ${e.subcommand} "${e.id}": ${u}`),{body:d,code:l.ok&&u===void 0?0:1,requestUrl:t}},I=e=>e===void 0?void 0:q(e),$e=async e=>{const{logger:r}=e,a=I(e.fromUrl??e.toUrl),t=I(e.toUrl??e.fromUrl);if(a===t)return r.error("source and target are the same deployment — pass distinct --from-url and --to-url so the D1 export and Hyperdrive import don't run against one database"),{code:1};const n=e.out===void 0?N(c(x(),"lunora-d1ps-")):void 0,s=e.out??c(n,"dump.ndjson");try{r.info(`Exporting .global() data from the D1 source (${a??"http://localhost:8787"}) …`);const o=await Z({fetchImpl:e.fetchImpl,logger:r,out:s,prod:e.prod,tables:e.tables,token:e.fromToken,url:a});if(o.code!==0)return{code:o.code};r.info(`Exported ${String(o.rows)} row(s) (${String(o.bytes)} bytes).`),r.info(`Importing into the Hyperdrive target (${t??"http://localhost:8787"}) …`);const i=await K({batchSize:e.batchSize,fetchImpl:e.fetchImpl,file:s,logger:r,prod:e.prod,token:e.toToken,url:t,yes:e.yes});return i.code!==0?{code:i.code}:(i.inserted===o.rows?r.info(`✓ Migrated ${String(o.rows)} row(s) — counts match. Verify your app reads from Hyperdrive, then decommission the D1 binding.`):r.warn(`Imported ${String(i.inserted)} of ${String(o.rows)} exported row(s) — the remainder likely already existed in the target (see conflicts above). Re-run after resolving, or inspect the dump with --out.`),{code:0})}finally{n!==void 0&&M(n,{force:!0,recursive:!0})}},ze=B(({argument:e,cwd:r,logger:a,options:t})=>{const n=e[0];if(n==="generate")return te({cwd:r,logger:a,name:e[1]??t.name});if(n==="d1-to-hyperdrive")return $e({batchSize:t.batchSize,fromToken:t.fromToken??t.token,fromUrl:t.fromUrl??t.url,logger:a,out:t.out,prod:t.prod===!0,tables:t.tables,toToken:t.toToken??t.token,toUrl:t.toUrl??t.url,yes:t.yes===!0});if(n==="create"){const s=e[1]??t.name;return s?ge({cwd:r,logger:a,name:s,table:t.table}):(a.error("migrate create requires a name. Usage: lunora migrate create <name> [--table <table>]"),{code:1})}if(n==="up"||n==="down"||n==="status"){const s=e[1]??t.name;return s?ye({batchSize:t.batchSize,cwd:r,dryRun:t.dryRun===!0,id:s,logger:a,maxBatches:t.steps,prod:t.prod===!0,subcommand:n,token:t.token,url:W({cwd:r,prod:t.prod===!0,url:t.url}),yes:t.yes===!0}):(a.error(`migrate ${n} requires a migration id. Usage: lunora migrate ${n} <id>`),{code:1})}return a.error(`unknown migrate subcommand: "${n??""}" — expected generate | create | up | down | status`),{code:1}});export{ze as execute,ge as runMigrateCreateCommand,ye as runMigrateDataCommand,te as runMigrateGenerateCommand,$e as runMigrateToHyperdriveCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{existsSync as
|
|
1
|
+
import{existsSync as i,rmSync as d}from"node:fs";import{join as n,relative as m}from"@visulima/path";import{d as f}from"../packem_shared/command-DwC11Cwe.mjs";import{b as a}from"../packem_shared/tui-prompts-DzYd2fL3.mjs";const l=async e=>{const o=e.cwd??process.cwd(),t=[n(o,".wrangler","state")];if(e.all&&t.push(n(o,".lunora-cache")),!e.yes){const r=t.map(s=>m(o,s)).join(" and ");if(!process.stdin.isTTY&&e.confirm===void 0)return e.logger.error(`reset: stdin is not a TTY — re-run with --yes to confirm deleting ${r}`),{code:1,removed:[]};if(!await(e.confirm??a)(`This will delete ${r}. Continue?`))return e.logger.info("reset: aborted"),{code:1,removed:[]}}const c=[];for(const r of t)i(r)?(d(r,{force:!0,recursive:!0}),c.push(r),e.logger.success(`removed ${r}`)):e.logger.info(`skipped (not present): ${r}`);return{code:0,removed:c}},p=f(({cwd:e,logger:o,options:t})=>l({all:t.all===!0,cwd:e,logger:o,yes:t.yes===!0}));export{p as execute,l as runResetCommand};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as a,R as s,V as C,r as N}from"./cli-
|
|
1
|
+
import{C as a,R as s,V as C,r as N}from"./cli-DIb5Ay4K.mjs";import"./createLogger-hGafwf-3.mjs";export{a as COMMANDS,s as REGISTERED_COMMAND_NAMES,C as VERSION,N as runCli};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./admin-token-VdUnvnKW.mjs";import"./admin-url-BhF5ufg1.mjs";import{D as a,r as i}from"./import-
|
|
1
|
+
import"./admin-token-VdUnvnKW.mjs";import"./admin-url-BhF5ufg1.mjs";import{D as a,r as i}from"./import-Dqd1MOOv.mjs";import"./shared-D-zCOmgY.mjs";export{a as DEFAULT_IMPORT_BATCH_SIZE,i as runImportCommand};
|