@lunora/cli 1.0.0-alpha.462 → 1.0.0-alpha.463
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/index.d.mts +76 -55
- package/dist/index.d.ts +76 -55
- package/dist/index.mjs +1 -1
- package/dist/packem_chunks/cli.mjs +2 -2
- package/dist/packem_chunks/dispatch.mjs +1 -1
- package/dist/packem_chunks/handler.mjs +10 -10
- package/dist/packem_chunks/handler12.mjs +1 -1
- package/dist/packem_chunks/handler15.mjs +2 -2
- package/dist/packem_chunks/handler17.mjs +1 -1
- package/dist/packem_chunks/handler24.mjs +3 -3
- package/dist/packem_chunks/handler6.mjs +1 -1
- package/dist/packem_chunks/handler7.mjs +1 -1
- package/dist/packem_chunks/runInitCommand.mjs +87 -63
- package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-CyOfZWMk.mjs +1 -0
- package/dist/packem_shared/export-rows-EzdNDYpa.mjs +3 -0
- package/dist/packem_shared/health-probe-BLnoq_oC.mjs +13 -0
- package/dist/packem_shared/import-C-XRRHrZ.mjs +13 -0
- package/dist/packem_shared/runDeployCommand-2tEbutD6.mjs +1 -0
- package/dist/packem_shared/runExportCommand-Dy6pSX68.mjs +5 -0
- package/dist/packem_shared/{runMigrateGenerateCommand-Bd2W9t1k.mjs → runMigrateGenerateCommand-CFy3hXXu.mjs} +3 -3
- package/dist/packem_shared/shared-CV7ESvuj.mjs +2 -0
- package/package.json +9 -8
- package/skills/lunora-deploy/SKILL.md +18 -17
- package/skills/lunora-migration-helper/SKILL.md +25 -11
- package/dist/packem_shared/DEFAULT_IMPORT_BATCH_SIZE-5xxKz-zB.mjs +0 -1
- package/dist/packem_shared/health-probe-Bw9JFfIy.mjs +0 -1
- package/dist/packem_shared/import-DoAUdyfU.mjs +0 -13
- package/dist/packem_shared/runDeployCommand-Tgy9tGRV.mjs +0 -1
- package/dist/packem_shared/runExportCommand-DiMCQ-Il.mjs +0 -5
- package/dist/packem_shared/shared-D-zCOmgY.mjs +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import{existsSync as m,mkdirSync as
|
|
1
|
+
import{existsSync as m,mkdirSync as E,writeFileSync as g,readFileSync as x,appendFileSync as it,readdirSync as Y,rmSync as R,lstatSync as ve,mkdtempSync as we,copyFileSync as st,renameSync as lt}from"node:fs";import{tmpdir as ye}from"node:os";import{detectFramework as ct,DEV_VARS_EXAMPLE_FILE as be,DEV_VARS_FILE as dt,isInteractive as b,LUNA_ART as ut,LUNA_NAME as ht,LUNA_SIGNOFF as pt,BADGES as v,paintAnswer as ft,detectLintTools as mt,readProjectDependencies as ke,applyLintIgnores as gt,readProjectManifest as vt}from"@lunora/config";import{readJsonSync as wt,walkSync as yt}from"@visulima/fs";import{relative as D,join as u,dirname as S,basename as _,resolve as xe}from"@visulima/path";import{downloadTemplate as Le}from"giget";import{modify as bt,applyEdits as kt}from"jsonc-parser";import{join as J,dirname as xt}from"node:path";import{installArgsFor as Se,execArgsFor as Lt,detectPackageManager as U,detectInstalledManagers as St,runScriptCommand as At,addArgsFor as Ct}from"@lunora/config/cli";import{d as Et}from"../packem_shared/command-B6vu47iR.mjs";import{EXIT_CODE as w}from"../packem_shared/EXIT_CODE-DVjUgIaG.mjs";import Mt from"magic-string";import{Project as It,SyntaxKind as y}from"ts-morph";import{P as X}from"../packem_shared/prompt-cancelled-BvsNxg_Q.mjs";import{l as Ae,m as _t,n as Ce,o as Ee,a as Nt}from"../packem_shared/resolve-Bdc9KEUv.mjs";import{defaultSpawner as Me}from"../packem_shared/createRecordingSpawner-01ZngIwK.mjs";import{d as Tt,e as Rt,f as Ot,a as Ie,t as O,g as _e,h as $t,b as Ne,i as Te,w as Pt,j as Dt,k as Re,l as Ut}from"../packem_shared/tui-prompts-B3YwUhGw.mjs";import{A as Oe,p as jt,w as Bt,M as Vt,r as Ft,E as $e,k as Wt,e as Ht,c as Pe,l as De,i as zt,f as Kt}from"../packem_shared/storage-BLLoZRJa.mjs";import{r as qt}from"../packem_shared/commands-DC3ZX1yk.mjs";import{findWranglerFile as Gt,readWranglerJsonc as Yt,DEFAULT_OBSERVABILITY as Jt,CLOUDFLARE_TOOLCHAIN_VERSIONS as re}from"@lunora/config/cloudflare";import{logStep as ae}from"../packem_shared/createLogger-4TujevyB.mjs";import{r as Xt}from"../packem_shared/lint-ignore-report-DKZagpqk.mjs";import Qt from"node:dns/promises";const Q={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
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"}}
|
|
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"}},$=(e,t)=>{const r=Lt(e,"lunora",t);return[r.command,...r.args].join(" ")},ne=e=>` - uses: actions/checkout@v4
|
|
6
6
|
${e.githubSetupStep} - uses: actions/setup-node@v4
|
|
7
7
|
with:
|
|
8
8
|
node-version: 22
|
|
@@ -22,6 +22,8 @@ ${r}
|
|
|
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
|
|
25
|
+
# LUNORA_DEPLOY_URL — the production worker's URL (after the first deploy)
|
|
26
|
+
# LUNORA_ADMIN_TOKEN — the production worker's admin token
|
|
25
27
|
env:
|
|
26
28
|
CLOUDFLARE_API_TOKEN: \${{ secrets.CLOUDFLARE_API_TOKEN }}
|
|
27
29
|
CLOUDFLARE_ACCOUNT_ID: \${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
|
|
@@ -35,20 +37,27 @@ jobs:
|
|
|
35
37
|
contents: read
|
|
36
38
|
steps:
|
|
37
39
|
${ne(t)}
|
|
38
|
-
#
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
40
|
+
# When a schema change tightens a table, the drift gate reads that table's
|
|
41
|
+
# stored rows from this worker and lets the change ship if every row fits.
|
|
42
|
+
# Unset (a first deploy), the gate blocks as before. A *.workers.dev URL is
|
|
43
|
+
# only trusted when the project is linked and .lunora/ is not committed, so
|
|
44
|
+
# CI has no link: there the gate stays blocked, and a tightening needs a
|
|
45
|
+
# migration or --allow-schema-drift. A custom domain on a declared route works.
|
|
46
|
+
- run: ${$(e,["deploy","--migrate-url",'"${{ secrets.LUNORA_DEPLOY_URL }}"'])}
|
|
47
|
+
env:
|
|
48
|
+
LUNORA_ADMIN_TOKEN: \${{ secrets.LUNORA_ADMIN_TOKEN }}
|
|
49
|
+
|
|
50
|
+
# Every pull request runs the full deploy pipeline, bundle included, and
|
|
51
|
+
# publishes nothing. A Worker version would share production's Durable
|
|
52
|
+
# Objects and D1, so a PR never uploads one.
|
|
53
|
+
check:
|
|
45
54
|
if: github.event_name == 'pull_request'
|
|
46
55
|
runs-on: ubuntu-latest
|
|
47
56
|
permissions:
|
|
48
57
|
contents: read
|
|
49
58
|
steps:
|
|
50
59
|
${ne(t)}
|
|
51
|
-
- run: ${
|
|
60
|
+
- run: ${$(e,["deploy","--dry-run"])}
|
|
52
61
|
`},er=e=>{const t=Q[e],r=[...t.gitlabProvisionScript,t.installCmd].map(a=>` - ${a}`).join(`
|
|
53
62
|
`);return`stages:
|
|
54
63
|
- deploy
|
|
@@ -57,9 +66,17 @@ ${ne(t)}
|
|
|
57
66
|
# (below) requires it — run \`${e} install\` locally and commit the lockfile
|
|
58
67
|
# before pushing, or the first pipeline fails.
|
|
59
68
|
#
|
|
60
|
-
# Set these as
|
|
69
|
+
# Set these as CI/CD variables (Settings → CI/CD → Variables), each Masked AND
|
|
70
|
+
# Protected, with Environment scope "production":
|
|
61
71
|
# CLOUDFLARE_API_TOKEN — a Workers-scoped API token
|
|
62
72
|
# CLOUDFLARE_ACCOUNT_ID — your Cloudflare account id
|
|
73
|
+
# LUNORA_DEPLOY_URL — the production worker's URL (after the first deploy)
|
|
74
|
+
# LUNORA_ADMIN_TOKEN — the production worker's admin token
|
|
75
|
+
# Protected variables reach only pipelines on protected branches and tags, so a
|
|
76
|
+
# merge-request pipeline from a feature branch, which runs the project's own
|
|
77
|
+
# code, gets none of them. Keep your default branch protected (it is by default).
|
|
78
|
+
# The "production" scope reaches only jobs that declare environment: production,
|
|
79
|
+
# which is the deploy job alone; the check job below uses none of these.
|
|
63
80
|
.lunora_base:
|
|
64
81
|
image: ${t.gitlabImage}
|
|
65
82
|
stage: deploy
|
|
@@ -69,55 +86,62 @@ ${r}
|
|
|
69
86
|
# Production deploy on the default branch.
|
|
70
87
|
deploy:
|
|
71
88
|
extends: .lunora_base
|
|
89
|
+
environment:
|
|
90
|
+
name: production
|
|
72
91
|
rules:
|
|
73
92
|
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
|
|
74
93
|
script:
|
|
75
|
-
#
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
#
|
|
80
|
-
#
|
|
81
|
-
|
|
94
|
+
# When a schema change tightens a table, the drift gate reads that table's
|
|
95
|
+
# stored rows from this worker and lets the change ship if every row fits.
|
|
96
|
+
# Unset (a first deploy), the gate blocks as before. A *.workers.dev URL is
|
|
97
|
+
# only trusted when the project is linked and .lunora/ is not committed, so
|
|
98
|
+
# CI has no link: there the gate stays blocked, and a tightening needs a
|
|
99
|
+
# migration or --allow-schema-drift. A custom domain on a declared route works.
|
|
100
|
+
- ${$(e,["deploy","--migrate-url",'"$LUNORA_DEPLOY_URL"'])}
|
|
101
|
+
|
|
102
|
+
# Every merge request runs the full deploy pipeline, bundle included, and
|
|
103
|
+
# publishes nothing. A Worker version would share production's Durable Objects
|
|
104
|
+
# and D1, so an MR never uploads one.
|
|
105
|
+
check:
|
|
82
106
|
extends: .lunora_base
|
|
83
107
|
rules:
|
|
84
108
|
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
|
|
85
109
|
script:
|
|
86
|
-
- ${
|
|
87
|
-
`},
|
|
110
|
+
- ${$(e,["deploy","--dry-run"])}
|
|
111
|
+
`},Ue={github:{file:J(".github","workflows","deploy.yml"),secretsHint:"repository secrets (Settings → Secrets and variables → Actions)"},gitlab:{file:".gitlab-ci.yml",secretsHint:"CI/CD variables, Masked and Protected, scoped to the production environment (Settings → CI/CD → Variables)"}},tr=(e,t)=>e==="github"?Zt(t):er(t),rr=e=>e==="github"||e==="gitlab",ar=(e,t,r,a={})=>{const n=J(e,Ue[t].file);return m(n)&&a.overwrite!==!0?{path:n,skipped:!0,written:!1}:(E(xt(n),{recursive:!0}),g(n,tr(t,r),"utf8"),{path:n,skipped:!1,written:!0})},nr=(e,t,r,a,n={})=>{const o=Ue[t];try{const s=ar(e,t,r,n);if(s.skipped)a.info(`--ci ${t}: ${o.file} already exists — left unchanged (re-run with overwrite to replace).`);else{const i=Se(r),l=[i.command,...i.args].join(" "),{installCmd:c,lockfile:d}=Q[r];a.success(`--ci ${t}: wrote ${o.file}`),a.info(`--ci ${t}: set CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID as ${o.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 ${o.file} (${i})`),{path:J(e,o.file),skipped:!1,written:!1}}},or={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"},ir=e=>{const t=ct(e);return{...t,adapter:or[t.framework]}},T="lunora()",oe='import { lunora } from "@lunora/vite";',sr="@lunora/vite",lr="lunora",cr=e=>{for(const t of e.getStatements()){if(t.getKind()!==y.ExportAssignment)continue;const r=t.asKindOrThrow(y.ExportAssignment).getExpression();if(r.getKind()!==y.CallExpression)continue;const a=r.asKindOrThrow(y.CallExpression);if(a.getExpression().getText()!=="defineConfig")continue;const n=a.getArguments()[0];if(n?.getKind()===y.ObjectLiteralExpression)return n.asKindOrThrow(y.ObjectLiteralExpression)}},dr=e=>{for(const t of e.getStatements()){if(t.getKind()!==y.ExportAssignment)continue;const r=t.asKindOrThrow(y.ExportAssignment).getExpression();if(r.getKind()===y.ObjectLiteralExpression)return r.asKindOrThrow(y.ObjectLiteralExpression)}},ur=e=>e.getDescendantsOfKind(y.CallExpression).some(t=>t.getExpression().getText()===lr),hr=e=>e.getImportDeclarations().some(t=>t.getModuleSpecifierValue()===sr),pr=e=>new It({compilerOptions:{allowJs:!0},useInMemoryFileSystem:!0}).createSourceFile("vite.config.ts",e,{overwrite:!0}),fr=(e,t)=>{const r=t.getImportDeclarations().at(-1)?.getEnd()??0;r===0?e.prepend(`${oe}
|
|
88
112
|
`):e.appendLeft(r,`
|
|
89
|
-
${
|
|
90
|
-
`);return}const a=r.getDescendantsOfKind(y.ArrayLiteralExpression)[0];if(a===void 0)return"the Vite config's `plugins` is not an array literal — add `lunora()` to it by hand";const n=a.getElements();if(n.length===0){e.appendLeft(a.getStart()+1,
|
|
113
|
+
${oe}`)},mr=(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: [${T}] `);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: [${T}],
|
|
114
|
+
`);return}const a=r.getDescendantsOfKind(y.ArrayLiteralExpression)[0];if(a===void 0)return"the Vite config's `plugins` is not an array literal — add `lunora()` to it by hand";const n=a.getElements();if(n.length===0){e.appendLeft(a.getStart()+1,T);return}const o=n[0];if(o===void 0)return"could not locate the first entry of the Vite config's `plugins` array";e.appendLeft(o.getStart(),`${T}, `)},je=e=>{const t=pr(e);if(ur(t))return{changed:!1,code:e,reason:"lunora plugin already present"};const r=cr(t)??dr(t);if(r===void 0)return{changed:!1,code:e,reason:"could not locate a Vite config plugins array to patch"};const a=new Mt(e);hr(t)||fr(a,t);const n=mr(a,r);return n!==void 0?{changed:!1,code:e,reason:n}:{changed:!0,code:a.toString()}},gr=/enotfound|eai_again|econnrefused|etimedout|network|fetch failed|getaddrinfo/u,vr=/404|not found|could not find|no such/u,wr=(e,t)=>{const r=e instanceof Error?e.message:String(e),a=r.toLowerCase(),n=`failed to download template "${t.templateType}" from ${t.remote}: ${r}`;return vr.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}`}:gr.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:n}:{hints:["If this is a network/offline issue, scaffold from a local root with `lunora init --from <dir>`."],message:n}},Be=[{description:"No sign-in yet; add it later with `lunora add auth`",label:"None",value:"none"},{description:"Users and sessions in your own D1, via better-auth (@lunora/auth)",label:"Lunora auth",value:"lunora"},{description:"Clerk owns the session; the Worker verifies its session token",label:"Clerk",value:"clerk"},{description:"WorkOS AuthKit owns the session; the Worker verifies its access token",label:"WorkOS AuthKit",value:"workos"},{description:"Auth0 owns the session; the Worker verifies its access token",label:"Auth0",value:"auth0"}],ie=Be.map(e=>e.value),Z={auth0:{clientSnippet:["// @auth0/auth0-react: <Auth0Provider authorizationParams={{ audience: AUTH0_AUDIENCE }} useRefreshTokens>","// const { getAccessTokenSilently, isLoading, user } = useAuth0();","// In a useEffect over [client, getAccessTokenSilently, isLoading, user?.sub]:","if (isLoading) return;","if (!user) return client.setAuthToken(null);","const fetchToken = () => getAccessTokenSilently().catch((error) => {",' if (["login_required", "missing_refresh_token"].includes(error?.error)) return null; // signed out'," throw error;","});","return setAuthTokenProvider(client, fetchToken, { subject: user.sub });"].join(`
|
|
91
115
|
`),envVars:["AUTH0_DOMAIN","AUTH0_AUDIENCE"],identity:"auth0Identity",identityFile:"auth0",item:"auth-auth0-jwt"},clerk:{clientSnippet:["// @clerk/react: const { getToken, isLoaded, isSignedIn, userId } = useAuth();","// In a useEffect over [client, getToken, isLoaded, isSignedIn, userId]:","if (!isLoaded) return;","if (!isSignedIn) return client.setAuthToken(null);","return setAuthTokenProvider(client, getToken, { subject: userId });"].join(`
|
|
92
116
|
`),envVars:["CLERK_PUBLISHABLE_KEY","CLERK_AUTHORIZED_PARTIES"],identity:"clerkIdentity",identityFile:"clerk",item:"auth-clerk-jwt"},workos:{clientSnippet:["// @workos-inc/authkit-react: const { getAccessToken, isLoading, user } = useAuth();","// In a useEffect over [client, getAccessToken, isLoading, user?.id]:","if (isLoading) return;","if (!user) return client.setAuthToken(null);","const fetchToken = () => getAccessToken().catch((error) => {"," if (error instanceof LoginRequiredError) return null; // signed out"," throw error;","});","return setAuthTokenProvider(client, fetchToken, { subject: user.id });"].join(`
|
|
93
|
-
`),envVars:["WORKOS_CLIENT_ID"],identity:"workosIdentity",identityFile:"workos",item:"auth-workos-jwt"}},yr=e=>Object.hasOwn(Z,e),br=(e,t)=>{const r=e.trim().toLowerCase();return
|
|
94
|
-
`,t);return n===-1?e.length:n}if(r==="/"&&e[t+1]==="*"){const n=e.indexOf("*/",t+2);return n===-1?e.length:n+2}if(r!=='"'&&r!=="'"&&r!=="`")return t;let a=t+1;for(;a<e.length&&e[a]!==r;)a+=e[a]==="\\"?2:1;return a+1},Ir=(e,t)=>{let r=0,a=t;for(;a<e.length;){const n=Mr(e,a);if(n!==a){a=n;continue}const
|
|
95
|
-
${
|
|
96
|
-
${
|
|
117
|
+
`),envVars:["WORKOS_CLIENT_ID"],identity:"workosIdentity",identityFile:"workos",item:"auth-workos-jwt"}},yr=e=>Object.hasOwn(Z,e),br=(e,t)=>{const r=e.trim().toLowerCase();return ie.includes(r)?r:(t(`init: unknown --auth "${e}" — expected ${ie.join(" | ")}; skipping auth.`),"none")},kr=["lunora/app.ts","src/app.ts","lunora/server.ts","src/server.ts","src/server/index.ts","src/server/index.tsx","src/index.ts","src/worker.ts"],xr="virtual:lunora/worker",Lr=["lunora.config.ts","lunora.config.mts","lunora.config.js","lunora.config.mjs"],Sr=["src","app","pages","plugins"],Ar=/\.(?:[jt]sx?|svelte|vue)$/u,H="new LunoraClient({",se=/\n([\t ]*)\.build(?:FrameworkWorker)?\(/uy,Cr=new Set(["(","[","{"]),Er=new Set([")","]","}"]),Mr=(e,t)=>{const r=e[t];if(r==="/"&&e[t+1]==="/"){const n=e.indexOf(`
|
|
118
|
+
`,t);return n===-1?e.length:n}if(r==="/"&&e[t+1]==="*"){const n=e.indexOf("*/",t+2);return n===-1?e.length:n+2}if(r!=='"'&&r!=="'"&&r!=="`")return t;let a=t+1;for(;a<e.length&&e[a]!==r;)a+=e[a]==="\\"?2:1;return a+1},Ir=(e,t)=>{let r=0,a=t;for(;a<e.length;){const n=Mr(e,a);if(n!==a){a=n;continue}const o=e[a]??"";se.lastIndex=a;const s=r===0?se.exec(e)??void 0:void 0;if(s!==void 0)return{at:a,indent:s[1]??" "};if(r===0&&o===";")return{at:a,indent:" "};r+=Cr.has(o)?1:0,r-=Er.has(o)?1:0,a+=1}},_r=(e,t,r)=>{const a=D(S(u(e,t)),u(e,"lunora","identity",r.identityFile));return`${a.startsWith(".")?a:`./${a}`}.js`},Nr=/\bresolveIdentity\b/u,Tr=/^import[^"']*["'][^"'\n]*["'][^\n]*\n/u,Rr=(e,t,r,a)=>{const n=r.indexOf("defineApp<"),o=n===-1?void 0:Ir(r,n);if(o===void 0)return;if(r.includes(`${a.identity}(env)`))return{outcome:"already-wired"};if(Nr.test(r))return{outcome:"has-resolver"};const{at:s,indent:i}=o,l=`
|
|
119
|
+
${i}// Verify the provider's token on every request and feed it into ctx.auth (memoized for 5 s).
|
|
120
|
+
${i}.extend((env) => ({ resolveIdentity: ${a.identity}(env) }))`,c=`import { ${a.identity} } from "${_r(e,t,a)}";
|
|
97
121
|
`,d=r.lastIndexOf(`
|
|
98
|
-
import `,n),
|
|
122
|
+
import `,n),p=d===-1?void 0:Tr.exec(r.slice(d+1)),f=p==null?0:d+1+p[0].length;return{outcome:"wired",patched:r.slice(0,f)+c+r.slice(f,s)+l+r.slice(s)}},Or=(e,t)=>{for(const r of kr){const a=u(e,r),n=m(a)?Rr(e,r,x(a,"utf8"),t):void 0;if(n?.outcome==="wired"&&g(a,n.patched),n!==void 0)return{file:r,outcome:n.outcome}}},$r=e=>{const t=Gt(e);return t!==void 0&&Yt(t).parsed?.main===xr},Pr=(e,t)=>{if(!(!$r(e)||Lr.some(r=>m(u(e,r)))))return g(u(e,"lunora.config.ts"),`import type { AppBuilder, LunoraConfig } from "./lunora/_generated/app";
|
|
99
123
|
import { ${t.identity} } from "./lunora/identity/${t.identityFile}";
|
|
100
124
|
|
|
101
125
|
export default {
|
|
102
126
|
// Verify the provider's token on every request and feed it into ctx.auth (memoized for 5 s).
|
|
103
127
|
app: (app: AppBuilder<object>): AppBuilder<object> => app.extend((env) => ({ resolveIdentity: ${t.identity}(env) })),
|
|
104
128
|
} satisfies LunoraConfig<object>;
|
|
105
|
-
`),"lunora.config.ts"},Ve=(e,t=0)=>t>3||!m(e)?[]:Y(e,{withFileTypes:!0}).flatMap(r=>{const a=u(e,r.name);return r.isDirectory()?r.name==="node_modules"?[]:Ve(a,t+1):
|
|
129
|
+
`),"lunora.config.ts"},Ve=(e,t=0)=>t>3||!m(e)?[]:Y(e,{withFileTypes:!0}).flatMap(r=>{const a=u(e,r.name);return r.isDirectory()?r.name==="node_modules"?[]:Ve(a,t+1):Ar.test(r.name)?[a]:[]}),Dr=e=>Sr.flatMap(t=>Ve(u(e,t))).filter(t=>{const r=x(t,"utf8");return!r.includes(H)||r.includes("authTokenOnUpgrade")?!1:(g(t,r.replaceAll(H,`${H} authTokenOnUpgrade: true,`)),!0)}),Ur=(e,t)=>{const r=u(e,be),a=u(e,dt),n=m(r)?x(r,"utf8"):"",o=m(a)?x(a,"utf8").split(`
|
|
106
130
|
`):[],s=t.envVars.filter(c=>!n.split(`
|
|
107
|
-
`).some(d=>d.startsWith(`${c}=`)));if(s.length===0)return!1;const
|
|
131
|
+
`).some(d=>d.startsWith(`${c}=`)));if(s.length===0)return!1;const i=s.map(c=>o.find(d=>d.startsWith(`${c}=`))??`${c}=`),l=n.length===0||n.endsWith(`
|
|
108
132
|
`)?"":`
|
|
109
|
-
`;return
|
|
110
|
-
${
|
|
133
|
+
`;return it(r,`${l}# ${t.item}: the identity provider the Worker verifies tokens from.
|
|
134
|
+
${i.join(`
|
|
111
135
|
`)}
|
|
112
|
-
`),!0},
|
|
136
|
+
`),!0},jr=(e,t,r)=>{const a=Z[t],n=()=>{const s=Pr(e,a);return s===void 0?void 0:{file:s,outcome:"wired"}},o=Or(e,a)??n();o===void 0?r.warn(`auth: add \`.extend((env) => ({ resolveIdentity: ${a.identity}(env) }))\` to your app builder (lunora.config.ts \`app\` hook or the Worker entry) — ${a.identity} is in lunora/identity/${a.identityFile}.ts.`):o.outcome==="already-wired"?r.info(`auth: ${o.file} already wires ${a.identity}; left as is.`):o.outcome==="has-resolver"?r.warn(`auth: ${o.file} already sets resolveIdentity, so it was left as is. Compose the two: \`resolveIdentity: composeIdentityResolvers([${a.identity}(env), <your resolver>])\` — ${a.identity} is in lunora/identity/${a.identityFile}.ts.`):r.success(`auth: wired ${a.identity} as resolveIdentity in ${o.file}`),Ur(e,a)&&r.success(`auth: listed ${a.envVars.join(", ")} in ${be}`);for(const s of Dr(e))r.success(`auth: turned on authTokenOnUpgrade in ${D(e,s)}`);r.info(`auth: hand the provider's token to Lunora once signed in (setAuthTokenProvider from lunorash/client or @lunora/client):
|
|
113
137
|
${a.clientSnippet}
|
|
114
|
-
Fill in the env vars the item wrote to .dev.vars.`)},P=async(e,t,r)=>{if(b()){await
|
|
138
|
+
Fill in the env vars the item wrote to .dev.vars.`)},P=async(e,t,r)=>{if(b()){await Rt(v[e],t,r);return}if(process.stdout.write(`
|
|
115
139
|
`),r===void 0||r===""){ae(e,t);return}const a=r.split(`
|
|
116
140
|
`).map(n=>ft(n)).join(`
|
|
117
141
|
`);ae(e,`${t}
|
|
118
|
-
${a}`)},
|
|
142
|
+
${a}`)},Br=async e=>{if(b()){await Tt();return}e.info(`
|
|
119
143
|
${ut}
|
|
120
|
-
${
|
|
144
|
+
${ht}: ${pt}`)},Fe=[{description:"LLMs via Workers AI (summarize, generate, stream)",label:"AI",value:"ai"},{description:"Sign-up / sign-in with @lunora/auth (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"}],le=Fe.map(e=>e.value),ce=Fe.filter(e=>e.value!=="auth"),We=new Set(["auth","auth-ui"]),Vr=e=>e==="email"?$e:e,Fr=(e,t)=>{const r=[];for(const a of e.split(",").map(n=>n.trim()).filter(Boolean))le.includes(a)?r.includes(a)||r.push(a):t(`init: unknown --add feature "${a}" — expected ${le.join(" | ")}; skipping.`);return r},He=e=>e.resolveAuthUiItem===void 0?"auth-ui-react":e.resolveAuthUiItem(),Wr=async e=>{const t=await Ht(e.select),r=await Pe(e.text,e.projectName);return{label:"auth",names:[t],transformManifest:a=>De(a,r)}},Hr=async e=>{const t=await e.text(Vt,{placeholder:"you@yourdomain.com"}),r=Ft(t,a=>{e.logger.warn(a)});return{label:"email",names:[$e],transformManifest:r===void 0?void 0:a=>Wt(a,r)}},zr=async(e,t)=>{const r=He(e);if(r===void 0){e.logger.error(`init: ${Oe}`);return}if(t)return{label:"auth-ui",names:[r]};const a=await Pe(e.text,e.projectName);return{label:"auth-ui",names:[r],transformManifest:n=>De(n,a)}},Kr=async e=>{const t=await jt(e.text,e.projectName);return{label:"storage",names:["storage"],transformManifest:r=>Bt(r,t)}},qr=(e,t)=>{const r=[];let a=!1;for(const n of t){if(n!=="auth-ui"){r.push({label:n,names:[Vr(n)]});continue}const o=He(e);if(o===void 0){e.logger.error(`init: ${Oe}`),a=!0;continue}r.push({label:n,names:[o]})}return{plans:r,refused:a}},ze=e=>e!==void 0&&yr(e)?{externalAuth:e,label:e,names:[Z[e].item]}:void 0,Gr={auth:Wr,"auth-ui":async(e,t)=>zr(e,t.includes("auth")),email:Hr,storage:Kr},Yr=async e=>{const t=ze(e.auth),r=e.auth!==void 0&&e.auth!=="lunora",a=new Set(r?(e.preselected??[]).filter(l=>We.has(l)):[]),n=(e.preselected??[]).filter(l=>!a.has(l));for(const l of a)e.logger.warn(`--auth ${String(e.auth)} rules out Lunora auth; ignoring \`${l}\` from --add.`);e.auth==="lunora"&&!n.includes("auth")&&n.unshift("auth");const{plans:o,refused:s}=qr(e,n);return t!==void 0&&o.unshift(t),await e.applyAll(o)&&!s&&a.size===0},de=async e=>{if(e.preselected!==void 0&&e.preselected.length>0||e.auth!==void 0&&!e.interactive)return Yr(e);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=e.auth??await e.selectAuth("Which auth do you want?",Be,{default:"none"})??"none",r=ze(t),a=t==="lunora"?ce:ce.filter(i=>!We.has(i.value)),n=await e.multiSelect("Which features do you want to add?",a,{defaults:[]}),o=t==="lunora"&&!n.includes("auth")?["auth",...n]:n;if(o.length===0&&r===void 0)return!0;const s=r===void 0?[]:[r];for(const i of o){const l=Gr[i],c=l?await l(e,o):{label:i,names:[i]};c!==void 0&&s.push(c)}return await e.applyAll(s),!0},Jr=[{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"}],Xr="Which linter/formatter do you use? We'll tell it to skip Lunora's generated files.",Qr=async e=>{const t=e.interactive?await e.multiSelect(Xr,Jr,{defaults:e.detected}):[...e.detected];if(t.length===0)return[];const r=e.apply(t);return Xt(r,e.logger),r},N="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",I=`/* The welcome page is a full-bleed starter — reset the browser's default
|
|
121
145
|
body margin/padding so it sits flush; everything else is scoped under
|
|
122
146
|
.lunora-welcome (collision-safe). */
|
|
123
147
|
body {
|
|
@@ -264,7 +288,7 @@ export default function App() {
|
|
|
264
288
|
<div className="lw-wrap">
|
|
265
289
|
<div className="brand">
|
|
266
290
|
<svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
|
|
267
|
-
<path d="${
|
|
291
|
+
<path d="${N}" fill="currentColor" fillRule="evenodd" />
|
|
268
292
|
</svg>
|
|
269
293
|
<span className="word">Lunora</span>
|
|
270
294
|
</div>
|
|
@@ -423,7 +447,7 @@ const toggle = (): void => {
|
|
|
423
447
|
<div class="lw-wrap">
|
|
424
448
|
<div class="brand">
|
|
425
449
|
<svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
|
|
426
|
-
<path d="${
|
|
450
|
+
<path d="${N}" fill="currentColor" fill-rule="evenodd" />
|
|
427
451
|
</svg>
|
|
428
452
|
<span class="word">Lunora</span>
|
|
429
453
|
</div>
|
|
@@ -579,7 +603,7 @@ export default function App() {
|
|
|
579
603
|
<div class="lw-wrap">
|
|
580
604
|
<div class="brand">
|
|
581
605
|
<svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
|
|
582
|
-
<path d="${
|
|
606
|
+
<path d="${N}" fill="currentColor" fill-rule="evenodd" />
|
|
583
607
|
</svg>
|
|
584
608
|
<span class="word">Lunora</span>
|
|
585
609
|
</div>
|
|
@@ -741,7 +765,7 @@ export default function App() {
|
|
|
741
765
|
<div class="lw-wrap">
|
|
742
766
|
<div class="brand">
|
|
743
767
|
<svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
|
|
744
|
-
<path d="${
|
|
768
|
+
<path d="${N}" fill="currentColor" fill-rule="evenodd" />
|
|
745
769
|
</svg>
|
|
746
770
|
<span class="word">Lunora</span>
|
|
747
771
|
</div>
|
|
@@ -884,7 +908,7 @@ const welcomeHtml = \`
|
|
|
884
908
|
<div class="lw-wrap">
|
|
885
909
|
<div class="brand">
|
|
886
910
|
<svg viewBox="0 0 543 446" role="img" aria-label="Lunora">
|
|
887
|
-
<path d="${
|
|
911
|
+
<path d="${N}" fill="currentColor" fill-rule="evenodd" />
|
|
888
912
|
</svg>
|
|
889
913
|
<span class="word">Lunora</span>
|
|
890
914
|
</div>
|
|
@@ -1023,7 +1047,7 @@ const count = document.querySelector<HTMLSpanElement>("#lw-count")!;
|
|
|
1023
1047
|
client.subscribe(api.messages.list, { channelId: "channel:demo" }, (result) => {
|
|
1024
1048
|
count.textContent = String(result.messages.length);
|
|
1025
1049
|
});
|
|
1026
|
-
`,
|
|
1050
|
+
`,j="const url = (import.meta.env.VITE_LUNORA_URL as string | undefined) ?? globalThis.location.origin;",na=`import "./index.css";
|
|
1027
1051
|
|
|
1028
1052
|
import { LunoraProvider } from "@lunora/react";
|
|
1029
1053
|
import { LunoraClient } from "lunorash/client";
|
|
@@ -1035,7 +1059,7 @@ import App from "./App.tsx";
|
|
|
1035
1059
|
// \`@lunora/vite\` runs the Worker on the same origin as Vite, so default to
|
|
1036
1060
|
// \`location.origin\`. Point \`VITE_LUNORA_URL\` at a deployed Worker to develop
|
|
1037
1061
|
// the client against production data.
|
|
1038
|
-
${
|
|
1062
|
+
${j}
|
|
1039
1063
|
const client = new LunoraClient({ url });
|
|
1040
1064
|
|
|
1041
1065
|
const root = document.getElementById("root");
|
|
@@ -1051,7 +1075,7 @@ createRoot(root).render(
|
|
|
1051
1075
|
</LunoraProvider>
|
|
1052
1076
|
</StrictMode>,
|
|
1053
1077
|
);
|
|
1054
|
-
`,
|
|
1078
|
+
`,oa=`import "./style.css";
|
|
1055
1079
|
|
|
1056
1080
|
import { createLunora } from "@lunora/vue";
|
|
1057
1081
|
import { LunoraClient } from "lunorash/client";
|
|
@@ -1060,9 +1084,9 @@ import { createApp } from "vue";
|
|
|
1060
1084
|
import App from "./App.vue";
|
|
1061
1085
|
|
|
1062
1086
|
// Provide one LunoraClient at the app root via the Vue plugin form.
|
|
1063
|
-
${
|
|
1087
|
+
${j}
|
|
1064
1088
|
createApp(App).use(createLunora(new LunoraClient({ url }))).mount("#app");
|
|
1065
|
-
`,
|
|
1089
|
+
`,ia=`import "./index.css";
|
|
1066
1090
|
|
|
1067
1091
|
import { LunoraProvider } from "@lunora/solid";
|
|
1068
1092
|
import { LunoraClient } from "lunorash/client";
|
|
@@ -1070,7 +1094,7 @@ import { render } from "solid-js/web";
|
|
|
1070
1094
|
|
|
1071
1095
|
import App from "./App";
|
|
1072
1096
|
|
|
1073
|
-
${
|
|
1097
|
+
${j}
|
|
1074
1098
|
const client = new LunoraClient({ url });
|
|
1075
1099
|
const root = document.getElementById("root");
|
|
1076
1100
|
|
|
@@ -1088,7 +1112,7 @@ render(
|
|
|
1088
1112
|
|
|
1089
1113
|
import App from "./App.svelte";
|
|
1090
1114
|
|
|
1091
|
-
${
|
|
1115
|
+
${j}
|
|
1092
1116
|
setLunoraClient(new LunoraClient({ url }));
|
|
1093
1117
|
<\/script>
|
|
1094
1118
|
|
|
@@ -1103,7 +1127,7 @@ import Root from "./Root.svelte";
|
|
|
1103
1127
|
const app = mount(Root, { target: document.getElementById("app")! });
|
|
1104
1128
|
|
|
1105
1129
|
export default app;
|
|
1106
|
-
`,
|
|
1130
|
+
`,B={react:{adapter:"@lunora/react",createViteTemplate:"react-ts",files:[{contents:na,path:"src/main.tsx"},{contents:Zr,path:"src/App.tsx"},{contents:I,path:"src/index.css"}],label:"React"},solid:{adapter:"@lunora/solid",createViteTemplate:"solid-ts",files:[{contents:ia,path:"src/index.tsx"},{contents:ta,path:"src/App.tsx"},{contents:I,path:"src/index.css"}],label:"Solid"},svelte:{adapter:"@lunora/svelte",createViteTemplate:"svelte-ts",files:[{contents:sa,path:"src/Root.svelte"},{contents:la,path:"src/main.ts"},{contents:ra,path:"src/App.svelte"},{contents:I,path:"src/app.css"}],label:"Svelte"},vanilla:{adapter:"lunorash/client",createViteTemplate:"vanilla-ts",files:[{contents:aa,path:"src/main.ts"},{contents:I,path:"src/style.css"}],label:"Vanilla"},vue:{adapter:"@lunora/vue",createViteTemplate:"vue-ts",files:[{contents:oa,path:"src/main.ts"},{contents:ea,path:"src/App.vue"},{contents:I,path:"src/style.css"}],label:"Vue"}},V=e=>Object.hasOwn(B,e),ca=`/**
|
|
1107
1131
|
* Rate-limit schema extension + plugin.
|
|
1108
1132
|
*
|
|
1109
1133
|
* Defines the \`ratelimit_buckets\` table used by \`createDbStore\` for durable,
|
|
@@ -1239,7 +1263,7 @@ export const send = mutation
|
|
|
1239
1263
|
|
|
1240
1264
|
return { channelId: args.channelId, id, text: args.text };
|
|
1241
1265
|
});
|
|
1242
|
-
`,
|
|
1266
|
+
`,ha=`import type { ShardNamespaceLike } from "lunorash/runtime";
|
|
1243
1267
|
|
|
1244
1268
|
import { defineApp } from "../lunora/_generated/app.js";
|
|
1245
1269
|
|
|
@@ -1253,7 +1277,7 @@ const app = defineApp<Env>()
|
|
|
1253
1277
|
|
|
1254
1278
|
export const ShardDO = app.ShardDO;
|
|
1255
1279
|
export default app;
|
|
1256
|
-
`,
|
|
1280
|
+
`,pa=`{ ${Object.entries(Jt).map(([e,t])=>`${JSON.stringify(e)}: ${JSON.stringify(t)}`).join(", ")} }`,fa=`{
|
|
1257
1281
|
"$schema": "node_modules/wrangler/config-schema.json",
|
|
1258
1282
|
"name": "__NAME__",
|
|
1259
1283
|
"main": "src/server.ts",
|
|
@@ -1263,25 +1287,25 @@ export default app;
|
|
|
1263
1287
|
"bindings": [{ "name": "SHARD", "class_name": "ShardDO" }],
|
|
1264
1288
|
},
|
|
1265
1289
|
"migrations": [{ "tag": "v1", "new_sqlite_classes": ["ShardDO"] }],
|
|
1266
|
-
"observability": ${
|
|
1290
|
+
"observability": ${pa},
|
|
1267
1291
|
}
|
|
1268
1292
|
`,ue=[".wrangler",".env",".env.*","!.env.example",".dev.vars",".dev.vars.*","!.dev.vars.example",".lunora/",".lunora-cache","lunora/_generated"],ma=`# Lunora endpoint for the browser client.
|
|
1269
1293
|
# Vite statically replaces \`import.meta.env.VITE_LUNORA_URL\` at \`vite dev\` / build.
|
|
1270
1294
|
# Leave it unset to use the page origin; set it to point at a deployed Worker:
|
|
1271
1295
|
#
|
|
1272
1296
|
# VITE_LUNORA_URL=https://my-app.example.workers.dev
|
|
1273
|
-
`,
|
|
1297
|
+
`,ga={"@cloudflare/workers-types":re["@cloudflare/workers-types"],wrangler:re.wrangler},A=(e,t,r,a)=>{const n=u(e,t);E(S(n),{recursive:!0}),g(n,r,"utf8"),a.push(n)},va=/\r?\n/,wa=e=>{const t=u(e,".gitignore"),r=m(t)?x(t,"utf8"):"",a=new Set(r.split(va)),n=ue.filter(i=>!a.has(i));if(n.length===0)return;const o=n.some(i=>!i.startsWith("!"))?[...n.filter(i=>!i.startsWith("!")),...ue.filter(i=>i.startsWith("!"))]:n,s=r.length>0&&!r.endsWith(`
|
|
1274
1298
|
`)?`
|
|
1275
|
-
`:"";
|
|
1299
|
+
`:"";g(t,`${r}${s}
|
|
1276
1300
|
# Lunora
|
|
1277
|
-
${
|
|
1301
|
+
${o.join(`
|
|
1278
1302
|
`)}
|
|
1279
|
-
`,"utf8")},F=e=>e==="lunorash"||e.startsWith("@lunora/"),ya=(e,t,r,a)=>F(e)?a.get(e)??r:t,
|
|
1280
|
-
`,"utf8")},ka=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],Ke=e=>ka.map(t=>u(e,t)).find(t=>m(t)),xa=(e,t)=>{const r=Ke(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=
|
|
1303
|
+
`,"utf8")},F=e=>e==="lunorash"||e.startsWith("@lunora/"),ya=(e,t,r,a)=>F(e)?a.get(e)??r:t,C=(e,t,r)=>({...e,[t]:r}),he=(e,t,r)=>Object.fromEntries(Object.entries(e).map(([a,n])=>[a,ya(a,n,t,r)])),ba=async(e,t,r,a)=>{const n=u(e,"package.json"),o=wt(n);let s=C(o.dependencies??{},"lunorash",a);s=C(s,"@lunora/ratelimit",a),r.adapter.startsWith("@lunora/")&&(s=C(s,r.adapter,a));for(const[d,p]of Object.entries(r.extraDependencies??{}))s=C(s,d,p);let i=C(o.devDependencies??{},"@lunora/vite",a);i=C(i,"@lunora/studio",a);for(const[d,p]of Object.entries(ga))i=C(i,d,p);const l=[...Object.keys(s),...Object.keys(i)].filter(d=>F(d)),c=await Ae(l,a);o.name=t,o.imports={...o.imports,"#lunora/*":"./lunora/*"},o.dependencies=he(s,a,c),o.devDependencies=he(i,a,c),o.scripts={...o.scripts,codegen:"lunora codegen",deploy:"lunora deploy"},g(n,`${JSON.stringify(o,void 0,4)}
|
|
1304
|
+
`,"utf8")},ka=["vite.config.ts","vite.config.mts","vite.config.js","vite.config.mjs"],Ke=e=>ka.map(t=>u(e,t)).find(t=>m(t)),xa=(e,t)=>{const r=Ke(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=je(x(r,"utf8"));a.changed&&g(r,a.code,"utf8")},La=async e=>{const{adapter:t,distTag:r,logger:a,name:n,target:o}=e,s=[];A(o,u("lunora","ratelimit","schema.ts"),ca,s),A(o,u("lunora","schema.ts"),da,s),A(o,u("lunora","messages.ts"),ua,s),A(o,u("src","server.ts"),ha,s),A(o,"wrangler.jsonc",fa.replaceAll("__NAME__",n),s),A(o,".env.example",ma,s);for(const i of t.files)A(o,i.path,i.contents,s);return xa(o,a),await ba(o,n,t,r),wa(o),s},Sa=["lunar","silver","silent","waning","waxing","crescent","cosmic","stellar","orbital","gibbous","twilight","midnight","shimmering","drifting","weightless"],Aa=["moon","tide","crater","comet","eclipse","halo","orbit","nebula","voyager","lander","rover","beacon","harbor","meadow","fox"],pe=e=>e[Math.floor(Math.random()*e.length)],Ca=()=>`${pe(Sa)}-${pe(Aa)}`,Ea=async()=>Qt.lookup("github.com").then(()=>!0,()=>!1),Ma=/^(?:gh|github):([^/]+)\/([^#/]+)(?:\/[^#]*)?(?:#(.+))?$/,qe=e=>{const t=Ma.exec(e);if(t===null)return;const[,r,a,n]=t;if(!(r===void 0||a===void 0))return{owner:r,ref:n??"HEAD",repo:a}},Ia=async e=>{const t=qe(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}},Ge=async e=>e.isLocal||!(e.source===void 0||qe(e.source)!==void 0)?!0:await Ea()?e.source!==void 0&&await Ia(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),L={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?"},_a=new Set([".gitignore",".html",".js",".json",".jsonc",".md",".mjs",".ts",".tsx"]),Na=`import { defineConfig } from "vite";
|
|
1281
1305
|
import { lunora } from "@lunora/vite";
|
|
1282
1306
|
|
|
1283
1307
|
export default defineConfig({ plugins: [lunora()] });
|
|
1284
|
-
|
|
1308
|
+
`,Ta=`import { defineSchema, defineTable, v } from "@lunora/server";
|
|
1285
1309
|
|
|
1286
1310
|
export default defineSchema({
|
|
1287
1311
|
messages: defineTable({
|
|
@@ -1291,7 +1315,7 @@ export default defineSchema({
|
|
|
1291
1315
|
.shardBy("channelId")
|
|
1292
1316
|
.index("by_channel", ["channelId"]),
|
|
1293
1317
|
});
|
|
1294
|
-
`,
|
|
1318
|
+
`,Ra=`import { mutation, query, v } from "./_generated/server";
|
|
1295
1319
|
|
|
1296
1320
|
export const list = query
|
|
1297
1321
|
.input({ channelId: v.string(), limit: v.optional(v.number()) })
|
|
@@ -1304,8 +1328,8 @@ export const send = mutation
|
|
|
1304
1328
|
.mutation(async ({ args }) => {
|
|
1305
1329
|
return { channelId: args.channelId, text: args.text };
|
|
1306
1330
|
});
|
|
1307
|
-
`,
|
|
1308
|
-
`),Je=e=>{const t=u(e,Ye);m(t)||
|
|
1309
|
-
`),e.success(`scaffolded ${String(t.length)} files into ${r}`)},qa=(e,t)=>{const{args:r,command:a}=
|
|
1310
|
-
`))},Qa=e=>e.yes!==!0&&(e.installPrompt!==void 0||b()),Za=async(e,t)=>{if(!Qa(e)||te(
|
|
1311
|
-
`),t.info(f?.commit?`template: ${f.source} @ ${f.commit} (${String(k.length)} files)`:`template: ${f?.source??h} (${String(k.length)} files)`),ee(t,p,s),{code:0,files:p,target:s}}catch(d){if(d instanceof X)throw d;const{hints:h,message:f}=wr(d,{ref:Ee(n),remote:q(o,i,n),templateType:o});t.error(f);for(const p of h)t.warn(p);return{code:1,files:[],target:s}}finally{R(l,{force:!0,recursive:!0})}},rn=e=>{for(const t of["_gitignore","_npmrc","_gitattributes"]){const r=u(e,t);m(r)&<(r,u(e,`.${t.slice(1)}`))}},an=async e=>{const{framework:t,logger:r,markComplete:a,name:n,overlayBaseFrom:i,target:s}=e,o=j[t],l=we(u(ye(),"lunora-vite-base-"));try{let c;if(i!==void 0&&(c=u(i,`template-${o.createViteTemplate}`),!m(c)))return r.error(`create-vite base not found on disk: ${c}`),{code:w.NOT_FOUND,files:[],target:s};const d=async()=>{if(c!==void 0){me(c,s);return}const f=u(l,"base"),p=await _t(fe,"main",r),k=`github:${fe}/packages/create-vite/template-${o.createViteTemplate}#${p}`;await Se(k,{cwd:l,dir:f,force:!0,install:!1,silent:!0}),rn(f),me(f,s)};let h=[];return await Ne([{label:`create-vite (${o.label}) base ready`,run:d},{label:`Lunora overlay applied (${o.label})`,run:async()=>{h=await Sa({adapter:o,distTag:Ae(),logger:r,name:n,target:s})}}],{end:Ze,start:"Project initializing…"}),a(),ee(r,h,s),{code:0,files:[...W(s)],target:s}}catch(c){if(c instanceof X)throw c;const d=c instanceof Error?c.message:String(c);return r.error(`failed to scaffold the ${o.label} base: ${d}`),{code:1,files:[],target:s}}finally{R(l,{force:!0,recursive:!0})}},G=(e,t,r,a,n)=>(n.error(`init --in-place: could not ${e} ${t}: ${r instanceof Error?r.message:String(r)}`),{code:1,files:[],target:a}),nn=(e,t)=>{const r=u(e,"vite.config.ts");try{v(r,Ta,"utf8")}catch(a){return G("write",r,a,e,t)}return t.success(`created ${r} with lunora() plugin`),{code:0,files:[r],target:e}},on=(e,t,r)=>{let a;try{a=x(e,"utf8")}catch(i){return G("read",e,i,t,r)}const n=Ue(a);if(!n.changed)return r.info(`${e}: ${n.reason??"no changes needed"}`),{code:0,files:[],target:t};try{v(e,n.code,"utf8")}catch(i){return G("write",e,i,t,r)}return r.success(`patched ${e} — added lunora() plugin`),{code:0,files:[e],target:t}},sn=(e,t)=>{const r=u(e,"lunora"),a=u(r,"schema.ts");if(m(a))return t.info(`lunora/ already present — left ${a} untouched`),[];const n=[];try{M(r,{recursive:!0}),v(a,$a,"utf8"),n.push(a);const i=u(r,"messages.ts");m(i)||(v(i,Na,"utf8"),n.push(i)),t.success(`scaffolded lunora/ (${String(n.length)} file(s))`)}catch(i){const s=i instanceof Error?i.message:String(i);t.error(`init --here: could not scaffold lunora/: ${s}`)}return n},tt=e=>e==="sveltekit"||e==="nuxt"||e==="astro",ln=(e,t,r)=>{const{adapter:a,class:n,framework:i}=e;r.info(""),r.info(`detected framework: ${i} (class ${n})`),r.info("next steps:");const s=[a,"@lunora/client","@lunora/runtime","@lunora/server"];tt(i)||s.push("@lunora/vite"),r.info(` 1. install the adapter: ${qa(t,s)}`),r.info(" 2. run codegen: lunora codegen"),n==="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")):n==="B"?(r.info(" 3. inject Lunora: mount Lunora realtime under /_lunora/* in your server hook"),r.info(` (${i} 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("")},cn=(e,t,r)=>{if(tt(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=Ke(e);return a===void 0?nn(e,r):on(a,e,r)},dn=(e,t)=>{const r=or(e),a=cn(e,r.framework,t);if(a.code!==0)return a;const n=sn(e,t);return ln(r,B(e),t),{code:0,files:[...a.files,...n],target:e}},un=e=>e.yes!==!0&&(e.prompt!==void 0||(e.interactive??b())),ve=async(e,t,r)=>{r.dryRun!==!0&&await Qr({apply:a=>vt(e,a),detected:mt(e),interactive:t,logger:r.logger,multiSelect:r.lintPrompt??((a,n,i)=>_e(a,n,{...i,badge:g.add}))})},pn=async(e,t)=>{const r=un(e),a=e.add===void 0?[]:Fr(e.add,o=>{e.logger.warn(o)}),n=async o=>{if(o.length===0)return!0;if(e.dryRun===!0)return I(e.logger,`add ${o.map(p=>p.externalAuth===void 0?p.label:`${p.label} (and wire resolveIdentity)`).join(", ")}`),!0;const l=[],c=b()?{error:p=>{l.push({level:"error",message:p})},info:()=>{},success:()=>{},warn:p=>{l.push({level:"warn",message:p})}}:e.logger,d=o.map(p=>({running:`adding ${p.label}…`,task:()=>qt({allowUnsafeSource:e.allowUnsafeSource,cwd:t,from:e.registryFrom,logger:c,names:[...p.names],ref:e.ref,source:e.registrySource,transformManifest:p.transformManifest,yes:!0})})),h=`added ${o.map(p=>p.label).join(", ")}`,f=await Bt(g.add,d,h);for(const{level:p,message:k}of l)e.logger[p](k);for(const[p,k]of o.entries())k.externalAuth!==void 0&&f[p]?.code===0&&Ur(t,k.externalAuth,e.logger);return f.every(p=>p.code===0)},i=e.auth===void 0?void 0:br(e.auth,o=>{e.logger.warn(o)}),s={applyAll:n,auth:i,interactive:r,logger:e.logger,multiSelect:e.prompt?.multiSelect??((o,l,c)=>_e(o,l,{...c,badge:g.add})),preselected:a.length>0?a:void 0,projectName:T(t),resolveAuthUiItem:()=>{const o=ke(t);if(!zt(o))return Kt(o)??"auth-ui-react"},select:e.prompt?.select??((o,l,c)=>O(o,l,{...c,badge:g.add})),selectAuth:e.prompt===void 0?(o,l,c)=>O(o,l,{...c,badge:g.add}):e.prompt.selectAuth??(()=>Promise.resolve("none")),text:e.prompt?.text??((o,l)=>Ie(o,{...l,badge:g.add}))};if(a.length>0||i!==void 0&&!r){const o=await de(s);return await ve(t,r,e),o}return b()&&await Ot(S.extras),await de(s),await ve(t,r,e),!0},z="react",rt=[{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:"React SPA on Rsbuild — the Worker runs under wrangler dev behind the dev server",label:"React · Rsbuild",value:"rspack-react"},{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 (React) on Rsbuild — SSR composed into the Lunora worker",label:"TanStack Start · React · Rsbuild",value:"tanstack-start-react-rspack"},{description:"SaaS kit — multi-tenant app on TanStack Start: organizations, projects, activity, admin",label:"SaaS kit",value:"saas"},{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:"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"}],at=Object.keys(j).join("|"),nt=rt.filter(e=>!V(e.value)).map(e=>e.value),it=nt.join("|"),hn=e=>V(e)?{framework:e,kind:"overlay"}:{kind:"template",templateType:e},fn=async e=>e.vite!==void 0?{framework:e.vite,kind:"overlay"}:e.templateType!==void 0?{kind:"template",templateType:e.templateType}:!b()||e.yes===!0?{framework:z,kind:"overlay"}:hn(await O(S.framework,rt,{badge:g.tmpl,default:z})??z),mn=e=>{if(b()||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 <${at}>\` for an SPA, or \`-t <${it}>\` 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.`},vn=async(e,t,r,a,n)=>V(t)?await Ge({isLocal:e.overlayBaseFrom!==void 0,logger:e.logger})?(M(a,{recursive:!0}),an({framework:t,logger:e.logger,markComplete:n,name:r,overlayBaseFrom:e.overlayBaseFrom,target:a})):{code:1,files:[],target:a}:(e.logger.error(`init: unknown framework "${t}". Supported overlays: ${Object.keys(j).join(", ")}.`),{code:w.USAGE,files:[],target:a}),gn=async(e,t,r,a,n)=>e.from!==void 0?await en(e.from,t,a,r,e.logger,n):e.source!==void 0&&e.source.length>0&&!e.allowUnsafeSource&&!Ka(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:w.USAGE,files:[],target:a}):await Ge({isLocal:!1,logger:e.logger,source:q(t,e.source,e.ref)})?tn({logger:e.logger,markComplete:n,name:r,ref:e.ref,source:e.source,target:a,templateType:t}):{code:1,files:[],target:a},wn=(e,t)=>{if(te(t))return;let r;try{r=B(e)}catch{return}r==="pnpm"&&Je(e)},yn=async(e,t,r)=>{await Rt("realtime backend on Cloudflare Workers + Durable Objects");const a=mn(e);if(a!==void 0)return e.logger.error(a),{code:w.USAGE,files:[],target:""};const n=Aa(),i=e.name??await Ie(S.name,{badge:g.dir,default:n,placeholder:n}),s=await fn(e),o=i.trim();if(o.length===0)return e.logger.error("init: refusing an empty project name — pass a directory name (e.g. `lunora init my-app`)."),{code:w.USAGE,files:[],target:""};if(o.includes("/")||o.includes("\\")||o===".."||o===".")return e.logger.error(`init: refusing project name "${o}" — must not contain path separators or be "." / "..".`),{code:w.USAGE,files:[],target:""};if(!Pa.test(o))return e.logger.error(`init: refusing project name "${o}" — a Cloudflare Worker name must be lowercase letters, digits, "-" or "_" (starting with a letter, digit or "_"), and wrangler rejects anything else. Try \`${Ua(o)}\`.`),{code:w.USAGE,files:[],target:""};const l=xe(t,o),c=ge(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:w.CONFLICT,files:[],target:l};const d=c!==void 0;if(d&&Y(l).length>0)return e.logger.error(`target directory not empty: ${l}`),{code:w.CONFLICT,files:[],target:l};if(e.dryRun===!0){const f=s.kind==="overlay"?`the ${s.framework} create-vite overlay`:`the ${s.templateType} template`;return I(e.logger,`scaffold ${f} into ${l}`),{code:0,files:[],target:l}}r.record(l,d);const h=s.kind==="overlay"?await vn(e,s.framework,o,l,r.complete):await gn(e,s.templateType,o,l,r.complete);return h.code===0&&wn(l,t),h},K=(e,t)=>{const{target:r,targetPreExisted:a}=e;if(!(r===void 0||!m(r))){if(a===!0)for(const n of Y(r))R(u(r,n),{force:!0,recursive:!0});else R(r,{force:!0,recursive:!0});t.info(`removed the partially-created project at ${r}`)}},bn=async(e,t,r)=>e.inPlace!==!0?yn(e,t,r):e.dryRun===!0?(I(e.logger,`configure Lunora into ${t}`),{code:0,files:[],target:t}):dn(t,e.logger),kn=async(e,t,r)=>{const a=await pn(e,t.target),n=e.inPlace===!0?void 0:await Za(e,t.target);if(e.inPlace!==!0){await Ja(e,t.target);const i=n??B(t.target);await Xa(T(t.target),n,i,te(r)),await jr(e.logger)}return a},xn=(e,t,r)=>{if(t.code!==0||e.ci===void 0)return;if(e.dryRun===!0){I(e.logger,`scaffold a ${e.ci} CI deploy pipeline`);return}const a=e.inPlace===!0?r:t.target;try{const n=B(a);nr(a,e.ci,n,e.logger)}catch{e.logger.warn(`--ci ${e.ci}: could not detect a package manager for this project — skipped the CI pipeline.`)}},Sn=async e=>{const t=e.cwd??process.cwd(),r={};let a;try{a=await bn(e,t,{complete:()=>{r.target=void 0},record:(n,i)=>{r.target=n,r.targetPreExisted=i}}),a.code===0&&a.target!==""?(r.target=void 0,await kn(e,a,t)||(a={...a,code:1})):a.code!==0&&K(r,e.logger)}catch(n){if(n instanceof X)return K(r,e.logger),process.stdout.write("\n ✖ Setup cancelled — run `lunora init` again whenever you're ready. 🌙\n"),{code:130,files:[],target:""};throw K(r,e.logger),n}return xn(e,a,t),a},Cn=e=>typeof e=="string"&&nt.includes(e),Ln=(e,t)=>{if(e!==void 0){if(rr(e))return e;t.warn(`init: unknown --ci "${e}" — expected github | gitlab; skipping CI scaffold.`)}},An=e=>e===void 0?{}:Cn(e)?{templateType:e}:V(e)?{vite:e}:{error:`init: unknown --template "${e}" — expected a bespoke template (${it}) or an overlay framework (${at}).`},Jn=Et(({argument:e,cwd:t,logger:r,options:a})=>{const n=An(a.template);return"error"in n?(r.error(n.error),{code:w.USAGE}):Sn({add:a.add,auth:a.auth,allowUnsafeSource:a.allowUnsafeSource===!0,cwd:t,ci:Ln(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:n.templateType,vite:a.vite??n.vite,yes:a.yes===!0})});export{rt as FRAMEWORK_CHOICES,Jn as execute,Cn as isTemplate,An as resolveTemplateFlag,q as resolveTemplateSource,Sn as runInitCommand};
|
|
1331
|
+
`,Oa="gh:anolilab/lunora/templates",$a=e=>{const t=e.lastIndexOf(".");return t===-1?!1:_a.has(e.slice(t))},Pa=/^[a-z0-9_][a-z0-9\-_]*$/u,Da=/([a-z0-9])([A-Z])/gu,Ua=/[^a-z0-9_]/gu,ja=e=>{const t=e.replaceAll(Da,"$1-$2").toLowerCase().replaceAll(Ua,"-").split("-").filter(r=>r.length>0);return t.length>0?t.join("-"):"my-app"},Ba=(e,t)=>e.replaceAll("{{name}}",t),Va=async(e,t)=>{const r=new Set;for(const a of e)if(_(a)==="package.json")for(const n of Object.keys(ke(S(a))))F(n)&&r.add(n);return Ae(r,t)},Fa=(e,t,r)=>{let a;try{a=JSON.parse(e)}catch{return e}let n=e;for(const o of["dependencies","devDependencies"])for(const s of Object.keys(a[o]??{})){if(!F(s))continue;const i=r.get(s)??t,l=bt(n,[o,s],i,{formattingOptions:{insertSpaces:!0,tabSize:4}});n=kt(n,l)}return n},Wa=["@parcel/watcher","esbuild","lmdb","msgpackr-extract","rs-module-lexer","sharp","unrs-resolver","vue-demi","workerd"],Ha=["cpu-features","protobufjs","ssh2"],Ye="pnpm-workspace.yaml",za=()=>["# 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:",...Wa.map(e=>` '${e}': true`),...Ha.map(e=>` '${e}': false`),""].join(`
|
|
1332
|
+
`),Je=e=>{const t=u(e,Ye);m(t)||g(t,za(),"utf8")},W=e=>{const t=[];for(const r of yt(e,{includeDirs:!1,includeFiles:!0}))ve(r.path).isSymbolicLink()||t.push(r.path);return t},fe="vitejs/vite",me=(e,t)=>{for(const r of W(e)){const a=u(t,D(e,r));E(S(a),{recursive:!0}),st(r,a)}},Xe=async(e,t,r)=>{const a=W(e),n=[],o=Ce(),s=await Va(a,o);for(const i of a){const l=D(e,i),c=u(t,l);E(S(c),{recursive:!0});const d=x(i);let p=$a(i)?Ba(d.toString("utf8"),r):void 0;p!==void 0&&_(i)==="package.json"&&(p=Fa(p,o,s)),p===void 0?g(c,d):g(c,p,"utf8"),n.push(c)}return n},q=(e,t,r)=>t!==void 0&&t.length>0?t:`${Oa}/${e}#${Ee(r)}`,Ka=e=>e.includes("..")?!1:e.startsWith("gh:")||e.startsWith("github:")||e.startsWith("https://"),M=(e,t)=>{e.info(`[dry-run] would ${t}`)},Qe=(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:w.NOT_FOUND,files:[],target:t}),Ze="Template files copied.",ee=(e,t,r)=>{b()&&process.stdout.write(`
|
|
1333
|
+
`),e.success(`scaffolded ${String(t.length)} files into ${r}`)},qa=(e,t)=>{const{args:r,command:a}=Ct(e,t);return`${a} ${r.join(" ")}`},et=(e,t)=>{let r=xe(e);for(;;){if(t(r))return!0;const a=S(r);if(a===r)return!1;r=a}},Ga=e=>m(u(e,Ye))?!0:vt(e)?.workspaces!==void 0,te=e=>et(e,Ga),Ya=e=>et(e,t=>m(u(t,".git"))),Ja=async(e,t)=>{if(e.yes===!0||!b()||Ya(S(t)))return;if(!await Ne(L.git,{badge:v.git,defaultYes:!1})){await Te("Sounds good! You can always run git init manually.");return}if(e.dryRun===!0){M(e.logger,"initialize a git repository");return}const r=e.spawner??Me;(await Pt("Initializing a git repository…",()=>r({args:["init"],command:"git",cwd:t}))).code===0?await P("git","Initialized an empty git repository."):e.logger.warn("`git init` failed — initialize it yourself later with `git init`.")},Xa=async(e,t,r,a)=>{const n=[{code:`cd ./${e}`,lead:"Enter your project directory using"}];t===void 0&&n.push({code:`${r} install`,lead:"Install dependencies with",tail:a?" from the workspace root":void 0}),n.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 o=[{code:"https://lunora.sh/docs",lead:"Read the docs at"},{code:"https://lunora.sh/chat",lead:"Stuck? Join the chat at"}];if(b()){await Dt(v.next,L.nextHeader,n,o);return}const s=n.map(i=>`${i.lead} ${i.code}${i.tail??""}`);s.push("",...o.map(i=>`${i.lead} ${i.code}${i.tail??""}`)),await P("next",L.nextHeader,s.join(`
|
|
1334
|
+
`))},Qa=e=>e.yes!==!0&&(e.installPrompt!==void 0||b()),Za=async(e,t)=>{if(!Qa(e)||te(S(t)))return;const r=St(e.packageManagerProbe),[a]=r;if(a===void 0)return;if(!await(e.installPrompt?.confirmInstall??(async()=>Ne(L.install,{badge:v.deps,defaultYes:!0})))()){await Te("No problem! Remember to install dependencies after setup.");return}let o=a;if(r.length>1&&(o=e.installPrompt?await e.installPrompt.selectManager(r):await O(L.packageManager,r.map(d=>({label:d,value:d})),{badge:v.deps,default:a})??a),e.dryRun===!0){M(e.logger,`install dependencies with ${o}`);return}o==="pnpm"&&Je(t);const s=e.spawner??Me,{args:i,command:l}=Se(o);await P("deps",`Installing dependencies with ${o}…`);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 P("deps",`Dependencies installed with ${o}.`),o},en=async(e,t,r,a,n,o)=>{const s=u(e,t);if(!m(s))return n.error(`template not found in local source: ${s}`),{code:w.NOT_FOUND,files:[],target:r};const i=await Xe(s,r,a);return i.length===0?Qe(n,r,s):(o(),ee(n,i,r),{code:0,files:i,target:r})},tn=async e=>{const{logger:t,markComplete:r,name:a,ref:n,source:o,target:s,templateType:i}=e,l=we(u(ye(),"lunora-init-fetch-")),c=u(l,"template");try{const d=o!==void 0&&o.length>0?n:await Nt(n,t),p=q(i,o,d);let f,h=[];if(await Re([{label:`${i} template fetched`,run:async()=>{f=await Le(p,{cwd:l,dir:c,force:!0,install:!1,silent:!0})}},{label:`files copied into ${a}/`,run:async()=>{h=await Xe(c,s,a)}}],{end:Ze,start:"Project initializing…"}),h.length===0)return Qe(t,s,f?.source??p);r();const k=W(c);return b()&&process.stdout.write(`
|
|
1335
|
+
`),t.info(f?.commit?`template: ${f.source} @ ${f.commit} (${String(k.length)} files)`:`template: ${f?.source??p} (${String(k.length)} files)`),ee(t,h,s),{code:0,files:h,target:s}}catch(d){if(d instanceof X)throw d;const{hints:p,message:f}=wr(d,{ref:Ee(n),remote:q(i,o,n),templateType:i});t.error(f);for(const h of p)t.warn(h);return{code:1,files:[],target:s}}finally{R(l,{force:!0,recursive:!0})}},rn=e=>{for(const t of["_gitignore","_npmrc","_gitattributes"]){const r=u(e,t);m(r)&<(r,u(e,`.${t.slice(1)}`))}},an=async e=>{const{framework:t,logger:r,markComplete:a,name:n,overlayBaseFrom:o,target:s}=e,i=B[t],l=we(u(ye(),"lunora-vite-base-"));try{let c;if(o!==void 0&&(c=u(o,`template-${i.createViteTemplate}`),!m(c)))return r.error(`create-vite base not found on disk: ${c}`),{code:w.NOT_FOUND,files:[],target:s};const d=async()=>{if(c!==void 0){me(c,s);return}const f=u(l,"base"),h=await _t(fe,"main",r),k=`github:${fe}/packages/create-vite/template-${i.createViteTemplate}#${h}`;await Le(k,{cwd:l,dir:f,force:!0,install:!1,silent:!0}),rn(f),me(f,s)};let p=[];return await Re([{label:`create-vite (${i.label}) base ready`,run:d},{label:`Lunora overlay applied (${i.label})`,run:async()=>{p=await La({adapter:i,distTag:Ce(),logger:r,name:n,target:s})}}],{end:Ze,start:"Project initializing…"}),a(),ee(r,p,s),{code:0,files:[...W(s)],target:s}}catch(c){if(c instanceof X)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})}},G=(e,t,r,a,n)=>(n.error(`init --in-place: could not ${e} ${t}: ${r instanceof Error?r.message:String(r)}`),{code:1,files:[],target:a}),nn=(e,t)=>{const r=u(e,"vite.config.ts");try{g(r,Na,"utf8")}catch(a){return G("write",r,a,e,t)}return t.success(`created ${r} with lunora() plugin`),{code:0,files:[r],target:e}},on=(e,t,r)=>{let a;try{a=x(e,"utf8")}catch(o){return G("read",e,o,t,r)}const n=je(a);if(!n.changed)return r.info(`${e}: ${n.reason??"no changes needed"}`),{code:0,files:[],target:t};try{g(e,n.code,"utf8")}catch(o){return G("write",e,o,t,r)}return r.success(`patched ${e} — added lunora() plugin`),{code:0,files:[e],target:t}},sn=(e,t)=>{const r=u(e,"lunora"),a=u(r,"schema.ts");if(m(a))return t.info(`lunora/ already present — left ${a} untouched`),[];const n=[];try{E(r,{recursive:!0}),g(a,Ta,"utf8"),n.push(a);const o=u(r,"messages.ts");m(o)||(g(o,Ra,"utf8"),n.push(o)),t.success(`scaffolded lunora/ (${String(n.length)} file(s))`)}catch(o){const s=o instanceof Error?o.message:String(o);t.error(`init --here: could not scaffold lunora/: ${s}`)}return n},tt=e=>e==="sveltekit"||e==="nuxt"||e==="astro",ln=(e,t,r)=>{const{adapter:a,class:n,framework:o}=e;r.info(""),r.info(`detected framework: ${o} (class ${n})`),r.info("next steps:");const s=[a,"@lunora/client","@lunora/runtime","@lunora/server"];tt(o)||s.push("@lunora/vite"),r.info(` 1. install the adapter: ${qa(t,s)}`),r.info(" 2. run codegen: lunora codegen"),n==="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")):n==="B"?(r.info(" 3. inject Lunora: mount Lunora realtime under /_lunora/* in your server hook"),r.info(` (${o} 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("")},cn=(e,t,r)=>{if(tt(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=Ke(e);return a===void 0?nn(e,r):on(a,e,r)},dn=(e,t)=>{const r=ir(e),a=cn(e,r.framework,t);if(a.code!==0)return a;const n=sn(e,t);return ln(r,U(e),t),{code:0,files:[...a.files,...n],target:e}},un=e=>e.yes!==!0&&(e.prompt!==void 0||(e.interactive??b())),ge=async(e,t,r)=>{r.dryRun!==!0&&await Qr({apply:a=>gt(e,a),detected:mt(e),interactive:t,logger:r.logger,multiSelect:r.lintPrompt??((a,n,o)=>_e(a,n,{...o,badge:v.add}))})},hn=async(e,t)=>{const r=un(e),a=e.add===void 0?[]:Fr(e.add,i=>{e.logger.warn(i)}),n=async i=>{if(i.length===0)return!0;if(e.dryRun===!0)return M(e.logger,`add ${i.map(h=>h.externalAuth===void 0?h.label:`${h.label} (and wire resolveIdentity)`).join(", ")}`),!0;const l=[],c=b()?{error:h=>{l.push({level:"error",message:h})},info:()=>{},success:()=>{},warn:h=>{l.push({level:"warn",message:h})}}:e.logger,d=i.map(h=>({running:`adding ${h.label}…`,task:()=>qt({allowUnsafeSource:e.allowUnsafeSource,cwd:t,from:e.registryFrom,logger:c,names:[...h.names],ref:e.ref,source:e.registrySource,transformManifest:h.transformManifest,yes:!0})})),p=`added ${i.map(h=>h.label).join(", ")}`,f=await Ut(v.add,d,p);for(const{level:h,message:k}of l)e.logger[h](k);for(const[h,k]of i.entries())k.externalAuth!==void 0&&f[h]?.code===0&&jr(t,k.externalAuth,e.logger);return f.every(h=>h.code===0)},o=e.auth===void 0?void 0:br(e.auth,i=>{e.logger.warn(i)}),s={applyAll:n,auth:o,interactive:r,logger:e.logger,multiSelect:e.prompt?.multiSelect??((i,l,c)=>_e(i,l,{...c,badge:v.add})),preselected:a.length>0?a:void 0,projectName:_(t),resolveAuthUiItem:()=>{const i=ke(t);if(!zt(i))return Kt(i)??"auth-ui-react"},select:e.prompt?.select??((i,l,c)=>O(i,l,{...c,badge:v.add})),selectAuth:e.prompt===void 0?(i,l,c)=>O(i,l,{...c,badge:v.add}):e.prompt.selectAuth??(()=>Promise.resolve("none")),text:e.prompt?.text??((i,l)=>Ie(i,{...l,badge:v.add}))};if(a.length>0||o!==void 0&&!r){const i=await de(s);return await ge(t,r,e),i}return b()&&await $t(L.extras),await de(s),await ge(t,r,e),!0},z="react",rt=[{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:"React SPA on Rsbuild — the Worker runs under wrangler dev behind the dev server",label:"React · Rsbuild",value:"rspack-react"},{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 (React) on Rsbuild — SSR composed into the Lunora worker",label:"TanStack Start · React · Rsbuild",value:"tanstack-start-react-rspack"},{description:"SaaS kit — multi-tenant app on TanStack Start: organizations, projects, activity, admin",label:"SaaS kit",value:"saas"},{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:"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"}],at=Object.keys(B).join("|"),nt=rt.filter(e=>!V(e.value)).map(e=>e.value),ot=nt.join("|"),pn=e=>V(e)?{framework:e,kind:"overlay"}:{kind:"template",templateType:e},fn=async e=>e.vite!==void 0?{framework:e.vite,kind:"overlay"}:e.templateType!==void 0?{kind:"template",templateType:e.templateType}:!b()||e.yes===!0?{framework:z,kind:"overlay"}:pn(await O(L.framework,rt,{badge:v.tmpl,default:z})??z),mn=e=>{if(b()||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 <${at}>\` for an SPA, or \`-t <${ot}>\` 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.`},gn=async(e,t,r,a,n)=>V(t)?await Ge({isLocal:e.overlayBaseFrom!==void 0,logger:e.logger})?(E(a,{recursive:!0}),an({framework:t,logger:e.logger,markComplete:n,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:w.USAGE,files:[],target:a}),vn=async(e,t,r,a,n)=>e.from!==void 0?await en(e.from,t,a,r,e.logger,n):e.source!==void 0&&e.source.length>0&&!e.allowUnsafeSource&&!Ka(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:w.USAGE,files:[],target:a}):await Ge({isLocal:!1,logger:e.logger,source:q(t,e.source,e.ref)})?tn({logger:e.logger,markComplete:n,name:r,ref:e.ref,source:e.source,target:a,templateType:t}):{code:1,files:[],target:a},wn=(e,t)=>{if(te(t))return;let r;try{r=U(e)}catch{return}r==="pnpm"&&Je(e)},yn=async(e,t,r)=>{await Ot("realtime backend on Cloudflare Workers + Durable Objects");const a=mn(e);if(a!==void 0)return e.logger.error(a),{code:w.USAGE,files:[],target:""};const n=Ca(),o=e.name??await Ie(L.name,{badge:v.dir,default:n,placeholder:n}),s=await fn(e),i=o.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:w.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:w.USAGE,files:[],target:""};if(!Pa.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 \`${ja(i)}\`.`),{code:w.USAGE,files:[],target:""};const l=xe(t,i),c=ve(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:w.CONFLICT,files:[],target:l};const d=c!==void 0;if(d&&Y(l).length>0)return e.logger.error(`target directory not empty: ${l}`),{code:w.CONFLICT,files:[],target:l};if(e.dryRun===!0){const f=s.kind==="overlay"?`the ${s.framework} create-vite overlay`:`the ${s.templateType} template`;return M(e.logger,`scaffold ${f} into ${l}`),{code:0,files:[],target:l}}r.record(l,d);const p=s.kind==="overlay"?await gn(e,s.framework,i,l,r.complete):await vn(e,s.templateType,i,l,r.complete);return p.code===0&&wn(l,t),p},K=(e,t)=>{const{target:r,targetPreExisted:a}=e;if(!(r===void 0||!m(r))){if(a===!0)for(const n of Y(r))R(u(r,n),{force:!0,recursive:!0});else R(r,{force:!0,recursive:!0});t.info(`removed the partially-created project at ${r}`)}},bn=async(e,t,r)=>e.inPlace!==!0?yn(e,t,r):e.dryRun===!0?(M(e.logger,`configure Lunora into ${t}`),{code:0,files:[],target:t}):dn(t,e.logger),kn=async(e,t,r)=>{const a=await hn(e,t.target),n=e.inPlace===!0?void 0:await Za(e,t.target);if(e.inPlace!==!0){await Ja(e,t.target);const o=n??U(t.target);await Xa(_(t.target),n,o,te(r)),await Br(e.logger)}return a},xn=(e,t,r)=>{if(t.code!==0||e.ci===void 0)return;if(e.dryRun===!0){M(e.logger,`scaffold a ${e.ci} CI deploy pipeline`);return}const a=e.inPlace===!0?r:t.target;try{const n=U(a);nr(a,e.ci,n,e.logger)}catch{e.logger.warn(`--ci ${e.ci}: could not detect a package manager for this project — skipped the CI pipeline.`)}},Ln=async e=>{const t=e.cwd??process.cwd(),r={};let a;try{a=await bn(e,t,{complete:()=>{r.target=void 0},record:(n,o)=>{r.target=n,r.targetPreExisted=o}}),a.code===0&&a.target!==""?(r.target=void 0,await kn(e,a,t)||(a={...a,code:1})):a.code!==0&&K(r,e.logger)}catch(n){if(n instanceof X)return K(r,e.logger),process.stdout.write("\n ✖ Setup cancelled — run `lunora init` again whenever you're ready. 🌙\n"),{code:130,files:[],target:""};throw K(r,e.logger),n}return xn(e,a,t),a},Sn=e=>typeof e=="string"&&nt.includes(e),An=(e,t)=>{if(e!==void 0){if(rr(e))return e;t.warn(`init: unknown --ci "${e}" — expected github | gitlab; skipping CI scaffold.`)}},Cn=e=>e===void 0?{}:Sn(e)?{templateType:e}:V(e)?{vite:e}:{error:`init: unknown --template "${e}" — expected a bespoke template (${ot}) or an overlay framework (${at}).`},Jn=Et(({argument:e,cwd:t,logger:r,options:a})=>{const n=Cn(a.template);return"error"in n?(r.error(n.error),{code:w.USAGE}):Ln({add:a.add,auth:a.auth,allowUnsafeSource:a.allowUnsafeSource===!0,cwd:t,ci:An(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:n.templateType,vite:a.vite??n.vite,yes:a.yes===!0})});export{rt as FRAMEWORK_CHOICES,Jn as execute,Sn as isTemplate,Cn as resolveTemplateFlag,q as resolveTemplateSource,Ln as runInitCommand};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./shared-CV7ESvuj.mjs";import"./admin-token-VdUnvnKW.mjs";import"./admin-url-DJB8P6Jh.mjs";import"./EXIT_CODE-DVjUgIaG.mjs";import"./tui-prompts-B3YwUhGw.mjs";import{D as I,r as T}from"./import-C-XRRHrZ.mjs";export{I as DEFAULT_IMPORT_BATCH_SIZE,T as runImportCommand};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{LunoraError as r}from"@lunora/errors";import{E as y,c as N}from"./shared-CV7ESvuj.mjs";const g=async(l,f,h)=>{const n=await l.fetchImpl(`${l.baseUrl}${y}`,{body:JSON.stringify({tables:f}),headers:{authorization:`Bearer ${l.token}`,"content-type":"application/json"},method:"POST"});if(!n.ok)throw new r("INTERNAL",`reading the deployment's rows failed (HTTP ${String(n.status)})`);if(!n.body)throw new r("INTERNAL","reading the deployment's rows failed: the export response carried no body");const s=n.body.getReader(),w=new TextDecoder;let t="",i=0;const c=N(),p=o=>{if(i+=1,o.trim().length===0)return!0;const a=`reading the deployment's rows failed: export line ${String(i)} (${String(o.length)} characters) is not a { table, doc } row`;let e;try{e=JSON.parse(o)}catch{throw new r("INTERNAL",a)}try{if(!c.read(e))return!0}catch{throw new r("INTERNAL",`reading the deployment's rows failed: export line ${String(i)} follows the export's end marker`)}if(e===null||typeof e.table!="string"||e.doc===null||typeof e.doc!="object")throw new r("INTERNAL",a);return h({doc:e.doc,table:e.table})!==!1};try{for(;;){const{done:a,value:e}=await s.read();if(a)break;t+=w.decode(e,{stream:!0});let d=t.indexOf(`
|
|
2
|
+
`);for(;d!==-1;){const m=t.slice(0,d);if(t=t.slice(d+1),!p(m)){await s.cancel().catch(()=>{});return}d=t.indexOf(`
|
|
3
|
+
`)}}if(t.trim().length>0)throw new r("INTERNAL",`reading the deployment's rows failed: the export ended inside line ${String(i+1)}`);const o=c.problem();if(o!==void 0)throw new r("INTERNAL",`reading the deployment's rows failed: ${o}`)}finally{s.releaseLock()}};export{g as f};
|