zerostarter 0.0.15 → 0.0.16-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 +10 -9
- package/package.json +1 -1
package/dist/bin/index.mjs
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
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-hP2szrh8.mjs";import{basename as f,join as p,resolve as m}from"node:path";import{existsSync as h,readdirSync as g}from"node:fs";import{createInterface as _}from"node:readline/promises";import{parseArgs as v}from"node:util";import{execFileSync as y}from"node:child_process";import{randomBytes as b}from"node:crypto";var
|
|
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-hP2szrh8.mjs";import{basename as f,join as p,resolve as m}from"node:path";import{existsSync as h,readdirSync as g}from"node:fs";import{createInterface as _}from"node:readline/promises";import{parseArgs as v}from"node:util";import{execFileSync as y}from"node:child_process";import{randomBytes as b}from"node:crypto";var x={name:`zerostarter`,version:`0.0.16-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 S=()=>!!(process.stdin.isTTY&&process.stdout.isTTY),ee=(e,t=e)=>process.stdout.isTTY?`\x1b]8;;${e}\x07${t}\x1b]8;;\x07`:e,C=(e,t=process.stdout)=>n=>t.isTTY?`\x1b[${e}m${n}\x1b[0m`:n,w=C(`38;5;208`),T=C(`38;2;63;185;80`),E=C(`38;2;210;153;34`),D=C(`38;2;248;81;73`,process.stderr),te=async(e,t=``)=>{let n=_({input:process.stdin,output:process.stdout});try{return(await n.question(`${e}${t?` (${t})`:``}: `)).trim()||t}finally{n.close()}},O=async(e,t=!0)=>{let n=_({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()}},k=`pglaunch@5.5.7`,A=(e,t,n)=>y(e,t,{cwd:n,encoding:`utf8`,maxBuffer:1<<26,stdio:[`ignore`,`pipe`,`pipe`]}),j=()=>{try{return y(`docker`,[`info`],{stdio:`ignore`}),!0}catch{return!1}},M=e=>{let r=p(e,`.env`);if(!s(r)){let i=p(e,`.env.example`);n(r,s(i)?t(i):``)}return r},N=(e,n)=>{let r=`${n}=`,i=t(e).split(`
|
|
3
|
+
`).find(e=>e.startsWith(r));return i?i.slice(r.length).trim():``},P=(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
|
-
`))},
|
|
5
|
+
`))},F=e=>{let t=M(e);N(t,`BETTER_AUTH_SECRET`)||P(t,`BETTER_AUTH_SECRET`,b(32).toString(`base64`))},I=e=>{let t=p(e,`.env`);return s(t)&&N(t,`POSTGRES_URL`)!==``},L=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]:``,reused:!n}},R=(e,t)=>{let n=t?[k,`-k`,`-c`]:[k,`-k`],r;try{r=A(`bunx`,n,e)}catch(e){let t=e;r=[t.stdout,t.stderr].filter(Boolean).join(`
|
|
6
|
+
`)}return L(r)},z=e=>{Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,e)},ne=e=>{if(e)for(let t=0;t<30;t++)try{y(`docker`,[`exec`,e,`pg_isready`,`-U`,`postgres`],{stdio:`ignore`});return}catch{z(1e3)}},re=e=>{let t=M(e),n=n=>{P(t,`POSTGRES_URL`,n.url),ne(n.container),A(`bun`,[`run`,`db:migrate`],e)},r=R(e,!1);if(r&&r.reused){n(r);return}if(r)try{n(r);return}catch{}let i=R(e,!0);if(!i)throw Error(`pglaunch did not print a connection URL`);n(i)},B=(e,t,n)=>y(e,t,{cwd:n,encoding:`utf8`,stdio:[`ignore`,`pipe`,`pipe`]}),ie=(e,t=`main`)=>{B(`bunx`,[`gitpick@6.0.0`,`https://github.com/nrjdalal/zerostarter/tree/${t}`,e])},V=(e,t=`main`)=>{B(`bunx`,[`gitpick@6.0.0`,`https://github.com/nrjdalal/zerostarter/tree/${t}`,e,`-o`])},ae=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()},H=e=>B(`git`,[`status`,`--porcelain`],e).trim()===``,U=(e,t)=>{for(let n of t)try{B(`git`,[`checkout`,`--`,n],e),B(`git`,[`clean`,`-fd`,`--`,n],e)}catch{}},W=e=>{B(`git`,[`reset`,`--hard`,`HEAD`],e),B(`git`,[`clean`,`-fd`],e)},G=(e,t,n)=>{if(!s(p(e,`.git`)))throw Error(t);if(!H(e))throw Error(n)},K=async(e,t,n)=>{try{await n()}catch(n){throw W(e),console.log(t),n}},q=e=>{B(`bun`,[`install`],e)},oe=e=>{B(`git`,[`init`,`-q`,`-b`,`canary`],e)},se=(e,t)=>{B(`git`,[`branch`,t],e)},J=(e,t)=>{B(`git`,[`add`,`-A`],e);try{B(`git`,[`commit`,`--no-verify`,`-q`,`-m`,t],e)}catch{}},ce=e=>!h(e)||g(e).filter(e=>e!==`.git`).length===0,Y=e=>s(p(e,`packages/config/src/site.ts`)),le=async e=>{let{positionals:t,values:n}=v({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:
|
|
6
7
|
$ bunx zerostarter init [dir] [options]
|
|
7
8
|
|
|
8
9
|
Scaffold ZeroStarter into dir (default .) as a fresh product. The author's
|
|
@@ -15,11 +16,11 @@ Options:
|
|
|
15
16
|
-y, --yes Skip prompts, taking defaults (provisions Postgres when Docker is running)
|
|
16
17
|
--db Provision a local Postgres (pglaunch) and migrate; needs Docker
|
|
17
18
|
--dry-run Print the plan without writing anything
|
|
18
|
-
-h, --help Display help`);return}let r=
|
|
19
|
-
Push to an empty GitHub repo when ready:`),console.log(` ${
|
|
19
|
+
-h, --help Display help`);return}let r=S()&&!n.yes,i=t[0]??`.`,a=m(i),o=Y(a);if(!o&&!ce(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 te(`Directory isn't empty. Project name`);if(!e)throw Error(`No directory name provided.`);i=e}let c=m(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 O(E(`Convert ${c} in place? This rewrites files and commits.`),!1)){console.log(`Aborted.`);return}console.log(),Y(c)||(console.log(`Fetching the latest ZeroStarter ...`),ie(c)),s(p(c,`.git`))||(oe(c),J(c,`ci(init): scaffold from zerostarter`),se(c,`main`)),console.log(`Removing starter content and rebranding ...`),u(c,d),console.log(`Installing dependencies ...`),q(c),J(c,`ci(init): re-baseline as ${l}`),F(c);let h=!1,g=j(),_=I(c),y=!1;if(_?n.db&&console.log(E(` --db ignored: POSTGRES_URL is already set in .env.`)):y=n.db?!0:r?await O(`Provision a local Postgres database now?`,g):g,y&&g)try{console.log(`Provisioning a local database with pglaunch and migrating ...`),re(c),h=!0}catch(e){let t=e.stderr,n=t?String(t).trim():e instanceof Error?e.message:String(e);console.log(E(` Database setup failed; set POSTGRES_URL in .env yourself.`)),n&&console.log(E(` ${n}`))}else y&&console.log(E(` 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${T(`✓`)} ${l} is ready.\n`),console.log(`Next steps:`),c!==process.cwd()&&console.log(` ${w(`cd ${i}`)}`),h||(console.log(` ${w(`set POSTGRES_URL in .env`)} # your Postgres connection string`),console.log(` ${w(`bun run db:migrate`)}`)),console.log(` ${w(`bun run dev`)}`),console.log(`
|
|
20
|
+
Push to an empty GitHub repo when ready:`),console.log(` ${w(`git push origin canary`)}`),console.log(`canary becomes the default branch; your next push seeds main and opens the release PR.`),console.log(`
|
|
20
21
|
Make it yours:`);for(let[e,t]of b)console.log(` ${e.padEnd(29)} ${t}`);console.log(h?`
|
|
21
22
|
Everything works out of the box. Try it now; add OAuth or other credentials to .env whenever you like.`:`
|
|
22
|
-
It needs a Postgres database to run: a hosted one like Neon works, or a local Docker one. OAuth and other credentials are optional.`)},
|
|
23
|
+
It needs a Postgres database to run: a hosted one like Neon works, or a local Docker one. OAuth and other credentials are optional.`)},ue=async t=>{let{positionals:n,values:r}=v({allowPositionals:!0,args:t,options:{help:{short:`h`,type:`boolean`},yes:{short:`y`,type:`boolean`}}});if(r.help){console.log(`Usage:
|
|
23
24
|
$ bunx zerostarter reinit [dir] [options]
|
|
24
25
|
|
|
25
26
|
Re-scaffold an existing git repo (default .) as a fresh ZeroStarter: delete every
|
|
@@ -29,7 +30,7 @@ branch; push when ready.
|
|
|
29
30
|
|
|
30
31
|
Options:
|
|
31
32
|
-y, --yes Skip the confirmation prompt
|
|
32
|
-
-h, --help Display help`);return}let i=m(n[0]??`.`),a=f(i),o=
|
|
33
|
+
-h, --help Display help`);return}let i=m(n[0]??`.`),a=f(i),o=S()&&!r.yes;if(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 O(E(`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,E(`reinit failed; restored your committed files (deleted gitignored files, except .env*, are gone).`),()=>{e(i),console.log(`Fetching the latest ZeroStarter ...`),V(i),console.log(`Rebranding ...`),u(i,{name:a}),console.log(`Installing dependencies ...`),q(i),F(i),J(i,`ci(reinit): re-baseline as ${a}`)}),console.log(`\n${T(`✓`)} ${a} re-scaffolded; .git history, remote, and .env* files are intact.`),console.log(`Next steps:`),I(i)||(console.log(` ${w(`set POSTGRES_URL in .env`)} # your Postgres connection string`),console.log(` ${w(`bun run db:migrate`)}`)),console.log(` ${w(`bun run dev`)}`),console.log(` ${w(`git push`)} # to your existing remote`)},de=async e=>{let{positionals:t,values:n}=v({allowPositionals:!0,args:e,options:{help:{short:`h`,type:`boolean`}}});if(n.help){console.log(`Usage:
|
|
33
34
|
$ bunx zerostarter sync [dir] [options]
|
|
34
35
|
|
|
35
36
|
Re-baseline an existing fork (default .) on the latest ZeroStarter: a gitpick overlay
|
|
@@ -38,7 +39,7 @@ identity, and favicon are preserved. Requires a clean tree; lands as a reviewabl
|
|
|
38
39
|
you commit yourself.
|
|
39
40
|
|
|
40
41
|
Options:
|
|
41
|
-
-h, --help Display help`);return}let u=m(t[0]??`.`);
|
|
42
|
+
-h, --help Display help`);return}let u=m(t[0]??`.`);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=p(u,`package.json`),h=new Map(l(u).map(e=>[e,a(e)])),g=i(await ae());g.length===0&&console.log(E(`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,E(`Sync failed; rolled the working tree back to your last commit.`),()=>{V(u),o(u),d(p(u,`.gitpickignore`));for(let[e,t]of h)s(e)&&r(e,c(t,a(e),e===f));U(u,g)}),console.log(`Installing dependencies ...`),q(u),console.log(),console.log(w(`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(E(`Review the diff and commit: git -C ${u} status`))},{author:X,name:Z,version:Q}=x,$=`Version:
|
|
42
43
|
${Z}@${Q}
|
|
43
44
|
|
|
44
45
|
Go from zero to a production-ready SaaS, rebranded and ready to ship.
|
|
@@ -57,4 +58,4 @@ Options:
|
|
|
57
58
|
-h, --help Display help
|
|
58
59
|
|
|
59
60
|
Author:
|
|
60
|
-
${X.name} <${X.email}> (${
|
|
61
|
+
${X.name} <${X.email}> (${ee(X.url)})`;(async()=>{try{let e=process.argv.slice(2),t=e[0],n=e.slice(1);switch(t){case`init`:return await le(n);case`reinit`:return await ue(n);case`sync`:return await de(n);case void 0:case`-h`:case`--help`:console.log($);return;case`-v`:case`--version`:console.log(`${Z}@${Q}`);return;default:console.error(D(`Unknown command: ${t}\n`)),console.log($),process.exit(1)}}catch(e){console.error(D(e instanceof Error?e.message:String(e))),process.exit(1)}})();export{};
|