generatesaas 1.19.2 → 1.20.1
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.js +262 -241
- package/dist/skill/content/scripts/_helpers.js +13 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{Command as ea}from"commander";import*as no from"@clack/prompts";import{existsSync as vs,readdirSync as bs,rmSync as ks}from"fs";import{join as Ss,resolve as ws}from"path";import{Option as Y}from"commander";import*as E from"@clack/prompts";import*as at from"@clack/prompts";import Dt from"picocolors";function ar(e){let t=e?` GenerateSaaS v${e} `:" GenerateSaaS ";at.intro(Dt.bgYellow(Dt.black(t)))}function cr(){at.outro(Dt.yellow("Happy building!"))}import*as h from"@clack/prompts";import y from"picocolors";var qe={nextjs:{label:"Next.js",hint:"React 19 + Next.js 16"},nuxt:{label:"Nuxt",hint:"Vue 3 + Nuxt 4"}},Je={fullstack:{label:"Fullstack",hint:"Frontend hosts the API - works on serverless or long-running"},separate:{label:"Separate",hint:"Standalone Hono backend - long-running runtimes only (Docker, Render, Fly.io, Railway, Coolify, Dokploy)"}},ct={stripe:{label:"Stripe"},polar:{label:"Polar"},none:{label:"None",hint:"disable payments"}},lt={smtp:{label:"SMTP",hint:"Mailpit for local dev"},ses:{label:"Amazon SES"},resend:{label:"Resend"}},pt={user:{label:"Per user",hint:"each user has their own subscription"},organization:{label:"Per organization",hint:"org subscription shared by members"}},Te={postgres:{label:"PostgreSQL",hint:"port 5432",port:5432},redis:{label:"Redis",hint:"port 6379",port:6379},inngest:{label:"Inngest",hint:"port 8288",port:8288},mailpit:{label:"Mailpit",hint:"port 1025",port:1025}},We={"claude-code":{label:"Claude Code"},cursor:{label:"Cursor"},codex:{label:"Codex"},"gemini-cli":{label:"Gemini CLI"},windsurf:{label:"Windsurf"}};var ye={USD:{symbol:"$",name:"US Dollar",place:"left",space:!1},EUR:{symbol:"\u20AC",name:"Euro",place:"right",space:!1},GBP:{symbol:"\xA3",name:"British Pound",place:"left",space:!1},CAD:{symbol:"CA$",name:"Canadian Dollar",place:"left",space:!1},AUD:{symbol:"A$",name:"Australian Dollar",place:"left",space:!1},BRL:{symbol:"R$",name:"Brazilian Real",place:"left",space:!1},JPY:{symbol:"\xA5",name:"Japanese Yen",place:"left",space:!1}};var Q={node:{label:"Node.js / Docker",hint:"long-running runtime - Render, Fly.io, Railway, Coolify, Dokploy, VPS",edgeRuntime:!1},vercel:{label:"Vercel",hint:"serverless functions",edgeRuntime:!0}},F={postgres:{label:"PostgreSQL (self-hosted)",hint:"local Docker, drizzle-orm/node-postgres",managed:!1,envVars:[{key:"DATABASE_URL",defaultValue:"postgres://postgres:postgres@localhost:5432/saas"}]},neon:{label:"Neon",hint:"serverless Postgres",managed:!0,envVars:[{key:"DATABASE_URL",comment:"# TODO: Add your Neon connection string"}]},supabase:{label:"Supabase",hint:"managed Postgres",managed:!0,envVars:[{key:"DATABASE_URL",comment:"# TODO: Add your Supabase connection string"}]}},ee={redis:{label:"Redis (self-hosted)",hint:"local Docker, ioredis",managed:!1,envVars:[{key:"REDIS_URL",defaultValue:"redis://localhost:6379"}]},upstash:{label:"Upstash",hint:"serverless Redis",managed:!0,envVars:[{key:"UPSTASH_REDIS_REST_URL",comment:"# TODO: Add your Upstash REST URL"},{key:"UPSTASH_REDIS_REST_TOKEN",comment:"# TODO: Add your Upstash REST token"}]}},Xe=[{target:"vercel",provider:"redis",reason:"Vercel serverless cannot maintain persistent Redis connections. Consider Upstash."}],Ze=[{architecture:"separate",target:"vercel",reason:"Standalone backends need a long-running runtime. Vercel's per-function TypeScript check conflicts with pnpm's isolated install. Use --architecture fullstack for serverless, or deploy the standalone backend to a long-running runtime (Render, Fly.io, Railway, Coolify, Dokploy, or your own VPS via Docker)."}],lr=["Local file storage (sharp, geoip-lite)","SMTP email (use Resend or SES instead)","Content API git integration"];function dt(e){let t=F[e.databaseProvider].managed,r=ee[e.cacheProvider].managed;return e.dockerServices.some(n=>!(n==="postgres"&&t||n==="redis"&&r))}var oe={google:{label:"Google",envVars:[{name:"GOOGLE_CLIENT_ID",secret:!1},{name:"GOOGLE_CLIENT_SECRET",secret:!0}]},github:{label:"GitHub",envVars:[{name:"GITHUB_CLIENT_ID",secret:!1},{name:"GITHUB_CLIENT_SECRET",secret:!0}]},facebook:{label:"Facebook",envVars:[{name:"FACEBOOK_CLIENT_ID",secret:!1},{name:"FACEBOOK_CLIENT_SECRET",secret:!0}]},discord:{label:"Discord",envVars:[{name:"DISCORD_CLIENT_ID",secret:!1},{name:"DISCORD_CLIENT_SECRET",secret:!0}]},x:{label:"X",envVars:[{name:"TWITTER_CLIENT_ID",secret:!1},{name:"TWITTER_CLIENT_SECRET",secret:!0}]}};var ve=["nextjs","nuxt"],Re=["fullstack","separate"],_e=["stripe","polar","none"],Oe=["smtp","ses","resend"],xe=["postgres","redis","inngest","mailpit"],De=["claude-code","cursor","codex","gemini-cli","windsurf"],Ce=["user","organization"],ie=["USD","EUR","GBP","CAD","AUD","BRL","JPY"],se=["node","vercel"],ae=["postgres","neon","supabase"],ce=["redis","upstash"],Ne=["google","github","facebook","discord","x"];function ut(e){return e.split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function mt(e){return/^[a-z][a-z0-9-]*$/.test(e)}function x(e){return e instanceof Error?e.message:String(e)}function P(e){h.isCancel(e)&&(h.cancel("Setup cancelled."),process.exit(0))}function Ct(e){let t=[];e.databaseProvider==="neon"&&t.push({key:"DATABASE_URL",message:"Neon connection string (optional):",placeholder:"postgres://...",secret:!0}),e.databaseProvider==="supabase"&&t.push({key:"DATABASE_URL",message:"Supabase connection string (optional):",placeholder:"postgres://...",secret:!0}),e.cacheProvider==="upstash"&&(t.push({key:"UPSTASH_REDIS_REST_URL",message:"Upstash REST URL (optional):",placeholder:"https://...",secret:!1}),t.push({key:"UPSTASH_REDIS_REST_TOKEN",message:"Upstash REST token (optional):",secret:!0})),e.paymentProvider==="stripe"&&(t.push({key:"STRIPE_SECRET_KEY",message:"Stripe secret key (optional):",placeholder:"sk_test_...",secret:!0}),t.push({key:"STRIPE_WEBHOOK_SECRET",message:"Stripe webhook secret (optional):",placeholder:"whsec_...",secret:!0})),e.paymentProvider==="polar"&&(t.push({key:"POLAR_ACCESS_TOKEN",message:"Polar access token (optional):",secret:!0}),t.push({key:"POLAR_WEBHOOK_SECRET",message:"Polar webhook secret (optional):",secret:!0})),e.emailProvider==="resend"&&t.push({key:"RESEND_API_KEY",message:"Resend API key (optional):",placeholder:"re_...",secret:!0}),e.emailProvider==="ses"&&(t.push({key:"AMAZON_SES_REGION",message:"Amazon SES region (optional):",placeholder:"us-east-1",secret:!1}),t.push({key:"AMAZON_SES_KEY",message:"Amazon SES access key (optional):",secret:!0}),t.push({key:"AMAZON_SES_SECRET",message:"Amazon SES secret (optional):",secret:!0}));for(let r of e.socialProviders){let n=oe[r];for(let o of n.envVars)t.push({key:o.name,message:`${o.name} (${n.label}, optional):`,secret:o.secret})}return e.demo&&t.push({key:"TURNSTILE_SECRET_KEY",message:"Cloudflare Turnstile secret key (optional):",secret:!0}),t}async function pr(e,t){let r=!1;h.log.info(y.bold("Project"));let n=e?.projectName??await(async()=>{r=!0;let l=await h.text({message:"Project name:",placeholder:"my-saas",validate:d=>{if(!d?.trim())return"Project name is required.";if(!mt(d))return"Use lowercase letters, numbers, and hyphens only. Must start with a letter."}});return P(l),l})(),o=e?.appName??await(async()=>{r=!0;let l=await h.text({message:"App name:",initialValue:ut(n),validate:d=>{if(!d?.trim())return"App name is required."}});return P(l),l})(),i=e?.projectDir??await(async()=>{r=!0;let l=await h.text({message:"Project location:",initialValue:`./${n}`});return P(l),l==="."?process.cwd():l})(),s=e?.frontend??await(async()=>{r=!0;let l=Object.keys(qe),d=await h.select({message:"Frontend framework:",options:l.map(k=>({value:k,label:qe[k].label,hint:qe[k].hint}))});return P(d),d})();h.log.info(y.bold("Infrastructure"));let a=e?.deploymentTarget??"node";if(e?.deploymentTarget===void 0){r=!0;let l=await h.select({message:"Deployment target:",options:se.map(d=>({value:d,label:Q[d].label,hint:Q[d].hint}))});P(l),a=l}let p=e?.architecture?Ze.find(l=>l.architecture===e.architecture&&l.target===a):void 0;if(p)throw new Error(`Incompatible: --architecture ${p.architecture} + --deploy ${p.target}. ${p.reason}`);let f=new Set(Ze.filter(l=>l.target===a).map(l=>l.architecture)),m=Re.filter(l=>!f.has(l)),u=e?.architecture??await(async()=>{if(m.length===1){let d=m[0];return h.log.info(`Auto-selected ${Je[d].label} architecture (only compatible option for ${Q[a].label}).`),d}r=!0;let l=await h.select({message:"Architecture:",options:m.map(d=>({value:d,label:Je[d].label,hint:Je[d].hint}))});return P(l),l})(),v=e?.databaseProvider??await(async()=>{r=!0;let l=ae.filter(k=>!Xe.some(M=>M.target===a&&M.provider===k));if(l.length===1){let k=l[0];return h.log.info(`Auto-selected ${F[k].label} (only compatible option for ${Q[a].label}).`),k}let d=await h.select({message:"Database provider:",options:l.map(k=>({value:k,label:F[k].label,hint:F[k].hint}))});return P(d),d})(),w=e?.cacheProvider??await(async()=>{r=!0;let l=ce.filter(k=>!Xe.some(M=>M.target===a&&M.provider===k));if(l.length===1){let k=l[0];return h.log.info(`Auto-selected ${ee[k].label} (only compatible option for ${Q[a].label}).`),k}let d=await h.select({message:"Cache provider:",options:l.map(k=>({value:k,label:ee[k].label,hint:ee[k].hint}))});return P(d),d})();if(Q[a]?.edgeRuntime){let l=lr.map(d=>` - ${d}`).join(`
|
|
3
|
-
`);
|
|
4
|
-
`),
|
|
5
|
-
`),
|
|
6
|
-
`),
|
|
7
|
-
`);
|
|
8
|
-
`),"Summary");let
|
|
9
|
-
`,{mode:384})}async function
|
|
10
|
-
`))}}async function
|
|
11
|
-
`)}function
|
|
12
|
-
- **Payments:** ${
|
|
2
|
+
import{Command as Rs}from"commander";import*as _i from"@clack/prompts";import{existsSync as Ha,readdirSync as za,rmSync as Ya}from"fs";import{join as qa,resolve as Ja}from"path";import{Option as Q}from"commander";import*as A from"@clack/prompts";import*as ft from"@clack/prompts";import Gt from"picocolors";function xn(e){let t=e?` GenerateSaaS v${e} `:" GenerateSaaS ";ft.intro(Gt.bgYellow(Gt.black(t)))}function Cn(){ft.outro(Gt.yellow("Happy building!"))}import*as g from"@clack/prompts";import y from"picocolors";var et={nextjs:{label:"Next.js",hint:"React 19 + Next.js 16"},nuxt:{label:"Nuxt",hint:"Vue 3 + Nuxt 4"}},tt={fullstack:{label:"Fullstack",hint:"Frontend hosts the API - works on serverless or long-running"},separate:{label:"Separate",hint:"Standalone Hono backend - long-running runtimes only (Docker, Render, Fly.io, Railway, Coolify, Dokploy)"}},gt={stripe:{label:"Stripe"},polar:{label:"Polar"},none:{label:"None",hint:"disable payments"}},ht={smtp:{label:"SMTP",hint:"Mailpit for local dev"},ses:{label:"Amazon SES"},resend:{label:"Resend"}},yt={user:{label:"Per user",hint:"each user has their own subscription"},organization:{label:"Per organization",hint:"org subscription shared by members"}},De={postgres:{label:"PostgreSQL",hint:"port 5432",port:5432},redis:{label:"Redis",hint:"port 6379",port:6379},inngest:{label:"Inngest",hint:"port 8288",port:8288},mailpit:{label:"Mailpit",hint:"port 1025",port:1025}},nt={"claude-code":{label:"Claude Code"},cursor:{label:"Cursor"},codex:{label:"Codex"},"gemini-cli":{label:"Gemini CLI"},windsurf:{label:"Windsurf"}};var Se={USD:{symbol:"$",name:"US Dollar",place:"left",space:!1},EUR:{symbol:"\u20AC",name:"Euro",place:"right",space:!1},GBP:{symbol:"\xA3",name:"British Pound",place:"left",space:!1},CAD:{symbol:"CA$",name:"Canadian Dollar",place:"left",space:!1},AUD:{symbol:"A$",name:"Australian Dollar",place:"left",space:!1},BRL:{symbol:"R$",name:"Brazilian Real",place:"left",space:!1},JPY:{symbol:"\xA5",name:"Japanese Yen",place:"left",space:!1}};var ne={node:{label:"Node.js / Docker",hint:"long-running runtime - Render, Fly.io, Railway, Coolify, Dokploy, VPS",edgeRuntime:!1},vercel:{label:"Vercel",hint:"serverless functions",edgeRuntime:!0}},G={postgres:{label:"PostgreSQL (self-hosted)",hint:"local Docker, drizzle-orm/node-postgres",managed:!1,envVars:[{key:"DATABASE_URL",defaultValue:"postgres://postgres:postgres@localhost:5432/saas"}]},neon:{label:"Neon",hint:"serverless Postgres",managed:!0,envVars:[{key:"DATABASE_URL",comment:"# TODO: Add your Neon connection string"}]},supabase:{label:"Supabase",hint:"managed Postgres",managed:!0,envVars:[{key:"DATABASE_URL",comment:"# TODO: Add your Supabase connection string"}]}},re={redis:{label:"Redis (self-hosted)",hint:"local Docker, ioredis",managed:!1,envVars:[{key:"REDIS_URL",defaultValue:"redis://localhost:6379"}]},upstash:{label:"Upstash",hint:"serverless Redis",managed:!0,envVars:[{key:"UPSTASH_REDIS_REST_URL",comment:"# TODO: Add your Upstash REST URL"},{key:"UPSTASH_REDIS_REST_TOKEN",comment:"# TODO: Add your Upstash REST token"}]}},rt=[{target:"vercel",provider:"redis",reason:"Vercel serverless cannot maintain persistent Redis connections. Consider Upstash."}],it=[{architecture:"separate",target:"vercel",reason:"Standalone backends need a long-running runtime. Vercel's per-function TypeScript check conflicts with pnpm's isolated install. Use --architecture fullstack for serverless, or deploy the standalone backend to a long-running runtime (Render, Fly.io, Railway, Coolify, Dokploy, or your own VPS via Docker)."}],Dn=["Local file storage (sharp, geoip-lite)","SMTP email (use Resend or SES instead)","Content API git integration"];function vt(e){let t=G[e.databaseProvider].managed,n=re[e.cacheProvider].managed;return e.dockerServices.some(r=>!(r==="postgres"&&t||r==="redis"&&n))}var se={google:{label:"Google",envVars:[{name:"GOOGLE_CLIENT_ID",secret:!1},{name:"GOOGLE_CLIENT_SECRET",secret:!0}]},github:{label:"GitHub",envVars:[{name:"GITHUB_CLIENT_ID",secret:!1},{name:"GITHUB_CLIENT_SECRET",secret:!0}]},facebook:{label:"Facebook",envVars:[{name:"FACEBOOK_CLIENT_ID",secret:!1},{name:"FACEBOOK_CLIENT_SECRET",secret:!0}]},discord:{label:"Discord",envVars:[{name:"DISCORD_CLIENT_ID",secret:!1},{name:"DISCORD_CLIENT_SECRET",secret:!0}]},x:{label:"X",envVars:[{name:"TWITTER_CLIENT_ID",secret:!1},{name:"TWITTER_CLIENT_SECRET",secret:!0}]}};var Ee=["nextjs","nuxt"],Ne=["fullstack","separate"],Le=["stripe","polar","none"],$e=["smtp","ses","resend"],je=["postgres","redis","inngest","mailpit"],Ue=["claude-code","cursor","codex","gemini-cli","windsurf"],Me=["user","organization"],ce=["USD","EUR","GBP","CAD","AUD","BRL","JPY"],le=["node","vercel"],pe=["postgres","neon","supabase"],de=["redis","upstash"],Ve=["google","github","facebook","discord","x"];function kt(e){return e.split("-").map(t=>t.charAt(0).toUpperCase()+t.slice(1)).join(" ")}function wt(e){return/^[a-z][a-z0-9-]*$/.test(e)}function C(e){return e instanceof Error?e.message:String(e)}var Nn=["companion","mcpServer","rag"];function zt(e){if(!Nn.some(n=>e[n]===!0))return e;if(e.ai===!1)throw new Error("--companion / --mcp-server / --rag require AI features; remove --no-ai.");return e.ai===void 0&&(e.ai=!0),e}function Ln(e){return Nn.some(n=>e[n]===!0)&&(e.ai=!0),e}function $n(e){let t={};if(e.name!==void 0){if(!wt(e.name))throw new Error(`Invalid project name "${e.name}". Use lowercase letters, numbers, and hyphens only. Must start with a letter.`);t.projectName=e.name}if(e.appName!==void 0){if(!e.appName.trim())throw new Error("App name cannot be empty.");t.appName=e.appName}if(e.location!==void 0?t.projectDir=e.location==="."?process.cwd():e.location:t.projectName!==void 0&&(t.projectDir=`./${t.projectName}`),e.frontend!==void 0){if(!Ee.includes(e.frontend))throw new Error(`Invalid frontend "${e.frontend}". Valid values: ${Ee.join(", ")}`);t.frontend=e.frontend}if(e.architecture!==void 0&&(t.architecture=e.architecture),e.payment!==void 0&&(t.paymentProvider=e.payment),e.email!==void 0&&(t.emailProvider=e.email),e.org!==void 0&&(t.multiTenancy=e.org),e.billingScope!==void 0){if(e.org!==!0)throw new Error("--billing-scope requires --org to be enabled.");t.billingScope=e.billingScope}if(e.blog!==void 0&&(t.blog=e.blog),e.docs!==void 0&&(t.docs=e.docs),e.desktop!==void 0&&(t.desktop=e.desktop),e.desktopAuto!==void 0&&(t.desktopAutoRelease=e.desktopAuto),e.desktopAi!==void 0){if(e.desktopAi===!0&&e.desktop!==!0)throw new Error("--desktop-ai requires --desktop to be enabled.");t.desktopAi=e.desktopAi}if(e.ai!==void 0&&(t.ai=e.ai),e.rag!==void 0&&(t.rag=e.rag),e.companion!==void 0&&(t.companion=e.companion),e.mcpServer!==void 0&&(t.mcpServer=e.mcpServer),e.aiByok!==void 0&&(t.aiByok=e.aiByok),zt(t),e.revenueSharing!==void 0&&(t.revenueSharing=e.revenueSharing),e.credits!==void 0){if(e.credits===!0&&e.payment==="none")throw new Error("--credits requires a payment provider (got --payment none).");t.credits=e.credits}if(e.docker!==void 0&&(t.dockerServices=Ht(e.docker,je,"docker service")),e.aiTools!==void 0&&(t.aiTools=Ht(e.aiTools,Ue,"AI tool")),e.socialProviders!==void 0&&(t.socialProviders=Ht(e.socialProviders,Ve,"social provider")),e.currency!==void 0){if(!ce.includes(e.currency))throw new Error(`Invalid currency "${e.currency}". Valid values: ${ce.join(", ")}`);t.defaultCurrency=e.currency}if(e.deploy!==void 0){if(!le.includes(e.deploy))throw new Error(`Invalid deployment target "${e.deploy}". Valid values: ${le.join(", ")}`);t.deploymentTarget=e.deploy}if(e.database!==void 0){if(!pe.includes(e.database))throw new Error(`Invalid database provider "${e.database}". Valid values: ${pe.join(", ")}`);t.databaseProvider=e.database}if(e.cache!==void 0){if(!de.includes(e.cache))throw new Error(`Invalid cache provider "${e.cache}". Valid values: ${de.join(", ")}`);t.cacheProvider=e.cache}if(e.demo===!0&&(t.demo=!0),e.baseUrl!==void 0){let n=e.baseUrl.trim();if(n==="")throw new Error("--base-url cannot be empty. Provide an absolute URL like https://example.com.");let r;try{r=new URL(n)}catch{throw new Error(`Invalid --base-url "${e.baseUrl}". Must be an absolute URL like https://example.com.`)}if(r.protocol!=="http:"&&r.protocol!=="https:")throw new Error(`Invalid --base-url "${e.baseUrl}". Must use http or https.`);t.baseUrl=`${r.protocol}//${r.host}`}return t}var ue={projectName:"my-saas",frontend:"nextjs",architecture:"fullstack",paymentProvider:"stripe",emailProvider:"smtp",multiTenancy:!1,billingScope:"user",blog:!0,docs:!1,desktop:!1,desktopAutoRelease:!1,desktopAi:!1,ai:!1,rag:!1,companion:!1,mcpServer:!1,aiByok:!0,revenueSharing:!1,credits:!0,dockerServices:["postgres","redis","inngest"],aiTools:[],socialProviders:[],defaultCurrency:"USD",deploymentTarget:"node",databaseProvider:"postgres",cacheProvider:"redis"};function jn(e){let t=e.projectName??ue.projectName,n=e.projectDir??`./${t}`,r=e.appName??kt(t),i=e.deploymentTarget??ue.deploymentTarget,o=ne[i]?.edgeRuntime??!1,a=e.databaseProvider??(o?"neon":ue.databaseProvider),s=e.cacheProvider??(o?"upstash":ue.cacheProvider),p=e.emailProvider??(o?"resend":ue.emailProvider),f=e.dockerServices??(o?ue.dockerServices.filter(d=>d!=="postgres"&&d!=="redis"):ue.dockerServices),m={...ue,...e,projectName:t,appName:r,projectDir:n,deploymentTarget:i,databaseProvider:a,cacheProvider:s,emailProvider:p,dockerServices:f};m.paymentProvider==="none"&&(m.credits=!1),m.multiTenancy||(m.billingScope="user"),m.ai||(m.aiByok=ue.aiByok);for(let d of rt){if(m.deploymentTarget!==d.target)continue;let v=m.databaseProvider===d.provider?"database":"cache";if(m.databaseProvider===d.provider||m.cacheProvider===d.provider)throw new Error(`Incompatible: --deploy ${d.target} + --${v} ${d.provider}. ${d.reason}`)}for(let d of it)if(m.architecture===d.architecture&&m.deploymentTarget===d.target)throw new Error(`Incompatible: --architecture ${d.architecture} + --deploy ${d.target}. ${d.reason}`);return m}function Ht(e,t,n){if(e.trim()==="")return[];let r=e.split(",").map(o=>o.trim()).filter(Boolean),i=r.filter(o=>!t.includes(o));if(i.length>0)throw new Error(`Invalid ${n}(s): ${i.join(", ")}. Valid values: ${t.join(", ")}`);return r}function E(e){g.isCancel(e)&&(g.cancel("Setup cancelled."),process.exit(0))}function Yt(e){let t=[];e.databaseProvider==="neon"&&t.push({key:"DATABASE_URL",message:"Neon connection string (optional):",placeholder:"postgres://...",secret:!0}),e.databaseProvider==="supabase"&&t.push({key:"DATABASE_URL",message:"Supabase connection string (optional):",placeholder:"postgres://...",secret:!0}),e.cacheProvider==="upstash"&&(t.push({key:"UPSTASH_REDIS_REST_URL",message:"Upstash REST URL (optional):",placeholder:"https://...",secret:!1}),t.push({key:"UPSTASH_REDIS_REST_TOKEN",message:"Upstash REST token (optional):",secret:!0})),e.paymentProvider==="stripe"&&(t.push({key:"STRIPE_SECRET_KEY",message:"Stripe secret key (optional):",placeholder:"sk_test_...",secret:!0}),t.push({key:"STRIPE_WEBHOOK_SECRET",message:"Stripe webhook secret (optional):",placeholder:"whsec_...",secret:!0})),e.paymentProvider==="polar"&&(t.push({key:"POLAR_ACCESS_TOKEN",message:"Polar access token (optional):",secret:!0}),t.push({key:"POLAR_WEBHOOK_SECRET",message:"Polar webhook secret (optional):",secret:!0})),e.emailProvider==="resend"&&t.push({key:"RESEND_API_KEY",message:"Resend API key (optional):",placeholder:"re_...",secret:!0}),e.emailProvider==="ses"&&(t.push({key:"AMAZON_SES_REGION",message:"Amazon SES region (optional):",placeholder:"us-east-1",secret:!1}),t.push({key:"AMAZON_SES_KEY",message:"Amazon SES access key (optional):",secret:!0}),t.push({key:"AMAZON_SES_SECRET",message:"Amazon SES secret (optional):",secret:!0}));for(let n of e.socialProviders){let r=se[n];for(let i of r.envVars)t.push({key:i.name,message:`${i.name} (${r.label}, optional):`,secret:i.secret})}return e.demo&&t.push({key:"TURNSTILE_SECRET_KEY",message:"Cloudflare Turnstile secret key (optional):",secret:!0}),t}async function Un(e,t){let n=!1;e&&zt(e),g.log.info(y.bold("Project"));let r=e?.projectName??await(async()=>{n=!0;let c=await g.text({message:"Project name:",placeholder:"my-saas",validate:u=>{if(!u?.trim())return"Project name is required.";if(!wt(u))return"Use lowercase letters, numbers, and hyphens only. Must start with a letter."}});return E(c),c})(),i=e?.appName??await(async()=>{n=!0;let c=await g.text({message:"App name:",initialValue:kt(r),validate:u=>{if(!u?.trim())return"App name is required."}});return E(c),c})(),o=e?.projectDir??await(async()=>{n=!0;let c=await g.text({message:"Project location:",initialValue:`./${r}`});return E(c),c==="."?process.cwd():c})(),a=e?.frontend??await(async()=>{n=!0;let c=Object.keys(et),u=await g.select({message:"Frontend framework:",options:c.map(S=>({value:S,label:et[S].label,hint:et[S].hint}))});return E(u),u})();g.log.info(y.bold("Infrastructure"));let s=e?.deploymentTarget??"node";if(e?.deploymentTarget===void 0){n=!0;let c=await g.select({message:"Deployment target:",options:le.map(u=>({value:u,label:ne[u].label,hint:ne[u].hint}))});E(c),s=c}let p=e?.architecture?it.find(c=>c.architecture===e.architecture&&c.target===s):void 0;if(p)throw new Error(`Incompatible: --architecture ${p.architecture} + --deploy ${p.target}. ${p.reason}`);let f=new Set(it.filter(c=>c.target===s).map(c=>c.architecture)),m=Ne.filter(c=>!f.has(c)),d=e?.architecture??await(async()=>{if(m.length===1){let u=m[0];return g.log.info(`Auto-selected ${tt[u].label} architecture (only compatible option for ${ne[s].label}).`),u}n=!0;let c=await g.select({message:"Architecture:",options:m.map(u=>({value:u,label:tt[u].label,hint:tt[u].hint}))});return E(c),c})(),v=e?.databaseProvider??await(async()=>{n=!0;let c=pe.filter(S=>!rt.some(F=>F.target===s&&F.provider===S));if(c.length===1){let S=c[0];return g.log.info(`Auto-selected ${G[S].label} (only compatible option for ${ne[s].label}).`),S}let u=await g.select({message:"Database provider:",options:c.map(S=>({value:S,label:G[S].label,hint:G[S].hint}))});return E(u),u})(),b=e?.cacheProvider??await(async()=>{n=!0;let c=de.filter(S=>!rt.some(F=>F.target===s&&F.provider===S));if(c.length===1){let S=c[0];return g.log.info(`Auto-selected ${re[S].label} (only compatible option for ${ne[s].label}).`),S}let u=await g.select({message:"Cache provider:",options:c.map(S=>({value:S,label:re[S].label,hint:re[S].hint}))});return E(u),u})();if(ne[s]?.edgeRuntime){let c=Dn.map(u=>` - ${u}`).join(`
|
|
3
|
+
`);g.note(c,"Unavailable on edge runtime")}g.log.info(y.bold("Features"));let I=e?.paymentProvider??await(async()=>{n=!0;let c=await g.select({message:"Payment provider:",options:Le.map(u=>({value:u,label:gt[u].label,hint:gt[u].hint}))});return E(c),c})(),z=e?.defaultCurrency??await(async()=>{if(I==="none")return"USD";n=!0;let c=await g.select({message:"Default currency:",options:ce.map(u=>({value:u,label:u,hint:Se[u].name}))});return E(c),c})(),L=e?.emailProvider??await(async()=>{n=!0;let c=await g.select({message:"Email provider:",options:$e.map(u=>({value:u,label:ht[u].label,hint:ht[u].hint}))});return E(c),c})(),K=e?.multiTenancy??await(async()=>{n=!0;let c=await g.confirm({message:"Enable multi-tenancy (organizations)?",initialValue:!1});return E(c),c})(),ge=K?e?.billingScope??"user":"user";if(K&&e?.billingScope===void 0){n=!0;let c=await g.select({message:"Billing scope:",options:Me.map(u=>({value:u,label:yt[u].label,hint:yt[u].hint}))});E(c),ge=c}let Y=e?.blog??await(async()=>{n=!0;let c=await g.confirm({message:"Enable blog?",initialValue:!0});return E(c),c})(),k=e?.docs??await(async()=>{n=!0;let c=await g.confirm({message:"Include docs app? (self-hosted Fumadocs documentation site)",initialValue:!1});return E(c),c})(),T=t?.desktopAllowed!==!1,P=e?.desktop??(T?await(async()=>{n=!0;let c=await g.confirm({message:"Include the Electron desktop app? (apps/desktop - cross-platform, device-auth)",initialValue:!1});return E(c),c})():(g.log.info(y.dim("Desktop app: available on the Pro plan and up - skipped.")),!1)),ae=P?e?.desktopAutoRelease??await(async()=>{n=!0;let c=await g.select({message:"Desktop release trigger:",options:[{value:!1,label:"Manual only",hint:"run from the Actions tab (saves CI minutes)"},{value:!0,label:"Automatic",hint:"release on every CI success on main"}],initialValue:!1});return E(c),c})():!1,$=e?.ai??await(async()=>{n=!0;let c=await g.confirm({message:"Add AI features? (chat, models, schedules, integrations - and unlocks the companion + MCP server)",initialValue:!1});return E(c),c})(),R=$?e?.rag??await(async()=>{n=!0;let c=await g.confirm({message:"Add server-side RAG knowledge (pgvector embeddings + semantic search)?",initialValue:!1});return E(c),c})():!1,we=$?e?.companion??await(async()=>{n=!0;let c=await g.confirm({message:"Add the companion daemon? A small program your users install on their own machine or VPS to run their Claude Code / Codex / OpenCode subscription for this app 24/7 - the AI runs on their hardware, not yours.",initialValue:!1});return E(c),c})():!1,Pn=$?e?.mcpServer??await(async()=>{n=!0;let c=await g.confirm({message:"Add the outward MCP server? Lets external agents (Claude Code, Codex, Hermes, OpenClaw) control the app on a user's behalf over an authenticated MCP endpoint.",initialValue:!1});return E(c),c})():!1,Rn=$?e?.aiByok??await(async()=>{n=!0;let c=await g.confirm({message:"AI BYOK mode? (end-users bring their own provider key; no = operator-keyed, credit-metered)",initialValue:!0});return E(c),c})():!0,Tn=e?.revenueSharing??await(async()=>{n=!0;let c=await g.confirm({message:"Enable revenue sharing? (opt-in MRR leaderboard with dofollow backlinks)",initialValue:!1});return E(c),c})(),_n=I==="none"?!1:e?.credits??await(async()=>{n=!0;let c=await g.confirm({message:"Enable credits? (metered usage on top of subscription plans)",initialValue:!0});return E(c),c})(),ut=e?.socialProviders??await(async()=>{n=!0;let c=Ve.map(S=>({value:S,label:se[S].label,hint:`requires ${se[S].envVars.map(F=>F.name).join(" / ")}`})),u=await g.multiselect({message:"Which social login providers should the sign-in screen show?",options:c,initialValues:[],required:!1});return E(u),u})();g.log.info(y.bold("Tooling"));let Ft=e?.dockerServices??await(async()=>{n=!0;let c=[...je].filter(B=>B!=="mailpit");L==="smtp"&&c.push("mailpit");let u=c.map(B=>({value:B,label:De[B].label,hint:De[B].hint})),S=u.map(B=>B.value).filter(B=>!(B==="postgres"&&(v==="neon"||v==="supabase")||B==="redis"&&b==="upstash")),F=await g.multiselect({message:"Which services should we set up in Docker for you?",options:u,initialValues:S,required:!1});return E(F),F})(),Bt=e?.aiTools??await(async()=>{n=!0;let c=Ue.map(S=>({value:S,label:nt[S].label})),u=await g.multiselect({message:"Which AI coding tools do you use?",options:c,initialValues:[],required:!1});return E(u),u})(),Kt=e?.demo,mt=Yt({databaseProvider:v,cacheProvider:b,paymentProvider:I,emailProvider:L,socialProviders:ut,demo:Kt}),Qe={};if(mt.length>0&&n){g.log.info(y.bold("Credentials")+y.dim(" all optional - press Enter to skip, fill in .env later"));for(let c of mt)if(n=!0,c.secret){let u=await g.password({message:c.message,mask:"*"});E(u),typeof u=="string"&&u.trim()&&(Qe[c.key]=u.trim())}else{let u=await g.text({message:c.message,placeholder:c.placeholder});E(u),typeof u=="string"&&u.trim()&&(Qe[c.key]=u.trim())}}if(n){let c=[` Name: ${y.cyan(r)}`,` App name: ${y.cyan(i)}`,` Location: ${y.cyan(o)}`,` Frontend: ${y.cyan(et[a].label)}`,` Architecture: ${y.cyan(tt[d].label)}`].join(`
|
|
4
|
+
`),u=[` Deploy target: ${y.cyan(ne[s]?.label??"Node.js / Docker")}`,` Database: ${y.cyan(G[v].label)}`,` Cache: ${y.cyan(re[b].label)}`,Ft.length>0?` Docker: ${y.cyan(Ft.map(be=>De[be].label).join(", "))}`:` Docker: ${y.dim("none")}`].filter(Boolean).join(`
|
|
5
|
+
`),S=[I!=="none"?` Payment: ${y.cyan(gt[I].label)} (${z})`:` Payment: ${y.dim("none")}`,` Credits: ${_n?y.cyan("Yes"):y.dim("No")}`,` AI features: ${$?y.cyan("Yes"):y.dim("No")}`,...$?[` AI mode: ${y.cyan(Rn?"BYOK":"Operator-keyed (credits)")}`,` RAG knowledge: ${R?y.cyan("Yes"):y.dim("No")}`,` Companion: ${we?y.cyan("Yes"):y.dim("No")}`,` MCP server: ${Pn?y.cyan("Yes"):y.dim("No")}`]:[],` Email: ${y.cyan(ht[L].label)}`,` Multi-tenancy: ${K?y.cyan("Yes")+` (billing: ${yt[ge].label})`:y.dim("No")}`,` Blog: ${Y?y.cyan("Yes"):y.dim("No")}`,` Docs app: ${k?y.cyan("Yes"):y.dim("No")}`,` Desktop app: ${P?y.cyan("Yes"):y.dim("No")}`,...P?[` Releases: ${y.cyan(ae?"Automatic on CI":"Manual only")}`]:[],` Rev. sharing: ${Tn?y.cyan("Yes"):y.dim("No")}`,ut.length>0?` Social login: ${y.cyan(ut.map(be=>se[be].label).join(", "))}`:` Social login: ${y.dim("none")}`,Bt.length>0?` AI tools: ${y.cyan(Bt.map(be=>nt[be].label).join(", "))}`:` AI tools: ${y.dim("none")}`].join(`
|
|
6
|
+
`),F=[y.bold("Project"),c,"",y.bold("Infrastructure"),u,"",y.bold("Features"),S];if(mt.length>0){let be=mt.map(On=>{let Oi=Qe[On.key]?y.green("provided"):y.dim("skipped");return` ${On.key}: ${Oi}`}).join(`
|
|
7
|
+
`);F.push("",y.bold("Credentials"),be)}g.note(F.join(`
|
|
8
|
+
`),"Summary");let B=await g.confirm({message:"Proceed with these settings?"});(g.isCancel(B)||!B)&&(g.cancel("Setup cancelled."),process.exit(0))}return{projectName:r,appName:i,projectDir:o,frontend:a,architecture:d,deploymentTarget:s,databaseProvider:v,cacheProvider:b,paymentProvider:I,emailProvider:L,multiTenancy:K,billingScope:ge,blog:Y,docs:k,desktop:P,desktopAutoRelease:ae,desktopAi:P?e?.desktopAi??!1:!1,ai:$,rag:R,companion:we,mcpServer:Pn,aiByok:Rn,revenueSharing:Tn,credits:_n,dockerServices:Ft,aiTools:Bt,socialProviders:ut,defaultCurrency:z,...Object.keys(Qe).length>0?{credentials:Qe}:{},...e?.baseUrl!==void 0?{baseUrl:e.baseUrl}:{},...Kt!==void 0?{demo:Kt}:{}}}import{createReadStream as Vi}from"fs";import{mkdir as Fi}from"fs/promises";import{Readable as Bi}from"stream";import{pipeline as zn}from"stream/promises";import{extract as Ki}from"tar";import{join as Ae}from"path";import{homedir as xi}from"os";var ot=process.env.GENERATESAAS_API_URL??"https://cli.generatesaas.com",q=".generatesaas",he=Ae(q,"manifest.json"),Mn=Ae(q,"hashes.json"),bt=Ae(q,"template-hashes.json"),St=Ae(q,"template"),Vn=Ae(q,"staging"),Fn=Ae(q,"staging.json"),me=Ae(xi(),".generatesaas");var U=class extends Error{constructor(n,r,i){super(r);this.status=n;this.body=i}status;body;name="ApiError"};function fe(e){return{apiKey:e,baseUrl:ot}}async function ye(e,t,n){let r=`${e.baseUrl}${t}`,i=await fetch(r,{...n,headers:{...n?.headers,Authorization:`Bearer ${e.apiKey}`,"User-Agent":"generatesaas-cli"}});if(!i.ok){let o,a;try{a=await i.json(),o=a.error??`API ${i.status}: ${t}`}catch{o=`API ${i.status}: ${t}`}throw new U(i.status,o,a)}return i}import{existsSync as Ci,readFileSync as Di,writeFileSync as Ni,mkdirSync as Li}from"fs";import{dirname as $i}from"path";import*as ve from"@clack/prompts";function at(){if(!Ci(me))return null;try{let e=JSON.parse(Di(me,"utf-8"));return e.apiKey?e.apiKey:(e.token&&!e.apiKey&&ve.log.warning(`Found old GitHub token in ${me}. Run 'generatesaas init' to set up your API key.`),null)}catch{return null}}function Ie(e){Li($i(me),{recursive:!0}),Ni(me,JSON.stringify({apiKey:e},null," ")+`
|
|
9
|
+
`,{mode:384})}async function Fe(e){if(e?.apiKey)return e.apiKey;let t=process.env.GENERATESAAS_API_KEY;if(t)return t;let n=at();if(n)return n;if(!e?.prompt)throw new Error("API key not found. Set GENERATESAAS_API_KEY or run 'generatesaas init' to configure.");return st()}async function st(){let e=await ve.text({message:"Enter your GenerateSaaS API key:",placeholder:"gs_live_...",validate:t=>{if(!t?.trim())return"API key is required."}});return ve.isCancel(e)&&(ve.cancel("Setup cancelled."),process.exit(0)),e.trim()}async function ke(e){return process.env.GENERATESAAS_OFFLINE_LICENSE==="1"?{latest:"0.0.0-ci",versions:[{version:"0.0.0-ci",date:new Date().toISOString(),breaking:!1}],entitlements:null}:await(await ye(e,"/versions")).json()}async function qt(e,t){try{return await(await ye(e,`/changelog/${encodeURIComponent(t)}`)).text()}catch(n){if(n instanceof U&&n.status===404)return null;throw n}}async function Bn(e,t){return await(await ye(e,`/skill/${encodeURIComponent(t)}`)).json()}function Et(e){if(!(e instanceof U)||e.status!==403)return null;let t=e.body;return!t||t.code!=="update_window_expired"?null:{message:e.message,lastAllowedVersion:t.lastAllowedVersion??null}}function Kn(e){return{frontend:e.frontend,architecture:e.architecture,deployTarget:e.deploymentTarget,database:e.databaseProvider,cache:e.cacheProvider,payment:e.paymentProvider,email:e.emailProvider,multiTenancy:e.multiTenancy,billingScope:e.billingScope,blog:e.blog,docs:e.docs,desktop:e.desktop,credits:e.credits,revenueSharing:e.revenueSharing,socialProviders:e.socialProviders,aiTools:e.aiTools,currency:e.defaultCurrency}}async function Jt(e,t){return process.env.GENERATESAAS_OFFLINE_LICENSE==="1"?{token:"offline-test-token",licenseId:"offline-test-license-id",installId:t.installId}:await(await ye(e,"/license/sign",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json()}async function Gn(e,t){return await(await ye(e,"/license/refresh",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json()}async function Wt(e,t){let n=await fetch(`${e}/license/verify`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)});if(!n.ok)throw new Error(`Verification service returned ${n.status}`);return await n.json()}async function Hn(e,t,n){let r=await fetch(`${e}/license/inspect`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${t}`},body:JSON.stringify(n)});if(!r.ok){let i=await r.json().catch(()=>null);throw new Error(i?.error??`Inspect endpoint returned ${r.status}`)}return await r.json()}var Xt=new Set([".git","node_modules",".pnpm-store",".env",".env.test",".turbo",".nuxt",".output",".data","dist",".next",".svelte-kit",".wrangler",".devcontainer","playwright-report","test-results"]),Zt=new Set(["pnpm-lock.yaml"]);function Be(e){if(Qt(e))return!0;for(let t of e.split("/"))if(Zt.has(t))return!0;return!1}var ji=new Set(["data","mksaas","references","scripts",".cursor",".agents",".codex",".generatesaas",".vscode",".mcp.json","README.md","TODO.md","OVERVIEW.md"]),Ui=["scripts/knowledge-corpus.ts","scripts/knowledge-corpus.test.ts","scripts/knowledge-lint.ts","scripts/knowledge-build.ts","scripts/dev-ai-setup.ts","scripts/docs-lint.ts"],Mi=["docs/superpowers","packages/cli","packages/cli-api","infra/docker-compose.yml",".claude/commands",".claude/skills/web-next-port",".claude/skills/web-next-port-workspace",".claude/settings.local.json",".claude/worktrees"];function Qt(e){let t=e.split("/");for(let n of t)if(Xt.has(n))return!0;if(Ui.includes(e))return!1;if(ji.has(t[0]))return!0;for(let n of Mi)if(e===n||e.startsWith(n+"/"))return!0;return!1}async function At(e,t,n){await Fi(n,{recursive:!0});let r=process.env.GENERATESAAS_TEMPLATE_TARBALL;if(r){await zn(Vi(r),Yn(n));return}let i=await ye(e,`/template/${encodeURIComponent(t)}`);if(!i.body)throw new Error("Empty response body");let o=Bi.fromWeb(i.body);await zn(o,Yn(n))}function Yn(e){return Ki({cwd:e,strip:1,filter:t=>{let n=t.replace(/^[^/]+\//,"");return n?!Qt(n):!0},sync:!1})}import{readdir as Gi,readFile as en,rm as Jn,writeFile as tn}from"fs/promises";import{join as Ke}from"path";var Hi=["apps/web-nuxt/public/images/blog","apps/web-next/public/images/blog","packages/content/en/blog","packages/content/ro/blog"];async function Wn(e){await Promise.all(Hi.map(t=>Jn(Ke(e,t),{recursive:!0,force:!0})))}var zi="packages/config/src/blog.ts";async function Xn(e){let t=Ke(e,zi),n=await en(t,"utf-8"),r=qn(qn(n,"blogCategories",t),"blogAuthors",t);await tn(t,r)}function qn(e,t,n){let r=new RegExp(`(export const ${t}\\b[^=]*=\\s*)\\[[\\s\\S]*?\\];`);if(!r.test(e))throw new Error(`emptyBlogConfig: could not find the \`export const ${t} = [...]\` declaration in ${n}. The boilerplate blog config may have been renamed or restructured; update the CLI strip in cleanup.ts.`);return e.replace(r,"$1[];")}async function Zn(e){let t=Ke(e,"packages/i18n/translations"),n;try{n=await Gi(t)}catch{return}for(let r of n){let i=Ke(t,r,"web.json"),o;try{o=await en(i,"utf-8")}catch{continue}let a=JSON.parse(o);!a.blog||a.blog.categories===void 0||(a.blog.categories={},await tn(i,JSON.stringify(a,null," ")+`
|
|
10
|
+
`))}}async function Qn(e,t){t.includes("claude-code")||await Jn(Ke(e,".claude"),{recursive:!0,force:!0})}async function er(e,t){let n=Ke(e,".claude","settings.json"),r;try{r=await en(n,"utf8")}catch{return}let i=JSON.parse(r);delete i.alwaysThinkingEnabled,delete i.enableAllProjectMcpServers,i.env&&(delete i.env.CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS,Object.keys(i.env).length===0&&delete i.env),i.permissions?.allow&&(i.permissions.allow=i.permissions.allow.filter(o=>Yi(o,t))),await tn(n,JSON.stringify(i,null," ")+`
|
|
11
|
+
`)}function Yi(e,t){return!(e.startsWith("mcp__")||t!=="nuxt"&&e.includes("nuxt"))}import{join as tr}from"path";import{mkdir as qi,readdir as Ji,rm as Wi,rmdir as Xi,writeFile as Zi}from"fs/promises";import{dirname as It,join as Qi,relative as eo,sep as to}from"path";function Pe(e){return e.split(to).join("/")}async function Pt(e){await qi(e,{recursive:!0})}async function l(e,t){await Pt(It(e)),await Zi(e,t,"utf-8")}async function nn(e,t){await Wi(e,{force:!0});let n=It(e);for(;n!==t&&n!==It(n);){try{await Xi(n)}catch{return}n=It(n)}}async function Re(e,t,n){let r=[],i=await Ji(e,{withFileTypes:!0});for(let o of i){let a=Qi(e,o.name),s=Pe(eo(t,a));n(s)||(o.isDirectory()?r.push(...await Re(a,t,n)):o.isFile()&&r.push(a))}return r}var no={postgres:"Postgres",neon:"Neon (managed Postgres)",supabase:"Supabase (managed Postgres)"},ro={resend:"Resend",ses:"Amazon SES",smtp:"SMTP"},io={redis:"Redis",upstash:"Upstash Redis"},oo={node:"Node.js / Docker",vercel:"Vercel"},ao={stripe:"Stripe",polar:"Polar"};function so(e){let t=e.frontend==="nuxt",n=t?"Nuxt 4":"Next.js 16",r=t?"apps/web-nuxt":"apps/web-next",i=t?"`app/` pages + components + composables":"`app/` routes, `components/`, `lib/`",o=e.architecture==="fullstack",a=o?"(fullstack - Hono API mounted inside the app)":"(separate - standalone Hono backend)",s=o?`Mounted inside \`${r}\`. A standalone \`apps/backend\` is also kept (inert) so you can switch to separate later.`:"Runs from `apps/backend`; the frontend reaches it over HTTP.",p=io[e.cacheProvider],f=oo[e.deploymentTarget],m=e.paymentProvider==="none"?"":`
|
|
12
|
+
- **Payments:** ${ao[e.paymentProvider]}`,d=e.desktop?", and the Electron desktop app under `docs/desktop/`":"",v=t?"`$t('key')` in templates (global helper); `useI18n()` from `vue-i18n` in `<script setup>` for `locale`/`setLocale`/`t()`.":"`useTranslations()` from `next-intl` in components; messages are loaded in `apps/web-next/i18n/request.ts`.",b=t?"**Navigation:** always use `localePath()` for paths (hardcoded paths break non-default locales); `await navigateTo()` in SSR.":"**Navigation:** `next/link` for links; `redirect()` from `next/navigation` for programmatic redirects in Server Components.";return`# AGENTS.md
|
|
13
13
|
|
|
14
14
|
Guidelines for AI coding agents (Claude Code, Codex, Cursor, \u2026) in this project.
|
|
15
15
|
Keep this file tight: add a rule only when it prevents a recurring mistake - too
|
|
@@ -23,7 +23,7 @@ and go find it:
|
|
|
23
23
|
|
|
24
24
|
1. \`docs/${t?"nuxt":"next"}/index.mdx\` - the catalog of every shipped feature and its config flag.
|
|
25
25
|
2. \`packages/config/src/index.ts\` - the flag that turns the feature on/off (check it before rendering).
|
|
26
|
-
3. Search \`packages/\` and \`${
|
|
26
|
+
3. Search \`packages/\` and \`${r}/\` for the name before creating anything.
|
|
27
27
|
|
|
28
28
|
Already built - extend these, never re-implement: auth (email / OAuth / 2FA / passkeys),
|
|
29
29
|
billing & subscriptions, credits, organizations & teams, notifications, email, SMS,
|
|
@@ -35,12 +35,12 @@ flag, route, or translation is the most common and most costly mistake in this r
|
|
|
35
35
|
|
|
36
36
|
## Stack
|
|
37
37
|
|
|
38
|
-
- **Frontend:** ${
|
|
39
|
-
- **API:** Hono, RPC-typed. ${
|
|
40
|
-
- **Database:** Drizzle ORM + ${
|
|
38
|
+
- **Frontend:** ${n} ${a}
|
|
39
|
+
- **API:** Hono, RPC-typed. ${s}
|
|
40
|
+
- **Database:** Drizzle ORM + ${no[e.databaseProvider]}
|
|
41
41
|
- **Cache + jobs:** ${p} + Inngest
|
|
42
42
|
- **Auth:** Better Auth${m}
|
|
43
|
-
- **Email:** ${
|
|
43
|
+
- **Email:** ${ro[e.emailProvider]}
|
|
44
44
|
- **Deploy:** ${f}
|
|
45
45
|
|
|
46
46
|
## Where things live (extend these - don't reinvent)
|
|
@@ -51,8 +51,12 @@ flag, route, or translation is the most common and most costly mistake in this r
|
|
|
51
51
|
- \`packages/auth/src/config.ts\` - Better Auth config.
|
|
52
52
|
- \`packages/runtime/src/env.ts\` - the validated (Zod) env schema. New env var \u2192 add it here **and** to \`.env.example\` (the committed reference); set the local value in \`.env\`.
|
|
53
53
|
- \`packages/{payments,mail,sms,storage,notifications}\` - config-gated integrations. Every provider's files stay even when its feature is off, so flipping a flag is enough to enable it.
|
|
54
|
-
- \`${
|
|
55
|
-
- \`docs/${t?"nuxt":"next"}/\` - feature & architecture documentation for this stack (Markdown). Consult it before searching from scratch; it cites real config keys, package names, and file paths you can act on. The GenerateSaaS CLI lives under \`docs/cli/\`${
|
|
54
|
+
- \`${r}\` - the ${n} app (${i}).
|
|
55
|
+
- \`docs/${t?"nuxt":"next"}/\` - feature & architecture documentation for this stack (Markdown). Consult it before searching from scratch; it cites real config keys, package names, and file paths you can act on. The GenerateSaaS CLI lives under \`docs/cli/\`${d}.
|
|
56
|
+
|
|
57
|
+
## Knowledge
|
|
58
|
+
|
|
59
|
+
\`knowledge/\` is the product knowledge that grounds the AI: read-only markdown entries, confidential, never user-facing - injected into the model's context so it answers from your facts. When you add or maintain an entry, FOLLOW THE RULES in \`knowledge/AGENTS.md\` (one concept per entry, frontmatter, \`[[wikilinks]]\`) and run \`pnpm knowledge:lint\` to validate. \`pnpm knowledge:build\` seeds the web search index (gated by \`config.rag.enabled\`); the desktop app self-indexes its bundled copy. See \`docs/${t?"nuxt":"next"}/knowledge.mdx\`.
|
|
56
60
|
|
|
57
61
|
## Code style
|
|
58
62
|
|
|
@@ -70,7 +74,7 @@ flag, route, or translation is the most common and most costly mistake in this r
|
|
|
70
74
|
- **Hono routes:** keep the method chain (\`.get().post()\`) - RPC type inference depends on it. Validate with \`sValidator\` from \`@hono/standard-validator\`.
|
|
71
75
|
- **Feature flags:** respect \`config.*\` - hide/skip a feature when its flag is off (the files stay so you can flip it later).
|
|
72
76
|
- **i18n:** strings live in \`packages/i18n/translations/{locale}/{scope}.json\`; edit \`en/\` only, keep keys generic. ${v} A pre-commit hook runs \`pnpm translate\` (needs \`OPENROUTER_API_KEY\`) to sync other locales from \`en\`; without the key it skips.
|
|
73
|
-
- ${
|
|
77
|
+
- ${b}
|
|
74
78
|
- **Routes:** use \`config.routes.*\`, never hardcoded path strings.
|
|
75
79
|
- **Secrets:** never send them to an external service; generate tokens/QR codes client-side.
|
|
76
80
|
|
|
@@ -81,25 +85,25 @@ In \`@repo/*\` backend packages prefer web-standard APIs: \`crypto.randomUUID()\
|
|
|
81
85
|
## This project
|
|
82
86
|
|
|
83
87
|
Scaffolded from the GenerateSaaS boilerplate. To pull upstream boilerplate updates, ask your agent to **"update my GenerateSaaS project"**. To remove the license heartbeat + manifest: \`pnpm dlx generatesaas eject\`.
|
|
84
|
-
`}async function
|
|
85
|
-
`)}import{join as
|
|
88
|
+
`}async function nr(e){await l(tr(e.projectDir,"AGENTS.md"),so(e)),await l(tr(e.projectDir,"CLAUDE.md"),`@AGENTS.md
|
|
89
|
+
`)}import{join as co}from"path";var lo={postgres:"Postgres (self-hosted)",neon:"Neon (managed Postgres)",supabase:"Supabase (managed Postgres)"};function po(e){let t=e.appName.trim()||e.projectName,n=e.frontend==="nuxt",r=n?"Nuxt 4":"Next.js 16",i=n?"apps/web-nuxt":"apps/web-next",o=lo[e.databaseProvider],a=vt(e),s=e.architecture==="fullstack"?`${r} app at \`${i}/\` with the Hono API mounted inside it. A standalone \`apps/backend/\` is also included (inert in this fullstack setup) so you can split the API into a separate service later without re-scaffolding.`:`${r} app at \`${i}/\` and a separate Hono backend at \`apps/backend/\`.`,p=e.architecture==="fullstack"?`- App + API: http://localhost:3000
|
|
86
90
|
- Inngest dev server: http://127.0.0.1:8288`:`- App: http://localhost:3000
|
|
87
91
|
- API: http://localhost:3010
|
|
88
|
-
- Inngest dev server: http://127.0.0.1:8288`,f=
|
|
92
|
+
- Inngest dev server: http://127.0.0.1:8288`,f=a?`pnpm infra # optional: starts local Docker services (Postgres / Redis / Inngest / Mailpit)
|
|
89
93
|
`:"",m=e.deploymentTarget==="vercel"?"### Deployment\n\nDeploy to Vercel: `vercel deploy` (or connect the repo in the Vercel dashboard). Required environment variables are listed in `.env`.":`### Deployment
|
|
90
94
|
|
|
91
|
-
This project ships with Dockerfiles for each app. Build images with \`docker build\` and deploy to your runtime of choice (Render / Fly.io / Railway / Coolify / Dokploy / your own VPS).${
|
|
95
|
+
This project ships with Dockerfiles for each app. Build images with \`docker build\` and deploy to your runtime of choice (Render / Fly.io / Railway / Coolify / Dokploy / your own VPS).${a?"\n\nThe `infra/` directory ships a Docker Compose file for the local-only services (Postgres / Redis / Inngest / Mailpit, filtered by your provider choices).":""}`,d=e.aiTools.length>0?"To pull the latest boilerplate changes into this project, open it in your AI coding agent and ask: `update my GenerateSaaS project`.":"To pull the latest boilerplate changes into this project, install an AI coding agent (Claude Code / Cursor / Codex / Gemini CLI / Windsurf) and ask: `update my GenerateSaaS project`. The skill bundle that drives the update lives under each tool's skill root.";return`# ${t}
|
|
92
96
|
|
|
93
|
-
${
|
|
97
|
+
${s}
|
|
94
98
|
|
|
95
99
|
## Stack
|
|
96
100
|
|
|
97
|
-
- **Frontend:** ${
|
|
101
|
+
- **Frontend:** ${r}
|
|
98
102
|
- **Backend:** Hono (TypeScript, RPC-typed)
|
|
99
103
|
- **Auth:** Better Auth
|
|
100
|
-
- **ORM / DB:** Drizzle + ${
|
|
104
|
+
- **ORM / DB:** Drizzle + ${o}
|
|
101
105
|
- **Background jobs:** Inngest
|
|
102
|
-
- **i18n:** ${
|
|
106
|
+
- **i18n:** ${n?"@nuxtjs/i18n":"next-intl"}
|
|
103
107
|
|
|
104
108
|
## Development
|
|
105
109
|
|
|
@@ -108,7 +112,8 @@ pnpm install
|
|
|
108
112
|
# A ready-to-run \`.env\` was generated for you - open it and fill in the
|
|
109
113
|
# values marked \`# TODO\` (provider API keys). \`.env.example\` is the committed
|
|
110
114
|
# reference. All apps load the single root \`.env\`.
|
|
111
|
-
${f}pnpm
|
|
115
|
+
${f}pnpm db:setup # first run: enable pgvector + create the schema (idempotent)
|
|
116
|
+
pnpm dev
|
|
112
117
|
\`\`\`
|
|
113
118
|
|
|
114
119
|
${p}
|
|
@@ -124,7 +129,8 @@ App-level configuration lives in \`packages/config/src/index.ts\`. Translation s
|
|
|
124
129
|
## Database
|
|
125
130
|
|
|
126
131
|
\`\`\`bash
|
|
127
|
-
pnpm
|
|
132
|
+
pnpm db:setup # enable pgvector + push schema + knowledge indexes (idempotent)
|
|
133
|
+
pnpm -F @repo/database push # push schema changes only (once pgvector exists)
|
|
128
134
|
pnpm -F @repo/database migrate # run migrations
|
|
129
135
|
pnpm -F @repo/database studio # open Drizzle Studio
|
|
130
136
|
pnpm auth:generate # regenerate Better Auth schema after config changes
|
|
@@ -142,12 +148,12 @@ pnpm dlx generatesaas eject
|
|
|
142
148
|
|
|
143
149
|
## Updates
|
|
144
150
|
|
|
145
|
-
${
|
|
146
|
-
`}async function
|
|
151
|
+
${d}
|
|
152
|
+
`}async function rr(e){await l(co(e.projectDir,"README.md"),po(e))}import{join as Rt}from"path";function uo(e){let t=e.split(".");return t.length>=3?t.slice(1).join("."):e}function mo(e){return e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"app"}function fo(e,t){let n=mo(e);return{appId:`${t.split(".").reverse().join(".")}.${n.replace(/-/g,"")}`,productName:e,protocol:n}}async function ir(e){let t=e.appName.replace(/\\/g,"\\\\").replace(/"/g,'\\"'),n=e.paymentProvider!=="none",r=e.baseUrl??"http://localhost:3000",i=e.baseUrl?new URL(e.baseUrl).hostname:"example.com",o=uo(i),a=e.demo?"false":"true",s=e.demo?`
|
|
147
153
|
support: {
|
|
148
154
|
enableInDev: true,
|
|
149
155
|
crisp: { websiteId: "7e221cec-ed61-46b7-b1b4-8cbc16557cca" }
|
|
150
|
-
},`:"",p=e.frontend==="nextjs"&&e.architecture==="fullstack"?"false":"true",f=
|
|
156
|
+
},`:"",p=e.frontend==="nextjs"&&e.architecture==="fullstack"?"false":"true",f=fo(t,o),m=`{ enabled: ${e.rag} }`,d=e.companion?'{ enabled: true, clientId: "companion" }':'{ enabled: false, clientId: "companion" }',v=`{ enabled: ${e.mcpServer} }`,b=`import type { AppConfig } from "@repo/config/types";
|
|
151
157
|
import { desktopConfig } from "./desktop.mjs";
|
|
152
158
|
import { tenancyConfig } from "./tenancy-flags.mjs";
|
|
153
159
|
|
|
@@ -156,9 +162,9 @@ const trustedOrigins = process.env.TRUSTED_ORIGINS?.split(",").map((s) => s.trim
|
|
|
156
162
|
export const config: AppConfig = {
|
|
157
163
|
siteName: "${t}",
|
|
158
164
|
fullSiteName: "${t}",
|
|
159
|
-
domain: "${
|
|
160
|
-
baseUrl: process.env.BASE_URL ?? "${
|
|
161
|
-
indexable: ${
|
|
165
|
+
domain: "${i}",
|
|
166
|
+
baseUrl: process.env.BASE_URL ?? "${r}",
|
|
167
|
+
indexable: ${a},
|
|
162
168
|
logo: {
|
|
163
169
|
main: "/images/logo.svg",
|
|
164
170
|
square: "/images/logo-square.svg"
|
|
@@ -183,16 +189,16 @@ export const config: AppConfig = {
|
|
|
183
189
|
limitPerSecond: 3,
|
|
184
190
|
senders: {
|
|
185
191
|
transactional: {
|
|
186
|
-
email: "noreply@${
|
|
192
|
+
email: "noreply@${o}",
|
|
187
193
|
senderName: "${t}"
|
|
188
194
|
},
|
|
189
195
|
marketing: {
|
|
190
|
-
email: "hello@${
|
|
196
|
+
email: "hello@${o}",
|
|
191
197
|
senderName: "${t}",
|
|
192
198
|
signatureName: "Alex"
|
|
193
199
|
},
|
|
194
200
|
support: {
|
|
195
|
-
email: "support@${
|
|
201
|
+
email: "support@${o}",
|
|
196
202
|
senderName: "${t} Support"
|
|
197
203
|
}
|
|
198
204
|
},
|
|
@@ -204,7 +210,7 @@ export const config: AppConfig = {
|
|
|
204
210
|
maxFileSizeMB: 5,
|
|
205
211
|
dailyUploadLimit: 20
|
|
206
212
|
},
|
|
207
|
-
payment: ${
|
|
213
|
+
payment: ${n?`{
|
|
208
214
|
enabled: true,
|
|
209
215
|
provider: "${e.paymentProvider}",
|
|
210
216
|
bannedCountries: ["BY", "CU", "IR", "KP", "RU", "SY"]
|
|
@@ -234,7 +240,7 @@ export const config: AppConfig = {
|
|
|
234
240
|
enabled: true,
|
|
235
241
|
provider: "turnstile",
|
|
236
242
|
siteKey: "0x4AAAAAACJo9y9FxH8lqkGu"
|
|
237
|
-
}`:"{ enabled: false }"},${
|
|
243
|
+
}`:"{ enabled: false }"},${s}
|
|
238
244
|
currency: ${e.demo?`{
|
|
239
245
|
// Demo mirrors the boilerplate's showcase config so geo\u2192currency
|
|
240
246
|
// switching can be demonstrated. Real users get a single-currency
|
|
@@ -254,7 +260,7 @@ export const config: AppConfig = {
|
|
|
254
260
|
}`:`{
|
|
255
261
|
base: "${e.defaultCurrency}",
|
|
256
262
|
list: [
|
|
257
|
-
{ symbol: "${
|
|
263
|
+
{ symbol: "${Se[e.defaultCurrency].symbol}", name: "${Se[e.defaultCurrency].name}", code: "${e.defaultCurrency}", place: "${Se[e.defaultCurrency].place}", space: ${Se[e.defaultCurrency].space} }
|
|
258
264
|
],
|
|
259
265
|
countryMap: {
|
|
260
266
|
default: "${e.defaultCurrency}"
|
|
@@ -277,8 +283,11 @@ export const config: AppConfig = {
|
|
|
277
283
|
contentDir: "content/docs"
|
|
278
284
|
},
|
|
279
285
|
ai: {
|
|
280
|
-
enabled:
|
|
281
|
-
|
|
286
|
+
enabled: ${e.ai},
|
|
287
|
+
// AI billing mode chosen at init (--ai-byok / --no-ai-byok). BYOK: end-users bring their
|
|
288
|
+
// own provider key, all catalog providers are usable, and chat is NOT credit-metered. The
|
|
289
|
+
// operator-keyed, credit-metered platform mode (false) uses the models/credits below.
|
|
290
|
+
byok: ${e.aiByok},
|
|
282
291
|
models: {
|
|
283
292
|
// EXAMPLE entry - set provider/modelId for your model and update the
|
|
284
293
|
// rates below to the provider's CURRENT pricing. These numbers are
|
|
@@ -290,9 +299,18 @@ export const config: AppConfig = {
|
|
|
290
299
|
outputPerMTok: 25
|
|
291
300
|
}
|
|
292
301
|
},
|
|
293
|
-
credits: { creditsPerUsd: 100, margin: 1, fallbackRatePerMTok: { input: 5, output: 25 } }
|
|
302
|
+
credits: { creditsPerUsd: 100, margin: 1, fallbackRatePerMTok: { input: 5, output: 25 } },
|
|
303
|
+
// Let end-users author their own AI schedules. Set to false to ship only the
|
|
304
|
+
// create-disabled view (existing schedules still list/run/edit/delete).
|
|
305
|
+
userSchedules: true
|
|
294
306
|
},
|
|
295
307
|
desktop: desktopConfig,
|
|
308
|
+
// Server-side RAG (pgvector knowledge with embeddings + semantic search). Off by default.
|
|
309
|
+
rag: ${m},
|
|
310
|
+
// Companion daemon (apps/companion): drives the user's subscription CLIs for this app. Off by default.
|
|
311
|
+
companion: ${d},
|
|
312
|
+
// Outward MCP server exposing the capability layer to external agents. Off by default.
|
|
313
|
+
mcpServer: ${v},
|
|
296
314
|
seo: {
|
|
297
315
|
description: "Production-ready SaaS application",
|
|
298
316
|
foundingDate: "${new Date().getFullYear()}-01-01"
|
|
@@ -313,6 +331,7 @@ export const config: AppConfig = {
|
|
|
313
331
|
export const mainCurrency = config.currency.list.find((c) => c.code === config.currency.base)
|
|
314
332
|
?? config.currency.list[0]!;
|
|
315
333
|
|
|
334
|
+
export * from "./ai-providers";
|
|
316
335
|
export * from "./billing-fields";
|
|
317
336
|
export * from "./social-providers";
|
|
318
337
|
export * from "./blog";
|
|
@@ -324,7 +343,7 @@ export * from "./pricing";
|
|
|
324
343
|
export * from "./roles";
|
|
325
344
|
export * from "./section-tabs";
|
|
326
345
|
export * from "./tenancy";
|
|
327
|
-
`,
|
|
346
|
+
`,I=Rt(e.projectDir,"packages/config/src/index.ts");await l(I,b),await l(Rt(e.projectDir,"packages/config/src/desktop.mjs"),`// Plain-JS desktop app identity. NO env reads, so tooling that cannot import the
|
|
328
347
|
// TypeScript config index reads it directly: the Electron renderer + main process
|
|
329
348
|
// (electron-vite bundles @repo/config/desktop) and electron-builder (Node ESM).
|
|
330
349
|
// Edit these values once to rebrand - they are the same in dev and production, so
|
|
@@ -336,12 +355,12 @@ export const desktopConfig = {
|
|
|
336
355
|
appId: "${f.appId}",
|
|
337
356
|
productName: "${f.productName}",
|
|
338
357
|
protocol: "${f.protocol}",
|
|
339
|
-
baseUrl: "${
|
|
358
|
+
baseUrl: "${r}",
|
|
340
359
|
// Name of the app's data folder (created under the OS app-data dir). Where the app
|
|
341
360
|
// and its AI agents persist files - logs, gathered data, generated artifacts. Rename
|
|
342
361
|
// it freely; it is a plain folder name, not a path.
|
|
343
362
|
dataFolder: "data",
|
|
344
|
-
autoUpdate: { provider: "generic", url: "https://cdn.${
|
|
363
|
+
autoUpdate: { provider: "generic", url: "https://cdn.${o}/desktop" },
|
|
345
364
|
agents: {
|
|
346
365
|
// Feature toggles only. Agents (their structure + prompts) live in the desktop
|
|
347
366
|
// app at apps/desktop/src/main/ai/agents/ - typed TypeScript wiring next to
|
|
@@ -358,10 +377,13 @@ export const desktopConfig = {
|
|
|
358
377
|
oauth: {},
|
|
359
378
|
// Let end users author their own background schedules on the Schedules screen.
|
|
360
379
|
// Set to false to ship only builder-registered schedules.
|
|
361
|
-
userSchedules: true
|
|
380
|
+
userSchedules: true,
|
|
381
|
+
// Cap how many chat conversations are kept per agent on the user's machine;
|
|
382
|
+
// creating a new chat past this limit deletes the oldest. Set to 0 for no limit.
|
|
383
|
+
maxChatsPerAgent: 20
|
|
362
384
|
}
|
|
363
385
|
};
|
|
364
|
-
`),await
|
|
386
|
+
`),await l(Rt(e.projectDir,"packages/config/src/tenancy-flags.mjs"),`// Plain-JS tenancy flags. NO env reads, so tooling that cannot import the
|
|
365
387
|
// TypeScript config index reads it directly (the Electron renderer). Mirrors the
|
|
366
388
|
// desktop.mjs pattern. The config index re-exports this as config.tenancy.
|
|
367
389
|
|
|
@@ -370,11 +392,11 @@ export const tenancyConfig = ${e.multiTenancy?`{
|
|
|
370
392
|
organizationLimit: 5,
|
|
371
393
|
billingScope: "${e.billingScope}"
|
|
372
394
|
}`:"{ multiTenant: false }"};
|
|
373
|
-
`),e.desktop&&await
|
|
374
|
-
url: https://cdn.${
|
|
395
|
+
`),e.desktop&&await l(Rt(e.projectDir,"apps/desktop/dev-app-update.yml"),`provider: generic
|
|
396
|
+
url: https://cdn.${o}/desktop
|
|
375
397
|
updaterCacheDirName: ${f.protocol}-updater
|
|
376
|
-
`)}import{join as
|
|
377
|
-
`)}async function
|
|
398
|
+
`)}import{join as go}from"path";function ho(e){return e==="stripe"?' stripePriceId: "",':' polarProductId: "",'}function rn(e){let t=[];return e.withCredits&&(t.push(` credits: ${e.credits},`),t.push(" creditInterval: 30,")),t.push(` apiRateLimit: { maxRequests: ${e.rateLimit} }`),t.join(`
|
|
399
|
+
`)}async function or(e){let t=go(e.projectDir,"packages/config/src/pricing.ts"),n=e.defaultCurrency;if(e.paymentProvider==="none"){let d=`import type { PricingConfig } from "@repo/config/types";
|
|
378
400
|
|
|
379
401
|
export const pricingConfig: PricingConfig = {
|
|
380
402
|
defaultPlan: "free",
|
|
@@ -394,7 +416,7 @@ export const pricingConfig: PricingConfig = {
|
|
|
394
416
|
prices: [
|
|
395
417
|
{
|
|
396
418
|
interval: "lifetime",
|
|
397
|
-
amounts: { ${
|
|
419
|
+
amounts: { ${n}: 0 }
|
|
398
420
|
}
|
|
399
421
|
],
|
|
400
422
|
apiRateLimit: { maxRequests: 100 }
|
|
@@ -403,7 +425,7 @@ export const pricingConfig: PricingConfig = {
|
|
|
403
425
|
credits: { enabled: false },
|
|
404
426
|
products: { enabled: false, items: [] }
|
|
405
427
|
};
|
|
406
|
-
`;await
|
|
428
|
+
`;await l(t,d);return}let r=e.paymentProvider,i=ho(r),o=e.credits,a=rn({credits:5,rateLimit:100,withCredits:o}),s=rn({credits:10,rateLimit:1e3,withCredits:o}),p=rn({credits:50,rateLimit:5e3,withCredits:o}),m=`import type { PricingConfig } from "@repo/config/types";
|
|
407
429
|
|
|
408
430
|
export const pricingConfig: PricingConfig = {
|
|
409
431
|
defaultPlan: "free",
|
|
@@ -424,10 +446,10 @@ export const pricingConfig: PricingConfig = {
|
|
|
424
446
|
prices: [
|
|
425
447
|
{
|
|
426
448
|
interval: "lifetime",
|
|
427
|
-
amounts: { ${
|
|
449
|
+
amounts: { ${n}: 0 }
|
|
428
450
|
}
|
|
429
451
|
],
|
|
430
|
-
${
|
|
452
|
+
${a}
|
|
431
453
|
},
|
|
432
454
|
{
|
|
433
455
|
id: "starter",
|
|
@@ -442,18 +464,18 @@ ${s}
|
|
|
442
464
|
],
|
|
443
465
|
prices: [
|
|
444
466
|
{
|
|
445
|
-
${
|
|
467
|
+
${i}
|
|
446
468
|
interval: "month",
|
|
447
|
-
amounts: { ${
|
|
469
|
+
amounts: { ${n}: 9 }
|
|
448
470
|
},
|
|
449
471
|
{
|
|
450
|
-
${
|
|
472
|
+
${i}
|
|
451
473
|
interval: "year",
|
|
452
|
-
amounts: { ${
|
|
453
|
-
anchorAmounts: { ${
|
|
474
|
+
amounts: { ${n}: 90 },
|
|
475
|
+
anchorAmounts: { ${n}: 109 }
|
|
454
476
|
}
|
|
455
477
|
],
|
|
456
|
-
${
|
|
478
|
+
${s}
|
|
457
479
|
},
|
|
458
480
|
{
|
|
459
481
|
id: "pro",
|
|
@@ -471,34 +493,34 @@ ${a}
|
|
|
471
493
|
],
|
|
472
494
|
prices: [
|
|
473
495
|
{
|
|
474
|
-
${
|
|
496
|
+
${i}
|
|
475
497
|
interval: "month",
|
|
476
|
-
amounts: { ${
|
|
477
|
-
anchorAmounts: { ${
|
|
498
|
+
amounts: { ${n}: 29 },
|
|
499
|
+
anchorAmounts: { ${n}: 39 },
|
|
478
500
|
featured: true
|
|
479
501
|
},
|
|
480
502
|
{
|
|
481
|
-
${
|
|
503
|
+
${i}
|
|
482
504
|
interval: "year",
|
|
483
|
-
amounts: { ${
|
|
484
|
-
anchorAmounts: { ${
|
|
505
|
+
amounts: { ${n}: 290 },
|
|
506
|
+
anchorAmounts: { ${n}: 349 }
|
|
485
507
|
}
|
|
486
508
|
],
|
|
487
509
|
${p}
|
|
488
510
|
}
|
|
489
511
|
],
|
|
490
|
-
${
|
|
512
|
+
${o?" credits: { enabled: true }":" credits: { enabled: false }"},
|
|
491
513
|
products: {
|
|
492
514
|
enabled: false,
|
|
493
515
|
items: []
|
|
494
516
|
}
|
|
495
517
|
};
|
|
496
|
-
`;await
|
|
497
|
-
`)}function
|
|
498
|
-
`)}async function
|
|
499
|
-
`+
|
|
500
|
-
`+
|
|
501
|
-
image:
|
|
518
|
+
`;await l(t,m)}var yo={smtp:[{key:"SMTP_HOST",defaultValue:"localhost"},{key:"SMTP_PORT",defaultValue:"1025"},{key:"SMTP_USER"},{key:"SMTP_PASSWORD"}],ses:[{key:"AMAZON_SES_REGION",comment:"# TODO: Configure Amazon SES credentials (e.g. us-east-1)"},{key:"AMAZON_SES_KEY"},{key:"AMAZON_SES_SECRET"}],resend:[{key:"RESEND_API_KEY",comment:"# TODO: Add your Resend API key"}]};function vo(e){let t=se[e];return t.envVars.map((n,r)=>({key:n.name,...r===0?{comment:`# TODO: Add your ${t.label} OAuth credentials`}:{}}))}var ko={stripe:[{key:"STRIPE_SECRET_KEY",comment:"# TODO: Add your Stripe keys"},{key:"STRIPE_WEBHOOK_SECRET"}],polar:[{key:"POLAR_ACCESS_TOKEN",comment:"# TODO: Add your Polar keys"},{key:"POLAR_WEBHOOK_SECRET"}]};function Ge(e,t){return t?e.map(n=>{let r=t[n.key];return r?{...n,defaultValue:r,comment:void 0}:n}):e}function He(e,t){for(let n of e)n.comment&&t.push(n.comment),n.defaultValue!==void 0?t.push(`${n.key}=${n.defaultValue}`):t.push(`#${n.key}=`)}function on(e){return Array.from(crypto.getRandomValues(new Uint8Array(e))).map(t=>t.toString(16).padStart(2,"0")).join("")}function sr(e){return e.architecture==="fullstack"?{apiUrl:"http://localhost:3000/api",baseUrl:"http://localhost:3000"}:{apiUrl:"http://localhost:3010",baseUrl:"http://localhost:3000"}}function wo(e){let{architecture:t,deploymentTarget:n}=e;return t==="fullstack"?n==="vercel"?{frontend:"https://your-app.vercel.app",backend:"https://your-app.vercel.app"}:n==="node"?{frontend:"https://your-app.example.com",backend:"https://your-app.example.com"}:null:{frontend:"https://your-app.example.com",backend:"https://your-app.example.com/api"}}function Tt(e,t,n,r){e.push(r==="example"?`${t}=`:`${t}=${n}`)}function ar(e,t){let n=t==="example"?void 0:e.credentials,{apiUrl:r,baseUrl:i}=sr(e),o=[];e.architecture==="separate"?o.push("# API Configuration","# Standalone backend's own URL (the frontend reaches it via the public var above).",`API_URL=${r}`,`BASE_URL=${i}`):o.push("# App","# (API_URL is derived from the frontend's *_PUBLIC_API_URL by the runtime env schema.)",`BASE_URL=${i}`),o.push("","# Database"),He(Ge(G[e.databaseProvider].envVars,n),o),o.push("","# Cache"),He(Ge(re[e.cacheProvider].envVars,n),o),o.push("","# Authentication"),t==="example"&&o.push("# Generate a strong secret, e.g. `openssl rand -hex 32`"),Tt(o,"BETTER_AUTH_SECRET",crypto.randomUUID(),t),o.push("","# Content API (random secret; required when contentApi feature is enabled in @repo/config)"),Tt(o,"CONTENT_API_KEY",on(32),t),o.push("","# Job Queue - Inngest","INNGEST_APP_ID=api"),Tt(o,"INNGEST_EVENT_KEY",on(32),t),Tt(o,"INNGEST_SIGNING_KEY",on(32),t),o.push("INNGEST_BASE_URL=http://127.0.0.1:8288"),e.architecture==="separate"&&(o.push("","# API Port (standalone backend)","API_PORT=3010"),o.push("","# CORS + cross-subdomain cookies (production only - leave unset for local dev)","# TRUSTED_ORIGINS=https://your-app.example.com","# AUTH_COOKIE_DOMAIN=.example.com"));let a=yo[e.emailProvider];if(a&&(o.push("","# Email"),He(Ge(a,n),o)),e.paymentProvider!=="none"){let s=ko[e.paymentProvider];s&&(o.push("","# Payment"),He(Ge(s,n),o))}if(e.socialProviders.length>0){o.push("","# Social auth");for(let s of e.socialProviders)He(Ge(vo(s),n),o)}return e.demo&&(o.push("","# Captcha (Cloudflare Turnstile)"),He(Ge([{key:"TURNSTILE_SECRET_KEY",comment:"# TODO: Add your Cloudflare Turnstile secret key"}],n),o)),o.push("","# Translations - OpenRouter (optional)","# Set to auto-translate en/* into your other locales with `pnpm translate`.","# The pre-commit hook runs it on commit; without a key it skips and untranslated","# locales fall back to the default locale. Get a key: https://openrouter.ai/keys","#OPENROUTER_API_KEY="),o.push("","# AI base - provider API keys (optional)","# Enable config.ai in packages/config and set the key for your chosen provider.","# OPENROUTER_API_KEY above also works as an AI provider key.","#ANTHROPIC_API_KEY=","#OPENAI_API_KEY="),o.push(""),o.join(`
|
|
519
|
+
`)}function bo(e){let{apiUrl:t}=sr(e),n=e.frontend==="nextjs"?"NEXT_PUBLIC_API_URL":"NUXT_PUBLIC_API_URL",r=["# API Configuration",`${n}=${t}`],i=wo(e);return i&&e.architecture==="separate"&&r.push("","# Production (uncomment and replace with your deployed hostnames):",`# ${n}=${i.backend}`),r.push(""),r.join(`
|
|
520
|
+
`)}async function cr(e){let t=bo(e);await l(`${e.projectDir}/.env`,t+`
|
|
521
|
+
`+ar(e,"env")),await l(`${e.projectDir}/.env.example`,t+`
|
|
522
|
+
`+ar(e,"example"))}import{join as So}from"path";async function lr(e){let t=[...e.dockerServices];if(G[e.databaseProvider].managed&&(t=t.filter(o=>o!=="postgres")),re[e.cacheProvider].managed&&(t=t.filter(o=>o!=="redis")),t.length===0)return!1;let n=[],r=[];t.includes("postgres")&&(n.push(` postgres:
|
|
523
|
+
image: pgvector/pgvector:pg18
|
|
502
524
|
ports:
|
|
503
525
|
- "\${POSTGRES_PORT:-5432}:5432"
|
|
504
526
|
environment:
|
|
@@ -512,7 +534,7 @@ ${i?" credits: { enabled: true }":" credits: { enabled: false }"},
|
|
|
512
534
|
test: ["CMD-SHELL", "pg_isready -U postgres"]
|
|
513
535
|
interval: 5s
|
|
514
536
|
timeout: 5s
|
|
515
|
-
retries: 5`),
|
|
537
|
+
retries: 5`),r.push(" postgres_data:")),t.includes("redis")&&(n.push(` redis:
|
|
516
538
|
image: redis:8-alpine
|
|
517
539
|
ports:
|
|
518
540
|
- "\${REDIS_PORT:-6379}:6379"
|
|
@@ -522,27 +544,27 @@ ${i?" credits: { enabled: true }":" credits: { enabled: false }"},
|
|
|
522
544
|
test: ["CMD", "redis-cli", "ping"]
|
|
523
545
|
interval: 5s
|
|
524
546
|
timeout: 5s
|
|
525
|
-
retries: 5`),
|
|
547
|
+
retries: 5`),r.push(" redis_data:")),t.includes("mailpit")&&n.push(` mailpit:
|
|
526
548
|
image: axllent/mailpit
|
|
527
549
|
ports:
|
|
528
550
|
- "\${MAILPIT_SMTP_PORT:-1025}:1025"
|
|
529
551
|
- "\${MAILPIT_UI_PORT:-8025}:8025"
|
|
530
552
|
environment:
|
|
531
553
|
MP_SMTP_AUTH_ACCEPT_ANY: 1
|
|
532
|
-
MP_SMTP_AUTH_ALLOW_INSECURE: 1`),t.includes("inngest")&&
|
|
554
|
+
MP_SMTP_AUTH_ALLOW_INSECURE: 1`),t.includes("inngest")&&n.push(` inngest:
|
|
533
555
|
image: inngest/inngest:v1.17.4
|
|
534
556
|
ports:
|
|
535
557
|
- "\${INNGEST_PORT:-8288}:8288"
|
|
536
|
-
command: inngest dev`);let
|
|
537
|
-
${
|
|
558
|
+
command: inngest dev`);let i=`services:
|
|
559
|
+
${n.join(`
|
|
538
560
|
|
|
539
561
|
`)}
|
|
540
|
-
`;return
|
|
562
|
+
`;return r.length>0&&(i+=`
|
|
541
563
|
volumes:
|
|
542
|
-
${
|
|
564
|
+
${r.join(`
|
|
543
565
|
`)}
|
|
544
|
-
`),await
|
|
545
|
-
`)}import{join as
|
|
566
|
+
`),await l(So(e.projectDir,"infra/docker-compose.yml"),i),!0}import{join as Eo}from"path";function Ao(e){let t=[];t.push({type:"node-terminal",request:"launch",name:"Dev",command:"pnpm dev",cwd:"${workspaceFolder}",skipFiles:["<node_internals>/**"],env:{NODE_ENV:"development"}}),e.architecture==="separate"&&t.push({type:"node-terminal",request:"launch",name:"Backend",command:"pnpm dev",cwd:"${workspaceFolder}/apps/backend",skipFiles:["<node_internals>/**"],env:{NODE_ENV:"development"}});let n=e.frontend==="nextjs"?"Next.js":"Nuxt";if(t.push({type:"node-terminal",request:"launch",name:n,command:"pnpm dev",cwd:`\${workspaceFolder}/apps/web-${e.frontend==="nextjs"?"next":"nuxt"}`,skipFiles:["<node_internals>/**"],env:{NODE_ENV:"development"}}),e.docs&&t.push({type:"node-terminal",request:"launch",name:"Docs",command:"pnpm dev",cwd:"${workspaceFolder}/apps/docs",skipFiles:["<node_internals>/**"],env:{NODE_ENV:"development"}}),e.desktop){let r=e.architecture==="separate"?"http://localhost:3010":"http://localhost:3000/api";t.push({type:"node-terminal",request:"launch",name:"Desktop",command:"pnpm dev",cwd:"${workspaceFolder}/apps/desktop",skipFiles:["<node_internals>/**"],env:{NODE_ENV:"development",BASE_URL:"http://localhost:3000",PUBLIC_API_URL:r}})}if(t.push({type:"node-terminal",request:"launch",name:"Inngest",command:"pnpm dev:inngest",cwd:"${workspaceFolder}",skipFiles:["<node_internals>/**"],env:{NODE_ENV:"development"}}),t.push({type:"node-terminal",request:"launch",name:"Mail",command:"pnpm dev:mail",cwd:"${workspaceFolder}",skipFiles:["<node_internals>/**"],env:{NODE_ENV:"development"}}),e.companion){let r=e.architecture==="separate"?"http://localhost:3010":"http://localhost:3000/api";t.push({type:"node-terminal",request:"launch",name:"Companion",command:`pnpm cli serve --url ${r}`,cwd:"${workspaceFolder}/apps/companion",skipFiles:["<node_internals>/**"]})}if(e.paymentProvider==="stripe"){let r=e.architecture==="separate"?"localhost:3010/auth/stripe/webhook":"localhost:3000/api/auth/stripe/webhook";t.push({type:"node-terminal",request:"launch",name:"Stripe",command:`stripe listen --forward-to ${r}`,cwd:"${workspaceFolder}",skipFiles:["<node_internals>/**"]})}return t}function Io(e){let t=e.frontend==="nextjs"?"Next.js":"Nuxt",n=[];return e.architecture==="separate"?n.push({name:`Dev (${t} + Backend + Inngest)`,configurations:["Backend",t,"Inngest"]}):n.push({name:`Dev (${t} + Inngest)`,configurations:[t,"Inngest"]}),n}async function pr(e){let t={version:"0.2.0",configurations:Ao(e),compounds:Io(e)};await l(Eo(e.projectDir,".vscode/launch.json"),JSON.stringify(t,null," ")+`
|
|
567
|
+
`)}import{join as Po}from"path";async function dr(e){if(e.architecture!=="separate")return;await l(Po(e.projectDir,"apps/backend/src/index.ts"),`import { serve } from "@hono/node-server";
|
|
546
568
|
import app from "@repo/api";
|
|
547
569
|
import { closeRedis, env, logger } from "@repo/runtime";
|
|
548
570
|
|
|
@@ -573,65 +595,12 @@ bootstrap().catch((error) => {
|
|
|
573
595
|
logger.error("[Backend] Fatal error", error);
|
|
574
596
|
process.exit(1);
|
|
575
597
|
});
|
|
576
|
-
`)}import{readFile as
|
|
577
|
-
export
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
export function affectedRowCount(result: unknown): number {
|
|
583
|
-
if (typeof result !== "object" || result === null) return 0;
|
|
584
|
-
const r = result as { rowCount?: number; count?: number };
|
|
585
|
-
return r.rowCount ?? r.count ?? 0;
|
|
586
|
-
}
|
|
587
|
-
`;function oi(e){return`import { drizzle } from "drizzle-orm/node-postgres";
|
|
588
|
-
import { z } from "zod";
|
|
589
|
-
import * as authSchema from "./db/auth";
|
|
590
|
-
import * as appSchema from "./db/schema";
|
|
591
|
-
|
|
592
|
-
const schema = { ...authSchema, ...appSchema };
|
|
593
|
-
export { schema };
|
|
594
|
-
|
|
595
|
-
const parsed = z.object({ DATABASE_URL: z.url() }).safeParse({ DATABASE_URL: process.env.DATABASE_URL });
|
|
596
|
-
if (!parsed.success) throw new Error("DATABASE_URL is not set or invalid");
|
|
597
|
-
|
|
598
|
-
export const db = drizzle(parsed.data.DATABASE_URL, { schema });
|
|
599
|
-
export const pool = db.$client;
|
|
600
|
-
|
|
601
|
-
${e}
|
|
602
|
-
${zt}`}function ii(e){return`import { neon } from "@neondatabase/serverless";
|
|
603
|
-
import { drizzle } from "drizzle-orm/neon-http";
|
|
604
|
-
import { z } from "zod";
|
|
605
|
-
import * as authSchema from "./db/auth";
|
|
606
|
-
import * as appSchema from "./db/schema";
|
|
607
|
-
|
|
608
|
-
const schema = { ...authSchema, ...appSchema };
|
|
609
|
-
export { schema };
|
|
610
|
-
|
|
611
|
-
const parsed = z.object({ DATABASE_URL: z.url() }).safeParse({ DATABASE_URL: process.env.DATABASE_URL });
|
|
612
|
-
if (!parsed.success) throw new Error("DATABASE_URL is not set or invalid");
|
|
613
|
-
|
|
614
|
-
const sql = neon(parsed.data.DATABASE_URL);
|
|
615
|
-
export const db = drizzle(sql, { schema });
|
|
616
|
-
|
|
617
|
-
${e}
|
|
618
|
-
${zt}`}function si(e){return`import { drizzle } from "drizzle-orm/postgres-js";
|
|
619
|
-
import postgres from "postgres";
|
|
620
|
-
import { z } from "zod";
|
|
621
|
-
import * as authSchema from "./db/auth";
|
|
622
|
-
import * as appSchema from "./db/schema";
|
|
623
|
-
|
|
624
|
-
const schema = { ...authSchema, ...appSchema };
|
|
625
|
-
export { schema };
|
|
626
|
-
|
|
627
|
-
const parsed = z.object({ DATABASE_URL: z.url() }).safeParse({ DATABASE_URL: process.env.DATABASE_URL });
|
|
628
|
-
if (!parsed.success) throw new Error("DATABASE_URL is not set or invalid");
|
|
629
|
-
|
|
630
|
-
const client = postgres(parsed.data.DATABASE_URL);
|
|
631
|
-
export const db = drizzle(client, { schema });
|
|
632
|
-
|
|
633
|
-
${e}
|
|
634
|
-
${zt}`}import{join as wt}from"path";async function Mr(e){switch(e.cacheProvider){case"redis":await ai(e),await ci(e);break;case"upstash":await li(e),await pi(e);break}}async function ai(e){await c(wt(e.projectDir,"packages/runtime/src/redis.ts"),`import type { Store } from "hono-rate-limiter";
|
|
598
|
+
`)}import{readFile as Ro}from"fs/promises";import{join as To}from"path";var an='import { drizzle } from "drizzle-orm/node-postgres";',sn=`export const db = drizzle(parsed.data.DATABASE_URL, { schema });
|
|
599
|
+
export const pool = db.$client;`,_o={postgres:{importLine:an,instantiation:sn},neon:{importLine:`import { neon } from "@neondatabase/serverless";
|
|
600
|
+
import { drizzle } from "drizzle-orm/neon-http";`,instantiation:`const sql = neon(parsed.data.DATABASE_URL);
|
|
601
|
+
export const db = drizzle(sql, { schema });`},supabase:{importLine:`import { drizzle } from "drizzle-orm/postgres-js";
|
|
602
|
+
import postgres from "postgres";`,instantiation:`const client = postgres(parsed.data.DATABASE_URL);
|
|
603
|
+
export const db = drizzle(client, { schema });`}};async function ur(e){let t=To(e.projectDir,"packages/database/src/index.ts"),n=await Ro(t,"utf-8");if(!n.includes(an)||!n.includes(sn))throw new Error("generateDbDriver: boilerplate packages/database/src/index.ts is missing the node-postgres driver anchors (the import line or the `db` instantiation block); the boilerplate drifted.");let r=_o[e.databaseProvider],i=n.replace(an,r.importLine).replace(sn,r.instantiation);await l(t,i)}import{join as _t}from"path";async function mr(e){switch(e.cacheProvider){case"redis":await Oo(e),await xo(e);break;case"upstash":await Co(e),await Do(e);break}}async function Oo(e){await l(_t(e.projectDir,"packages/runtime/src/redis.ts"),`import type { Store } from "hono-rate-limiter";
|
|
635
604
|
import { Redis } from "ioredis";
|
|
636
605
|
import { RedisStore, type RedisReply } from "rate-limit-redis";
|
|
637
606
|
import { env } from "./env";
|
|
@@ -647,7 +616,7 @@ export interface CacheSetOptions {
|
|
|
647
616
|
}
|
|
648
617
|
|
|
649
618
|
/**
|
|
650
|
-
*
|
|
619
|
+
* Small helpers extended onto the native \`redis\` client for the SDK
|
|
651
620
|
* methods whose signatures differ between ioredis and Upstash. Use these in
|
|
652
621
|
* your own code when you want a uniform API; everything else on \`redis\` is
|
|
653
622
|
* the native ioredis surface (or Upstash, on that backend) - use those
|
|
@@ -660,6 +629,8 @@ export interface BoilerplateRedisHelpers {
|
|
|
660
629
|
cacheGet(key: string): Promise<string | null>;
|
|
661
630
|
/** Iterate keys matching a glob pattern via SCAN. Yields each key as it's discovered. */
|
|
662
631
|
cacheScan(opts: { match: string; count?: number }): AsyncIterable<string>;
|
|
632
|
+
/** Run a Lua script via EVAL with explicit key and argument lists (the SDKs' native \`eval\` signatures differ). Returns the script's raw reply. */
|
|
633
|
+
cacheEval(script: string, keys: string[], args: (string | number)[]): Promise<unknown>;
|
|
663
634
|
}
|
|
664
635
|
|
|
665
636
|
// \`lazyConnect\` keeps the client from dialing Redis the moment this module is
|
|
@@ -686,9 +657,9 @@ ioredis.on("connect", () => {
|
|
|
686
657
|
});
|
|
687
658
|
|
|
688
659
|
/**
|
|
689
|
-
* Native ioredis client + the
|
|
690
|
-
* ioredis method (\`zadd\`, \`hset\`, \`pubsub\`,
|
|
691
|
-
* directly on this object - see ioredis's docs for usage. The
|
|
660
|
+
* Native ioredis client + the boilerplate helpers. Every native
|
|
661
|
+
* ioredis method (\`zadd\`, \`hset\`, \`pubsub\`, etc.) is available
|
|
662
|
+
* directly on this object - see ioredis's docs for usage. The
|
|
692
663
|
* \`cache*\` helpers cover the SDK calls whose signatures differ between
|
|
693
664
|
* ioredis and Upstash.
|
|
694
665
|
*/
|
|
@@ -714,6 +685,9 @@ export const redis: Redis & BoilerplateRedisHelpers = Object.assign(ioredis, {
|
|
|
714
685
|
for (const k of keys) yield k;
|
|
715
686
|
cursor = next;
|
|
716
687
|
} while (cursor !== "0");
|
|
688
|
+
},
|
|
689
|
+
async cacheEval(script: string, keys: string[], args: (string | number)[]): Promise<unknown> {
|
|
690
|
+
return ioredis.eval(script, keys.length, ...keys, ...args);
|
|
717
691
|
}
|
|
718
692
|
});
|
|
719
693
|
|
|
@@ -755,7 +729,7 @@ export async function closeRedis() {
|
|
|
755
729
|
closed = true;
|
|
756
730
|
}
|
|
757
731
|
}
|
|
758
|
-
`)}async function
|
|
732
|
+
`)}async function xo(e){await l(_t(e.projectDir,"packages/runtime/src/mutex.ts"),`import { Mutex } from "redis-semaphore";
|
|
759
733
|
import { redis } from "./redis";
|
|
760
734
|
|
|
761
735
|
export class MutexTimeoutError extends Error {
|
|
@@ -792,7 +766,7 @@ export async function withMutex<T>(
|
|
|
792
766
|
await mutex.release();
|
|
793
767
|
}
|
|
794
768
|
}
|
|
795
|
-
`)}async function
|
|
769
|
+
`)}async function Co(e){await l(_t(e.projectDir,"packages/runtime/src/redis.ts"),`import { Redis } from "@upstash/redis";
|
|
796
770
|
import type { Store } from "hono-rate-limiter";
|
|
797
771
|
import { env } from "./env";
|
|
798
772
|
|
|
@@ -807,7 +781,7 @@ export interface CacheSetOptions {
|
|
|
807
781
|
}
|
|
808
782
|
|
|
809
783
|
/**
|
|
810
|
-
*
|
|
784
|
+
* Small helpers extended onto the native \`redis\` client for the SDK
|
|
811
785
|
* methods whose signatures differ between ioredis and Upstash. Use these in
|
|
812
786
|
* your own code when you want a uniform API; everything else on \`redis\` is
|
|
813
787
|
* the native Upstash surface (or ioredis, on that backend) - use those
|
|
@@ -820,6 +794,8 @@ export interface BoilerplateRedisHelpers {
|
|
|
820
794
|
cacheGet(key: string): Promise<string | null>;
|
|
821
795
|
/** Iterate keys matching a glob pattern via SCAN. Yields each key as it's discovered. */
|
|
822
796
|
cacheScan(opts: { match: string; count?: number }): AsyncIterable<string>;
|
|
797
|
+
/** Run a Lua script via EVAL with explicit key and argument lists (the SDKs' native \`eval\` signatures differ). Returns the script's raw reply. */
|
|
798
|
+
cacheEval(script: string, keys: string[], args: (string | number)[]): Promise<unknown>;
|
|
823
799
|
}
|
|
824
800
|
|
|
825
801
|
/**
|
|
@@ -835,9 +811,9 @@ const upstash = new Redis({
|
|
|
835
811
|
});
|
|
836
812
|
|
|
837
813
|
/**
|
|
838
|
-
* Native Upstash REST client + the
|
|
839
|
-
* Upstash method (\`zadd\`, \`hset\`, \`json.*\`,
|
|
840
|
-
* directly on this object - see Upstash's docs for usage. The
|
|
814
|
+
* Native Upstash REST client + the boilerplate helpers. Every native
|
|
815
|
+
* Upstash method (\`zadd\`, \`hset\`, \`json.*\`, etc.) is available
|
|
816
|
+
* directly on this object - see Upstash's docs for usage. The
|
|
841
817
|
* \`cache*\` helpers cover the SDK calls whose signatures differ between
|
|
842
818
|
* Upstash and ioredis.
|
|
843
819
|
*/
|
|
@@ -867,6 +843,9 @@ export const redis: Redis & BoilerplateRedisHelpers = Object.assign(upstash, {
|
|
|
867
843
|
for (const k of keys) yield k;
|
|
868
844
|
cursor = next;
|
|
869
845
|
} while (cursor !== "0");
|
|
846
|
+
},
|
|
847
|
+
async cacheEval(script: string, keys: string[], args: (string | number)[]): Promise<unknown> {
|
|
848
|
+
return upstash.eval(script, keys, args);
|
|
870
849
|
}
|
|
871
850
|
});
|
|
872
851
|
|
|
@@ -905,7 +884,7 @@ export const limiterStore: Store = createLimiterStore();
|
|
|
905
884
|
|
|
906
885
|
/** No persistent connection to close with Upstash REST. */
|
|
907
886
|
export async function closeRedis(): Promise<void> {}
|
|
908
|
-
`)}async function
|
|
887
|
+
`)}async function Do(e){await l(_t(e.projectDir,"packages/runtime/src/mutex.ts"),`import { Lock } from "@upstash/lock";
|
|
909
888
|
import { redis } from "./redis";
|
|
910
889
|
|
|
911
890
|
export class MutexTimeoutError extends Error {
|
|
@@ -950,7 +929,7 @@ export async function withMutex<T>(
|
|
|
950
929
|
await lock.release();
|
|
951
930
|
}
|
|
952
931
|
}
|
|
953
|
-
`)}async function
|
|
932
|
+
`)}async function fr(e){await l(`${e.projectDir}/packages/runtime/src/env.ts`,No(e))}function No(e){return`import { z } from "zod";
|
|
954
933
|
|
|
955
934
|
const EnvSchema = z.object({
|
|
956
935
|
NODE_ENV: z.enum(["development", "production"]).default("development"),
|
|
@@ -999,6 +978,8 @@ ${e.cacheProvider==="upstash"?` UPSTASH_REDIS_REST_URL: z.string(),
|
|
|
999
978
|
|
|
1000
979
|
SMTP_HOST: z.string().optional(),
|
|
1001
980
|
SMTP_PORT: z.coerce.number().int().positive().optional(),
|
|
981
|
+
SMTP_USER: z.string().optional(),
|
|
982
|
+
SMTP_PASSWORD: z.string().optional(),
|
|
1002
983
|
|
|
1003
984
|
TWILIO_ACCOUNT_SID: z.string().optional(),
|
|
1004
985
|
TWILIO_AUTH_TOKEN: z.string().optional(),
|
|
@@ -1069,17 +1050,17 @@ export const env = (() => {
|
|
|
1069
1050
|
const parsedApiUrl = new URL(env.API_URL);
|
|
1070
1051
|
export const apiBasePath = parsedApiUrl.pathname === "/" ? "" : parsedApiUrl.pathname;
|
|
1071
1052
|
export const apiOrigin = parsedApiUrl.origin;
|
|
1072
|
-
`}import{readFile as
|
|
1073
|
-
`)}function
|
|
1074
|
-
`)}var
|
|
1075
|
-
`))}}import{readFile as
|
|
1076
|
-
`);let
|
|
1053
|
+
`}import{readFile as Lo}from"fs/promises";import{join as ie}from"path";var Ot={"@upstash/redis":"^1.37.0","@upstash/lock":"^0.2.1","@neondatabase/serverless":"^1.0.1",postgres:"^3.4.7"};async function Ye(e){let t=await Lo(e,"utf-8");return JSON.parse(t)}async function qe(e,t){await l(e,JSON.stringify(t,null," ")+`
|
|
1054
|
+
`)}function ct(e,t){for(let n of t)delete e.dependencies?.[n],delete e.devDependencies?.[n]}function ze(e,t,n,r=!1){let i=r?"devDependencies":"dependencies";e[i]||(e[i]={}),e[i][t]=n}async function gr(e){await $o(e),await jo(e),await Uo(e),await Mo(e),e.frontend==="nextjs"?await Fo(e):await Vo(e)}async function $o(e){let t=ie(e.projectDir,"packages/api/package.json"),n=await Ye(t);ct(n,["sharp","@types/sharp"]),await qe(t,n)}async function jo(e){let t=ie(e.projectDir,"packages/runtime/package.json"),n=await Ye(t);e.cacheProvider==="upstash"&&(ct(n,["ioredis","rate-limit-redis","redis-semaphore"]),ze(n,"@upstash/redis",Ot["@upstash/redis"]),ze(n,"@upstash/lock",Ot["@upstash/lock"])),await qe(t,n)}async function Uo(e){let t=ie(e.projectDir,"packages/database/package.json"),n=await Ye(t);e.databaseProvider==="neon"?(ct(n,["pg","@types/pg"]),ze(n,"@neondatabase/serverless",Ot["@neondatabase/serverless"])):e.databaseProvider==="supabase"&&(ct(n,["pg","@types/pg"]),ze(n,"postgres",Ot.postgres)),await qe(t,n)}async function Mo(e){if(e.architecture!=="separate")return;let t=ie(e.projectDir,"apps/backend/package.json"),n=await Ye(t);e.deploymentTarget!=="node"&&ct(n,["@hono/node-server"]),await qe(t,n)}async function Vo(e){if(e.architecture!=="separate")return;let t=ie(e.projectDir,"apps/web-nuxt");await nn(ie(t,"server/api/[...paths].ts"),t);let n=ie(t,"package.json"),r=await Ye(n),i=r.dependencies?.["@repo/api"];i&&(delete r.dependencies?.["@repo/api"],ze(r,"@repo/api",i,!0)),await qe(n,r)}async function Fo(e){if(e.architecture!=="separate")return;let t=ie(e.projectDir,"apps/web-next");await nn(ie(t,"app/api/[[...rest]]/route.ts"),t);let n=ie(t,"package.json"),r=await Ye(n),i=r.dependencies?.["@repo/api"];i&&(delete r.dependencies?.["@repo/api"],ze(r,"@repo/api",i,!0)),await qe(n,r)}import{readFile as yr}from"fs/promises";import{join as vr}from"path";async function kr(e){let t=vr(e.projectDir,"turbo.json"),n;try{n=await yr(t,"utf-8")}catch{return}let r=JSON.parse(n),i=r.tasks?.build;if(!i)return;let o=e.frontend==="nextjs"?"NUXT_PUBLIC_*":"NEXT_PUBLIC_*",a=e.frontend==="nextjs"?new Set([".nuxt/**",".output/**"]):new Set([".next/**","!.next/cache/**"]),s=!1;if(Array.isArray(i.env)){let p=i.env.filter(f=>f!==o);p.length!==i.env.length&&(i.env=p,s=!0)}if(Array.isArray(i.outputs)){let p=i.outputs.filter(f=>!a.has(f));p.length!==i.outputs.length&&(i.outputs=p,s=!0)}s&&await l(t,JSON.stringify(r,null," ")+`
|
|
1055
|
+
`)}var Bo=["base.json","node.json","next.json"],hr="GenerateSaaS ";async function wr(e){if(!e.demo)for(let t of Bo){let n=vr(e.projectDir,"tooling/typescript",t),r;try{r=await yr(n,"utf-8")}catch{continue}let i=JSON.parse(r);typeof i.display!="string"||!i.display.startsWith(hr)||(i.display=i.display.slice(hr.length),await l(n,JSON.stringify(i,null," ")+`
|
|
1056
|
+
`))}}import{readFile as Ko,rm as Go}from"fs/promises";import{existsSync as br}from"fs";import{join as Sr}from"path";async function Er(e){if(e.frontend==="nuxt")return;let t=Sr(e.projectDir,"packages/i18n/package.json");if(!br(t))throw new Error(`pruneI18nNuxt: expected ${t} to exist - did the i18n package move?`);let n=JSON.parse(await Ko(t,"utf-8")),r=!!(n.exports?.["./module"]??n.exports?.["./nuxt"]),i=!1;if(n.exports)for(let a of["./module","./nuxt"])a in n.exports&&(delete n.exports[a],i=!0);n.devDependencies&&"@nuxt/kit"in n.devDependencies&&(delete n.devDependencies["@nuxt/kit"],i=!0),i&&await l(t,JSON.stringify(n,null," ")+`
|
|
1057
|
+
`);let o=Sr(e.projectDir,"packages/i18n/nuxt");if(r&&!br(o))throw new Error(`pruneI18nNuxt: packages/i18n declares a Nuxt export surface but ${o} is missing - did the i18n Nuxt module move?`);await Go(o,{recursive:!0,force:!0})}import{readFile as Ar,rm as Ho}from"fs/promises";import{join as cn}from"path";async function Ir(e){e.cacheProvider==="upstash"&&await Promise.all([zo(e.projectDir),Yo(e.projectDir),Ho(cn(e.projectDir,"packages/runtime/tests/redis.test.ts"),{force:!0})])}async function zo(e){let t=cn(e,"packages/runtime/tests/setup.ts"),n;try{n=await Ar(t,"utf-8")}catch{return}let r=n.replace(/\tREDIS_URL:\s*"[^"]*",?\n/,` UPSTASH_REDIS_REST_URL: "https://test.upstash.io",
|
|
1077
1058
|
UPSTASH_REDIS_REST_TOKEN: "test-token",
|
|
1078
|
-
`);n
|
|
1059
|
+
`);r!==n&&await l(t,r)}async function Yo(e){let t=cn(e,"packages/api/tests/setup.ts"),n;try{n=await Ar(t,"utf-8")}catch{return}let r=n;r=r.replace(/\tREDIS_URL:\s*"[^"]*",?\n/g,` UPSTASH_REDIS_REST_URL: "https://test.upstash.io",
|
|
1079
1060
|
UPSTASH_REDIS_REST_TOKEN: "test-token",
|
|
1080
|
-
`),
|
|
1061
|
+
`),r=r.replace(/vi\.mock\("ioredis"[\s\S]*?\n\}\);\n\n?/,""),r=r.replace(/vi\.mock\("rate-limit-redis"[\s\S]*?\n\}\);\n\n?/,""),r=r.replace(/\t\t\tREDIS_URL:\s*"[^"]*",?\n/,` UPSTASH_REDIS_REST_URL: "https://test.upstash.io",
|
|
1081
1062
|
UPSTASH_REDIS_REST_TOKEN: "test-token",
|
|
1082
|
-
`),
|
|
1063
|
+
`),r=r.replace(/(^vi\.mock\("@repo\/runtime")/m,`vi.mock("@upstash/redis", () => {
|
|
1083
1064
|
class Redis {
|
|
1084
1065
|
get = vi.fn().mockResolvedValue(null);
|
|
1085
1066
|
set = vi.fn().mockResolvedValue("OK");
|
|
@@ -1096,20 +1077,67 @@ vi.mock("@upstash/lock", () => {
|
|
|
1096
1077
|
return { Lock };
|
|
1097
1078
|
});
|
|
1098
1079
|
|
|
1099
|
-
$1`),n
|
|
1100
|
-
|
|
1101
|
-
`)}
|
|
1080
|
+
$1`),r!==n&&await l(t,r)}import{readdir as fn,readFile as j,rm as w}from"fs/promises";import{join as h}from"path";import{readFile as Ct,rm as qo}from"fs/promises";import{join as xt}from"path";function Jo(e){return new RegExp(`^[ \\t]*(?:\\/\\/|\\{\\/\\*|\\*) gsaas:${e}-start(?: \\*\\/\\})?[ \\t]*\\r?\\n[\\s\\S]*?^[ \\t]*(?:\\/\\/|\\{\\/\\*|\\*) gsaas:${e}-end(?: \\*\\/\\})?[ \\t]*\\r?\\n`,"gm")}function J(e,t,n="ai",r="stripDesktopAi"){let i=Jo(n);if(e.match(i)===null)throw new Error(`${r}: expected gsaas ${n} markers in ${t}, but found none (boilerplate drift).`);let o=e.replace(i,"");if(o.includes(`gsaas:${n}-start`)||o.includes(`gsaas:${n}-end`))throw new Error(`${r}: an unbalanced gsaas ${n} marker is left in ${t} (boilerplate drift).`);return o.replace(/\n{3,}/g,`
|
|
1081
|
+
|
|
1082
|
+
`)}async function _(e,t,n,r,i){let o=await Ct(e,"utf-8"),a=o.indexOf(t);if(a===-1)throw new Error(`${i}: expected to find the ${r} seam, but it was missing (boilerplate drift).`);if(o.indexOf(t,a+t.length)!==-1)throw new Error(`${i}: the ${r} seam appears more than once (boilerplate drift).`);await l(e,o.slice(0,a)+n+o.slice(a+t.length))}function lt(e,t,n,r){if(!(t in e))throw new Error(`${r}: expected ${n} (boilerplate drift).`);delete e[t]}function Dt(e){return e.frontend==="nextjs"?"next":"nuxt"}async function Nt(e,t,n,r,i,o){let a=xt(e,"docs",t);await qo(xt(a,`${n}.mdx`)),await _(xt(a,"meta.json"),` "${n}",
|
|
1083
|
+
`,"",`${t} meta.json ${n} nav entry`,i);let s=xt(a,"ai.mdx"),f=(await Ct(s,"utf-8")).split(`
|
|
1084
|
+
`).find(m=>m.includes(`href="${r}"`));if(f===void 0)throw new Error(`${i}: expected the ai.mdx card linking to ${r} (boilerplate drift).`);if(await _(s,`${f}
|
|
1085
|
+
`,"",`${t} ai.mdx ${n} card`,i),o!==void 0){let m=`| **${o}** |`,v=(await Ct(s,"utf-8")).split(`
|
|
1086
|
+
`).find(b=>b.startsWith(m));if(v===void 0)throw new Error(`${i}: expected the ai.mdx "${o}" hub-table row (boilerplate drift).`);await _(s,`${v}
|
|
1087
|
+
`,"",`${t} ai.mdx ${o} hub-table row`,i)}}async function Lt(e){let t=`import { config } from "@repo/config";
|
|
1088
|
+
`,n=await Ct(e,"utf-8");if(!n.includes(t))return;let r=n.replace(t,""),i=r.replace(/\/\*[\s\S]*?\*\//g,"").replace(/\/\/[^\n]*/g,"").replace(/"(?:\\.|[^"\\])*"/g,'""').replace(/'(?:\\.|[^'\\])*'/g,"''").replace(/`(?:\\.|[^`\\])*`/g,"``");/\bconfig\b/.test(i)||await l(e,r)}import{readFile as Wo}from"fs/promises";import{join as Xo}from"path";async function ln(e){if(e.rag)return;let t=Xo(e.projectDir,"packages/config/src/index.ts"),n=await Wo(t,"utf-8");if(!/rag:\s*\{\s*enabled:\s*false\s*\}/.test(n))throw new Error("stripRag: expected `config.rag` emitted with `enabled: false` for a rag-off build, but it was missing (generator drift).")}import{readFile as Pr,rm as pn}from"fs/promises";import{join as Te}from"path";async function dn(e){if(e.mcpServer)return;let t=e.projectDir,n="stripMcpServer";await pn(Te(t,"packages/api/src/routes/internal/ai/mcp.ts")),await pn(Te(t,"packages/api/tests/routes/mcp.test.ts")),await pn(Te(t,"packages/auth/src/mcp.ts"));let r=Te(t,"packages/api/src/routes/internal/index.ts");await _(r,`import mcpRoutes from "./ai/mcp";
|
|
1089
|
+
`,"","internal router mcp import",n),await _(r,'\n// Outward MCP server (`/mcp` + its OAuth `.well-known` discovery), gated on `config.mcpServer`.\n// Mounted at the API root so the discovery metadata sits at `{apiBasePath}/.well-known/...` where\n// an external agent probes it. Off by default, so the routes are absent entirely when disabled. It\n// is not chained into the typed router above: external agents (not the typed RPC client) call it,\n// so it needs no `AppType` inference, and gating it keeps the feature truly inert when off.\nif (config.mcpServer?.enabled) {\n app.route("/", mcpRoutes);\n}\n',"","internal router mcp mount",n),await Lt(r);let i=Te(t,"packages/auth/src/config.ts");await _(i,` magicLink,
|
|
1090
|
+
mcp,
|
|
1091
|
+
organization,`,` magicLink,
|
|
1092
|
+
organization,`,"auth config mcp plugin import",n),await _(i,` // Outward MCP server: turns Better Auth into an OAuth 2.1 provider so an
|
|
1093
|
+
// external agent (Hermes/OpenClaw) can authenticate and drive the app's
|
|
1094
|
+
// capability layer over MCP. Brings the oauthApplication/oauthAccessToken/
|
|
1095
|
+
// oauthConsent tables (run \`pnpm auth:generate\` after toggling).
|
|
1096
|
+
...(config.mcpServer?.enabled
|
|
1097
|
+
? [mcp({ loginPage: \`\${config.baseUrl}\${config.routes.auth}/login\` })]
|
|
1098
|
+
: []),
|
|
1099
|
+
`,"","auth config mcp plugin block",n);let o=Te(t,"packages/auth/package.json"),a=JSON.parse(await Pr(o,"utf-8"));if(!a.exports)throw new Error(`${n}: expected an exports map in packages/auth/package.json (boilerplate drift).`);lt(a.exports,"./mcp",'the "./mcp" export in packages/auth/package.json',n),await l(o,JSON.stringify(a,null," ")+`
|
|
1100
|
+
`);let s=Te(t,"packages/api/package.json"),p=JSON.parse(await Pr(s,"utf-8"));if(!p.dependencies)throw new Error(`${n}: expected dependencies in packages/api/package.json (boilerplate drift).`);lt(p.dependencies,"@modelcontextprotocol/sdk","@modelcontextprotocol/sdk in packages/api dependencies",n),await l(s,JSON.stringify(p,null," ")+`
|
|
1101
|
+
`);let f=Dt(e);await Nt(t,f,"companion-agent-mcp",`/${f}/companion-agent-mcp`,n,"MCP")}import{rm as W}from"fs/promises";import{join as X}from"path";import{readFile as un}from"fs/promises";import{join as Je}from"path";async function Rr(e,t){let n=Je(e,"packages/api/src/routes/internal/index.ts");await l(n,J(await un(n,"utf-8"),"internal router","companion",t)),await Lt(n);let r=Je(e,"packages/api/package.json"),i=JSON.parse(await un(r,"utf-8"));if(!i.dependencies)throw new Error(`${t}: expected dependencies in packages/api/package.json (boilerplate drift).`);lt(i.dependencies,"@repo/companion-protocol","@repo/companion-protocol in packages/api dependencies",t),await l(r,JSON.stringify(i,null," ")+`
|
|
1102
|
+
`);let o=Je(e,"packages/api/src/ai/schedule-runner.ts");await l(o,J(await un(o,"utf-8"),"schedule-runner.ts","companion",t));let a=Je(e,"packages/api/src/ai/settings-store.ts");await _(a,`import { parseCompanionKey } from "../relay/companion-key";
|
|
1103
|
+
|
|
1104
|
+
`,"","settings-store.ts relay import",t),await _(a," * - COMPANION (when `config.companion.enabled`): a well-formed companion key\n * `<connectionId>@<deviceId>@<modelId>` is also accepted, so a default/fallback model that points\n * at a paired CLI persists (the run path resolves it, and the daemon handles an offline device).\n * Without this, the `@`-separated key is neither a registry key nor a `provider::modelId` key, so\n * it would silently clear to `null` on save and vanish on reload.\n","","settings-store.ts COMPANION docstring bullet",t),await _(a," *\n * When `opts.allowCompanion` is `false`, a companion key is REJECTED even when the companion is\n * enabled - used by the builder-task surfaces, whose runs are background/cloud-only and can never\n * dispatch to a device-bound CLI.\n","","settings-store.ts opts.allowCompanion docstring paragraph",t),await _(a," * @param opts - `allowCompanion` (default `true`) controls companion-key acceptance.\n","","settings-store.ts @param opts",t),await _(a,`export function validModelKey(
|
|
1105
|
+
key: string | null | undefined,
|
|
1106
|
+
opts: { allowCompanion?: boolean } = {}
|
|
1107
|
+
): string | null {
|
|
1108
|
+
`,`export function validModelKey(key: string | null | undefined): string | null {
|
|
1109
|
+
`,"settings-store.ts validModelKey signature",t),await _(a,` if (
|
|
1110
|
+
opts.allowCompanion !== false &&
|
|
1111
|
+
config.companion?.enabled === true &&
|
|
1112
|
+
parseCompanionKey(key) !== null
|
|
1113
|
+
) {
|
|
1114
|
+
return key;
|
|
1115
|
+
}
|
|
1116
|
+
`,"","settings-store.ts companion-key branch",t);let s=Je(e,"packages/api/src/ai/task-run.ts");await _(s,`import { parseCompanionKey } from "../relay/companion-key";
|
|
1117
|
+
`,"","task-run.ts relay import",t),await _(s,`/** Whether a chain link is usable for a task run: present and not a companion (device) key. */
|
|
1118
|
+
`,`/** Whether a chain link is usable for a task run: a present, non-empty key. */
|
|
1119
|
+
`,"task-run.ts usableTaskModelKey docstring",t),await _(s,` return typeof key === "string" && key.length > 0 && parseCompanionKey(key) === null;
|
|
1120
|
+
`,` return typeof key === "string" && key.length > 0;
|
|
1121
|
+
`,"task-run.ts usableTaskModelKey body",t),await _(s,` * override, then the builder's \`defaults.web.model\`, then the acting user's account default -
|
|
1122
|
+
* skipping companion (device-bound) links, which are valid for chat but never for a background
|
|
1123
|
+
* task - and delegating the final resolution to {@link resolveChatRun}, which owns BYOK/platform
|
|
1124
|
+
`," * override, then the builder's `defaults.web.model`, then the acting user's account default,\n * delegating the final resolution to {@link resolveChatRun}, which owns BYOK/platform\n","task-run.ts resolveTaskRun docstring model chain",t);let p=Je(e,"packages/api/src/routes/internal/ai/tasks-router.ts");await _(p,` modelKey: validModelKey(override?.modelKey ?? null, { allowCompanion: false }),
|
|
1125
|
+
`,` modelKey: validModelKey(override?.modelKey ?? null),
|
|
1126
|
+
`,"tasks-router.ts listTaskOverrides validModelKey",t),await _(p,` if (typeof body.modelKey === "string" && validModelKey(body.modelKey, { allowCompanion: false }) === null) {
|
|
1127
|
+
`,` if (typeof body.modelKey === "string" && validModelKey(body.modelKey) === null) {
|
|
1128
|
+
`,"tasks-router.ts putTask validModelKey",t)}async function mn(e){if(e.companion)return;let t=e.projectDir,n="stripCompanion";await W(X(t,"apps/companion"),{recursive:!0}),await W(X(t,"packages/companion-protocol"),{recursive:!0}),e.desktop&&e.desktopAi||await W(X(t,"packages/agent-runtime"),{recursive:!0}),await W(X(t,"packages/api/src/relay"),{recursive:!0}),await W(X(t,"packages/api/tests/relay"),{recursive:!0}),await W(X(t,"packages/api/src/routes/internal/companion.ts")),await W(X(t,"packages/api/src/routes/internal/companion-transport.ts")),await W(X(t,"packages/api/src/routes/internal/companion-install.ts")),await W(X(t,"packages/api/tests/routes/companion.test.ts")),await W(X(t,"packages/api/tests/routes/companion-transport.test.ts")),await W(X(t,"packages/api/tests/routes/companion-install.test.ts")),await Rr(t,n);let r=Dt(e);await Nt(t,r,"companion",`/${r}/companion`,n,"Companions")}var Zo=new Set(["ci.yml","desktop-release.yml"]),Qo=["cli","cli:clean","demo:bench","playground:regen","playground:test","playground:test:units","playground:test:build"];async function _r(e){let t=h(e.projectDir,".github/workflows"),n=await fn(t).catch(()=>[]);for(let r of n)Zo.has(r)||await w(h(t,r),{recursive:!0,force:!0})}async function Or(e){let t=h(e.projectDir,"package.json"),n=await j(t,"utf-8"),r=JSON.parse(n),i=!1;if(r.scripts){for(let o of Qo)o in r.scripts&&(delete r.scripts[o],i=!0);if(!vt(e))for(let o of["infra","infra:stop"])o in r.scripts&&(delete r.scripts[o],i=!0)}i&&await l(t,JSON.stringify(r,null," ")+`
|
|
1129
|
+
`)}async function xr(e){let t=h(e.projectDir,"package.json"),n=await j(t,"utf-8"),r=JSON.parse(n);!r.scripts||!("dev"in r.scripts)||(r.scripts.dev=e.architecture==="separate"?"turbo run dev --continue":"turbo run dev --continue --filter=!backend",await l(t,JSON.stringify(r,null," ")+`
|
|
1130
|
+
`))}async function Cr(e){let t=e.frontend==="nextjs"?"apps/web-nuxt":"apps/web-next";await w(h(e.projectDir,t),{recursive:!0,force:!0})}async function Dr(e){e.docs||await w(h(e.projectDir,"apps/docs"),{recursive:!0})}async function Nr(e){let t=e.frontend==="nextjs"?"docs/nuxt":"docs/next";if(await w(h(e.projectDir,t),{recursive:!0,force:!0}),await w(h(e.projectDir,"docs/index.mdx")),!e.desktop)await w(h(e.projectDir,"docs/desktop"),{recursive:!0,force:!0});else if(!e.desktopAi){await w(h(e.projectDir,"docs/desktop/ai"),{recursive:!0,force:!0});let n=h(e.projectDir,"docs/desktop/meta.json"),r=JSON.parse(await j(n,"utf-8"));r.pages=r.pages.filter(i=>i!=="ai"),await l(n,`${JSON.stringify(r,null,2)}
|
|
1131
|
+
`)}}async function Lr(e){if(e.desktop)return;await w(h(e.projectDir,"apps/desktop"),{recursive:!0});let t=h(e.projectDir,"packages/i18n/translations");for(let n of await fn(t,{withFileTypes:!0}))n.isDirectory()&&await w(h(t,n.name,"desktop.json"),{force:!0});await w(h(e.projectDir,".github/workflows/desktop-release.yml"))}var Tr=`
|
|
1102
1132
|
# Local-embedding model binaries are fetched on install/build (see
|
|
1103
1133
|
# scripts/fetch-embedding-model.mjs), never committed.
|
|
1104
1134
|
resources/models/
|
|
1105
|
-
`;function
|
|
1106
|
-
`)}function
|
|
1107
|
-
|
|
1108
|
-
`)}async function
|
|
1109
|
-
`);let i=g(t,"apps/desktop/.gitignore"),s=await j(i,"utf-8");await c(i,Ti(s)),await Ri(t);let a=g(t,"packages/i18n/translations");for(let p of await Yt(a,{withFileTypes:!0})){if(!p.isDirectory())continue;let f=g(a,p.name,"desktop.json"),m=await j(f,"utf-8").catch(()=>null);if(m===null)continue;let u=JSON.parse(m),v=!1;"agents"in u&&(delete u.agents,v=!0),"schedules"in u&&(delete u.schedules,v=!0),"integrations"in u&&(delete u.integrations,v=!0),v&&await c(f,JSON.stringify(u,null," ")+`
|
|
1110
|
-
`)}}async function Ri(e){let t=g(e,"apps/desktop/src/main/ipc.ts"),r=Ge(await j(t,"utf-8"),"main/ipc.ts");await c(t,r);let n=g(e,"apps/desktop/src/main/config.ts"),o=await j(n,"utf-8");o=D(o,`,
|
|
1135
|
+
`;function ea(e){if(!e.includes(Tr))throw new Error("stripDesktopAi: expected the resources/models .gitignore block in apps/desktop/.gitignore, but it was missing (boilerplate drift).");return e.replace(Tr,`
|
|
1136
|
+
`)}function M(e,t,n,r){let i=e.indexOf(t);if(i===-1)throw new Error(`stripDesktopAi: expected to find the ${r} seam, but it was missing (boilerplate drift).`);if(e.indexOf(t,i+t.length)!==-1)throw new Error(`stripDesktopAi: the ${r} seam appears more than once (boilerplate drift).`);return e.slice(0,i)+n+e.slice(i+t.length)}async function $r(e){if(!e.desktop||e.desktopAi)return;let t=e.projectDir;await w(h(t,"apps/desktop/src/main/ai"),{recursive:!0}),await w(h(t,"apps/desktop/resources/ai-skills"),{recursive:!0}),await w(h(t,"apps/desktop/resources/knowledge"),{recursive:!0,force:!0}),await w(h(t,"apps/desktop/scripts/fetch-embedding-model.mjs")),await w(h(t,"apps/desktop/resources/models"),{recursive:!0,force:!0}),await w(h(t,"apps/desktop/src/renderer/src/screens/agents"),{recursive:!0}),await w(h(t,"apps/desktop/src/renderer/src/screens/integrations"),{recursive:!0}),await w(h(t,"apps/desktop/src/renderer/src/screens/ai"),{recursive:!0}),await w(h(t,"apps/desktop/src/renderer/src/lib/ai.ts")),await w(h(t,"apps/desktop/src/renderer/src/hooks/use-ai.ts")),await w(h(t,"apps/desktop/src/renderer/src/hooks/use-ai-scope.ts")),await w(h(t,"apps/desktop/src/renderer/src/screens/schedules.tsx")),await w(h(t,"apps/desktop/src/renderer/src/components/side-panel-dock.tsx")),await w(h(t,"apps/desktop/src/renderer/src/components/side-panel.tsx")),await w(h(t,"apps/desktop/src/renderer/src/config/side-panels.tsx")),await w(h(t,"apps/desktop/src/renderer/src/lib/side-panel-state.ts")),await w(h(t,"apps/desktop/tests/renderer/lib/side-panel-state.test.ts")),await w(h(t,"apps/desktop/src/renderer/src/lib/chat-prefs.ts")),await w(h(t,"apps/desktop/tests/renderer/lib/chat-prefs.test.ts")),await w(h(t,"apps/desktop/src/renderer/src/lib/ai-tab-state.ts")),await w(h(t,"apps/desktop/tests/renderer/lib/ai-tab-state.test.ts")),await w(h(t,"apps/desktop/tests/main/ai"),{recursive:!0}),await w(h(t,"apps/desktop/tests/main/ai-import-boundary.test.ts")),await w(h(t,"apps/desktop/tests/renderer/lib/ai.test.ts"));let n=h(t,"apps/desktop/package.json"),r=JSON.parse(await j(n,"utf-8")),i=["@repo/ai","@repo/agent-runtime","@anthropic-ai/claude-agent-sdk","@modelcontextprotocol/sdk","cross-spawn","@huggingface/transformers","@orama/orama","@homebridge/node-pty-prebuilt-multiarch","@xterm/xterm","@xterm/addon-fit"];for(let p of i){if(!r.dependencies||!(p in r.dependencies))throw new Error(`stripDesktopAi: expected ${p} in apps/desktop dependencies (boilerplate drift).`);delete r.dependencies[p]}for(let p of["fetch:model","predev","prebuild"]){if(!r.scripts||!(p in r.scripts))throw new Error(`stripDesktopAi: expected the ${p} script in apps/desktop package.json (boilerplate drift).`);delete r.scripts[p]}await l(n,JSON.stringify(r,null," ")+`
|
|
1137
|
+
`);let o=h(t,"apps/desktop/.gitignore"),a=await j(o,"utf-8");await l(o,ea(a)),await ta(t);let s=h(t,"packages/i18n/translations");for(let p of await fn(s,{withFileTypes:!0})){if(!p.isDirectory())continue;let f=h(s,p.name,"desktop.json"),m=await j(f,"utf-8").catch(()=>null);if(m===null)continue;let d=JSON.parse(m),v=!1;"agents"in d&&(delete d.agents,v=!0),"ai_hub"in d&&(delete d.ai_hub,v=!0),"schedules"in d&&(delete d.schedules,v=!0),"integrations"in d&&(delete d.integrations,v=!0),v&&await l(f,JSON.stringify(d,null," ")+`
|
|
1138
|
+
`)}}async function ta(e){let t=h(e,"apps/desktop/src/main/ipc.ts"),n=J(await j(t,"utf-8"),"main/ipc.ts");await l(t,n);let r=h(e,"apps/desktop/src/main/config.ts"),i=await j(r,"utf-8");i=M(i,`,
|
|
1111
1139
|
/** AI tool orchestration ("agents") feature flags. */
|
|
1112
|
-
agents: desktopConfig.agents`,"","main/config agents field"),await
|
|
1140
|
+
agents: desktopConfig.agents`,"","main/config agents field"),await l(r,i);let o=h(e,"apps/desktop/src/preload/index.ts"),a=await j(o,"utf-8");a=M(a,`import type {
|
|
1113
1141
|
AdapterCapabilities,
|
|
1114
1142
|
AuthStatus,
|
|
1115
1143
|
ConnectionRef,
|
|
@@ -1117,53 +1145,46 @@ resources/models/
|
|
|
1117
1145
|
DetectResult,
|
|
1118
1146
|
IntegrationInfo,
|
|
1119
1147
|
ModelInfo,
|
|
1148
|
+
ModelRef,
|
|
1120
1149
|
PermissionDecision,
|
|
1121
|
-
RunEvent
|
|
1122
|
-
RunRequest
|
|
1150
|
+
RunEvent
|
|
1123
1151
|
} from '@repo/ai/backends'
|
|
1124
|
-
`,"","preload @repo/ai type import"),
|
|
1125
|
-
`,"","preload @repo/ai/agents type import"),
|
|
1126
|
-
`,"","preload ReasoningEffort type import"),
|
|
1127
|
-
`,"","preload DesktopTaskSpec import"),
|
|
1128
|
-
`,"","preload ScheduleView import");let
|
|
1129
|
-
`),
|
|
1130
|
-
`,"","router clientConfig import"),v=
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
`,"
|
|
1134
|
-
`,"","router
|
|
1135
|
-
`,"","router
|
|
1136
|
-
`,"","router integrations route spread"),await c(u,v);let w=g(e,"apps/desktop/src/renderer/src/config/sidebar.ts"),T=await j(w,"utf-8");T=D(T,`import {
|
|
1152
|
+
`,"","preload @repo/ai type import"),a=M(a,`import type { ChatSession, ScheduleRun, ScheduleTrigger } from '@repo/ai/agents'
|
|
1153
|
+
`,"","preload @repo/ai/agents type import"),a=M(a,`import type { ReasoningEffort } from '@repo/ai/backends'
|
|
1154
|
+
`,"","preload ReasoningEffort type import"),a=M(a,`import type { DesktopTaskSpec } from '@repo/config/types'
|
|
1155
|
+
`,"","preload DesktopTaskSpec import"),a=M(a,`import type { ScheduleView } from '../main/ai/ipc'
|
|
1156
|
+
`,"","preload ScheduleView import");let s=/,\n[ \t]*\/\/ gsaas:ai-start\n[\s\S]*?\n[ \t]*\/\/ gsaas:ai-end\n/g,p=a.match(s);if(p===null)throw new Error("stripDesktopAi: expected the preload `ai` bridge marker region, but it was missing (boilerplate drift).");if(p.length>1)throw new Error("stripDesktopAi: the preload `ai` bridge marker region appears more than once (boilerplate drift).");a=a.replace(s,`
|
|
1157
|
+
`),a=J(a,"preload/index.ts"),await l(o,a);let f=h(e,"apps/desktop/src/renderer/src/components/shell.tsx"),m=J(await j(f,"utf-8"),"components/shell.tsx");await l(f,m);let d=h(e,"apps/desktop/src/renderer/src/router.tsx"),v=await j(d,"utf-8");v=M(v,`import { clientConfig } from '@/lib/config'
|
|
1158
|
+
`,"","router clientConfig import"),v=M(v,` createRouter,
|
|
1159
|
+
redirect
|
|
1160
|
+
} from '@tanstack/react-router'`,` createRouter
|
|
1161
|
+
} from '@tanstack/react-router'`,"router redirect import specifier"),v=M(v,`import { AiHubScreen } from '@/screens/ai'
|
|
1162
|
+
`,"","router AiHubScreen import"),v=J(v,"router.tsx"),v=M(v,` ...(clientConfig.agentsEnabled ? [aiRoute, agentsRoute, schedulesRoute, integrationsRoute] : []),
|
|
1163
|
+
`,"","router ai route spread"),await l(d,v);let b=h(e,"apps/desktop/src/renderer/src/config/sidebar.ts"),I=await j(b,"utf-8");I=M(I,`import {
|
|
1137
1164
|
BuildingsIcon,
|
|
1138
|
-
ClockCountdownIcon,
|
|
1139
1165
|
GearIcon,
|
|
1140
1166
|
HouseIcon,
|
|
1141
|
-
PlugsConnectedIcon,
|
|
1142
1167
|
RobotIcon,
|
|
1143
1168
|
UserCircleIcon
|
|
1144
|
-
} from '@phosphor-icons/react'`,"import { BuildingsIcon, GearIcon, HouseIcon, UserCircleIcon } from '@phosphor-icons/react'","sidebar icon imports"),
|
|
1145
|
-
/** Whether the AI tool orchestration ("agents") feature is enabled. */
|
|
1146
|
-
agentsEnabled: desktopConfig.agents.enabled,
|
|
1147
|
-
/** Whether end users may author their own background schedules (default true). */
|
|
1148
|
-
userSchedulesEnabled: desktopConfig.agents.userSchedules !== false`,"","lib/config agent flags"),await c(G,L);let W=g(e,"apps/desktop/src/renderer/src/lib/sidebar-flags.ts"),X=Ge(await j(W,"utf-8"),"lib/sidebar-flags.ts");await c(W,X);let ne=g(e,"apps/desktop/electron.vite.config.ts"),b=await j(ne,"utf-8");b=D(b,",\n // The local-embeddings worker (`embeddings.ts`) spawns `embeddings-worker.js`,\n // which must sit next to the main `index.js`. Declaring both as named rollup\n // inputs emits `out/main/index.js` (the app entry) and\n // `out/main/embeddings-worker.js` (the worker) as `[name].js`, so the host's\n // `join(__dirname, 'embeddings-worker.js')` resolves in dev and packaged builds.\n rollupOptions: {\n // `@huggingface/transformers` loads its model runtime from `onnxruntime-node`,\n // a native addon that resolves its `.node` binding with a dynamic\n // `require('../bin/napi-v6/<platform>/onnxruntime_binding.node')`. A native\n // addon cannot be Rollup-bundled, so both packages stay external and load from\n // `node_modules` at runtime; electron-builder ships their trees (see\n // `electron-builder.mjs` `files`/`asarUnpack`). The CLI strips this whole\n // rollup block for an AI-off desktop build (the worker is removed with it).\n external: ['@huggingface/transformers', 'onnxruntime-node'],\n input: {\n index: resolve('src/main/index.ts'),\n 'embeddings-worker': resolve('src/main/ai/embeddings-worker.ts')\n }\n }","","electron.vite.config rollup worker block"),await c(ne,b);let I=g(e,"apps/desktop/electron-builder.mjs"),R=await j(I,"utf-8");R=D(R," // The main, preload, and renderer are self-contained bundles (electron-vite with\n // build.externalizeDeps:false), so the packaged app needs almost ZERO runtime\n // node_modules: exclude them all by default to keep the thin client small (the\n // backend dependency trees `@repo/api` drags in - express, pg, aws-sdk - are never\n // `require`d at runtime once bundled). Then RE-INCLUDE only the trees the local\n // embeddings worker keeps external (the native ONNX runtime can't be Rollup-bundled).\n // The worker `require`s `@huggingface/transformers`, whose Node build eagerly, at\n // import, pulls in `onnxruntime-node` (its prebuilt `.node` binding) + the shared\n // `onnxruntime-common`, AND `sharp` (a top-level `require(\"sharp\")` in its image\n // util that runs even for text-only embedding); `sharp` in turn needs its `@img/*`\n // platform natives plus `detect-libc` and `semver` at load. All of these must ship\n // or the worker import throws and semantic search silently degrades to BM25. Each\n // glob matches against electron-builder's production-dependency collection, which\n // flattens pnpm's `.pnpm` virtual store into the packaged `node_modules/<name>`\n // (following symlinks) - so transitive names resolve even though, under pnpm's\n // isolated linker, only `@huggingface/transformers` is linked at the app's own\n // node_modules and the rest live in `.pnpm`. The CLI strips every re-include for an\n // AI-off desktop build (there is no external runtime to collect). The\n // `KB_SMOKE`-gated packaged-embedding test guards against this closure drifting.\n files: [\n 'out/**',\n 'resources/**',\n 'package.json',\n '!node_modules/**/*',\n 'node_modules/@huggingface/transformers/**/*',\n 'node_modules/onnxruntime-node/**/*',\n 'node_modules/onnxruntime-common/**/*',\n 'node_modules/sharp/**/*',\n 'node_modules/@img/**/*',\n 'node_modules/detect-libc/**/*',\n 'node_modules/semver/**/*'\n ],",` // The main, preload, and renderer are self-contained bundles (electron-vite with
|
|
1169
|
+
} from '@phosphor-icons/react'`,"import { BuildingsIcon, GearIcon, HouseIcon, UserCircleIcon } from '@phosphor-icons/react'","sidebar icon imports"),I=J(I,"config/sidebar.ts"),await l(b,I);let z=h(e,"apps/desktop/src/renderer/src/lib/config.ts"),L=await j(z,"utf-8");L=J(L,"lib/config.ts"),L=L.replace(/,(\n\} as const)/,"$1"),await l(z,L);let K=h(e,"apps/desktop/src/renderer/src/lib/sidebar-flags.ts"),ge=J(await j(K,"utf-8"),"lib/sidebar-flags.ts");await l(K,ge);let Y=h(e,"apps/desktop/electron.vite.config.ts"),k=await j(Y,"utf-8");k=M(k,",\n // The local-embeddings worker (`embeddings.ts`) spawns `embeddings-worker.js`,\n // which must sit next to the main `index.js`. Declaring both as named rollup\n // inputs emits `out/main/index.js` (the app entry) and\n // `out/main/embeddings-worker.js` (the worker) as `[name].js`, so the host's\n // `join(__dirname, 'embeddings-worker.js')` resolves in dev and packaged builds.\n rollupOptions: {\n // `@huggingface/transformers` loads its model runtime from `onnxruntime-node`,\n // a native addon that resolves its `.node` binding with a dynamic\n // `require('../bin/napi-v6/<platform>/onnxruntime_binding.node')`. A native\n // addon cannot be Rollup-bundled, so both packages stay external and load from\n // `node_modules` at runtime; electron-builder ships their trees (see\n // `electron-builder.mjs` `files`/`asarUnpack`). The embedded-terminal login flow\n // adds `@homebridge/node-pty-prebuilt-multiarch`, also a native addon (its\n // `pty.node` binding), kept external for the same reason. The CLI strips this whole\n // rollup block for an AI-off desktop build (the worker is removed with it).\n external: [\n '@huggingface/transformers',\n 'onnxruntime-node',\n '@homebridge/node-pty-prebuilt-multiarch'\n ],\n input: {\n index: resolve('src/main/index.ts'),\n 'embeddings-worker': resolve('src/main/ai/embeddings-worker.ts')\n }\n }","","electron.vite.config rollup worker block"),await l(Y,k);let T=h(e,"apps/desktop/electron-builder.mjs"),P=await j(T,"utf-8");P=M(P," // The main, preload, and renderer are self-contained bundles (electron-vite with\n // build.externalizeDeps:false), so the packaged app needs almost ZERO runtime\n // node_modules: exclude them all by default to keep the thin client small (the\n // backend dependency trees `@repo/api` drags in - express, pg, aws-sdk - are never\n // `require`d at runtime once bundled). Then RE-INCLUDE only the trees the local\n // embeddings worker keeps external (the native ONNX runtime can't be Rollup-bundled).\n // The worker `require`s `@huggingface/transformers`, whose Node build eagerly, at\n // import, pulls in `onnxruntime-node` (its prebuilt `.node` binding) + the shared\n // `onnxruntime-common`, AND `sharp` (a top-level `require(\"sharp\")` in its image\n // util that runs even for text-only embedding); `sharp` in turn needs its `@img/*`\n // platform natives plus `detect-libc` and `semver` at load. All of these must ship\n // or the worker import throws and semantic search silently degrades to BM25. Each\n // glob matches against electron-builder's production-dependency collection, which\n // flattens pnpm's `.pnpm` virtual store into the packaged `node_modules/<name>`\n // (following symlinks) - so transitive names resolve even though, under pnpm's\n // isolated linker, only `@huggingface/transformers` is linked at the app's own\n // node_modules and the rest live in `.pnpm`. The embedded-terminal login flow adds\n // `@homebridge/node-pty-prebuilt-multiarch` (its prebuilt `pty.node` binding); like the\n // ONNX runtime it cannot be Rollup-bundled, so its tree is re-included here too (the\n // `**/*.node` `asarUnpack` glob already unpacks `pty.node`). The CLI strips every\n // re-include for an AI-off desktop build (there is no external runtime to collect). The\n // `KB_SMOKE`-gated packaged-embedding test guards against this closure drifting.\n files: [\n 'out/**',\n 'resources/**',\n 'package.json',\n '!node_modules/**/*',\n 'node_modules/@huggingface/transformers/**/*',\n 'node_modules/onnxruntime-node/**/*',\n 'node_modules/onnxruntime-common/**/*',\n 'node_modules/sharp/**/*',\n 'node_modules/@img/**/*',\n 'node_modules/detect-libc/**/*',\n 'node_modules/semver/**/*',\n 'node_modules/@homebridge/node-pty-prebuilt-multiarch/**/*'\n ],",` // The main, preload, and renderer are self-contained bundles (electron-vite with
|
|
1149
1170
|
// build.externalizeDeps:false), so the packaged app ships ZERO runtime node_modules
|
|
1150
1171
|
// (every dependency is Rollup-bundled): keep only the built output, the resources,
|
|
1151
1172
|
// and the package.json, and exclude node_modules entirely.
|
|
1152
|
-
files: ['out/**', 'resources/**', 'package.json', '!node_modules/**/*'],`,"electron-builder files re-includes"),
|
|
1173
|
+
files: ['out/**', 'resources/**', 'package.json', '!node_modules/**/*'],`,"electron-builder files re-includes"),P=M(P,"'resources/**', '**/*.node'","'resources/**'","electron-builder asarUnpack entry"),await l(T,P)}import{readFile as na}from"fs/promises";import{join as ra}from"path";var jr=`on:
|
|
1153
1174
|
workflow_run:
|
|
1154
1175
|
workflows: ["CI"]
|
|
1155
1176
|
branches: [main]
|
|
1156
1177
|
types: [completed]
|
|
1157
|
-
workflow_dispatch:`,
|
|
1178
|
+
workflow_dispatch:`,ia=`on:
|
|
1158
1179
|
# Automatic release on CI success is disabled for this project to conserve
|
|
1159
1180
|
# GitHub Actions minutes. Re-enable by uncommenting the workflow_run trigger.
|
|
1160
1181
|
# workflow_run:
|
|
1161
1182
|
# workflows: ["CI"]
|
|
1162
1183
|
# branches: [main]
|
|
1163
1184
|
# types: [completed]
|
|
1164
|
-
workflow_dispatch:`;async function
|
|
1185
|
+
workflow_dispatch:`;async function Ur(e){if(!e.desktop||e.desktopAutoRelease)return;let t=ra(e.projectDir,".github/workflows/desktop-release.yml"),n=await na(t,"utf8");if(!n.includes(jr))throw new Error(`Cannot make desktop releases manual: the expected workflow_run trigger block was not found in ${t}. The boilerplate workflow may have drifted.`);await l(t,n.replace(jr,ia))}import{join as oa}from"path";async function Mr(e){let t=aa(e);await l(oa(e.projectDir,".github/workflows/ci.yml"),t)}function aa(e){let t=G[e.databaseProvider].managed,n=e.cacheProvider==="upstash",r=e.frontend==="nuxt",i=t?"":` services:
|
|
1165
1186
|
postgres:
|
|
1166
|
-
image:
|
|
1187
|
+
image: pgvector/pgvector:pg18
|
|
1167
1188
|
env:
|
|
1168
1189
|
POSTGRES_USER: postgres
|
|
1169
1190
|
POSTGRES_PASSWORD: postgres
|
|
@@ -1175,13 +1196,13 @@ resources/models/
|
|
|
1175
1196
|
--health-interval 10s
|
|
1176
1197
|
--health-timeout 5s
|
|
1177
1198
|
--health-retries 5
|
|
1178
|
-
`,
|
|
1199
|
+
`,o=t?"postgres://test:test@localhost:5432/saas_test":"postgres://postgres:postgres@localhost:5432/saas",a=n?`
|
|
1179
1200
|
UPSTASH_REDIS_REST_URL: https://test.upstash.io
|
|
1180
|
-
UPSTASH_REDIS_REST_TOKEN: test-token`:"",
|
|
1201
|
+
UPSTASH_REDIS_REST_TOKEN: test-token`:"",s=(()=>{switch(e.paymentProvider){case"stripe":return`
|
|
1181
1202
|
STRIPE_SECRET_KEY: test
|
|
1182
1203
|
STRIPE_WEBHOOK_SECRET: test`;case"polar":return`
|
|
1183
1204
|
POLAR_ACCESS_TOKEN: test
|
|
1184
|
-
POLAR_WEBHOOK_SECRET: test`;case"none":return"";default:{let
|
|
1205
|
+
POLAR_WEBHOOK_SECRET: test`;case"none":return"";default:{let d=e.paymentProvider;throw new Error(`buildCiYaml: unhandled payment provider "${String(d)}"`)}}})(),p=e.socialProviders.map(d=>se[d].envVars.map(v=>`
|
|
1185
1206
|
${v.name}: test`).join("")).join("");return`# Deployment is handled by the hosting platform (Vercel, Coolify, etc.)
|
|
1186
1207
|
# which auto-deploys on push. CI runs in parallel as a quality gate.
|
|
1187
1208
|
# For PR-based workflows, enable GitHub branch protection to require CI before merging.
|
|
@@ -1206,8 +1227,8 @@ jobs:
|
|
|
1206
1227
|
name: Checks
|
|
1207
1228
|
runs-on: ubuntu-latest
|
|
1208
1229
|
timeout-minutes: 20
|
|
1209
|
-
${
|
|
1210
|
-
CONTENT_API_KEY: test-contentapi-key-16chars${
|
|
1230
|
+
${i} env:
|
|
1231
|
+
CONTENT_API_KEY: test-contentapi-key-16chars${a}${s}${p}
|
|
1211
1232
|
STORAGE_REGION: test
|
|
1212
1233
|
STORAGE_ENDPOINT: http://test
|
|
1213
1234
|
STORAGE_ACCESS_KEY_ID: test
|
|
@@ -1220,7 +1241,7 @@ ${o} env:
|
|
|
1220
1241
|
|
|
1221
1242
|
- run: pnpm lint
|
|
1222
1243
|
|
|
1223
|
-
${
|
|
1244
|
+
${r?` # vue-tsc on web-nuxt OOMs on the GitHub runner's default heap once
|
|
1224
1245
|
# the type graph (Nuxt + Pinia + vue-i18n + content collections)
|
|
1225
1246
|
# crosses a threshold. Bump to 6 GB; ubuntu-latest has ~7 GB RAM.
|
|
1226
1247
|
- run: pnpm check-types
|
|
@@ -1228,49 +1249,49 @@ ${n?` # vue-tsc on web-nuxt OOMs on the GitHub runner's default heap once
|
|
|
1228
1249
|
NODE_OPTIONS: --max-old-space-size=6144`:" - run: pnpm check-types"}
|
|
1229
1250
|
|
|
1230
1251
|
- name: Write root env
|
|
1231
|
-
run: echo "DATABASE_URL=${
|
|
1252
|
+
run: echo "DATABASE_URL=${o}" > .env
|
|
1232
1253
|
|
|
1233
1254
|
- run: pnpm test
|
|
1234
|
-
`}import{readFile as
|
|
1235
|
-
`))}async function
|
|
1236
|
-
`))}async function
|
|
1255
|
+
`}import{readFile as Vr}from"fs/promises";import{existsSync as sa}from"fs";import{join as gn}from"path";var Fr="@repo/database";function ca(e){return e?"pnpm -F @repo/database reset && pnpm -F @repo/database run deploy -- --push":"pnpm -F @repo/database run deploy"}function la(e,t){switch(e){case"fullstack":return t==="nextjs"?"web-next":"web-nuxt";case"separate":return"backend";default:{let n=e;throw new Error(`schemaOwnerApp: unhandled architecture "${String(n)}"`)}}}async function pa(e,t,n){let r=await Vr(e,"utf-8"),i=JSON.parse(r),o=i.scripts?.[t];if(!o)throw new Error(`Cannot prepend to missing script "${t}" in ${e}`);o.includes(Fr)||(i.scripts={...i.scripts,[t]:`${n} && ${o}`},await l(e,JSON.stringify(i,null," ")+`
|
|
1256
|
+
`))}async function da(e,t){let n=sa(e)?JSON.parse(await Vr(e,"utf-8")):{$schema:"https://openapi.vercel.sh/vercel.json"},r=n.buildCommand?.trim()||"pnpm build";r.includes(Fr)||(n.buildCommand=`${t} && ${r}`,await l(e,JSON.stringify(n,null," ")+`
|
|
1257
|
+
`))}async function Br(e){let t=ca(e.demo===!0),n=la(e.architecture,e.frontend),r=gn(e.projectDir,"apps",n);switch(e.deploymentTarget){case"node":await pa(gn(r,"package.json"),"start",t);return;case"vercel":await da(gn(r,"vercel.json"),t);return;default:{let i=e.deploymentTarget;throw new Error(`generateDeployScripts: unhandled deployment target "${String(i)}"`)}}}import{readFile as ua}from"fs/promises";import{existsSync as ma}from"fs";import{join as $t}from"path";var fa=["stripe","polar"];async function Kr(e){let t=$t(e.projectDir,"packages/payments/src"),n=e.paymentProvider,r=`// Active payment provider. To switch, change the path below to
|
|
1237
1258
|
// "./polar/index" or "./none/index" (other folders are kept in place).
|
|
1238
|
-
export { ops } from "./${
|
|
1239
|
-
`;await
|
|
1240
|
-
`).filter(
|
|
1241
|
-
`)}import{readdir as
|
|
1242
|
-
`).filter(
|
|
1243
|
-
`).length&&await
|
|
1244
|
-
`))}async function
|
|
1245
|
-
`),await
|
|
1246
|
-
`)}import{relative as
|
|
1247
|
-
`);
|
|
1248
|
-
${
|
|
1249
|
-
`),
|
|
1250
|
-
`),
|
|
1251
|
-
`),H.yellow("Deployment"))}function hs(e){let t=["DATABASE_URL","BETTER_AUTH_SECRET"];return e.cacheProvider==="upstash"?t.push("UPSTASH_REDIS_REST_URL","UPSTASH_REDIS_REST_TOKEN"):t.push("REDIS_URL"),e.paymentProvider==="stripe"?t.push("STRIPE_SECRET_KEY","STRIPE_WEBHOOK_SECRET"):e.paymentProvider==="polar"&&t.push("POLAR_ACCESS_TOKEN","POLAR_WEBHOOK_SECRET"),e.emailProvider==="ses"?t.push("AMAZON_SES_REGION","AMAZON_SES_KEY","AMAZON_SES_SECRET"):e.emailProvider==="resend"?t.push("RESEND_API_KEY"):t.push("SMTP_HOST","SMTP_PORT"),t}function ys(e){switch(e.deploymentTarget){case"node":return"Deploy with Docker or your preferred Node.js host";case"vercel":return"vercel deploy # Deploy to Vercel"}}function Un(e){let t={};if(e.name!==void 0){if(!mt(e.name))throw new Error(`Invalid project name "${e.name}". Use lowercase letters, numbers, and hyphens only. Must start with a letter.`);t.projectName=e.name}if(e.appName!==void 0){if(!e.appName.trim())throw new Error("App name cannot be empty.");t.appName=e.appName}if(e.location!==void 0?t.projectDir=e.location==="."?process.cwd():e.location:t.projectName!==void 0&&(t.projectDir=`./${t.projectName}`),e.frontend!==void 0){if(!ve.includes(e.frontend))throw new Error(`Invalid frontend "${e.frontend}". Valid values: ${ve.join(", ")}`);t.frontend=e.frontend}if(e.architecture!==void 0&&(t.architecture=e.architecture),e.payment!==void 0&&(t.paymentProvider=e.payment),e.email!==void 0&&(t.emailProvider=e.email),e.org!==void 0&&(t.multiTenancy=e.org),e.billingScope!==void 0){if(e.org===!1)throw new Error("--billing-scope requires --org to be enabled.");t.billingScope=e.billingScope}if(e.blog!==void 0&&(t.blog=e.blog),e.docs!==void 0&&(t.docs=e.docs),e.desktop!==void 0&&(t.desktop=e.desktop),e.desktopAuto!==void 0&&(t.desktopAutoRelease=e.desktopAuto),e.desktopAi!==void 0){if(e.desktopAi===!0&&e.desktop!==!0)throw new Error("--desktop-ai requires --desktop to be enabled.");t.desktopAi=e.desktopAi}if(e.revenueSharing!==void 0&&(t.revenueSharing=e.revenueSharing),e.credits!==void 0){if(e.credits===!0&&e.payment==="none")throw new Error("--credits requires a payment provider (got --payment none).");t.credits=e.credits}if(e.docker!==void 0&&(t.dockerServices=tr(e.docker,xe,"docker service")),e.aiTools!==void 0&&(t.aiTools=tr(e.aiTools,De,"AI tool")),e.socialProviders!==void 0&&(t.socialProviders=tr(e.socialProviders,Ne,"social provider")),e.currency!==void 0){if(!ie.includes(e.currency))throw new Error(`Invalid currency "${e.currency}". Valid values: ${ie.join(", ")}`);t.defaultCurrency=e.currency}if(e.deploy!==void 0){if(!se.includes(e.deploy))throw new Error(`Invalid deployment target "${e.deploy}". Valid values: ${se.join(", ")}`);t.deploymentTarget=e.deploy}if(e.database!==void 0){if(!ae.includes(e.database))throw new Error(`Invalid database provider "${e.database}". Valid values: ${ae.join(", ")}`);t.databaseProvider=e.database}if(e.cache!==void 0){if(!ce.includes(e.cache))throw new Error(`Invalid cache provider "${e.cache}". Valid values: ${ce.join(", ")}`);t.cacheProvider=e.cache}if(e.demo===!0&&(t.demo=!0),e.baseUrl!==void 0){let r=e.baseUrl.trim();if(r==="")throw new Error("--base-url cannot be empty. Provide an absolute URL like https://example.com.");let n;try{n=new URL(r)}catch{throw new Error(`Invalid --base-url "${e.baseUrl}". Must be an absolute URL like https://example.com.`)}if(n.protocol!=="http:"&&n.protocol!=="https:")throw new Error(`Invalid --base-url "${e.baseUrl}". Must use http or https.`);t.baseUrl=`${n.protocol}//${n.host}`}return t}var ge={projectName:"my-saas",frontend:"nextjs",architecture:"fullstack",paymentProvider:"stripe",emailProvider:"smtp",multiTenancy:!1,billingScope:"user",blog:!0,docs:!1,desktop:!1,desktopAutoRelease:!1,desktopAi:!1,revenueSharing:!1,credits:!0,dockerServices:["postgres","redis","inngest"],aiTools:[],socialProviders:[],defaultCurrency:"USD",deploymentTarget:"node",databaseProvider:"postgres",cacheProvider:"redis"};function Mn(e){let t=e.projectName??ge.projectName,r=e.projectDir??`./${t}`,n=e.appName??ut(t),o=e.deploymentTarget??ge.deploymentTarget,i=Q[o]?.edgeRuntime??!1,s=e.databaseProvider??(i?"neon":ge.databaseProvider),a=e.cacheProvider??(i?"upstash":ge.cacheProvider),p=e.emailProvider??(i?"resend":ge.emailProvider),f=e.dockerServices??(i?ge.dockerServices.filter(u=>u!=="postgres"&&u!=="redis"):ge.dockerServices),m={...ge,...e,projectName:t,appName:n,projectDir:r,deploymentTarget:o,databaseProvider:s,cacheProvider:a,emailProvider:p,dockerServices:f};m.paymentProvider==="none"&&(m.credits=!1);for(let u of Xe){if(m.deploymentTarget!==u.target)continue;let v=m.databaseProvider===u.provider?"database":"cache";if(m.databaseProvider===u.provider||m.cacheProvider===u.provider)throw new Error(`Incompatible: --deploy ${u.target} + --${v} ${u.provider}. ${u.reason}`)}for(let u of Ze)if(m.architecture===u.architecture&&m.deploymentTarget===u.target)throw new Error(`Incompatible: --architecture ${u.architecture} + --deploy ${u.target}. ${u.reason}`);return m}function tr(e,t,r){if(e.trim()==="")return[];let n=e.split(",").map(i=>i.trim()).filter(Boolean),o=n.filter(i=>!t.includes(i));if(o.length>0)throw new Error(`Invalid ${r}(s): ${o.join(", ")}. Valid values: ${t.join(", ")}`);return n}import Es from"picocolors";var As="a10a6fb9d7cadde32e37dad52059d17b5d2b916b08c76d8fbcc99982e9a3d87f";async function Is(e){let t=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(`generatesaas-demo:${e}`)),r=[...new Uint8Array(t).subarray(0,16)].map(n=>n.toString(16).padStart(2,"0")).join("");return`${r.slice(0,8)}-${r.slice(8,12)}-${r.slice(12,16)}-${r.slice(16,20)}-${r.slice(20,32)}`}function Ps(e){if(e===void 0)return;let t=e.trim().replace(/^v/,"");if(!/^\d+\.\d+\.\d+$/.test(t))throw new Error(`Invalid template version "${e}". Use semver like 1.2.3.`);return t}function Vn(e){e.command("init").description("Scaffold a new GenerateSaaS project").argument("[apiKey]","license key (same as --api-key)").option("-n, --name <name>","project name (lowercase, hyphens, starts with letter)").option("--app-name <name>","display name for the app").option("-l, --location <path>","project directory (default: ./{name})").addOption(new Y("--frontend <type>","frontend framework").choices([...ve])).addOption(new Y("--architecture <type>","fullstack or separate").choices([...Re])).addOption(new Y("--payment <provider>","payment provider").choices([..._e])).addOption(new Y("--email <provider>","email provider").choices([...Oe])).option("--org","enable multi-tenancy (organizations)").option("--no-org","disable multi-tenancy").addOption(new Y("--billing-scope <scope>","billing scope (requires --org)").choices([...Ce])).option("--blog","enable blog").option("--no-blog","disable blog").option("--docs","include the docs app (apps/docs, Fumadocs)").option("--no-docs","exclude the docs app").option("--desktop","include the Electron desktop app (apps/desktop)").option("--no-desktop","exclude the Electron desktop app").option("--desktop-auto","auto-trigger the desktop release workflow on CI success (default: manual-only)").option("--no-desktop-auto","manual-only desktop releases (workflow_dispatch)").option("--desktop-ai","include the desktop AI orchestration layer (requires --desktop)").option("--no-desktop-ai","exclude the desktop AI orchestration layer").option("--revenue-sharing","enable revenue sharing").option("--no-revenue-sharing","disable revenue sharing").option("--credits","enable credits system").option("--no-credits","disable credits system (subscription-only)").option("--docker <services>","comma-separated: postgres,redis,inngest,mailpit").option("--ai-tools <tools>","comma-separated: claude-code,cursor,codex,gemini-cli,windsurf").option("--social-providers <providers>","comma-separated: google,github,facebook,discord,x").addOption(new Y("--currency <code>","default currency for billing").choices([...ie])).addOption(new Y("--deploy <target>","deployment target").choices([...se])).addOption(new Y("--database <provider>","database provider").choices([...ae])).addOption(new Y("--cache <provider>","cache provider").choices([...ce])).option("--template-version <version>","specific template version to scaffold").option("--api-key <key>","API key (skips interactive prompt)").option("--base-url <url>","public base URL (e.g. https://example.com) - bakes into canonical/og/sitemap").option("-y, --yes","accept defaults for unspecified options (non-interactive)").addOption(new Y("--demo","first-party demo build: keep sample content, mark site non-indexable - requires CI API key").hideHelp()).addOption(new Y("--no-db-migration","skip generating the baseline DB migration (internal: demos/CI/playground)").hideHelp()).action(async(t,r)=>{await Ts(t?{...r,apiKey:t}:r)})}async function Ts(e){let t=performance.now();ar("1.19.2");let r,n;try{r=Un(e),n=Ps(e.templateVersion)}catch(b){E.cancel(x(b)),process.exit(1)}let o=E.spinner(),i;try{i=await Le({apiKey:e.apiKey,prompt:!e.yes})}catch(b){E.cancel(x(b)),process.exit(1)}e.demo&&Jt(i)!==As&&(E.cancel("--demo is restricted to first-party demo deployments."),process.exit(1));let s=pe(i),a=async()=>{let b=await fe(s),I=b.latest,R=n??I;if(n&&!b.versions.some(K=>K.version===R))throw new Error(`Template version "${n}" is not available.`);return{latestVersion:I,selectedVersion:R,desktopAllowed:b.entitlements?.desktopAllowed??!0}};o.start("Verifying access...");let p,f,m=!0;try{({latestVersion:p,selectedVersion:f,desktopAllowed:m}=await a()),o.stop("Access verified."),ke(i)}catch(b){if(o.stop("Access verification failed."),b instanceof $&&b.status===401){e.yes&&(E.cancel("Invalid API key. Cannot prompt in non-interactive mode."),process.exit(1)),E.log.warning("Invalid API key."),i=await tt(),s=pe(i),o.start("Verifying access...");try{({latestVersion:p,selectedVersion:f,desktopAllowed:m}=await a()),o.stop("Access verified."),ke(i)}catch(I){o.stop("Access verification failed."),E.cancel(I instanceof $&&I.status===401?"Invalid API key.":x(I)),process.exit(1)}}else E.cancel(x(b)),process.exit(1)}E.log.success(`Latest version: ${p}`),f!==p&&E.log.success(`Using template version: ${f}`),r.desktop===!0&&!m&&(E.cancel("The desktop app is available on the Pro plan and up. Upgrade your plan at generatesaas.com."),process.exit(1));let u;e.yes?u=Mn(m?r:{...r,desktop:!1}):u=await pr(r,{desktopAllowed:m});let v;o.start("Activating license...");try{let b=e.demo&&u.baseUrl?await Is(u.baseUrl):crypto.randomUUID(),I=()=>({frontend:u.frontend,version:f,installId:b,projectName:u.projectName,options:gr(u)}),R;try{R=await Lt(s,I())}catch(K){let A=ht(K);if(!A?.lastAllowedVersion)throw K;o.stop("License activation failed."),e.yes&&(E.cancel(`${A.message} Re-run with --template-version ${A.lastAllowedVersion}.`),process.exit(1));let Z=await E.confirm({message:`Your update window has ended. Continue with v${A.lastAllowedVersion} (the last version your license covers)?`});(E.isCancel(Z)||!Z)&&(E.cancel("Setup cancelled."),process.exit(0)),f=A.lastAllowedVersion,o.start(`Activating license for v${f}...`),R=await Lt(s,I())}v={token:R.token,keyHash:Jt(i),installId:R.installId??b},o.stop("License activated.")}catch(b){o.stop("License activation failed."),E.cancel(x(b)),process.exit(1)}let w=ws(u.projectDir);if(vs(w)&&bs(w).length>0)if(e.yes)E.log.info(`Directory ${w} is not empty. Merging (keeping existing files, overwriting conflicts).`);else{let I=await E.select({message:`Directory ${w} is not empty.`,options:[{value:"merge",label:"Merge",hint:"keep existing files, overwrite conflicts"},{value:"overwrite",label:"Overwrite",hint:"delete everything and start fresh"},{value:"cancel",label:"Cancel"}]});(E.isCancel(I)||I==="cancel")&&(E.cancel("Setup cancelled."),process.exit(0)),I==="overwrite"&&ks(w,{recursive:!0,force:!0})}let T={...u,projectDir:w,version:f,...e.demo?{docs:!1}:{}};o.start("Downloading template...");try{await yt(s,f,w),o.stop("Template downloaded.")}catch(b){o.stop("Download failed."),E.cancel(x(b)),process.exit(1)}let G;o.start("Generating project files...");try{if({dockerComposeGenerated:G}=await It(T),!e.demo){let b=await Ke(w);await c(Ss(w,ft),JSON.stringify(b,null," ")+`
|
|
1252
|
-
`),await
|
|
1253
|
-
`),
|
|
1254
|
-
`);let
|
|
1255
|
-
`)}if(f.stop("Baseline template stored.")
|
|
1256
|
-
`),f.stop("Baseline hashes computed.")}if(await
|
|
1257
|
-
`),N.log.info(`Update staged: ${
|
|
1258
|
-
|
|
1259
|
-
${
|
|
1260
|
-
|
|
1261
|
-
`),title:`Changelog v${
|
|
1262
|
-
`);
|
|
1263
|
-
`),
|
|
1264
|
-
`).map(
|
|
1259
|
+
export { ops } from "./${n}/index";
|
|
1260
|
+
`;await l($t(t,"providers/index.ts"),r),await l($t(t,"index.ts"),await ga(t,n))}async function ga(e,t){let n=$t(e,"index.ts");if(!ma(n))throw new Error(`generatePaymentBarrel: expected ${n} to exist - did packages/payments move?`);let r=await ua(n,"utf-8"),i=fa.filter(a=>a!==t);return r.split(`
|
|
1261
|
+
`).filter(a=>!i.some(s=>a.includes(`./providers/${s}/`))).join(`
|
|
1262
|
+
`)}import{readdir as ha,readFile as ya}from"fs/promises";import{join as Gr}from"path";async function Hr(e){if(e.demo)return;let t=e.appName.trim()||e.projectName,n=JSON.stringify(t).slice(1,-1),r=Gr(e.projectDir,"packages/i18n/translations"),i;try{i=await ha(r)}catch{return}for(let o of i){let a=Gr(r,o,"web.json"),s;try{s=await ya(a,"utf-8")}catch{continue}let p=s.replaceAll("GenerateSaaS",n);p!==s&&await l(a,p)}}import{readFile as va}from"fs/promises";import{join as zr}from"path";var ka=[".nuxt/",".nuxt",".nitro/",".nitro",".output/",".output","_locales/"],wa=[".next/",".next",".svelte-kit/",".svelte-kit",".wrangler/",".wrangler",".dev.vars"];async function qr(e){let n=e.frontend==="nuxt"?wa:ka;await Yr(zr(e.projectDir,".gitignore"),n),await Yr(zr(e.projectDir,".dockerignore"),n)}async function Yr(e,t){let n;try{n=await va(e,"utf-8")}catch{return}let r=new Set(t),i=n.split(`
|
|
1263
|
+
`).filter(o=>!r.has(o.trim()));i.length!==n.split(`
|
|
1264
|
+
`).length&&await l(e,i.join(`
|
|
1265
|
+
`))}async function jt(e){let t=e.projectDir;e.demo||(await Wn(t),await Xn(t),await Zn(t)),await Qn(t,e.aiTools),await er(t,e.frontend),await nr(e),await rr(e),await ir(e),e.demo||await or(e),await cr(e);let n=await lr(e);return await pr(e),await dr(e),await ur(e),await mr(e),await fr(e),await gr(e),await kr(e),await wr(e),await Er(e),await Ir(e),await _r(e),await Mr(e),await Or(e),await xr(e),await Cr(e),await Dr(e),await Nr(e),await Lr(e),await $r(e),await Ur(e),await ln(e),await dn(e),await mn(e),await Br(e),await Kr(e),await Hr(e),await qr(e),{dockerComposeGenerated:n}}import{basename as Wr,join as Xr,relative as Sa}from"path";import{createHash as Jr}from"crypto";import{readFile as ba}from"fs/promises";async function Ut(e){let t=await ba(e);return Jr("sha256").update(t).digest("hex")}function hn(e){return Jr("sha256").update(e).digest("hex")}var Ea=new Set(["data",q]);function Aa(e){let t=e.split("/");for(let n of t)if(Xt.has(n)||Zt.has(n)||Ea.has(n)||n.startsWith(".env")&&!n.includes("example"))return!0;return!1}function Zr(e,t){return{projectName:e.projectName??Wr(t),appName:e.appName??e.projectName??Wr(t),projectDir:t,frontend:e.frontend==="nextjs"?"nextjs":"nuxt",architecture:e.architecture??"fullstack",paymentProvider:e.paymentProvider??"none",emailProvider:e.emailProvider??"smtp",multiTenancy:e.multiTenancy??!1,billingScope:e.billingScope??"user",blog:e.blog??!1,docs:e.docs??!1,desktop:e.desktop??!1,desktopAutoRelease:e.desktopAutoRelease??!0,desktopAi:e.desktopAi??!1,ai:e.ai??!1,rag:e.rag??!1,companion:e.companion??!1,mcpServer:e.mcpServer??!1,aiByok:e.aiByok??!0,revenueSharing:e.revenueSharing??!1,credits:e.credits??!1,dockerServices:e.dockerServices??[],aiTools:e.aiTools??[],socialProviders:e.socialProviders??[],defaultCurrency:e.defaultCurrency??"USD",deploymentTarget:e.deploymentTarget??"node",databaseProvider:e.databaseProvider??"postgres",cacheProvider:e.cacheProvider??"redis",version:e.version,baseUrl:e.baseUrl,credentials:{},demo:!1}}function Ia(e,t){return{version:e.version,initialVersion:e.version,repo:"Duzbee/GenerateSaaS",appName:e.appName,projectName:e.projectName,frontend:e.frontend,architecture:e.architecture,paymentProvider:e.paymentProvider,emailProvider:e.emailProvider,multiTenancy:e.multiTenancy,billingScope:e.billingScope,blog:e.blog,docs:e.docs,desktop:e.desktop,desktopAutoRelease:e.desktopAutoRelease,desktopAi:e.desktopAi,ai:e.ai,rag:e.rag,companion:e.companion,mcpServer:e.mcpServer,aiByok:e.aiByok,credits:e.credits,revenueSharing:e.revenueSharing,defaultCurrency:e.defaultCurrency,dockerServices:e.dockerServices,socialProviders:e.socialProviders,deploymentTarget:e.deploymentTarget,databaseProvider:e.databaseProvider,cacheProvider:e.cacheProvider,aiTools:e.aiTools,...e.baseUrl?{baseUrl:e.baseUrl}:{},...t&&{licenseToken:t.token,licenseKeyHash:t.keyHash,installId:t.installId}}}async function Qr(e,t){let r=(await Re(e.projectDir,e.projectDir,Aa)).sort(),i=await Promise.all(r.map(async s=>[Pe(Sa(e.projectDir,s)),await Ut(s)])),o=Object.fromEntries(i),a=Ia(e,t);await l(Xr(e.projectDir,he),JSON.stringify(a,null," ")+`
|
|
1266
|
+
`),await l(Xr(e.projectDir,Mn),JSON.stringify(o,null," ")+`
|
|
1267
|
+
`)}import{relative as Pa}from"path";async function We(e){let n=(await Re(e,e,Be)).sort(),r=await Promise.all(n.map(async i=>[Pe(Pa(e,i)),await Ut(i)]));return Object.fromEntries(r)}import{copyFile as Ra,mkdir as Ta,rm as _a}from"fs/promises";import{dirname as Oa,join as ei,relative as xa}from"path";import{existsSync as Ca}from"fs";async function yn(e,t){Ca(t)&&await _a(t,{recursive:!0,force:!0});let n=await Re(e,e,Be);for(let r of n){let i=Pe(xa(e,r)),o=ei(t,i);await Ta(Oa(o),{recursive:!0}),await Ra(r,o)}}async function ti(e,t){await yn(e,ei(t,St))}import{existsSync as Da}from"fs";import{readFile as ni,readdir as Na}from"fs/promises";import{join as oe,dirname as La,resolve as $a,sep as ja}from"path";import{fileURLToPath as Ua}from"url";var pt={"claude-code":".claude/skills",cursor:".cursor/skills",codex:".agents/skills","gemini-cli":".gemini/skills",windsurf:".windsurf/skills"},Id=Object.values(pt),vn="generatesaas-update",ri=La(Ua(import.meta.url));function Ma(){let e=oe(ri,"skill","content");return Da(e)?e:oe(ri,"content")}function kn(e){return!e||e.length===0?[]:e.map(t=>pt[t])}async function wn(e,t,n,r){let i=kn(r);for(let o of i){let a=oe(e,o,vn),s=oe(a,"scripts"),p=oe(a,"references");await Pt(s),await Pt(p),await l(oe(a,"SKILL.md"),t.replaceAll("__SKILL_ROOT__",o)),await l(oe(p,".gitkeep"),"");for(let[f,m]of Object.entries(n)){let d=$a(s,f);d.startsWith(s+ja)&&await l(d,m)}}}async function ii(e,t){let n=Ma(),r=await ni(oe(n,"SKILL.md"),"utf-8"),i=oe(n,"scripts"),o=await Na(i),a={};for(let s of o)s!==".gitkeep"&&(a[s]=await ni(oe(i,s),"utf-8"));await wn(e,r,a,t)}import{execFile as Va,execFileSync as Fa}from"child_process";import{access as oi,readFile as Ba}from"fs/promises";import{join as bn}from"path";import*as D from"@clack/prompts";function Oe(e){try{let t=process.platform==="win32"?"where":"which";return Fa(t,[e],{stdio:"ignore"}),!0}catch{return!1}}function _e(e,t,n,r=3e5){return new Promise((i,o)=>{Va(e,t,{cwd:n,timeout:r,maxBuffer:50*1024*1024},(a,s,p)=>{if(a){let f=String(s||"").trim(),d=[String(p||"").trim(),f].filter(Boolean).join(`
|
|
1268
|
+
`);o(new Error(d?`${a.message}
|
|
1269
|
+
${d}`:a.message))}else i()})})}async function ai(e){if(!Oe("pnpm"))return D.log.warn("pnpm not found. Skipping lockfile regeneration."),!1;try{return await _e("pnpm",["install","--lockfile-only","--no-frozen-lockfile","--config.minimumReleaseAge=0"],e),!0}catch(t){let n=t instanceof Error?t.message:String(t);return D.log.warn(`Lockfile regeneration failed: ${n}`),D.log.warn("Deploys using --frozen-lockfile may fail."),!1}}async function si(e){if(!Oe("pnpm"))return D.log.warn("pnpm not found. Skipping dependency installation."),D.log.info("Install pnpm: https://pnpm.io/installation"),!1;let t=D.spinner();t.start("Installing dependencies (this may take a minute)...");try{return await _e("pnpm",["install","--config.minimumReleaseAge=0"],e),t.stop("Dependencies installed."),!0}catch(n){t.stop("Dependency installation failed.");let r=n instanceof Error?n.message:String(n);return D.log.warn(`pnpm install failed: ${r}`),D.log.warn("You can run it manually later."),!1}}async function ci(e){if(!Oe("pnpm"))return!1;let t=D.spinner();t.start("Generating baseline database migration...");try{return await _e("pnpm",["-F","@repo/database","generate"],e),t.stop("Baseline migration generated."),!0}catch(n){t.stop("Baseline migration generation failed.");let r=n instanceof Error?n.message:String(n);return D.log.warn(`Could not generate baseline migration: ${r}`),D.log.warn("Run 'pnpm -F @repo/database generate' before your first deploy."),!1}}async function li(e){try{return await oi(bn(e,".git")),D.log.info("Git repository already exists, skipping init."),!0}catch{}if(!Oe("git"))return D.log.warn("git not found. Skipping repository initialization."),!1;let t=D.spinner();t.start("Initializing git repository...");try{return await _e("git",["init"],e),await _e("git",["add","-A"],e),await _e("git",["commit","--no-verify","-m","Initial commit from GenerateSaaS"],e),t.stop("Git repository initialized."),!0}catch{return t.stop("Git initialization failed."),D.log.warn("You can run git init manually later."),!1}}async function pi(e){if(!Oe("pnpm"))return!1;try{await oi(bn(e,".git"))}catch{return!1}try{let t=JSON.parse(await Ba(bn(e,"package.json"),"utf-8")),n=!!t.devDependencies?.["simple-git-hooks"],r=!!t["simple-git-hooks"];if(!n||!r)return!1}catch{return!1}try{return await _e("pnpm",["exec","simple-git-hooks"],e),!0}catch{return D.log.warn("Could not install git hooks. Run 'pnpm exec simple-git-hooks' manually."),!1}}import*as Xe from"@clack/prompts";import Z from"picocolors";function di(e,t){t.dockerComposeGenerated&&!t.dockerAvailable&&Xe.log.warn("Docker not found. Install Docker to run local services: https://docs.docker.com/get-docker/");let n=[];if(n.push(`cd ${e.projectDir}`),t.pnpmInstalled||n.push("pnpm install"),t.dockerComposeGenerated){let o=e.dockerServices.map(a=>De[a].label).join(", ");n.push(`pnpm infra ${Z.dim(`# ${o}`)}`)}if(n.push(`pnpm dev ${Z.dim("# http://localhost:3000")}`),t.skippedCredentials.length>0&&(n.push(""),n.push(Z.dim("Fill in remaining TODO values in .env"))),Xe.note(n.join(`
|
|
1270
|
+
`),Z.yellow("Start Development")),t.dockerComposeGenerated){let o=[];o.push(`App ${Z.cyan("http://localhost:3000")}`),e.architecture==="separate"&&o.push(`API ${Z.cyan("http://localhost:3010")}`),e.dockerServices.includes("mailpit")&&o.push(`Mailpit ${Z.cyan("http://localhost:8025")}`),e.dockerServices.includes("inngest")&&o.push(`Inngest ${Z.cyan("http://localhost:8288")}`),Xe.note(o.join(`
|
|
1271
|
+
`),Z.yellow("Dev Tools"))}let r=[],i=Ka(e);i.length>0&&r.push(`Set in production: ${Z.dim(i.join(", "))}`),r.push("pnpm db:setup # Enable pgvector + apply the database schema"),r.push(Ga(e)),Xe.note(r.join(`
|
|
1272
|
+
`),Z.yellow("Deployment"))}function Ka(e){let t=["DATABASE_URL","BETTER_AUTH_SECRET"];return e.cacheProvider==="upstash"?t.push("UPSTASH_REDIS_REST_URL","UPSTASH_REDIS_REST_TOKEN"):t.push("REDIS_URL"),e.paymentProvider==="stripe"?t.push("STRIPE_SECRET_KEY","STRIPE_WEBHOOK_SECRET"):e.paymentProvider==="polar"&&t.push("POLAR_ACCESS_TOKEN","POLAR_WEBHOOK_SECRET"),e.emailProvider==="ses"?t.push("AMAZON_SES_REGION","AMAZON_SES_KEY","AMAZON_SES_SECRET"):e.emailProvider==="resend"?t.push("RESEND_API_KEY"):t.push("SMTP_HOST","SMTP_PORT"),t}function Ga(e){switch(e.deploymentTarget){case"node":return"Deploy with Docker or your preferred Node.js host";case"vercel":return"vercel deploy # Deploy to Vercel"}}import Wa from"picocolors";var Xa="a10a6fb9d7cadde32e37dad52059d17b5d2b916b08c76d8fbcc99982e9a3d87f";async function Za(e){let t=await crypto.subtle.digest("SHA-256",new TextEncoder().encode(`generatesaas-demo:${e}`)),n=[...new Uint8Array(t).subarray(0,16)].map(r=>r.toString(16).padStart(2,"0")).join("");return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20,32)}`}function Qa(e){if(e===void 0)return;let t=e.trim().replace(/^v/,"");if(!/^\d+\.\d+\.\d+$/.test(t))throw new Error(`Invalid template version "${e}". Use semver like 1.2.3.`);return t}function ui(e){e.command("init").description("Scaffold a new GenerateSaaS project").argument("[apiKey]","license key (same as --api-key)").option("-n, --name <name>","project name (lowercase, hyphens, starts with letter)").option("--app-name <name>","display name for the app").option("-l, --location <path>","project directory (default: ./{name})").addOption(new Q("--frontend <type>","frontend framework").choices([...Ee])).addOption(new Q("--architecture <type>","fullstack or separate").choices([...Ne])).addOption(new Q("--payment <provider>","payment provider").choices([...Le])).addOption(new Q("--email <provider>","email provider").choices([...$e])).option("--org","enable multi-tenancy (organizations)").option("--no-org","disable multi-tenancy").addOption(new Q("--billing-scope <scope>","billing scope (requires --org)").choices([...Me])).option("--blog","enable blog").option("--no-blog","disable blog").option("--docs","include the docs app (apps/docs, Fumadocs)").option("--no-docs","exclude the docs app").option("--desktop","include the Electron desktop app (apps/desktop)").option("--no-desktop","exclude the Electron desktop app").option("--desktop-auto","auto-trigger the desktop release workflow on CI success (default: manual-only)").option("--no-desktop-auto","manual-only desktop releases (workflow_dispatch)").option("--desktop-ai","include the desktop AI orchestration layer (requires --desktop)").option("--no-desktop-ai","exclude the desktop AI orchestration layer").option("--ai","include the AI features (chat, models, schedules, integrations); unlocks the companion + MCP server").option("--no-ai","exclude the AI features").option("--rag","include server-side RAG knowledge (pgvector embeddings + semantic search)").option("--no-rag","exclude server-side RAG knowledge").option("--companion","include the companion daemon (apps/companion) + its HTTP transport").option("--no-companion","exclude the companion daemon").option("--mcp-server","include the outward MCP server (the /mcp route + Better Auth mcp() provider)").option("--no-mcp-server","exclude the outward MCP server").option("--ai-byok","AI BYOK mode: end-users bring their own provider key (default)").option("--no-ai-byok","operator-keyed, credit-metered AI platform mode").option("--revenue-sharing","enable revenue sharing").option("--no-revenue-sharing","disable revenue sharing").option("--credits","enable credits system").option("--no-credits","disable credits system (subscription-only)").option("--docker <services>","comma-separated: postgres,redis,inngest,mailpit").option("--ai-tools <tools>","comma-separated: claude-code,cursor,codex,gemini-cli,windsurf").option("--social-providers <providers>","comma-separated: google,github,facebook,discord,x").addOption(new Q("--currency <code>","default currency for billing").choices([...ce])).addOption(new Q("--deploy <target>","deployment target").choices([...le])).addOption(new Q("--database <provider>","database provider").choices([...pe])).addOption(new Q("--cache <provider>","cache provider").choices([...de])).option("--template-version <version>","specific template version to scaffold").option("--api-key <key>","API key (skips interactive prompt)").option("--base-url <url>","public base URL (e.g. https://example.com) - bakes into canonical/og/sitemap").option("-y, --yes","accept defaults for unspecified options (non-interactive)").addOption(new Q("--demo","first-party demo build: keep sample content, mark site non-indexable - requires CI API key").hideHelp()).addOption(new Q("--no-db-migration","skip generating the baseline DB migration (internal: demos/CI/playground)").hideHelp()).action(async(t,n)=>{await es(t?{...n,apiKey:t}:n)})}async function es(e){let t=performance.now();xn("1.20.1");let n,r;try{n=$n(e),r=Qa(e.templateVersion)}catch(k){A.cancel(C(k)),process.exit(1)}let i=A.spinner(),o;try{o=await Fe({apiKey:e.apiKey,prompt:!e.yes})}catch(k){A.cancel(C(k)),process.exit(1)}e.demo&&hn(o)!==Xa&&(A.cancel("--demo is restricted to first-party demo deployments."),process.exit(1));let a=fe(o),s=async()=>{let k=await ke(a),T=k.latest,P=r??T;if(r&&!k.versions.some(ae=>ae.version===P))throw new Error(`Template version "${r}" is not available.`);return{latestVersion:T,selectedVersion:P,desktopAllowed:k.entitlements?.desktopAllowed??!0}};i.start("Verifying access...");let p,f,m=!0;try{({latestVersion:p,selectedVersion:f,desktopAllowed:m}=await s()),i.stop("Access verified."),Ie(o)}catch(k){if(i.stop("Access verification failed."),k instanceof U&&k.status===401){e.yes&&(A.cancel("Invalid API key. Cannot prompt in non-interactive mode."),process.exit(1)),A.log.warning("Invalid API key."),o=await st(),a=fe(o),i.start("Verifying access...");try{({latestVersion:p,selectedVersion:f,desktopAllowed:m}=await s()),i.stop("Access verified."),Ie(o)}catch(T){i.stop("Access verification failed."),A.cancel(T instanceof U&&T.status===401?"Invalid API key.":C(T)),process.exit(1)}}else A.cancel(C(k)),process.exit(1)}A.log.success(`Latest version: ${p}`),f!==p&&A.log.success(`Using template version: ${f}`),n.desktop===!0&&!m&&(A.cancel("The desktop app is available on the Pro plan and up. Upgrade your plan at generatesaas.com."),process.exit(1));let d;e.yes?d=jn(m?n:{...n,desktop:!1}):d=await Un(n,{desktopAllowed:m});let v;i.start("Activating license...");try{let k=e.demo&&d.baseUrl?await Za(d.baseUrl):crypto.randomUUID(),T=()=>({frontend:d.frontend,version:f,installId:k,projectName:d.projectName,options:Kn(d)}),P;try{P=await Jt(a,T())}catch(ae){let $=Et(ae);if(!$?.lastAllowedVersion)throw ae;i.stop("License activation failed."),e.yes&&(A.cancel(`${$.message} Re-run with --template-version ${$.lastAllowedVersion}.`),process.exit(1));let R=await A.confirm({message:`Your update window has ended. Continue with v${$.lastAllowedVersion} (the last version your license covers)?`});(A.isCancel(R)||!R)&&(A.cancel("Setup cancelled."),process.exit(0)),f=$.lastAllowedVersion,i.start(`Activating license for v${f}...`),P=await Jt(a,T())}v={token:P.token,keyHash:hn(o),installId:P.installId??k},i.stop("License activated.")}catch(k){i.stop("License activation failed."),A.cancel(C(k)),process.exit(1)}let b=Ja(d.projectDir);if(Ha(b)&&za(b).length>0)if(e.yes)A.log.info(`Directory ${b} is not empty. Merging (keeping existing files, overwriting conflicts).`);else{let T=await A.select({message:`Directory ${b} is not empty.`,options:[{value:"merge",label:"Merge",hint:"keep existing files, overwrite conflicts"},{value:"overwrite",label:"Overwrite",hint:"delete everything and start fresh"},{value:"cancel",label:"Cancel"}]});(A.isCancel(T)||T==="cancel")&&(A.cancel("Setup cancelled."),process.exit(0)),T==="overwrite"&&Ya(b,{recursive:!0,force:!0})}let I={...d,projectDir:b,version:f,...e.demo?{docs:!1}:{}};i.start("Downloading template...");try{await At(a,f,b),i.stop("Template downloaded.")}catch(k){i.stop("Download failed."),A.cancel(C(k)),process.exit(1)}let z;i.start("Generating project files...");try{if({dockerComposeGenerated:z}=await jt(I),!e.demo){let k=await We(b);await l(qa(b,bt),JSON.stringify(k,null," ")+`
|
|
1273
|
+
`),await ti(b,b)}await ii(b,I.aiTools),await Qr(I,v),i.stop("Project files generated.")}catch(k){i.stop("Generation failed."),A.cancel(C(k)),process.exit(1)}await ai(b);let L=await si(b);L&&I.demo!==!0&&e.dbMigration!==!1&&await ci(b),await li(b),L&&await pi(b);let K=Oe("docker"),Y=Yt(I).map(k=>k.key).filter(k=>!I.credentials?.[k]);di(I,{pnpmInstalled:L,dockerComposeGenerated:z,dockerAvailable:K,skippedCredentials:Y}),Cn(),A.log.info(Wa.dim(`Done in ${((performance.now()-t)/1e3).toFixed(1)}s`))}import{existsSync as yi}from"fs";import{readFile as vi}from"fs/promises";import{join as dt,resolve as as}from"path";import*as N from"@clack/prompts";import Ze from"picocolors";import{mkdtemp as ts,rm as ns}from"fs/promises";import{tmpdir as rs}from"os";import{join as is}from"path";async function Sn(e,t,n,r){let i=await ts(is(rs(),"generatesaas-stage-"));try{await At(e,t,i),await jt({...n,projectDir:i}),await yn(i,r)}finally{await ns(i,{recursive:!0,force:!0})}}var mi=[{key:"frontend",label:"Frontend framework",hint:"Nuxt (Vue) or Next.js (React).",category:"Project",kind:"enum",default:"nuxt",choices:Ee,adoptable:!1,impact:"structural"},{key:"architecture",label:"Architecture",hint:"Fullstack (frontend hosts the API) or a standalone Hono backend.",category:"Infrastructure",kind:"enum",default:"fullstack",choices:Ne,adoptable:!1,impact:"structural"},{key:"deploymentTarget",label:"Deployment target",hint:"Node.js / Docker or Vercel serverless.",category:"Infrastructure",kind:"enum",default:"node",choices:le,adoptable:!1,impact:"config"},{key:"databaseProvider",label:"Database provider",hint:"Self-hosted PostgreSQL, Neon, or Supabase.",category:"Infrastructure",kind:"enum",default:"postgres",choices:pe,adoptable:!1,impact:"config"},{key:"cacheProvider",label:"Cache provider",hint:"Self-hosted Redis or Upstash.",category:"Infrastructure",kind:"enum",default:"redis",choices:de,adoptable:!1,impact:"config"},{key:"paymentProvider",label:"Payment provider",hint:"Stripe, Polar, or none.",category:"Features",kind:"enum",default:"none",choices:Le,adoptable:!1,impact:"structural"},{key:"defaultCurrency",label:"Default currency",hint:"Billing and pricing currency.",category:"Features",kind:"enum",default:"USD",choices:ce,adoptable:!1,impact:"config"},{key:"emailProvider",label:"Email provider",hint:"SMTP, Amazon SES, or Resend.",category:"Features",kind:"enum",default:"smtp",choices:$e,adoptable:!1,impact:"config"},{key:"multiTenancy",label:"Multi-tenancy (organizations)",hint:"Adds organizations - teams, members, and shared resources.",category:"Features",kind:"boolean",default:!1,adoptable:!0,impact:"structural"},{key:"billingScope",label:"Billing scope",hint:"Whether subscriptions belong to a user or an organization.",category:"Features",kind:"enum",default:"user",choices:Me,adoptable:!1,impact:"config",requires:e=>e.multiTenancy===!0,requiresLabel:"requires multi-tenancy"},{key:"blog",label:"Blog",hint:"Adds the marketing blog (content collection, list and post pages).",category:"Features",kind:"boolean",default:!1,adoptable:!0,impact:"structural"},{key:"docs",label:"Docs app",hint:"Adds the self-hosted Fumadocs documentation site (apps/docs).",category:"Features",kind:"boolean",default:!1,adoptable:!0,impact:"structural"},{key:"desktop",label:"Desktop app",hint:"Adds the cross-platform Electron desktop app (apps/desktop).",category:"Features",kind:"boolean",default:!1,adoptable:!0,impact:"structural"},{key:"desktopAutoRelease",label:"Desktop auto-release",hint:"Release the desktop app on every CI success (vs manual-only).",category:"Features",kind:"boolean",default:!0,adoptable:!1,impact:"config",requires:e=>e.desktop===!0,requiresLabel:"requires the desktop app"},{key:"desktopAi",label:"Desktop AI orchestration",hint:"Adds the desktop AI agents layer (requires the desktop app).",category:"Features",kind:"boolean",default:!1,adoptable:!0,impact:"structural",requires:e=>e.desktop===!0,requiresLabel:"requires the desktop app"},{key:"ai",label:"AI features",hint:"Adds the AI surface (chat, models, schedules, integrations) and unlocks the companion, MCP server, RAG, and BYOK options. Off keeps config.ai.enabled false so the AI nav stays hidden.",category:"Features",kind:"boolean",default:!1,adoptable:!0,impact:"config"},{key:"rag",label:"Server-side RAG (knowledge)",hint:"Adds pgvector knowledge with embeddings + semantic search.",category:"Features",kind:"boolean",default:!1,adoptable:!0,impact:"config",requires:e=>e.ai===!0,requiresLabel:"requires AI features"},{key:"companion",label:"Companion daemon",hint:"Adds the terminal companion (apps/companion) that drives the user's subscription CLIs over stateless HTTP. Works on any deployment.",category:"Features",kind:"boolean",default:!1,adoptable:!0,impact:"structural",requires:e=>e.ai===!0,requiresLabel:"requires AI features"},{key:"mcpServer",label:"Outward MCP server",hint:"Exposes the app's capability layer to external agents as an authenticated MCP OAuth server.",category:"Features",kind:"boolean",default:!1,adoptable:!0,impact:"structural",requires:e=>e.ai===!0,requiresLabel:"requires AI features"},{key:"aiByok",label:"AI billing mode (BYOK)",hint:"BYOK: end-users bring their own provider key, no credit metering. Off: operator-keyed, credit-metered platform mode.",category:"Features",kind:"boolean",default:!0,adoptable:!1,impact:"config",requires:e=>e.ai===!0,requiresLabel:"requires AI features"},{key:"credits",label:"Metered credits",hint:"Adds metered usage credits on top of subscription plans.",category:"Features",kind:"boolean",default:!1,adoptable:!0,impact:"config",requires:e=>e.paymentProvider!==void 0&&e.paymentProvider!=="none",requiresLabel:"requires a payment provider"},{key:"revenueSharing",label:"Revenue sharing",hint:"Opt-in MRR leaderboard with dofollow backlinks.",category:"Features",kind:"boolean",default:!1,adoptable:!0,impact:"config"},{key:"socialProviders",label:"Social login providers",hint:"Which social sign-in buttons the auth screen shows.",category:"Features",kind:"multiselect",default:[],choices:Ve,adoptable:!1,impact:"config"},{key:"dockerServices",label:"Docker services",hint:"Local services scaffolded in docker-compose.",category:"Tooling",kind:"multiselect",default:[],choices:je,adoptable:!1,impact:"config"},{key:"aiTools",label:"AI coding tools",hint:"Which AI assistants receive the bundled skill files.",category:"Tooling",kind:"multiselect",default:[],choices:Ue,adoptable:!1,impact:"config"}];function os(e,t){return e[t]!==void 0}function fi(e){return mi.filter(t=>t.adoptable&&!os(e,t.key)&&(t.requires?t.requires(e):!0)).map(t=>({key:t.key,label:t.label,hint:t.hint,kind:t.kind,default:t.default,...t.choices?{choices:t.choices}:{},impact:t.impact,...t.requiresLabel?{requiresLabel:t.requiresLabel}:{}}))}function gi(e){let t={};for(let n of mi)t[n.key]=Array.isArray(n.default)?[...n.default]:n.default;return{...t,...e}}function hi(e){let n=(e.startsWith("v")?e.slice(1):e).match(/^(\d+)\.(\d+)\.(\d+)$/);return n?[Number(n[1]),Number(n[2]),Number(n[3])]:null}function Mt(e,t){let n=hi(e),r=hi(t);if(!n||!r)return 0;for(let i=0;i<3;i++)if(n[i]!==r[i])return n[i]-r[i];return 0}function ki(e){e.command("update").description("Update AI skill files and stage template updates").argument("[mode]","pass 'auto' to mark the staged update for unattended apply by your AI assistant").option("--cwd <path>","project directory (default: current directory)").action(async(t,n)=>{let r=t==="auto"?"auto":void 0,i=as(n.cwd??process.cwd()),o=dt(i,he),a;try{a=JSON.parse(await vi(o,"utf-8"))}catch{N.cancel(".generatesaas/manifest.json not found. Run this from a GenerateSaaS project."),process.exit(1)}let s;try{s=await Fe()}catch(m){N.cancel(C(m)),process.exit(1)}let p=fe(s),f=N.spinner();try{f.start("Verifying access...");let m;try{m=await ke(p)}catch(R){throw R instanceof U&&R.status===401?new Error("Your saved API key was rejected. Run `generatesaas auth` to update it, or set GENERATESAAS_API_KEY."):R}f.stop("Access verified."),Ie(s),f.start("Fetching latest skill files...");let d=await Bn(p,m.latest);await wn(i,d.skillMd,d.scripts,a.aiTools);let v=kn(a.aiTools);if(f.stop("Skills updated."),N.log.success(`Skill files installed to ${Ze.cyan(v.length.toString())} locations.`),a.version===m.latest){N.log.info(`Already on the latest version (${a.version}).`);return}let b=JSON.stringify(a);Ln(a);let I=fi(a),z=gi(a),L=JSON.stringify(z)!==b;if(a=z,a.licenseToken)try{let R=await Gn(p,{currentToken:a.licenseToken,newVersion:m.latest});a.licenseToken=R.token,R.licenseKeyHash&&(a.licenseKeyHash=R.licenseKeyHash),await l(o,JSON.stringify(a,null," ")+`
|
|
1274
|
+
`),L=!1,N.log.success("License refreshed.")}catch(R){let we=Et(R);we&&(N.cancel(we.message),process.exit(1)),N.log.warn("License refresh skipped.")}L&&await l(o,JSON.stringify(a,null," ")+`
|
|
1275
|
+
`);let K=Zr(a,i),ge=dt(i,Vn);f.start(`Staging v${m.latest} (shaped for your config)...`),await Sn(p,m.latest,K,ge),f.stop("Template staged.");let{text:Y,title:k}=await ss(p,m,a.version);Y&&N.note(Y,k);let T=dt(i,bt),P=dt(i,St),ae=!yi(P),$=!yi(T);if(ae){if(f.start("Building baseline template (one-time migration)..."),await Sn(p,a.version,K,P),$){let R=await We(P);await l(T,JSON.stringify(R,null," ")+`
|
|
1276
|
+
`)}if(f.stop("Baseline template stored."),!$){let R=await cs(T,P);R>0&&N.log.warn(`Rebuilt baseline differs from the original for ${R} file(s) (the CLI's shaping evolved since this project was scaffolded). Classification still follows the committed template-hashes.json; upstream diffs for those files may include unrelated noise.`)}}else if($){f.start("Computing baseline template hashes...");let R=await We(P);await l(T,JSON.stringify(R,null," ")+`
|
|
1277
|
+
`),f.stop("Baseline hashes computed.")}if(await l(dt(i,Fn),JSON.stringify({currentVersion:a.version,targetVersion:m.latest,changelog:Y,stagedAt:new Date().toISOString(),...I.length>0?{newOptions:I}:{},...r?{mode:r}:{}},null," ")+`
|
|
1278
|
+
`),N.log.info(`Update staged: ${Ze.cyan(a.version)} \u2192 ${Ze.cyan(m.latest)}`),a.aiTools&&a.aiTools.length>0){let R=a.aiTools[0],we=nt[R].label;N.log.info(`Open your project in ${Ze.cyan(we)} and ask: ${Ze.cyan("'update my GenerateSaaS project'")}`)}else N.log.info(`Ask your AI coding assistant to ${Ze.cyan("'update my GenerateSaaS project'")}.`)}catch(m){f.stop("Failed."),N.cancel(`Update failed: ${C(m)}`),process.exit(1)}})}async function ss(e,t,n){let r=t.latest,i=t.versions.filter(a=>Mt(a.version,n)>0&&Mt(a.version,r)<=0).sort((a,s)=>Mt(a.version,s.version));if(i.length<=1)return{text:await qt(e,r),title:`Changelog v${r}`};let o=[];for(let a of i){let s=null;try{s=await qt(e,a.version)}catch{s=null}let p=a.date?` (${a.date.slice(0,10)})`:"",f=a.breaking?" [BREAKING]":"";o.push(`# v${a.version}${p}${f}
|
|
1279
|
+
|
|
1280
|
+
${s??"_No changelog available for this release._"}`)}return{text:o.join(`
|
|
1281
|
+
|
|
1282
|
+
`),title:`Changelog v${n} \u2192 v${r}`}}async function cs(e,t){let n=JSON.parse(await vi(e,"utf-8")),r=await We(t),i=0;for(let[o,a]of Object.entries(n))Be(o)||r[o]!==a&&i++;for(let o of Object.keys(r))o in n||i++;return i}import*as H from"@clack/prompts";import ee from"picocolors";import{readFile as ls}from"fs/promises";import{join as ps,resolve as ds}from"path";function wi(e){e.command("status").description("Show project status and check for updates").option("--cwd <path>","project directory (default: current directory)").action(async t=>{let n=ds(t.cwd??process.cwd()),r=ps(n,he),i;try{i=JSON.parse(await ls(r,"utf-8"))}catch{H.cancel(".generatesaas/manifest.json not found. Run this from a GenerateSaaS project."),process.exit(1)}let o=[`Version: ${ee.cyan(i.version)}`,`Frontend: ${ee.cyan(i.frontend)}`,i.deploymentTarget?`Deploy target: ${ee.cyan(i.deploymentTarget)}`:null,i.databaseProvider?`Database: ${ee.cyan(i.databaseProvider)}`:null,i.cacheProvider?`Cache: ${ee.cyan(i.cacheProvider)}`:null,i.aiTools&&i.aiTools.length>0?`AI tools: ${ee.cyan(i.aiTools.join(", "))}`:null].filter(Boolean).join(`
|
|
1283
|
+
`);H.note(o,ee.bold("Project Status"));let a=H.spinner();a.start("Checking for updates...");try{let s=await Fe(),p=fe(s),m=(await ke(p)).latest;i.version===m?(a.stop("Up to date."),H.log.success(`Already on the latest version (${ee.green(m)})`)):(a.stop("Update available."),H.log.warning(`Update available: ${ee.yellow(i.version)} \u2192 ${ee.green(m)}`),H.log.info(`Open this project in your AI coding agent and ask it to ${ee.cyan("update my GenerateSaaS project")} - it fetches and applies the update for you.`))}catch(s){a.stop("Check failed."),s instanceof U&&s.status===401?H.log.warning("Invalid API key. Run `generatesaas auth` to update it, or set GENERATESAAS_API_KEY."):H.log.warning(`Could not check for updates: ${C(s)}`)}})}import{readFile as us}from"fs/promises";import*as x from"@clack/prompts";import O from"picocolors";function ms(){return process.env.GENERATESAAS_API_KEY??at()}function fs(e){return{verdict:e.verdict,plan:e.license?.plan??e.domainInstalls.find(t=>t.ownerPlan)?.ownerPlan??null,mismatchDomain:e.install?.domain??null,ejectedAt:e.install?.ejectedAt??e.domainInstalls.find(t=>t.ejectedAt)?.ejectedAt??null}}function gs(e){return{verdict:e.verdict??"unknown",ejectedAt:e.ejectedAt??null}}function hs(e){switch(e.verdict){case"licensed":return x.log.success(`${O.green("LICENSED")} - resolves to an account with an active${e.plan?` ${e.plan}`:""} license.`),!0;case"ejected":return x.log.success(`${O.green("EJECTED")} - a licensed buyer opted this install out of telemetry${e.ejectedAt?` on ${e.ejectedAt.slice(0,10)}`:""}. The site is legitimate.`),!0;case"revoked":return x.log.error(`${O.red("REVOKED")} - the owning account no longer holds a plan (refund or chargeback). This deployment is no longer licensed.`),!1;case"token_domain_mismatch":return x.log.error(`${O.red("LEAKED TOKEN")} - this license belongs to a different deployment${e.mismatchDomain?` (${O.cyan(e.mismatchDomain)})`:""}, not this site. The token was copied from a licensed project.`),!1;case"no_license_history":return x.log.error(`${O.red("NO LICENSE HISTORY")} - no license has ever been associated with this site. If it runs GenerateSaaS, treat it as unlicensed.`),!1;default:return x.log.warn(`${O.yellow("UNKNOWN")} - could not cross-reference the records right now. Try again shortly.`),!1}}async function bi(e,t){let n=process.env.GENERATESAAS_API_URL??ot,r=ms();e.start("Cross-referencing license records...");try{let i=r?fs(await Hn(n,r,{lkh:t.lkh,nid:t.nid,domain:t.domain})):gs(await Wt(n,{token:t.token,domain:t.domain}));return e.stop(`${O.green("Checked")} - records cross-referenced`),hs(i)}catch(i){return e.stop(`${O.yellow("Skipped")} - ${C(i)}`),null}}function ys(e){let t=e.split(".");if(t.length!==3||!t[1])throw new Error("Invalid JWT format");let n=Buffer.from(t[1],"base64url").toString("utf-8");return JSON.parse(n)}function En(e){return typeof e!="number"?"unknown":new Date(e*1e3).toISOString().split("T")[0]}function Si(e){x.note([`License ID: ${O.cyan(String(e.lid??"unknown"))}`,`Version: ${O.cyan(String(e.ver??"unknown"))}`,`Init version: ${String(e.iver??"unknown")}`,`Frontend: ${String(e.fe??"unknown")}`,`Created: ${En(e.pat)}`,`Last updated: ${En(e.uat)}`,`Expires: ${En(e.exp)}`,`Install ID: ${String(e.nid??"unknown")}`].join(`
|
|
1284
|
+
`),O.yellow("License Details"))}function vs(e){let n=(/^https?:\/\//i.test(e)?e:`https://${e}`).replace(/\/+$/,"");if(n.endsWith("/api"))return[`${n}/license`];try{if(new URL(n).pathname!=="/")return[`${n}/license`]}catch{return[`${n}/license`]}return[`${n}/api/license`,`${n}/license`]}async function Ei(e){let t=x.spinner(),n=null,r="no candidates";for(let a of vs(e)){t.start(`Checking ${a}...`);try{let s=await fetch(a);if(!s.ok){r=`${a} returned ${s.status}`,t.stop(`${O.yellow("Not here")} - ${r}`);continue}let p=(await s.text()).trim();if(!p||p.split(".").length!==3){r=`${a} did not return a JWT`,t.stop(`${O.yellow("Not here")} - ${r}`);continue}n=p,t.stop(`${O.green("Found")} - license endpoint responded`);break}catch(s){r=`${a}: ${C(s)}`,t.stop(`${O.yellow("Unreachable")} - ${r}`)}}if(n===null){x.log.warn(`No license endpoint found (last: ${r}). The site may be ejected, not a GenerateSaaS app, or serving its API elsewhere.`);let a=Ai(e);return a?await bi(t,{domain:a})??!1:!1}let i;try{i=ys(n)}catch{return x.log.error("Could not decode JWT payload."),!1}t.start("Verifying signature...");try{let a=process.env.GENERATESAAS_API_URL??ot,s=await Wt(a,{token:n});if(s.valid)t.stop(`${O.green("Valid")} - signature verified`);else return t.stop(`${O.red("Invalid")} - ${s.reason}`),!1}catch{return t.stop(`${O.yellow("Skipped")} - could not reach verification service`),x.log.warn("Signature not verified. Displaying unverified claims:"),Si(i),!1}return Si(i),await bi(t,{token:n,lkh:typeof i.lkh=="string"?i.lkh:void 0,nid:typeof i.nid=="string"?i.nid:void 0,domain:Ai(e)})??!0}function Ai(e){try{return new URL(/^https?:\/\//i.test(e)?e:`https://${e}`).hostname}catch{return}}function Ii(e){e.command("verify").description("Verify a GenerateSaaS license on a deployed site").argument("[url]","URL of the site to verify (e.g. https://example.com or https://example.com/api)").option("--file <path>","file with URLs to check, one per line").action(async(t,n)=>{if(!t&&!n.file&&(x.cancel("Provide a URL or --file <path>."),process.exit(1)),n.file){let i=(await us(n.file,"utf-8")).split(`
|
|
1285
|
+
`).map(a=>a.trim()).filter(a=>a&&!a.startsWith("#"));i.length===0&&(x.cancel("No URLs found in file."),process.exit(1));let o=0;for(let a of i)await Ei(a)&&o++,x.log.info("");x.log.success(`${o}/${i.length} sites verified.`)}else await Ei(t)||process.exit(1)})}import{existsSync as ks,rmSync as ws}from"fs";import*as te from"@clack/prompts";function Pi(e){e.command("auth").description("Set or update your GenerateSaaS API key").option("--clear","remove saved API key").action(async t=>{if(t.clear){ks(me)?(ws(me),te.log.success("API key removed.")):te.log.info("No API key configured.");return}let n=at();n?te.log.info(`Current API key: ****${n.slice(-4)}`):te.log.info("No API key configured.");let r=await st(),i=fe(r),o=te.spinner();o.start("Verifying API key...");try{await ke(i),o.stop("API key verified."),Ie(r),te.log.success("API key saved.")}catch(a){o.stop("Verification failed."),a instanceof U&&a.status===401?te.cancel("Invalid API key."):te.cancel(C(a)),process.exit(1)}})}import{existsSync as Vt,rmSync as bs,readFileSync as In,writeFileSync as Ri}from"fs";import{join as xe}from"path";import*as V from"@clack/prompts";var Ss=["packages/api/src/functions/maintenance/license-heartbeat.ts","packages/api/src/lib/cron-spread.ts","packages/api/src/lib/manifest.ts","packages/api/src/routes/internal/license.ts"],Es=[{file:"packages/api/src/routes/inngest.ts",removals:[`import { licenseHeartbeatFunction } from "../functions/maintenance/license-heartbeat";
|
|
1265
1286
|
`,` licenseHeartbeatFunction,
|
|
1266
1287
|
`]},{file:"packages/api/src/routes/internal/index.ts",removals:[`import licenseRoutes from "./license";
|
|
1267
1288
|
`,` .route("/license", licenseRoutes)
|
|
1268
|
-
`]}];function
|
|
1269
|
-
`).filter(
|
|
1270
|
-
`);return n
|
|
1289
|
+
`]}];function As(e){return(e&&e.length>0?e.map(n=>pt[n]):Object.values(pt)).map(n=>xe(n,vn))}function An(e){return Vt(e)?(bs(e,{recursive:!0}),!0):!1}function Is(e,t){if(!Vt(e))return!1;let n=In(e,"utf-8"),r=n;for(let i of t)r=r.replace(i,"");return r===n?!1:(Ri(e,r,"utf-8"),!0)}function Ps(e){let t=xe(e,".gitignore");if(!Vt(t))return!1;let n=In(t,"utf-8"),r=n.split(`
|
|
1290
|
+
`).filter(i=>!i.includes(".generatesaas")).join(`
|
|
1291
|
+
`);return r===n?!1:(Ri(t,r,"utf-8"),!0)}function Ti(e){e.command("eject").description("Remove all GenerateSaaS ties - manifest, license, heartbeat, skills").action(async()=>{let t=process.cwd(),n=xe(t,he),r;try{r=JSON.parse(In(n,"utf-8"))}catch{V.cancel("No GenerateSaaS project found in this directory."),process.exit(1)}let i=await V.text({message:'Type "eject" to confirm (this cannot be undone):',validate:s=>{if(s!=="eject")return'Type "eject" to confirm, or press Ctrl+C to cancel.'}});if(V.isCancel(i)&&(V.cancel("Eject cancelled."),process.exit(0)),r.licenseToken)try{await fetch("https://generatesaas.com/api/v1/heartbeat",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${r.licenseToken}`},body:JSON.stringify({event:"eject",version:r.version,frontend:r.frontend}),signal:AbortSignal.timeout(5e3)}),V.log.info("Recorded the opt-out with generatesaas.com (final event - nothing is sent after this).")}catch{V.log.warn("Could not reach generatesaas.com to record the opt-out. Ejecting anyway.")}let o=[],a=[];for(let s of As(r.aiTools))An(xe(t,s))&&o.push(s);for(let s of Ss)An(xe(t,s))&&o.push(s);An(xe(t,q))&&o.push(q+"/");for(let s of Es){let p=xe(t,s.file);Is(p,s.removals)?a.push(s.file):Vt(p)&&V.log.warn(`Could not auto-modify ${s.file} - manually remove license/heartbeat references.`)}Ps(t)&&a.push(".gitignore");for(let s of o)V.log.info(`Deleted ${s}`);for(let s of a)V.log.info(`Modified ${s}`);V.log.success("Ejected successfully. This project is now fully standalone.")})}var Ce=new Rs().name("generatesaas").description("CLI for scaffolding and managing GenerateSaaS projects").version("1.20.1").addHelpText("after",`
|
|
1271
1292
|
Examples:
|
|
1272
1293
|
$ generatesaas init Interactive setup
|
|
1273
1294
|
$ generatesaas init -n my-app -y Quick setup with defaults
|
|
1274
1295
|
$ generatesaas status Check for updates
|
|
1275
1296
|
$ generatesaas auth Set or update API key
|
|
1276
|
-
`);
|
|
1297
|
+
`);ui(Ce);ki(Ce);wi(Ce);Ii(Ce);Pi(Ce);Ti(Ce);Ce.parseAsync().catch(e=>{_i.cancel("An unexpected error occurred."),console.error(e),process.exit(1)});
|