create-tnt-stack 0.4.0 → 0.4.2
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
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
#!/usr/bin/env node
|
2
|
-
import Ue from"path";import{execa as vt}from"execa";import $e from"fs-extra";import{confirm as G,input as ue,select as
|
2
|
+
import Ue from"path";import{execa as vt}from"execa";import $e from"fs-extra";import{confirm as G,input as ue,select as j}from"@inquirer/prompts";import{Command as tt}from"commander";import X from"path";import{fileURLToPath as Be}from"url";var We=Be(import.meta.url),Ve=X.dirname(We),p=X.join(Ve,"../"),Z=` ___ ___ ___ _ _____ ___ _____ _ _ _____ ___ _____ _ ___ _ __
|
3
3
|
/ __| _ \\ __| /_\\_ _| __| |_ _| \\| |_ _| / __|_ _/_\\ / __| |/ /
|
4
4
|
| (__| / _| / _ \\| | | _| | | | .\` | | | \\__ \\ | |/ _ \\ (__| ' <
|
5
5
|
\\___|_|_\\___/_/ \\_\\_| |___| |_| |_|\\_| |_| |___/ |_/_/ \\_\\___|_|\\_\\
|
6
|
-
`,I="my-tnt-stack",$="create-tnt-stack";import u from"path";import k from"fs-extra";import te from"path";import ne from"fs-extra";import ze from"sort-package-json";var ee={"next-auth":"^4.24.11","@auth/prisma-adapter":"^2.8.0",prisma:"^6.5.0","@prisma/client":"^6.5.0","@t3-oss/env-nextjs":"^0.12.0",zod:"^3.24.2",prettier:"^3.5.3","prettier-plugin-tailwindcss":"^0.6.11","@ianvs/prettier-plugin-sort-imports":"^4.4.1",eslint:"^9","eslint-config-next":"^15.2.4","@eslint/eslintrc":"^3.3.1",typescript:"^5.8.2","@types/node":"^22","@types/react":"^19","@types/react-dom":"^19",payload:"^3.33.0","@payloadcms/next":"^3.33.0","@payloadcms/payload-cloud":"^3.33.0","@payloadcms/richtext-lexical":"^3.33.0","@payloadcms/db-vercel-postgres":"^3.33.0","@payloadcms/db-sqlite":"^3.33.0",graphql:"^16.10.0",sharp:"^0.34.1"};var d=e=>{let{dependencies:o,devMode:s,projectDir:n}=e,t=ne.readJsonSync(te.join(n,"package.json"));o.forEach(i=>{let l=ee[i];s&&t.devDependencies?t.devDependencies[i]=l:t.dependencies&&(t.dependencies[i]=l)});let a=ze(t);ne.writeJsonSync(te.join(n,"package.json"),a,{spaces:2})};var ae=({projectDir:e,packages:o,databaseProvider:s})=>{let n=[],t=[];if(o?.payload.inUse)switch(n.push("payload"),n.push("@payloadcms/next"),n.push("@payloadcms/payload-cloud"),n.push("@payloadcms/richtext-lexical"),n.push("graphql"),s){case"sqlite":t.push("@payloadcms/db-sqlite");break;case"postgresql":t.push("@payloadcms/db-vercel-postgres");break}d({projectDir:e,dependencies:n,devMode:!1}),d({projectDir:e,dependencies:t,devMode:!1});let a=u.join(p,"template/packages"),i=u.join(a,"config/payload",`${s==="postgresql"?"with-postgres":"with-sqlite"}.ts`),l=u.join(e,"payload.config.ts");k.copyFileSync(i,l);let m=u.join(a,"src/payload/collections"),f=u.join(e,"src/collections");k.mkdirSync(f,{recursive:!0}),k.copyFileSync(u.join(m,"Media.ts"),u.join(f,"Media.ts")),k.copyFileSync(u.join(m,"Users.ts"),u.join(f,"Users.ts"));let g=u.join(a,"src/app/(payload)"),c=u.join(e,"src/app/(payload)");k.mkdirSync(c,{recursive:!0}),k.copySync(g,c);let h=u.join(e,"package.json"),x=k.readJSONSync(h);x.scripts={...x.scripts,payload:"payload","generate:importmap":"payload generate:importmap","generate:types":"payload generate:types"},k.writeJSONSync(h,x,{spaces:2})};import oe from"path";import Ke from"fs-extra";var se=({projectDir:e,packages:o})=>{let s=o?.typescript.inUse,n=o?.payload.inUse,t=[];s&&(t.push("typescript"),t.push("@types/node"),t.push("@types/react"),t.push("@types/react-dom")),d({projectDir:e,dependencies:t,devMode:!0});let a=oe.join(p,"template/packages/config/tsconfig",`${n?"with-payload":"base"}.json`),i=oe.join(e,"tsconfig.json");Ke.copyFileSync(a,i)};import E from"path";import q from"fs-extra";var ie=({projectDir:e,scopedAppName:o,packages:s,databaseProvider:n})=>{let t=s?.envVariables.inUse,a=s?.nextAuth.inUse,i=s?.prisma.inUse,l=s?.payload.inUse,m=[];t&&(m.push("@t3-oss/env-nextjs"),m.push("zod")),d({projectDir:e,dependencies:m,devMode:!1});let f=i,g=He(!!a,!!i,!!l,o,n),c="";if(f?a?c="with-next-auth-db.js":c="with-db.js":a&&(c="with-next-auth.js"),c!==""){let Je=E.join(p,"template/packages/src/env",c),Le=E.join(e,"src/env.js");q.copyFileSync(Je,Le)}let h=E.join(e,".env"),x=E.join(e,".env.example"),qe=Ye+g,Q=Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("base64"),Fe=g.replace('AUTH_SECRET=""',`AUTH_SECRET="${Q}" # Generated by create-tnt-stack`).replace('PAYLOAD_SECRET=""',`PAYLOAD_SECRET="${Q}" # Generated by create-tnt-stack`);q.writeFileSync(h,Fe,"utf-8"),q.writeFileSync(x,qe,"utf-8")};function He(e,o,s,n,t){let a=`
|
6
|
+
`,I="my-tnt-stack",$="create-tnt-stack";import u from"path";import k from"fs-extra";import te from"path";import ne from"fs-extra";import ze from"sort-package-json";var ee={"next-auth":"^4.24.11","@auth/prisma-adapter":"^2.8.0",prisma:"^6.5.0","@prisma/client":"^6.5.0","@t3-oss/env-nextjs":"^0.12.0",zod:"^3.24.2",prettier:"^3.5.3","prettier-plugin-tailwindcss":"^0.6.11","@ianvs/prettier-plugin-sort-imports":"^4.4.1",eslint:"^9","eslint-config-next":"^15.2.4","@eslint/eslintrc":"^3.3.1",typescript:"^5.8.2","@types/node":"^22","@types/react":"^19","@types/react-dom":"^19",payload:"^3.33.0","@payloadcms/next":"^3.33.0","@payloadcms/payload-cloud":"^3.33.0","@payloadcms/richtext-lexical":"^3.33.0","@payloadcms/db-vercel-postgres":"^3.33.0","@payloadcms/db-sqlite":"^3.33.0",graphql:"^16.10.0",sharp:"^0.34.1"};var d=e=>{let{dependencies:o,devMode:s,projectDir:n}=e,t=ne.readJsonSync(te.join(n,"package.json"));o.forEach(i=>{let l=ee[i];s&&t.devDependencies?t.devDependencies[i]=l:t.dependencies&&(t.dependencies[i]=l)});let a=ze(t);ne.writeJsonSync(te.join(n,"package.json"),a,{spaces:2})};var ae=({projectDir:e,packages:o,databaseProvider:s})=>{let n=[],t=[];if(o?.payload.inUse)switch(n.push("payload"),n.push("@payloadcms/next"),n.push("@payloadcms/payload-cloud"),n.push("@payloadcms/richtext-lexical"),n.push("graphql"),s){case"sqlite":t.push("@payloadcms/db-sqlite");break;case"postgresql":t.push("@payloadcms/db-vercel-postgres");break}d({projectDir:e,dependencies:n,devMode:!1}),d({projectDir:e,dependencies:t,devMode:!1});let a=u.join(p,"template/packages"),i=u.join(a,"config/payload",`${s==="postgresql"?"with-postgres":"with-sqlite"}.ts`),l=u.join(e,"payload.config.ts");k.copyFileSync(i,l);let m=u.join(a,"src/payload/collections"),f=u.join(e,"src/collections");k.mkdirSync(f,{recursive:!0}),k.copyFileSync(u.join(m,"Media.ts"),u.join(f,"Media.ts")),k.copyFileSync(u.join(m,"Users.ts"),u.join(f,"Users.ts"));let g=u.join(a,"src/app/(payload)"),c=u.join(e,"src/app/(payload)");k.mkdirSync(c,{recursive:!0}),k.copySync(g,c);let h=u.join(e,"package.json"),x=k.readJSONSync(h);x.scripts={...x.scripts,payload:"payload","generate:importmap":"payload generate:importmap","generate:types":"payload generate:types"},k.writeJSONSync(h,x,{spaces:2})};import oe from"path";import Ke from"fs-extra";var se=({projectDir:e,packages:o})=>{let s=o?.typescript.inUse,n=o?.payload.inUse,t=[];s&&(t.push("typescript"),t.push("@types/node"),t.push("@types/react"),t.push("@types/react-dom")),d({projectDir:e,dependencies:t,devMode:!0});let a=oe.join(p,"template/packages/config/tsconfig",`${n?"with-payload":"base"}.json`),i=oe.join(e,"tsconfig.json");Ke.copyFileSync(a,i)};import E from"path";import q from"fs-extra";var ie=({projectDir:e,scopedAppName:o,packages:s,databaseProvider:n})=>{let t=s?.envVariables.inUse,a=s?.nextAuth.inUse,i=s?.prisma.inUse,l=s?.payload.inUse,m=[];t&&(m.push("@t3-oss/env-nextjs"),m.push("zod")),d({projectDir:e,dependencies:m,devMode:!1});let f=i||l,g=He(!!a,!!i,!!l,o,n),c="";if(f?(console.log("Using a database, copying env file"),a?c="with-next-auth-db.js":l?c="with-payload.js":c="with-db.js"):a&&(c="with-next-auth.js"),c!==""){let Je=E.join(p,"template/packages/src/env",c),Le=E.join(e,"src/env.js");q.copyFileSync(Je,Le)}let h=E.join(e,".env"),x=E.join(e,".env.example"),qe=Ye+g,Q=Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("base64"),Fe=g.replace('AUTH_SECRET=""',`AUTH_SECRET="${Q}" # Generated by create-tnt-stack`).replace('PAYLOAD_SECRET=""',`PAYLOAD_SECRET="${Q}" # Generated by create-tnt-stack`);q.writeFileSync(h,Fe,"utf-8"),q.writeFileSync(x,qe,"utf-8")};function He(e,o,s,n,t){let a=`
|
7
7
|
# When adding additional environment variables, the schema in "/src/env.js"
|
8
8
|
# should be updated accordingly.
|
9
9
|
`.trim().concat(`
|
@@ -45,14 +45,14 @@ DISCORD_CLIENT_SECRET=""
|
|
45
45
|
package manager such as pnpm, npm, or Yarn Classic.
|
46
46
|
See: https://github.com/t3-oss/create-t3-app/issues/57`);let s=o.args[0];if(s&&(e.appName=s),e.flags=o.opts(),e.flags.CI)return e.packages=[],e.flags.nextAuth&&e.packages.push("nextAuth"),e.flags.prisma&&e.packages.push("prisma"),e.flags.prettier&&e.packages.push("prettier"),M.includes(e.flags.dbProvider)===!1&&(r.warn(`Incompatible database provided. Use: ${M.join(", ")}. Exiting.`),process.exit(0)),e.flags.backend==="payload"&&e.flags.dbProvider==="mysql"&&(r.warn("Payload CMS does not support MySQL. Exiting."),process.exit(0)),e;if(e.flags.default)return e;try{if(process.env.TERM_PROGRAM?.toLowerCase().includes("mintty"))throw r.warn(` WARNING: It looks like you are using MinTTY, which is non-interactive. This is most likely because you are
|
47
47
|
using Git Bash. If that's that case, please use Git Bash from another terminal, such as Windows Terminal. Alternatively, you
|
48
|
-
can provide the arguments from the CLI directly: https://create.tntstack.org/installation#experimental-usage to skip the prompts.`),new C("Non-interactive environment");let n=y(),t={};s||(t.name=await ue({message:"What will your project be called?",default:I,validate:i=>fe(i)})),t.backend=await
|
48
|
+
can provide the arguments from the CLI directly: https://create.tntstack.org/installation#experimental-usage to skip the prompts.`),new C("Non-interactive environment");let n=y(),t={};s||(t.name=await ue({message:"What will your project be called?",default:I,validate:i=>fe(i)})),t.backend=await j({message:"What backend framework would you like to use?",choices:[{value:"nextjs",name:"Next.js"},{value:"payload",name:"Payload CMS"}],default:"nextjs"}),t.backend==="payload"&&(t.databaseProvider=await j({message:"What database provider would you like to use?",choices:[{value:"sqlite",name:"SQLite"},{value:"postgresql",name:"PostgreSQL"}],default:"sqlite"})),t.backend==="nextjs"&&(t.authentication=await j({message:"What authentication provider would you like to use?",choices:[{value:"none",name:"None"},{value:"nextAuth",name:"NextAuth.js"}],default:"none"}),t.database=await j({message:"What database ORM would you like to use?",choices:[{value:"none",name:"None"},{value:"prisma",name:"Prisma"}],default:"none"}),t.database!=="none"&&(t.databaseProvider=await j({message:"What database provider would you like to use?",choices:[{value:"sqlite",name:"SQLite"},{value:"mysql",name:"MySQL"},{value:"postgresql",name:"PostgreSQL"}],default:"sqlite"}))),t.prettier=await G({message:"Should we install Prettier?",default:!b.flags.prettier}),e.flags.noGit||(t.noGit=await G({message:"Should we initialize a Git repository and stage the changes?",default:!b.flags.noGit})),e.flags.noInstall||(t.noInstall=await G({message:`Should we run '${n}`+(n==="yarn"?"'?":" install' for you?"),default:!b.flags.noInstall})),t.importAlias=await ue({message:"What import alias would you like to use?",default:b.flags.importAlias,validate:ge});let a=[];return t.authentication==="nextAuth"&&a.push("nextAuth"),t.database==="prisma"&&a.push("prisma"),t.prettier&&a.push("prettier"),t.backend==="payload"&&a.push("payload"),{appName:t.name??e.appName,packages:a,flags:{...e.flags,noGit:!t.noGit||e.flags.noGit,noInstall:!t.noInstall||e.flags.noInstall,importAlias:t.importAlias??e.flags.importAlias},databaseProvider:t.databaseProvider||"sqlite"}}catch(n){if(n instanceof C)r.warn(`${$} needs an interactive terminal to run.`),await G({message:"Continue scaffolding with default options?",default:!0})||(r.info("Exiting..."),process.exit(0)),r.info(`Scaffolding default tnt app in ./${e.appName}`);else throw n}return e}import it from"path";import he from"chalk";import nt from"ora";function be(e){let{packages:o}=e;r.info("Adding boilerplate...");for(let[s,n]of Object.entries(o))if(n.inUse){let t=nt(`Boilerplating ${s}...`).start();n.installer(e),t.succeed(he.green(`${he.green.bold(s)}`))}r.info("")}import B from"path";import{confirm as at,select as ot}from"@inquirer/prompts";import S from"chalk";import T from"fs-extra";import st from"ora";async function ve({projectName:e,projectDir:o,pkgManager:s,noInstall:n}){let t=B.join(p,"template/base");n?r.info(""):r.info(`
|
49
49
|
Using: ${S.cyan.bold(s)}
|
50
50
|
`);let a=st(`Scaffolding in: ${o}...
|
51
|
-
`).start();if(
|
51
|
+
`).start();if(T.existsSync(o))if(T.readdirSync(o).length===0)e!=="."&&a.info(`${S.cyan.bold(e)} exists but is empty, continuing...
|
52
52
|
`);else{a.stopAndPersist();let l=await ot({message:`${S.redBright.bold("Warning:")} ${S.cyan.bold(e)} already exists and isn't empty. How would you like to proceed?`,choices:[{value:"abort",name:"Abort installation (recommended)"},{value:"clear",name:"Clear the directory and continue installation"},{value:"overwrite",name:"Continue installation and overwrite conflicting files"}],default:"abort"});l==="abort"&&(a.fail("Aborting installation..."),process.exit(1)),await at({message:`Are you sure you want to ${l==="clear"?"clear the directory":"overwrite conflicting files"}`,default:!1})||(a.fail("Aborting installation..."),process.exit(1)),l==="clear"&&(a.info(`Emptying ${S.cyan.bold(e)} and creating tnt app...
|
53
|
-
`),
|
53
|
+
`),T.emptyDirSync(o))}a.start(),T.copySync(t,o),T.renameSync(B.join(o,"_gitignore"),B.join(o,".gitignore"));let i=e==="."?"App":S.cyan.bold(e);a.succeed(`${i} ${S.green.bold("scaffolded successfully!")}
|
54
54
|
`)}import v from"path";import W from"fs-extra";function ke({packages:e,projectDir:o}){let s=v.join(p,"template/packages/src/app/layout"),n=e.payload.inUse,t="base.tsx";n&&(t="with-payload.tsx");let a=v.join(s,t),i=v.join(o,`src/app/${n?"(frontend)":""}/layout.tsx`);W.copySync(a,i)}function we({packages:e,projectDir:o}){let s=v.join(p,"template/packages/src/app/page"),n=e.payload.inUse,t="base.tsx";n&&(t="with-payload.tsx");let a=v.join(s,t),i=v.join(o,`src/app/${n?"(frontend)":""}/page.tsx`);W.copySync(a,i)}function _e({packages:e,projectDir:o}){let s=v.join(p,"template/packages/src/app/globals"),n=e.payload.inUse,t="base.css";n&&(t="with-payload.css");let a=v.join(s,t),i=v.join(o,`src/app/${n?"(frontend)":""}/globals.css`);W.copySync(a,i)}async function xe({projectName:e,scopedAppName:o,packages:s,noInstall:n,databaseProvider:t}){let a=y(),i=it.resolve(process.cwd(),e);return await ve({projectName:e,projectDir:i,pkgManager:a,scopedAppName:o,noInstall:n,databaseProvider:t}),be({projectName:e,scopedAppName:o,projectDir:i,pkgManager:a,packages:s,noInstall:n,databaseProvider:t}),ke({packages:s,projectDir:i}),we({packages:s,projectDir:i}),_e({packages:s,projectDir:i}),i}import{execSync as z}from"child_process";import V from"path";import{confirm as Pe}from"@inquirer/prompts";import O from"chalk";import{execa as D}from"execa";import Se from"fs-extra";import rt from"ora";function lt(e){try{return z("git --version",{cwd:e}),!0}catch{return!1}}function K(e){return Se.existsSync(V.join(e,".git"))}async function H(e){try{return await D("git",["rev-parse","--is-inside-work-tree"],{cwd:e,stdout:"ignore"}),!0}catch{return!1}}function pt(){let o=z("git --version").toString().trim().split(" ")[2],s=o?.split(".")[0],n=o?.split(".")[1];return{major:Number(s),minor:Number(n)}}function ct(){return z("git config --global init.defaultBranch || echo main").toString().trim()}async function Ae(e){if(r.info("Initializing Git..."),!lt(e)){r.warn("Git is not installed. Skipping Git initialization.");return}let o=rt(`Creating a new git repo...
|
55
55
|
`).start(),s=K(e),n=await H(e),t=V.parse(e).name;if(n&&s){if(o.stop(),!await Pe({message:`${O.redBright.bold("Warning:")} Git is already initialized in "${t}". Initializing a new git repository would delete the previous history. Would you like to continue anyways?`,default:!1})){o.info("Skipping Git initialization.");return}Se.removeSync(V.join(e,".git"))}else if(n&&!s&&(o.stop(),!await Pe({message:`${O.redBright.bold("Warning:")} "${t}" is already in a git worktree. Would you still like to initialize a new git repository in this directory?`,default:!1}))){o.info("Skipping Git initialization.");return}try{let a=ct(),{major:i,minor:l}=pt();i<2||i==2&&l<28?(await D("git",["init"],{cwd:e}),await D("git",["symbolic-ref","HEAD",`refs/heads/${a}`],{cwd:e})):await D("git",["init",`--initial-branch=${a}`],{cwd:e}),await D("git",["add","."],{cwd:e}),o.succeed(`${O.green("Successfully initialized and staged")} ${O.green.bold("git")}
|
56
56
|
`)}catch{o.fail(`${O.bold.red("Failed:")} could not initialize git. Update git to the latest version!
|
57
|
-
`)}}import mt from"chalk";import{execa as Ie}from"execa";import Ce from"ora";var Y=async(e,o,s)=>{let{onDataHandle:n,args:t=["install"],stdout:a="pipe"}=s,i=Ce(`Running ${o} install...`).start(),l=Ie(o,t,{cwd:e,stdout:a});return await new Promise((m,f)=>{n&&l.stdout?.on("data",n(i)),l.on("error",g=>f(g)),l.on("close",()=>m())}),i},dt=async(e,o)=>{switch(e){case"npm":return await Ie(e,["install"],{cwd:o,stderr:"inherit"}),null;case"pnpm":return Y(o,e,{onDataHandle:s=>n=>{let t=n.toString();t.includes("Progress")&&(s.text=t.includes("|")?t.split(" | ")[1]??"":t)}});case"yarn":return Y(o,e,{onDataHandle:s=>n=>{s.text=n.toString()}});case"bun":return Y(o,e,{stdout:"ignore"})}},
|
58
|
-
`))};var
|
57
|
+
`)}}import mt from"chalk";import{execa as Ie}from"execa";import Ce from"ora";var Y=async(e,o,s)=>{let{onDataHandle:n,args:t=["install"],stdout:a="pipe"}=s,i=Ce(`Running ${o} install...`).start(),l=Ie(o,t,{cwd:e,stdout:a});return await new Promise((m,f)=>{n&&l.stdout?.on("data",n(i)),l.on("error",g=>f(g)),l.on("close",()=>m())}),i},dt=async(e,o)=>{switch(e){case"npm":return await Ie(e,["install"],{cwd:o,stderr:"inherit"}),null;case"pnpm":return Y(o,e,{onDataHandle:s=>n=>{let t=n.toString();t.includes("Progress")&&(s.text=t.includes("|")?t.split(" | ")[1]??"":t)}});case"yarn":return Y(o,e,{onDataHandle:s=>n=>{s.text=n.toString()}});case"bun":return Y(o,e,{stdout:"ignore"})}},je=async({projectDir:e})=>{r.info("Installing dependencies...");let o=y();(await dt(o,e)??Ce()).succeed(mt.green(`Successfully installed dependencies!
|
58
|
+
`))};var Te=async({projectName:e=I,packages:o,noInstall:s,projectDir:n,databaseProvider:t})=>{let a=y();r.info("Next steps:"),e!=="."&&r.info(` cd ${e}`),s&&(a==="yarn"?r.info(` ${a}`):r.info(` ${a} install`)),["postgresql","mysql"].includes(t)&&r.info(" Add your database connection string to .env"),o?.nextAuth.inUse&&r.info(" Fill in your .env with necessary values. See https://create.tntstack.org/usage/first-steps for more info."),["npm"].includes(a)?r.info(` ${a} run dev`):r.info(` ${a} dev`),!await H(n)&&!K(n)&&r.info(" git init"),r.info(' git commit -m "initial commit"')};import U from"fs";import ft from"path";function Oe(e,o,s){U.readdirSync(e).forEach(t=>{let a=ft.join(e,t);if(U.statSync(a).isDirectory())Oe(a,o,s);else{let l=U.readFileSync(a,"utf8").replace(new RegExp(o,"g"),s);U.writeFileSync(a,l,"utf8")}})}function De(e,o){let s=o.replace(/\*/g,"").replace(/[^\/]$/,"$&/");Oe(e,"@/",s)}import Ee from"path";function Me(e){let s=N(e).split("/"),n=s[s.length-1];if(n==="."){let i=Ee.resolve(process.cwd());n=Ee.basename(i)}let t=s.findIndex(i=>i.startsWith("@"));s.findIndex(i=>i.startsWith("@"))!==-1&&(n=s.slice(t).join("/"));let a=s.filter(i=>!i.startsWith("@")).join("/");return[n,a]}import gt from"gradient-string";var ut={magenta:"#765bc8",pink:"#a48897",yellow:"#c7b561",green:"#8bb8a0",blue:"#4b97d5",cyan:"#22b6d2"};function Re(){let e=gt(Object.values(ut)),o=y();(o==="yarn"||o==="pnpm")&&console.log(""),console.log(e.multiline(Z))}import{execSync as yt}from"child_process";import ht from"https";function Ne(e){let o=A();o.includes("beta")?(r.warn(" You are using a beta version of create-tnt-stack."),r.warn(" Please report any bugs you encounter.")):o!==e&&(r.warn(" You are using an outdated version of create-tnt-stack."),r.warn(" Your version:",o+".","Latest version in the npm registry:",e),r.warn(" Please run the CLI with @latest to get the latest updates.")),console.log("")}function bt(){return new Promise((e,o)=>{ht.get("https://registry.npmjs.org/-/package/tnt-stack/dist-tags",s=>{if(s.statusCode===200){let n="";s.on("data",t=>n+=t),s.on("end",()=>{e(JSON.parse(n).latest)})}else o()}).on("error",()=>{o()})})}var Ge=()=>bt().catch(()=>{try{return yt("npm view create-tnt-stack version").toString().trim()}catch{return null}});async function kt(){let e=await Ge(),o=y();Re(),e&&Ne(e);let{appName:s,packages:n,flags:{noGit:t,noInstall:a,importAlias:i},databaseProvider:l}=await ye(),m=de(n),[f,g]=Me(s),c=await xe({projectName:g,scopedAppName:f,packages:m,noInstall:a,databaseProvider:l}),h=$e.readJsonSync(Ue.join(c,"package.json"));h.name=f,h.ctntaMetadata={initVersion:A()};let{stdout:x}=await vt(o,["-v"],{cwd:c});h.packageManager=`${o}@${x.trim()}`,$e.writeJSONSync(Ue.join(c,"package.json"),h,{spaces:2}),i!=="@/"&&De(c,i),a||await je({projectDir:c}),t||await Ae(c),await Te({projectDir:c,projectName:g,packages:m,noInstall:a,databaseProvider:l}),process.exit(0)}kt().catch(e=>{r.error("Aborting installation..."),e instanceof Error?r.error(e.message):(r.error("An unknown error occurred. Please open an issue on GitHub with the below:"),console.error(e)),process.exit(1)});
|
package/package.json
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
import { createEnv } from "@t3-oss/env-nextjs"
|
2
|
+
import { z } from "zod"
|
3
|
+
|
4
|
+
export const env = createEnv({
|
5
|
+
/**
|
6
|
+
* Specify your server-side environment variables schema here. This way you can ensure the app
|
7
|
+
* isn't built with invalid env vars.
|
8
|
+
*/
|
9
|
+
server: {
|
10
|
+
NODE_ENV: z.enum(["development", "test", "production"]),
|
11
|
+
},
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Specify your client-side environment variables schema here. This way you can ensure the app
|
15
|
+
* isn't built with invalid env vars. To expose them to the client, prefix them with
|
16
|
+
* `NEXT_PUBLIC_`.
|
17
|
+
*/
|
18
|
+
client: {
|
19
|
+
// NEXT_PUBLIC_CLIENTVAR: z.string(),
|
20
|
+
},
|
21
|
+
|
22
|
+
/**
|
23
|
+
* You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g.
|
24
|
+
* middlewares) or client-side so we need to destruct manually.
|
25
|
+
*/
|
26
|
+
runtimeEnv: {
|
27
|
+
NODE_ENV: process.env.NODE_ENV,
|
28
|
+
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
|
29
|
+
},
|
30
|
+
/**
|
31
|
+
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially
|
32
|
+
* useful for Docker builds.
|
33
|
+
*/
|
34
|
+
skipValidation: !!process.env.SKIP_ENV_VALIDATION,
|
35
|
+
/**
|
36
|
+
* Makes it so that empty strings are treated as undefined. `SOME_VAR: z.string()` and
|
37
|
+
* `SOME_VAR=''` will throw an error.
|
38
|
+
*/
|
39
|
+
emptyStringAsUndefined: true,
|
40
|
+
})
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import { createEnv } from "@t3-oss/env-nextjs"
|
2
|
+
import { z } from "zod"
|
3
|
+
|
4
|
+
export const env = createEnv({
|
5
|
+
/**
|
6
|
+
* Specify your server-side environment variables schema here. This way you can ensure the app
|
7
|
+
* isn't built with invalid env vars.
|
8
|
+
*/
|
9
|
+
server: {
|
10
|
+
PAYLOAD_SECRET: z.string().min(32),
|
11
|
+
DATABASE_URL: z.string().url(),
|
12
|
+
NODE_ENV: z
|
13
|
+
.enum(["development", "test", "production"])
|
14
|
+
.default("development"),
|
15
|
+
},
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Specify your client-side environment variables schema here. This way you can ensure the app
|
19
|
+
* isn't built with invalid env vars. To expose them to the client, prefix them with
|
20
|
+
* `NEXT_PUBLIC_`.
|
21
|
+
*/
|
22
|
+
client: {
|
23
|
+
// NEXT_PUBLIC_CLIENTVAR: z.string(),
|
24
|
+
},
|
25
|
+
|
26
|
+
/**
|
27
|
+
* You can't destruct `process.env` as a regular object in the Next.js edge runtimes (e.g.
|
28
|
+
* middlewares) or client-side so we need to destruct manually.
|
29
|
+
*/
|
30
|
+
runtimeEnv: {
|
31
|
+
PAYLOAD_SECRET: process.env.PAYLOAD_SECRET,
|
32
|
+
DATABASE_URL: process.env.DATABASE_URL,
|
33
|
+
NODE_ENV: process.env.NODE_ENV,
|
34
|
+
// NEXT_PUBLIC_CLIENTVAR: process.env.NEXT_PUBLIC_CLIENTVAR,
|
35
|
+
},
|
36
|
+
/**
|
37
|
+
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially
|
38
|
+
* useful for Docker builds.
|
39
|
+
*/
|
40
|
+
skipValidation: !!process.env.SKIP_ENV_VALIDATION,
|
41
|
+
/**
|
42
|
+
* Makes it so that empty strings are treated as undefined. `SOME_VAR: z.string()` and
|
43
|
+
* `SOME_VAR=''` will throw an error.
|
44
|
+
*/
|
45
|
+
emptyStringAsUndefined: true,
|
46
|
+
})
|