zerostarter 0.0.19 → 0.0.20-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/index.mjs +17 -17
- package/package.json +1 -1
package/dist/bin/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{a as e,c as t,d as n,f as r,i,l as a,n as o,o as s,r as c,s as l,t as u,u as d}from"../convert-DMU8fiBc.mjs";import{
|
|
3
|
-
`).find(e=>e.startsWith(r));return i?i.slice(r.length).trim():``},
|
|
2
|
+
import{a as e,c as t,d as n,f as r,i,l as a,n as o,o as s,r as c,s as l,t as u,u as d}from"../convert-DMU8fiBc.mjs";import{basename as f,delimiter as p,join as m,resolve as h}from"node:path";import{existsSync as g,readdirSync as _}from"node:fs";import{createInterface as v}from"node:readline/promises";import{parseArgs as y}from"node:util";import{randomBytes as b}from"node:crypto";import{spawn as ee}from"node:child_process";import{access as te}from"node:fs/promises";import{homedir as ne}from"node:os";var re={name:`zerostarter`,version:`0.0.20-canary.0`,description:`Go from zero to a production-ready SaaS, rebranded and ready to ship.`,keywords:[`cli`,`saas`,`scaffold`,`starter`,`template`,`zerostarter`],homepage:`https://github.com/nrjdalal/zerostarter#readme`,bugs:`https://github.com/nrjdalal/zerostarter/issues`,license:`MIT`,author:{name:`Neeraj Dalal`,email:`admin@nrjdalal.com`,url:`https://nrjdalal.com`},repository:`nrjdalal/zerostarter`,funding:`https://github.com/sponsors/nrjdalal`,bin:{zerostarter:`dist/bin/index.mjs`},files:[`dist`],type:`module`,types:`./dist/index.d.mts`,exports:`./dist/index.mjs`,scripts:{build:`tsdown`,"check-types":`tsc --noEmit`,dev:`tsdown --watch`,test:`bun test`},devDependencies:{"@packages/config":`workspace:*`,"@types/bun":`catalog:`,"@types/node":`catalog:`,tsdown:`catalog:`,typescript:`catalog:`}};const x=()=>!!(process.stdin.isTTY&&process.stdout.isTTY),ie=(e,t=e)=>process.stdout.isTTY?`\x1b]8;;${e}\x07${t}\x1b]8;;\x07`:e,S=(e,t=process.stdout)=>n=>t.isTTY?`\x1b[${e}m${n}\x1b[0m`:n,C=S(`38;5;208`),w=S(`38;2;63;185;80`),T=S(`38;2;210;153;34`),E=S(`38;2;248;81;73`,process.stderr),ae=async(e,t=``)=>{let n=v({input:process.stdin,output:process.stdout});try{return(await n.question(`${e}${t?` (${t})`:``}: `)).trim()||t}finally{n.close()}},D=async(e,t=!0)=>{let n=v({input:process.stdin,output:process.stdout});try{let r=(await n.question(`${e} (${t?`Y/n`:`y/N`}) `)).trim().toLowerCase();return r?r===`y`||r===`yes`:t}finally{n.close()}};var oe=class extends Error{constructor(...e){super(...e),this.name=`SubprocessError`,this.stdout=``,this.stderr=``}};const O=[`.exe`,`.com`],k=e=>e.replaceAll(/([()\][%!^"`<>&|;, *?])/g,`^$1`),se=e=>k(k(`"${e.replaceAll(/(\\*)"/g,`$1$1\\"`).replace(/(\\*)$/,`$1$1`)}"`)),ce=async(e,t,n)=>{if(O.some(t=>e.toLowerCase().endsWith(t)))return!0;let r=(n.PATH||n.Path||``).split(p).filter(Boolean).map(e=>e.replace(/^"(.*)"$/,`$1`));try{return await Promise.any([t,...r].flatMap(t=>O.map(n=>te(`${h(t,e)}${n}`)))),!0}catch{return!1}},le=async(e,t,n,r=process.platform===`win32`)=>{let i=n.cwd?String(n.cwd):`.`,a=n.env||process.env;return r&&!n.shell&&!await ce(e,i,a)?[k(e),t.map(se),{...n,shell:!0}]:[e,t,n]},A=async(e,t,n)=>{let r=[e,...t].join(` `),[i,a,o]=await le(e,t,n);o.shell&&a.length>0&&(i=[i,...a].join(` `),a=[]);let s=ee(i,a,o),c=``,l=``;return new Promise((e,t)=>{let n=(e,n,r)=>{let i=new oe(e,r?{cause:r}:void 0);i.stdout=c,i.stderr=l,i.exitCode=n,t(i)},i=e=>{e.code!==`ERR_STREAM_PREMATURE_CLOSE`&&e.code!==`EPIPE`&&n(`Command failed: ${r}`,void 0,e)};s.stdout&&(s.stdout.setEncoding(`utf8`),s.stdout.on(`data`,e=>c+=e),s.stdout.on(`error`,i)),s.stderr&&(s.stderr.setEncoding(`utf8`),s.stderr.on(`data`,e=>l+=e),s.stderr.on(`error`,i)),s.on(`error`,e=>n(`Command failed: ${r}`,void 0,e)),s.on(`close`,(t,i)=>{if(i)return n(`Command was terminated with ${i}: ${r}`);if(t!==0)return n(`Command failed with exit code ${t}: ${r}`,t??void 0);e({stdout:c,stderr:l})})})},j=async(e,t,n)=>{let{stdout:r}=await A(e,t,{cwd:n,stdio:[`ignore`,`pipe`,`pipe`]});return r},M=async(e,t,n)=>{await A(e,t,{cwd:n,stdio:`inherit`})},N=async(e,t)=>{try{return await A(e,t,{stdio:`ignore`}),!0}catch{return!1}},P=`pglaunch@5.5.7`,ue=async()=>N(`docker`,[`info`]),F=e=>{let r=m(e,`.env`);if(!s(r)){let i=m(e,`.env.example`);n(r,s(i)?t(i):``)}return r},I=(e,n)=>{let r=`${n}=`,i=t(e).split(`
|
|
3
|
+
`).find(e=>e.startsWith(r));return i?i.slice(r.length).trim():``},L=(e,r,i)=>{let a=`${r}=`,o=t(e).split(`
|
|
4
4
|
`),s=o.findIndex(e=>e.startsWith(a));if(s>=0)o[s]=`${a}${i}`;else{for(;o.length&&o[o.length-1]===``;)o.pop();o.push(`${a}${i}`,``)}n(e,o.join(`
|
|
5
|
-
`))},
|
|
6
|
-
`)}return
|
|
7
|
-
bun is installed but isn't on this shell's PATH yet. Open a new terminal and re-run:`)),console.error(
|
|
8
|
-
Could not install bun. Install it from https://bun.sh, then re-run:`)),console.error(
|
|
5
|
+
`))},R=e=>{let t=F(e);I(t,`BETTER_AUTH_SECRET`)||L(t,`BETTER_AUTH_SECRET`,b(32).toString(`base64`))},z=e=>{let t=m(e,`.env`);return s(t)&&I(t,`POSTGRES_URL`)!==``},de=e=>{let t=e.match(/postgres(?:ql)?:\/\/[\w.:@\-/%?=&]+/);if(!t)return null;let n=e.match(/name "([^" ]+) :\d+" started/),r=e.match(/similar name "([^"]+)"/);return{url:t[0],container:n?n[1]:r?r[1]:``}},B=async(e,t)=>{let n=t?[`--bun`,P,`-k`,`-c`]:[`--bun`,P,`-k`],r;try{r=await j(`bunx`,n,e)}catch(e){let t=e;r=[t.stdout,t.stderr].filter(Boolean).join(`
|
|
6
|
+
`)}return de(r)},fe=e=>new Promise(t=>setTimeout(t,e)),pe=async e=>{if(e)for(let t=0;t<30;t++){if(await N(`docker`,[`exec`,e,`pg_isready`,`-U`,`postgres`]))return;await fe(1e3)}},me=async e=>{let t=F(e),n=await B(e,!1)||await B(e,!0);if(!n)throw Error(`pglaunch did not print a connection URL`);L(t,`POSTGRES_URL`,n.url),await pe(n.container),await M(`bun`,[`run`,`db:migrate`],e)},V=async e=>{await M(`bun`,[`install`],e)},H=async()=>{if(!await N(`bun`,[`--version`]))throw Error(`bun is not on PATH`)},U=async(e=H,t=!!process.versions.bun,n=process.env.npm_config_user_agent||``)=>{if(t||n.startsWith(`bun/`))return!0;try{return await e(),!0}catch{return!1}},he=async(e,t=`main`)=>{await j(`bunx`,[`--bun`,`gitpick@6.0.0`,`https://github.com/nrjdalal/zerostarter/tree/${t}`,e])},W=async(e,t=`main`)=>{await j(`bunx`,[`--bun`,`gitpick@6.0.0`,`https://github.com/nrjdalal/zerostarter/tree/${t}`,e,`-o`])},ge=async(e=`main`)=>{let t=`https://raw.githubusercontent.com/nrjdalal/zerostarter/${e}/.gitpickignore`,n=await fetch(t);if(!n.ok)throw Error(`Could not fetch .gitpickignore from ${e} (HTTP ${n.status}).`);return n.text()},_e=async e=>(await j(`git`,[`status`,`--porcelain`],e)).trim()===``,ve=async(e,t)=>{for(let n of t)try{await j(`git`,[`checkout`,`--`,n],e),await j(`git`,[`clean`,`-fd`,`--`,n],e)}catch{}},ye=async e=>{await j(`git`,[`reset`,`--hard`,`HEAD`],e),await j(`git`,[`clean`,`-fd`],e)},G=async(e,t,n)=>{if(!s(m(e,`.git`)))throw Error(t);if(!await _e(e))throw Error(n)},K=async(e,t,n)=>{try{await n()}catch(n){throw await ye(e),console.log(t),n}},be=async e=>{await j(`git`,[`init`,`-q`,`-b`,`canary`],e)},xe=async(e,t)=>{await j(`git`,[`branch`,t],e)},q=async(e,t)=>{await j(`git`,[`add`,`-A`],e);try{await j(`git`,[`commit`,`--no-verify`,`-q`,`-m`,t],e)}catch{}},Se=(e=process.env.npm_config_user_agent||``)=>e.startsWith(`bun/`)?`bunx`:e.startsWith(`pnpm/`)?`pnpm dlx`:e.startsWith(`yarn/`)?`yarn dlx`:e.startsWith(`npm/`)?`npx`:`unknown`,Ce=(e=process.platform)=>e===`win32`?{cmd:`powershell`,args:[`-Command`,`irm bun.sh/install.ps1 | iex`]}:{cmd:`bash`,args:[`-c`,`curl -fsSL https://bun.sh/install | bash`]},we=(e=process.argv.slice(2))=>[`zerostarter`,...e].join(` `),Te=()=>m(process.env.BUN_INSTALL||m(ne(),`.bun`),`bin`),J=async(e=!1)=>{if(await U())return;let t=Se(),n=`bunx --bun ${we()}`;if(console.error(E(`Seems like you are using ${t===`unknown`?`npx/pnpx`:t} or Windows, try using:`)),console.error(C(` ${n}`)),console.error(``),e||x()&&await D(`Or install bun now and continue?`,!0)){let{cmd:e,args:t}=Ce();console.error(`Installing bun from https://bun.sh/install ...`);try{if(await M(e,t),process.env.PATH=`${Te()}${p}${process.env.PATH||``}`,await U())return;console.error(E(`
|
|
7
|
+
bun is installed but isn't on this shell's PATH yet. Open a new terminal and re-run:`)),console.error(C(` ${n}`))}catch{console.error(E(`
|
|
8
|
+
Could not install bun. Install it from https://bun.sh, then re-run:`)),console.error(C(` ${n}`))}}process.exit(1)},Ee=e=>!g(e)||_(e).filter(e=>e!==`.git`).length===0,Y=e=>s(m(e,`packages/config/src/site.ts`)),De=async e=>{let{positionals:t,values:n}=y({allowPositionals:!0,args:e,options:{db:{type:`boolean`},"dry-run":{type:`boolean`},help:{short:`h`,type:`boolean`},yes:{short:`y`,type:`boolean`}}});if(n.help){console.log(`Usage:
|
|
9
9
|
$ bunx zerostarter init [dir] [options]
|
|
10
10
|
|
|
11
11
|
Scaffold ZeroStarter into dir (default .) as a fresh product. The author's
|
|
@@ -18,15 +18,15 @@ Options:
|
|
|
18
18
|
-y, --yes Skip prompts, taking defaults (provisions Postgres when Docker is running)
|
|
19
19
|
--db Provision a local Postgres (pglaunch) and migrate; needs Docker
|
|
20
20
|
--dry-run Print the plan without writing anything
|
|
21
|
-
-h, --help Display help`);return}n[`dry-run`]||await J(!!n.yes);let r=
|
|
22
|
-
Provisioning a local Postgres with pglaunch and migrating ...`),console.log(),
|
|
23
|
-
Postgres is provisioned, but the migration failed; run bun run db:migrate.`)):console.log(
|
|
24
|
-
Database setup failed; set POSTGRES_URL in .env yourself.`)),n&&console.log(
|
|
25
|
-
Docker isn't running, so the database wasn't provisioned. Set POSTGRES_URL in .env, or start Docker and re-run for automatic setup.`));let
|
|
26
|
-
Push to an empty GitHub repo when ready:`),console.log(` ${
|
|
27
|
-
Make it yours:`);for(let[e,t]of
|
|
21
|
+
-h, --help Display help`);return}n[`dry-run`]||await J(!!n.yes);let r=x()&&!n.yes,i=t[0]??`.`,a=h(i),o=Y(a);if(!o&&!Ee(a)){if(!r)throw Error(`Directory is not empty. Run it in an empty directory, or pass a project name: bunx zerostarter init <name>`);let e=await ae(`Directory isn't empty. Project name`);if(!e)throw Error(`No directory name provided.`);i=e}let c=h(i),l=f(c),d={name:l};if(n[`dry-run`]){console.log(`bunx zerostarter init (dry run)`),console.log(` target: ${c}`),console.log(` name: ${l}`),console.log(` mode: ${Y(c)?`in place`:`fetch first`}`);return}if(o&&r&&!await D(T(`Convert ${c} in place? This rewrites files and commits.`),!1)){console.log(`Aborted.`);return}console.log(),Y(c)||(console.log(`Fetching the latest ZeroStarter ...`),await he(c)),s(m(c,`.git`))||(await be(c),await q(c,`ci(init): scaffold from zerostarter`),await xe(c,`main`)),console.log(`Removing starter content and rebranding ...`),u(c,d),console.log(`Installing dependencies ...`),console.log(),await V(c),await q(c,`ci(init): re-baseline as ${l}`),R(c);let p=!1,g=await ue(),_=z(c),v=!1;if(_?n.db&&console.log(T(` --db ignored: POSTGRES_URL is already set in .env.`)):n.db?v=!0:r?(console.log(),v=await D(`Provision a local Postgres database now?`,g)):v=g,v&&g)try{console.log(`
|
|
22
|
+
Provisioning a local Postgres with pglaunch and migrating ...`),console.log(),await me(c),console.log(),p=!0}catch(e){let t=e.stderr,n=t?String(t).trim():e instanceof Error?e.message:String(e);z(c)?console.log(T(`
|
|
23
|
+
Postgres is provisioned, but the migration failed; run bun run db:migrate.`)):console.log(T(`
|
|
24
|
+
Database setup failed; set POSTGRES_URL in .env yourself.`)),n&&console.log(T(` ${n}`))}else v&&console.log(T(`
|
|
25
|
+
Docker isn't running, so the database wasn't provisioned. Set POSTGRES_URL in .env, or start Docker and re-run for automatic setup.`));let b=[[`packages/config/src/site.ts`,`your brand: name, tagline, links`],[`web/next/content`,`your docs and blog`],[`web/next/public`,`your logo and assets`]];console.log(`\n${w(`✓`)} ${l} is ready.\n`),console.log(`Next steps:`),c!==process.cwd()&&console.log(` ${C(`cd ${i}`)}`),z(c)||console.log(` ${C(`set POSTGRES_URL in .env`)} # your Postgres connection string`),p||console.log(` ${C(`bun run db:migrate`)}`),console.log(` ${C(`bun run dev`)}`),console.log(`
|
|
26
|
+
Push to an empty GitHub repo when ready:`),console.log(` ${C(`git push origin canary`)}`),console.log(`canary becomes the default branch; your next push seeds main and opens the release PR.`),console.log(`
|
|
27
|
+
Make it yours:`);for(let[e,t]of b)console.log(` ${e.padEnd(29)} ${t}`);console.log(p?`
|
|
28
28
|
Everything works out of the box: dependencies are installed and the local Postgres is migrated. Add OAuth or other credentials to .env whenever you like.`:`
|
|
29
|
-
It needs a Postgres database to run: a hosted one like Neon works, or a local Docker one (re-run with Docker running to auto-provision). OAuth and other credentials are optional.`)},
|
|
29
|
+
It needs a Postgres database to run: a hosted one like Neon works, or a local Docker one (re-run with Docker running to auto-provision). OAuth and other credentials are optional.`)},Oe=async t=>{let{positionals:n,values:r}=y({allowPositionals:!0,args:t,options:{help:{short:`h`,type:`boolean`},yes:{short:`y`,type:`boolean`}}});if(r.help){console.log(`Usage:
|
|
30
30
|
$ bunx zerostarter reinit [dir] [options]
|
|
31
31
|
|
|
32
32
|
Re-scaffold an existing git repo (default .) as a fresh ZeroStarter: delete every
|
|
@@ -36,7 +36,7 @@ branch; push when ready.
|
|
|
36
36
|
|
|
37
37
|
Options:
|
|
38
38
|
-y, --yes Skip the confirmation prompt
|
|
39
|
-
-h, --help Display help`);return}await J(!!r.yes);let i=
|
|
39
|
+
-h, --help Display help`);return}await J(!!r.yes);let i=h(n[0]??`.`),a=f(i),o=x()&&!r.yes;if(await G(i,`No git repository in ${i}. reinit re-scaffolds an existing repo; use init for a new project.`,`Working tree has uncommitted changes. Commit or stash them first; reinit deletes every tracked file.`),o&&!await D(T(`Delete every file in ${i} (keeping .git and .env*) and re-scaffold as ${a}?`),!1)){console.log(`Aborted.`);return}console.log(),console.log(`Removing all files (keeping .git and your .env* files) ...`),await K(i,T(`reinit failed; restored your committed files (deleted gitignored files, except .env*, are gone).`),async()=>{e(i),console.log(`Fetching the latest ZeroStarter ...`),await W(i),console.log(`Rebranding ...`),u(i,{name:a}),console.log(`Installing dependencies ...`),console.log(),await V(i),R(i),await q(i,`ci(reinit): re-baseline as ${a}`)}),console.log(`\n${w(`✓`)} ${a} re-scaffolded; .git history, remote, and .env* files are intact.`),console.log(`Next steps:`),z(i)||console.log(` ${C(`set POSTGRES_URL in .env`)} # your Postgres connection string`),console.log(` ${C(`bun run db:migrate`)}`),console.log(` ${C(`bun run dev`)}`),console.log(` ${C(`git push`)} # to your existing remote`)},ke=async e=>{let{positionals:t,values:n}=y({allowPositionals:!0,args:e,options:{help:{short:`h`,type:`boolean`}}});if(n.help){console.log(`Usage:
|
|
40
40
|
$ bunx zerostarter sync [dir] [options]
|
|
41
41
|
|
|
42
42
|
Re-baseline an existing fork (default .) on the latest ZeroStarter: a gitpick overlay
|
|
@@ -45,7 +45,7 @@ identity, and favicon are preserved. Requires a clean tree; lands as a reviewabl
|
|
|
45
45
|
you commit yourself.
|
|
46
46
|
|
|
47
47
|
Options:
|
|
48
|
-
-h, --help Display help`);return}await J();let u=
|
|
48
|
+
-h, --help Display help`);return}await J();let u=h(t[0]??`.`);await G(u,`No git repository in ${u}. Run sync inside an existing fork.`,`Working tree has uncommitted changes. Commit or stash them first so the sync lands as a reviewable diff.`);let f=m(u,`package.json`),p=new Map(l(u).map(e=>[e,a(e)])),g=i(await ge());g.length===0&&console.log(T(`Warning: no PRESERVE_ON_SYNC directive found; fork-owned files may be overwritten.`)),console.log(),console.log(`Overlaying the latest ZeroStarter (content, public/marketing, and site.ts preserved) ...`),await K(u,T(`Sync failed; rolled the working tree back to your last commit.`),async()=>{await W(u),o(u),d(m(u,`.gitpickignore`));for(let[e,t]of p)s(e)&&r(e,c(t,a(e),e===f));await ve(u,g)}),console.log(`Installing dependencies ...`),console.log(),await V(u),console.log(),console.log(C(`Synced to the latest ZeroStarter.`)),console.log(`Starter files were updated (edits to them were overwritten); files you added and your`),console.log(`content, public/marketing, and branding were preserved.`),console.log(T(`Review the diff and commit: git -C ${u} status`))},{author:X,name:Z,version:Q}=re,$=`Version:
|
|
49
49
|
${Z}@${Q}
|
|
50
50
|
|
|
51
51
|
Go from zero to a production-ready SaaS, rebranded and ready to ship.
|
|
@@ -64,4 +64,4 @@ Options:
|
|
|
64
64
|
-h, --help Display help
|
|
65
65
|
|
|
66
66
|
Author:
|
|
67
|
-
${X.name} <${X.email}> (${
|
|
67
|
+
${X.name} <${X.email}> (${ie(X.url)})`;(async()=>{try{let e=process.argv.slice(2),t=e[0],n=e.slice(1);switch(t){case`init`:return await De(n);case`reinit`:return await Oe(n);case`sync`:return await ke(n);case void 0:case`-h`:case`--help`:console.log($);return;case`-v`:case`--version`:console.log(`${Z}@${Q}`);return;default:console.error(E(`Unknown command: ${t}\n`)),console.log($),process.exit(1)}}catch(e){console.error(E(e instanceof Error?e.message:String(e))),process.exit(1)}})();export{};
|