create-tnt-stack 0.1.3 → 0.2.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.
Files changed (2) hide show
  1. package/dist/index.js +44 -44
  2. package/package.json +2 -4
package/dist/index.js CHANGED
@@ -1,53 +1,53 @@
1
1
  #!/usr/bin/env node
2
- import we from"path";import{execa as Qe}from"execa";import ke from"fs-extra";import*as p from"@clack/prompts";import{Command as De}from"commander";import B from"path";import{fileURLToPath as Ae}from"url";var Ie=Ae(import.meta.url),Se=B.dirname(Ie),u=B.join(Se,"../"),F=` ___ ___ ___ _ _____ ___ _____ _ _ _____ ___ _____ _ ___ _ __
2
+ import ke from"path";import{execa as Ze}from"execa";import Pe from"fs-extra";import{confirm as G,input as ne,select as $}from"@inquirer/prompts";import{Command as je}from"commander";import z from"path";import{fileURLToPath as Ie}from"url";var Se=Ie(import.meta.url),Te=z.dirname(Se),g=z.join(Te,"../"),B=` ___ ___ ___ _ _____ ___ _____ _ _ _____ ___ _____ _ ___ _ __
3
3
  / __| _ \\ __| /_\\_ _| __| |_ _| \\| |_ _| / __|_ _/_\\ / __| |/ /
4
4
  | (__| / _| / _ \\| | | _| | | | .\` | | | \\__ \\ | |/ _ \\ (__| ' <
5
5
  \\___|_|_\\___/_/ \\_\\_| |___| |_| |_|\\_| |_| |___/ |_/_/ \\_\\___|_|\\_\\
6
- `,h="my-tnt-stack",$="create-tnt-stack";import Te from"node:crypto";import E from"path";import j from"fs-extra";var H=({projectDir:e,packages:t,scopedAppName:n,databaseProvider:a})=>{let i=t?.nextAuth.inUse,o=t?.prisma.inUse,r=o,l=Ce(!!i,!!o,n,a),c="";if(r?i?c="with-next-auth-db.js":c="with-db.js":i&&(c="with-next-auth.js"),c!==""){let xe=E.join(u,"template/packages/src/env",c),Pe=E.join(e,"src/env.js");j.copyFileSync(xe,Pe)}let d=E.join(e,".env"),m=E.join(e,".env.example"),g=Ee+l,k=Buffer.from(Te.getRandomValues(new Uint8Array(32))).toString("base64"),D=l.replace('AUTH_SECRET=""',`AUTH_SECRET="${k}" # Generated by create-tnt-stack`);j.writeFileSync(d,D,"utf-8"),j.writeFileSync(m,g,"utf-8")};function Ce(e,t,n,a){let i=`
7
- # When adding additional environment variables, the schema in "/src/env.js"
8
- # should be updated accordingly.
9
- `.trim().concat(`
10
- `);return t&&(i+=`
11
- # Prisma
12
- # https://www.prisma.io/docs/reference/database-reference/connection-urls#env
13
- `),t&&(a==="mysql"?i+=`DATABASE_URL="mysql://root:password@localhost:3306/${n}"`:a==="postgresql"?i+=`DATABASE_URL="postgresql://postgres:password@localhost:5432/${n}"`:a==="sqlite"&&(i+='DATABASE_URL="file:./db.sqlite"'),i+=`
14
- `),e&&(i+=`
15
- # Next Auth
16
- # You can generate a new secret on the command line with:
17
- # npx auth secret
18
- # https://next-auth.js.org/configuration/options#secret
19
- AUTH_SECRET=""
6
+ `,k="my-tnt-stack",R="create-tnt-stack";import T from"path";import j from"fs-extra";var F=({projectDir:e,scopedAppName:t,packages:a,databaseProvider:i})=>{let n=a?.nextAuth.inUse,o=a?.prisma.inUse,r=o,l=Ce(!!n,!!o,t,i),c="";if(r?n?c="with-next-auth-db.js":c="with-db.js":n&&(c="with-next-auth.js"),c!==""){let xe=T.join(g,"template/packages/src/env",c),Ae=T.join(e,"src/env.js");j.copyFileSync(xe,Ae)}let d=T.join(e,".env"),p=T.join(e,".env.example"),f=Ee+l,b=Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("base64"),M=l.replace('AUTH_SECRET=""',`AUTH_SECRET="${b}" # Generated by create-tnt-stack`);j.writeFileSync(d,M,"utf-8"),j.writeFileSync(p,f,"utf-8")};function Ce(e,t,a,i){let n=`
7
+ # When adding additional environment variables, the schema in "/src/env.js"
8
+ # should be updated accordingly.
9
+ `.trim().concat(`
10
+ `);return t&&(n+=`
11
+ # Prisma
12
+ # https://www.prisma.io/docs/reference/database-reference/connection-urls#env
13
+ `),t&&(i==="mysql"?n+=`DATABASE_URL="mysql://root:password@localhost:3306/${a}"`:i==="postgresql"?n+=`DATABASE_URL="postgresql://postgres:password@localhost:5432/${a}"`:i==="sqlite"&&(n+='DATABASE_URL="file:./db.sqlite"'),n+=`
14
+ `),e&&(n+=`
15
+ # Next Auth
16
+ # You can generate a new secret on the command line with:
17
+ # npx auth secret
18
+ # https://next-auth.js.org/configuration/options#secret
19
+ AUTH_SECRET=""
20
20
 
21
- # Next Auth Discord Provider
22
- AUTH_DISCORD_ID=""
23
- AUTH_DISCORD_SECRET=""
24
- `),!e&&!t&&(i+=`
25
- # Example:
26
- # SERVERVAR="foo"
27
- # NEXT_PUBLIC_CLIENTVAR="bar"
28
- `),i}var Ee=`
29
- # Since the ".env" file is gitignored, you can use the ".env.example" file to
30
- # build a new ".env" file when you clone the repo. Keep this file up-to-date
31
- # when you add new variables to \`.env\`.
21
+ # Next Auth Discord Provider
22
+ AUTH_DISCORD_ID=""
23
+ AUTH_DISCORD_SECRET=""
24
+ `),!e&&!t&&(n+=`
25
+ # Example:
26
+ # SERVERVAR="foo"
27
+ # NEXT_PUBLIC_CLIENTVAR="bar"
28
+ `),n}var Ee=`
29
+ # Since the ".env" file is gitignored, you can use the ".env.example" file to
30
+ # build a new ".env" file when you clone the repo. Keep this file up-to-date
31
+ # when you add new variables to \`.env\`.
32
32
 
33
- # This file will be committed to version control, so make sure not to have any
34
- # secrets in it. If you are cloning this repo, create a copy of this file named
35
- # ".env" and populate it with your secrets.
36
- `.trim().concat(`
33
+ # This file will be committed to version control, so make sure not to have any
34
+ # secrets in it. If you are cloning this repo, create a copy of this file named
35
+ # ".env" and populate it with your secrets.
36
+ `.trim().concat(`
37
37
 
38
- `);import y from"path";import G from"fs-extra";import Y from"path";import Q from"fs-extra";import Ne from"sort-package-json";var K={"next-auth":"^4.24.11","@auth/prisma-adapter":"^2.8.0",prisma:"^6.4.1","@prisma/client":"^6.4.1"};var A=e=>{let{dependencies:t,devMode:n,projectDir:a}=e,i=Q.readJsonSync(Y.join(a,"package.json"));t.forEach(r=>{let l=K[r];n&&i.devDependencies?i.devDependencies[r]=l:i.dependencies&&(i.dependencies[r]=l)});let o=Ne(i);Q.writeJsonSync(Y.join(a,"package.json"),o,{spaces:2})};var X=({projectDir:e,packages:t})=>{let n=t?.prisma.inUse,a=["next-auth"];n&&a.push("@auth/prisma-adapter"),A({projectDir:e,dependencies:a,devMode:!1});let i=y.join(u,"template/packages"),o="src/app/api/auth/[...nextauth]/route.ts",r=y.join(i,o),l=y.join(e,o),c=y.join(i,"src/server/auth/config",n?"next-auth-with-prisma.ts":"next-auth.ts"),d=y.join(e,"src/server/auth/config.ts"),m=y.join(i,"src/server/auth/next-auth.ts"),g=y.join(e,"src/server/auth/index.ts");G.copySync(r,l),G.copySync(c,d),G.copySync(m,g)};import b from"path";import x from"fs-extra";var Z=({projectDir:e,packages:t,databaseProvider:n})=>{A({projectDir:e,dependencies:["prisma"],devMode:!0}),A({projectDir:e,dependencies:["@prisma/client"],devMode:!1});let a=b.join(u,"template/packages"),i=b.join(a,"prisma/schema",`${t?.nextAuth.inUse?"with-next-auth":"base"}.prisma`),o=x.readFileSync(i,"utf-8");n!=="sqlite"&&(o=o.replace('provider = "sqlite"',`provider = "${{mysql:"mysql",postgresql:"postgresql"}[n]}"`),["mysql"].includes(n)&&(o=o.replace("// @db.Text","@db.Text")));let r=b.join(e,"prisma/schema.prisma");x.mkdirSync(b.dirname(r),{recursive:!0}),x.writeFileSync(r,o);let l=b.join(a,"src/server/db/db-prisma.ts"),c=b.join(e,"src/server/db/index.ts"),d=b.join(e,"package.json"),m=x.readJSONSync(d);m.scripts={...m.scripts,postinstall:"prisma generate","db:push":"prisma db push","db:studio":"prisma studio","db:generate":"prisma migrate dev","db:migrate":"prisma migrate deploy"},x.copy(l,c),x.writeJSONSync(d,m,{spaces:2})};var N=["sqlite","mysql","postgresql"],ee=e=>({nextAuth:{inUse:e.includes("nextAuth"),installer:X},prisma:{inUse:e.includes("prisma"),installer:Z},envVariables:{inUse:!0,installer:H}});import Oe from"path";import Me from"fs-extra";function P(){let e=Oe.join(u,"package.json");return Me.readJSONSync(e).version??"1.0.0"}var f=()=>{let e=process.env.npm_config_user_agent;return e?e.startsWith("yarn")?"yarn":e.startsWith("pnpm")?"pnpm":e.startsWith("bun")?"bun":"npm":"npm"};var I=class extends Error{constructor(t){super(t)}};import O from"chalk";var s={error(...e){console.log(O.red(...e))},warn(...e){console.log(O.yellow(...e))},info(...e){console.log(O.cyan(...e))},success(...e){console.log(O.green(...e))}};var M=e=>(e.length>1&&e.endsWith("/")&&(e=e.slice(0,-1)),e);var Re=/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;function te(e){let t=M(e),n=t.split("/"),a=n.findIndex(o=>o.startsWith("@")),i=n[n.length-1];if(n.findIndex(o=>o.startsWith("@"))!==-1&&(i=n.slice(a).join("/")),!(t=="."||Re.test(i??"")))return"App name must consist of only lowercase alphanumeric characters, '-', and '_'"}var ne=e=>{if(e.startsWith(".")||e.startsWith("/"))return"Import alias can't start with '.' or '/'"};var v={appName:h,packages:["prisma"],flags:{noGit:!1,noInstall:!1,default:!1,CI:!1,prisma:!1,nextAuth:!1,importAlias:"@/",dbProvider:"sqlite"},databaseProvider:"sqlite"};async function ae(){let e=v,t=new De().name($).description("CLI for scaffolding new web apps with the TNT-Powered stack").version(P(),"-v, --version","Display the version number").argument("[dir]","The name of the application, as well as the name of the directory to create").option("--noGit","Explicitly tell the CLI to not initialize a new git repo in the project",!1).option("--noInstall","Explicitly tell the CLI to not run the package manager's install command",!1).option("-y, --default","Bypass the CLI and use all default options to bootstrap a new tnt-stack",!1).option("--CI","Boolean value if we're running in CI",!1).option("--nextAuth [boolean]","Experimental: Boolean value if we should install NextAuth.js. Must be used in conjunction with `--CI`.",a=>!!a&&a!=="false").option("--prisma [boolean]","Experimental: Boolean value if we should install Prisma. Must be used in conjunction with `--CI`.",a=>!!a&&a!=="false").option("-i, --import-alias","Explicitly tell the CLI to use a custom import alias",v.flags.importAlias).option("--dbProvider [provider]",`Choose a database provider to use. Possible values: ${N.join(", ")}`,v.flags.dbProvider).parse(process.argv);process.env.npm_config_user_agent?.startsWith("yarn/3")&&s.warn(` WARNING: It looks like you are using Yarn 3. This is currently not supported,
38
+ `);import y from"path";import D from"fs-extra";import K from"path";import Y from"fs-extra";import Ne from"sort-package-json";var H={"next-auth":"^4.24.11","@auth/prisma-adapter":"^2.8.0",prisma:"^6.5.0","@prisma/client":"^6.5.0"};var P=e=>{let{dependencies:t,devMode:a,projectDir:i}=e,n=Y.readJsonSync(K.join(i,"package.json"));t.forEach(r=>{let l=H[r];a&&n.devDependencies?n.devDependencies[r]=l:n.dependencies&&(n.dependencies[r]=l)});let o=Ne(n);Y.writeJsonSync(K.join(i,"package.json"),o,{spaces:2})};var Q=({projectDir:e,packages:t})=>{let a=t?.prisma.inUse,i=["next-auth"];a&&i.push("@auth/prisma-adapter"),P({projectDir:e,dependencies:i,devMode:!1});let n=y.join(g,"template/packages"),o="src/app/api/auth/[...nextauth]/route.ts",r=y.join(n,o),l=y.join(e,o),c=y.join(n,"src/server/auth/config",a?"next-auth-with-prisma.ts":"next-auth.ts"),d=y.join(e,"src/server/auth/config.ts"),p=y.join(n,"src/server/auth/next-auth.ts"),f=y.join(e,"src/server/auth/index.ts");D.copySync(r,l),D.copySync(c,d),D.copySync(p,f)};import u from"path";import h from"fs-extra";var X=({projectDir:e,packages:t,databaseProvider:a})=>{P({projectDir:e,dependencies:["prisma"],devMode:!0}),P({projectDir:e,dependencies:["@prisma/client"],devMode:!1});let i=u.join(g,"template/packages"),n=u.join(i,"prisma/schema",`${t?.nextAuth.inUse?"with-next-auth":"base"}.prisma`),o=h.readFileSync(n,"utf-8");a!=="sqlite"&&(o=o.replace('provider = "sqlite"',`provider = "${{mysql:"mysql",postgresql:"postgresql"}[a]}"`),["mysql"].includes(a)&&(o=o.replace("// @db.Text","@db.Text")));let r=u.join(e,"prisma/schema.prisma");h.mkdirSync(u.dirname(r),{recursive:!0}),h.writeFileSync(r,o);let l=u.join(i,"src/server/db/db-prisma.ts"),c=u.join(e,"src/server/db/index.ts");h.mkdirSync(u.dirname(c),{recursive:!0}),h.writeFileSync(c,h.readFileSync(l,"utf-8"));let d=u.join(e,"package.json"),p=h.readJSONSync(d);p.scripts={...p.scripts,postinstall:"prisma generate","db:push":"prisma db push","db:studio":"prisma studio","db:generate":"prisma migrate dev","db:migrate":"prisma migrate deploy"},h.writeJSONSync(d,p,{spaces:2})};var C=["sqlite","mysql","postgresql"],Z=e=>({nextAuth:{inUse:e.includes("nextAuth"),installer:Q},prisma:{inUse:e.includes("prisma"),installer:X},envVariables:{inUse:!0,installer:F}});import Oe from"path";import Me from"fs-extra";function _(){let e=Oe.join(g,"package.json");return Me.readJSONSync(e).version??"1.0.0"}var m=()=>{let e=process.env.npm_config_user_agent;return e?e.startsWith("yarn")?"yarn":e.startsWith("pnpm")?"pnpm":e.startsWith("bun")?"bun":"npm":"npm"};var x=class extends Error{constructor(t){super(t)}};import E from"chalk";var s={error(...e){console.log(E.red(...e))},warn(...e){console.log(E.yellow(...e))},info(...e){console.log(E.cyan(...e))},success(...e){console.log(E.green(...e))}};var N=e=>(e.length>1&&e.endsWith("/")&&(e=e.slice(0,-1)),e);var Re=/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;function ee(e){let t=N(e),a=t.split("/"),i=a.findIndex(o=>o.startsWith("@")),n=a[a.length-1];return a.findIndex(o=>o.startsWith("@"))!==-1&&(n=a.slice(i).join("/")),t=="."||Re.test(n??"")?!0:"App name must consist of only lowercase alphanumeric characters, '-', and '_'"}var te=e=>e.startsWith(".")||e.startsWith("/")?"Import alias can't start with '.' or '/'":!0;var w={appName:k,packages:[],flags:{noGit:!1,noInstall:!1,default:!1,CI:!1,nextAuth:!1,prisma:!1,importAlias:"@/",dbProvider:"sqlite"},databaseProvider:"sqlite"};async function ae(){let e=w,t=new je().name(R).description("CLI for scaffolding new web apps with the TNT-Powered stack").version(_(),"-v, --version","Output the current version of TNT").argument("[dir]","The name of the application, as well as the name of the directory to create").option("--noGit","Explicitly tell the CLI to not initialize a new git repo in the project",!1).option("--noInstall","Explicitly tell the CLI to not run the package manager's install command",!1).option("-y, --default","Bypass the CLI and use all default options to bootstrap a new tnt-stack",!1).option("--CI","Boolean value if we're running in CI",!1).option("--nextAuth [boolean]","Experimental: Boolean value if we should install NextAuth.js. Must be used in conjunction with `--CI`.",i=>!!i&&i!=="false").option("--prisma [boolean]","Experimental: Boolean value if we should install Prisma. Must be used in conjunction with `--CI`.",i=>!!i&&i!=="false").option("-i, --import-alias [alias]","Explicitly tell the CLI to use a custom import alias",w.flags.importAlias).option("--dbProvider [provider]",`Choose a database provider to use. Possible values: ${C.join(", ")}`,w.flags.dbProvider).parse(process.argv);process.env.npm_config_user_agent?.startsWith("yarn/3")&&s.warn(` WARNING: It looks like you are using Yarn 3. This is currently not supported,
39
39
  and likely to result in a crash. Please run create-tnt-stack with another
40
40
  package manager such as pnpm, npm, or Yarn Classic.
41
- See: https://github.com/t3-oss/create-t3-app/issues/57`);let n=t.args[0];if(n&&(e.appName=n),e.flags=t.opts(),e.flags.CI)return e.flags.nextAuth&&e.packages.push("nextAuth"),e.flags.prisma&&e.packages.push("prisma"),N.includes(e.flags.dbProvider)===!1&&(s.warn(`Incompatible database provided. Use: ${N.join(", ")}. Exiting.`),process.exit(0)),e.databaseProvider=e.packages.includes("prisma")?e.flags.dbProvider:"sqlite",e;if(e.flags.default)return e;try{if(process.env.TERM_PROGRAM?.toLowerCase().includes("mintty"))throw s.warn(` WARNING: It looks like you are using MinTTY, which is non-interactive. This is most likely because you are
42
- using Git Bash. If that's that case, please use Git Bash from another terminal, such as Windows Terminal. Alternatively, you
43
- can provide the arguments from the CLI directly: https://create.tntstack.org/installation#experimental-usage to skip the prompts.`),new I("Non-interactive environment");let a=f(),i=await p.group({...!n&&{name:()=>p.text({message:`What will your project be called? (e.g. ${h})`,defaultValue:n||h,validate:r=>te(r||h)})},authentication:()=>p.select({message:"What authentication provider would you like to use?",options:[{value:"none",label:"None"},{value:"nextAuth",label:"NextAuth.js"},{value:"lucia",label:"Lucia Auth (not a library)"}],initialValue:"none"}),database:()=>p.select({message:"What database ORM would you like to use?",options:[{value:"none",label:"None"},{value:"prisma",label:"Prisma"}],initialValue:"none"}),databaseProvider:({results:r})=>{if(r.database!=="none")return p.select({message:"",options:[{value:"sqlite",label:"SQLite (LibSQL)"},{value:"mysql",label:"MySQL"},{value:"postgresql",label:"PostgreSQL"}],initialValue:"sqlite"})},...!e.flags.noGit&&{git:()=>p.confirm({message:"Should be initialize a new Git repository and stage the changes?",initialValue:!v.flags.noGit})},...!e.flags.noInstall&&{install:()=>p.confirm({message:`Should we run '${a}`+(a==="yarn"?"'?":" install' for you?"),initialValue:!v.flags.noInstall})},importAlias:()=>p.text({message:"What import alias would you like to use?",defaultValue:v.flags.importAlias,placeholder:v.flags.importAlias,validate:ne})},{onCancel(){process.exit(1)}}),o=[];return i.authentication==="nextAuth"&&o.push("nextAuth"),i.database==="prisma"&&o.push("prisma"),{appName:i.name??e.appName,packages:o,databaseProvider:i.databaseProvider||"sqlite",flags:{...e.flags,noGit:!i.git||e.flags.noGit,noInstall:!i.install||e.flags.noInstall,importAlias:i.importAlias??e.flags.importAlias}}}catch(a){if(a instanceof I)s.warn(`${$} needs an interactive terminal to run.`),await p.confirm({message:"Continue scaffolding with default options?",initialValue:!0})||(s.info("Exiting..."),process.exit(0)),s.info(`Scaffolding default tnt app in ./${e.appName}`);else throw a}return e}import Ge from"path";import ie from"chalk";import $e from"ora";function oe(e){let{packages:t}=e;s.info("Adding boilerplate...");for(let[n,a]of Object.entries(t))if(a.inUse){let i=$e(`Boilerplating ${n}...`).start();a.installer(e),i.succeed(ie.green(`Successfully setup boilerplate for ${ie.green.bold(n)}`))}s.info("")}import V from"path";import*as w from"@clack/prompts";import _ from"chalk";import S from"fs-extra";import je from"ora";async function se({projectName:e,projectDir:t,pkgManager:n,noInstall:a}){let i=V.join(u,"template/base");a?s.info(""):s.info(`
44
- Using: ${_.cyan.bold(n)}
45
- `);let o=je(`Scaffolding in: ${t}...
46
- `).start();if(S.existsSync(t))if(S.readdirSync(t).length===0)e!=="."&&o.info(`${_.cyan.bold(e)} exists but is empty, continuing...
47
- `);else{o.stopAndPersist();let l=await w.select({message:`${_.redBright.bold("Warning:")} ${_.cyan.bold(e)} already exists and isn't empty. How would you like to proceed?`,options:[{value:"abort",label:"Abort installation (recommended)"},{value:"clear",label:"Clear the directory and continue installation"},{value:"overwrite",label:"Continue installation and overwrite conflicting files"}],initialValue:"abort"});(w.isCancel(l)||l==="abort")&&(o.fail("Aborting installation..."),process.exit(1));let c=await w.confirm({message:`Are you sure you want to ${l==="clear"?"clear the directory":"overwrite conflicting files"}`,initialValue:!1});(w.isCancel(c)||!c)&&(o.fail("Aborting installation..."),process.exit(1)),l==="clear"&&(o.info(`Emptying ${_.cyan.bold(e)} and creating tnt app...
48
- `),S.emptyDirSync(t))}o.start(),S.copySync(i,t),S.renameSync(V.join(t,"_gitignore"),V.join(t,".gitignore"));let r=e==="."?"App":_.cyan.bold(e);o.succeed(`${r} ${_.green.bold("scaffolded successfully!")}
49
- `)}async function re({projectName:e,scopedAppName:t,packages:n,noInstall:a,databaseProvider:i}){let o=f(),r=Ge.resolve(process.cwd(),e);return await se({projectName:e,projectDir:r,pkgManager:o,scopedAppName:t,noInstall:a,databaseProvider:i}),oe({projectName:e,scopedAppName:t,projectDir:r,pkgManager:o,packages:n,noInstall:a,databaseProvider:i}),r}import{execSync as J}from"child_process";import U from"path";import*as W from"@clack/prompts";import T from"chalk";import{execa as C}from"execa";import le from"fs-extra";import Ve from"ora";function Ue(e){try{return J("git --version",{cwd:e}),!0}catch{return!1}}function L(e){return le.existsSync(U.join(e,".git"))}async function q(e){try{return await C("git",["rev-parse","--is-inside-work-tree"],{cwd:e,stdout:"ignore"}),!0}catch{return!1}}function We(){let t=J("git --version").toString().trim().split(" ")[2],n=t?.split(".")[0],a=t?.split(".")[1];return{major:Number(n),minor:Number(a)}}function Je(){return J("git config --global init.defaultBranch || echo main").toString().trim()}async function ce(e){if(s.info("Initializing Git..."),!Ue(e)){s.warn("Git is not installed. Skipping Git initialization.");return}let t=Ve(`Creating a new git repo...
50
- `).start(),n=L(e),a=await q(e),i=U.parse(e).name;if(a&&n){if(t.stop(),!await W.confirm({message:`${T.redBright.bold("Warning:")} Git is already initialized in "${i}". Initializing a new git repository would delete the previous history. Would you like to continue anyways?`,initialValue:!1})){t.info("Skipping Git initialization.");return}le.removeSync(U.join(e,".git"))}else if(a&&!n&&(t.stop(),!await W.confirm({message:`${T.redBright.bold("Warning:")} "${i}" is already in a git worktree. Would you still like to initialize a new git repository in this directory?`,initialValue:!1}))){t.info("Skipping Git initialization.");return}try{let o=Je(),{major:r,minor:l}=We();r<2||r==2&&l<28?(await C("git",["init"],{cwd:e}),await C("git",["symbolic-ref","HEAD",`refs/heads/${o}`],{cwd:e})):await C("git",["init",`--initial-branch=${o}`],{cwd:e}),await C("git",["add","."],{cwd:e}),t.succeed(`${T.green("Successfully initialized and staged")} ${T.green.bold("git")}
51
- `)}catch{t.fail(`${T.bold.red("Failed:")} could not initialize git. Update git to the latest version!
52
- `)}}import Le from"chalk";import{execa as pe}from"execa";import me from"ora";var z=async(e,t,n)=>{let{onDataHandle:a,args:i=["install"],stdout:o="pipe"}=n,r=me(`Running ${t} install...`).start(),l=pe(t,i,{cwd:e,stdout:o});return await new Promise((c,d)=>{a&&l.stdout?.on("data",a(r)),l.on("error",m=>d(m)),l.on("close",()=>c())}),r},qe=async(e,t)=>{switch(e){case"npm":return await pe(e,["install"],{cwd:t,stderr:"inherit"}),null;case"pnpm":return z(t,e,{onDataHandle:n=>a=>{let i=a.toString();i.includes("Progress")&&(n.text=i.includes("|")?i.split(" | ")[1]??"":i)}});case"yarn":return z(t,e,{onDataHandle:n=>a=>{n.text=a.toString()}});case"bun":return z(t,e,{stdout:"ignore"})}},fe=async({projectDir:e})=>{s.info("Installing dependencies...");let t=f();(await qe(t,e)??me()).succeed(Le.green(`Successfully installed dependencies!
53
- `))};var de=async({projectName:e=h,packages:t,noInstall:n,projectDir:a,databaseProvider:i})=>{let o=f();s.info("Next steps:"),e!=="."&&s.info(` cd ${e}`),n&&(o==="yarn"?s.info(` ${o}`):s.info(` ${o} install`)),["postgresql","mysql"].includes(i)&&s.info(" Add your database connection string to .env"),t?.nextAuth.inUse&&s.info(" Fill in your .env with necessary values. See https://create.tntstack.org/usage/first-steps for more info."),["npm","bun"].includes(o)?s.info(` ${o} run dev`):s.info(` ${o} dev`),!await q(a)&&!L(a)&&s.info(" git init"),s.info(' git commit -m "initial commit"')};import R from"fs";import ze from"path";function ge(e,t,n){R.readdirSync(e).forEach(i=>{let o=ze.join(e,i);if(R.statSync(o).isDirectory())ge(o,t,n);else{let l=R.readFileSync(o,"utf8").replace(new RegExp(t,"g"),n);R.writeFileSync(o,l,"utf8")}})}function ue(e,t){let n=t.replace(/\*/g,"").replace(/[^\/]$/,"$&/");ge(e,"@/",n)}import he from"path";function ye(e){let n=M(e).split("/"),a=n[n.length-1];if(a==="."){let r=he.resolve(process.cwd());a=he.basename(r)}let i=n.findIndex(r=>r.startsWith("@"));n.findIndex(r=>r.startsWith("@"))!==-1&&(a=n.slice(i).join("/"));let o=n.filter(r=>!r.startsWith("@")).join("/");return[a,o]}import Be from"gradient-string";var Fe={blue:"#add7ff",cyan:"#89ddff",green:"#5de4c7",magenta:"#fae4fc",red:"#d0679d",yellow:"#fffac2"};function be(){let e=Be(Object.values(Fe)),t=f();(t==="yarn"||t==="pnpm")&&console.log(""),console.log(e.multiline(F))}import{execSync as He}from"child_process";import Ke from"https";function ve(e){let t=P();t.includes("beta")?(s.warn(" You are using a beta version of create-tnt-stack."),s.warn(" Please report any bugs you encounter.")):t!==e&&(s.warn(" You are using an outdated version of create-tnt-stack."),s.warn(" Your version:",t+".","Latest version in the npm registry:",e),s.warn(" Please run the CLI with @latest to get the latest updates.")),console.log("")}function Ye(){return new Promise((e,t)=>{Ke.get("https://registry.npmjs.org/-/package/tnt-stack/dist-tags",n=>{if(n.statusCode===200){let a="";n.on("data",i=>a+=i),n.on("end",()=>{e(JSON.parse(a).latest)})}else t()}).on("error",()=>{t()})})}var _e=()=>Ye().catch(()=>{try{return He("npm view create-tnt-stack version").toString().trim()}catch{return null}});async function Xe(){let e=await _e(),t=f();be(),e&&ve(e);let{appName:n,databaseProvider:a,flags:{noGit:i,noInstall:o,importAlias:r},packages:l}=await ae(),c=ee(l),[d,m]=ye(n),g=await re({projectName:m,scopedAppName:d,packages:c,noInstall:o,databaseProvider:a}),k=ke.readJSONSync(we.join(g,"package.json"));if(k.name=d,k.ctntaMetadata={initVersion:P()},t!=="bun"){let{stdout:D}=await Qe(t,["-v"],{cwd:g});k.packageManager=`${t}@${D.trim()}`}ke.writeJSONSync(we.join(g,"package.json"),k,{spaces:2}),r!=="@/"&&ue(g,r),o||await fe({projectDir:g}),i||await ce(g),await de({projectDir:g,projectName:m,packages:c,noInstall:o,databaseProvider:a}),process.exit(0)}Xe().catch(e=>{s.error("Aborting installation..."),e instanceof Error?s.error(e):(s.error("An unknown error occurred. Please open an issue on GitHub with the below:"),console.log(e)),process.exit(1)});
41
+ See: https://github.com/t3-oss/create-t3-app/issues/57`);let a=t.args[0];if(a&&(e.appName=a),e.flags=t.opts(),e.flags.CI)return e.flags.nextAuth&&e.packages.push("nextAuth"),e.flags.prisma&&e.packages.push("prisma"),C.includes(e.flags.dbProvider)===!1&&(s.warn(`Incompatible database provided. Use: ${C.join(", ")}. Exiting.`),process.exit(0)),e.databaseProvider=e.packages.includes("prisma")?e.flags.dbProvider:"sqlite",e;if(e.flags.default)return e;try{if(process.env.TERM_PROGRAM?.toLowerCase().includes("mintty"))throw s.warn(` WARNING: It looks like you are using MinTTY, which is non-interactive. This is most likely because you are
42
+ using Git Bash. If that's that case, please use Git Bash from another terminal, such as Windows Terminal. Alternatively, you
43
+ can provide the arguments from the CLI directly: https://create.tntstack.org/installation#experimental-usage to skip the prompts.`),new x("Non-interactive environment");let i=m(),n={};a||(n.name=await ne({message:"What will your project be called?",default:k,validate:r=>ee(r)})),n.authentication=await $({message:"What authentication provider would you like to use?",choices:[{value:"none",name:"None"},{value:"nextAuth",name:"NextAuth.js"}],default:"none"}),n.database=await $({message:"What database ORM would you like to use?",choices:[{value:"none",name:"None"},{value:"prisma",name:"Prisma"}],default:"none"}),n.database!=="none"&&(n.databaseProvider=await $({message:"What database provider would you like to use?",choices:[{value:"sqlite",name:"SQLite"},{value:"mysql",name:"MySQL"},{value:"postgresql",name:"PostgreSQL"}],default:"sqlite"})),e.flags.noGit||(n.git=await G({message:"Should we initialize a Git repository and stage the changes?",default:!w.flags.noGit})),e.flags.noInstall||(n.noInstall=await G({message:`Should we run '${i}`+(i==="yarn"?"'?":" install' for you?"),default:!w.flags.noInstall})),n.importAlias=await ne({message:"What import alias would you like to use?",default:w.flags.importAlias,validate:te});let o=[];return n.authentication==="nextAuth"&&o.push("nextAuth"),n.database==="prisma"&&o.push("prisma"),{appName:n.name??e.appName,packages:o,flags:{...e.flags,noGit:!n.git||e.flags.noGit,noInstall:!n.noInstall||e.flags.noInstall,importAlias:n.importAlias??e.flags.importAlias},databaseProvider:n.databaseProvider||"sqlite"}}catch(i){if(i instanceof x)s.warn(`${R} needs an interactive terminal to run.`),await G({message:"Continue scaffolding with default options?",default:!0})||(s.info("Exiting..."),process.exit(0)),s.info(`Scaffolding default tnt app in ./${e.appName}`);else throw i}return e}import We from"path";import ie from"chalk";import De from"ora";function oe(e){let{packages:t}=e;s.info("Adding boilerplate...");for(let[a,i]of Object.entries(t))if(i.inUse){let n=De(`Boilerplating ${a}...`).start();i.installer(e),n.succeed(ie.green(`Successfully setup boilerplate for ${ie.green.bold(a)}`))}s.info("")}import U from"path";import{confirm as Ge,select as $e}from"@inquirer/prompts";import v from"chalk";import A from"fs-extra";import Ue from"ora";async function se({projectName:e,projectDir:t,pkgManager:a,noInstall:i}){let n=U.join(g,"template/base");i?s.info(""):s.info(`
44
+ Using: ${v.cyan.bold(a)}
45
+ `);let o=Ue(`Scaffolding in: ${t}...
46
+ `).start();if(A.existsSync(t))if(A.readdirSync(t).length===0)e!=="."&&o.info(`${v.cyan.bold(e)} exists but is empty, continuing...
47
+ `);else{o.stopAndPersist();let l=await $e({message:`${v.redBright.bold("Warning:")} ${v.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"&&(o.fail("Aborting installation..."),process.exit(1)),await Ge({message:`Are you sure you want to ${l==="clear"?"clear the directory":"overwrite conflicting files"}`,default:!1})||(o.fail("Aborting installation..."),process.exit(1)),l==="clear"&&(o.info(`Emptying ${v.cyan.bold(e)} and creating tnt app...
48
+ `),A.emptyDirSync(t))}o.start(),A.copySync(n,t),A.renameSync(U.join(t,"_gitignore"),U.join(t,".gitignore"));let r=e==="."?"App":v.cyan.bold(e);o.succeed(`${r} ${v.green.bold("scaffolded successfully!")}
49
+ `)}async function re({projectName:e,scopedAppName:t,packages:a,noInstall:i,databaseProvider:n}){let o=m(),r=We.resolve(process.cwd(),e);return await se({projectName:e,projectDir:r,pkgManager:o,scopedAppName:t,noInstall:i,databaseProvider:n}),oe({projectName:e,scopedAppName:t,projectDir:r,pkgManager:o,packages:a,noInstall:i,databaseProvider:n}),r}import{execSync as J}from"child_process";import W from"path";import{confirm as le}from"@inquirer/prompts";import I from"chalk";import{execa as S}from"execa";import ce from"fs-extra";import Je from"ora";function qe(e){try{return J("git --version",{cwd:e}),!0}catch{return!1}}function q(e){return ce.existsSync(W.join(e,".git"))}async function V(e){try{return await S("git",["rev-parse","--is-inside-work-tree"],{cwd:e,stdout:"ignore"}),!0}catch{return!1}}function Ve(){let t=J("git --version").toString().trim().split(" ")[2],a=t?.split(".")[0],i=t?.split(".")[1];return{major:Number(a),minor:Number(i)}}function Le(){return J("git config --global init.defaultBranch || echo main").toString().trim()}async function pe(e){if(s.info("Initializing Git..."),!qe(e)){s.warn("Git is not installed. Skipping Git initialization.");return}let t=Je(`Creating a new git repo...
50
+ `).start(),a=q(e),i=await V(e),n=W.parse(e).name;if(i&&a){if(t.stop(),!await le({message:`${I.redBright.bold("Warning:")} Git is already initialized in "${n}". Initializing a new git repository would delete the previous history. Would you like to continue anyways?`,default:!1})){t.info("Skipping Git initialization.");return}ce.removeSync(W.join(e,".git"))}else if(i&&!a&&(t.stop(),!await le({message:`${I.redBright.bold("Warning:")} "${n}" is already in a git worktree. Would you still like to initialize a new git repository in this directory?`,default:!1}))){t.info("Skipping Git initialization.");return}try{let o=Le(),{major:r,minor:l}=Ve();r<2||r==2&&l<28?(await S("git",["init"],{cwd:e}),await S("git",["symbolic-ref","HEAD",`refs/heads/${o}`],{cwd:e})):await S("git",["init",`--initial-branch=${o}`],{cwd:e}),await S("git",["add","."],{cwd:e}),t.succeed(`${I.green("Successfully initialized and staged")} ${I.green.bold("git")}
51
+ `)}catch{t.fail(`${I.bold.red("Failed:")} could not initialize git. Update git to the latest version!
52
+ `)}}import ze from"chalk";import{execa as me}from"execa";import de from"ora";var L=async(e,t,a)=>{let{onDataHandle:i,args:n=["install"],stdout:o="pipe"}=a,r=de(`Running ${t} install...`).start(),l=me(t,n,{cwd:e,stdout:o});return await new Promise((c,d)=>{i&&l.stdout?.on("data",i(r)),l.on("error",p=>d(p)),l.on("close",()=>c())}),r},Be=async(e,t)=>{switch(e){case"npm":return await me(e,["install"],{cwd:t,stderr:"inherit"}),null;case"pnpm":return L(t,e,{onDataHandle:a=>i=>{let n=i.toString();n.includes("Progress")&&(a.text=n.includes("|")?n.split(" | ")[1]??"":n)}});case"yarn":return L(t,e,{onDataHandle:a=>i=>{a.text=i.toString()}});case"bun":return L(t,e,{stdout:"ignore"})}},fe=async({projectDir:e})=>{s.info("Installing dependencies...");let t=m();(await Be(t,e)??de()).succeed(ze.green(`Successfully installed dependencies!
53
+ `))};var ge=async({projectName:e=k,packages:t,noInstall:a,projectDir:i,databaseProvider:n})=>{let o=m();s.info("Next steps:"),e!=="."&&s.info(` cd ${e}`),a&&(o==="yarn"?s.info(` ${o}`):s.info(` ${o} install`)),["postgresql","mysql"].includes(n)&&s.info(" Add your database connection string to .env"),t?.nextAuth.inUse&&s.info(" Fill in your .env with necessary values. See https://create.tntstack.org/usage/first-steps for more info."),["npm"].includes(o)?s.info(` ${o} run dev`):s.info(` ${o} dev`),!await V(i)&&!q(i)&&s.info(" git init"),s.info(' git commit -m "initial commit"')};import O from"fs";import Fe from"path";function ue(e,t,a){O.readdirSync(e).forEach(n=>{let o=Fe.join(e,n);if(O.statSync(o).isDirectory())ue(o,t,a);else{let l=O.readFileSync(o,"utf8").replace(new RegExp(t,"g"),a);O.writeFileSync(o,l,"utf8")}})}function he(e,t){let a=t.replace(/\*/g,"").replace(/[^\/]$/,"$&/");ue(e,"@/",a)}import ye from"path";function ve(e){let a=N(e).split("/"),i=a[a.length-1];if(i==="."){let r=ye.resolve(process.cwd());i=ye.basename(r)}let n=a.findIndex(r=>r.startsWith("@"));a.findIndex(r=>r.startsWith("@"))!==-1&&(i=a.slice(n).join("/"));let o=a.filter(r=>!r.startsWith("@")).join("/");return[i,o]}import He from"gradient-string";var Ke={magenta:"#765bc8",pink:"#a48897",yellow:"#c7b561",green:"#8bb8a0",blue:"#4b97d5",cyan:"#22b6d2"};function be(){let e=He(Object.values(Ke)),t=m();(t==="yarn"||t==="pnpm")&&console.log(""),console.log(e.multiline(B))}import{execSync as Ye}from"child_process";import Qe from"https";function _e(e){let t=_();t.includes("beta")?(s.warn(" You are using a beta version of create-tnt-stack."),s.warn(" Please report any bugs you encounter.")):t!==e&&(s.warn(" You are using an outdated version of create-tnt-stack."),s.warn(" Your version:",t+".","Latest version in the npm registry:",e),s.warn(" Please run the CLI with @latest to get the latest updates.")),console.log("")}function Xe(){return new Promise((e,t)=>{Qe.get("https://registry.npmjs.org/-/package/tnt-stack/dist-tags",a=>{if(a.statusCode===200){let i="";a.on("data",n=>i+=n),a.on("end",()=>{e(JSON.parse(i).latest)})}else t()}).on("error",()=>{t()})})}var we=()=>Xe().catch(()=>{try{return Ye("npm view create-tnt-stack version").toString().trim()}catch{return null}});async function et(){let e=await we(),t=m();be(),e&&_e(e);let{appName:a,packages:i,flags:{noGit:n,noInstall:o,importAlias:r},databaseProvider:l}=await ae(),c=Z(i),[d,p]=ve(a),f=await re({projectName:p,scopedAppName:d,packages:c,noInstall:o,databaseProvider:l}),b=Pe.readJsonSync(ke.join(f,"package.json"));b.name=d,b.ctntaMetadata={initVersion:_()};let{stdout:M}=await Ze(t,["-v"],{cwd:f});b.packageManager=`${t}@${M.trim()}`,Pe.writeJSONSync(ke.join(f,"package.json"),b,{spaces:2}),r!=="@/"&&he(f,r),o||await fe({projectDir:f}),n||await pe(f),await ge({projectDir:f,projectName:p,packages:c,noInstall:o,databaseProvider:l}),process.exit(0)}et().catch(e=>{s.error("Aborting installation..."),e instanceof Error?s.error(e.message):(s.error("An unknown error occurred. Please open an issue on GitHub with the below:"),console.error(e)),process.exit(1)});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-tnt-stack",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "Create web application with the TNT-Powered stack",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -40,15 +40,13 @@
40
40
  "clean": "rm -rf dist .turbo node_modules"
41
41
  },
42
42
  "dependencies": {
43
- "@clack/core": "^0.4.1",
44
- "@clack/prompts": "^0.10.0",
45
43
  "@ianvs/prettier-plugin-sort-imports": "^4.4.1",
44
+ "@inquirer/prompts": "^7.3.3",
46
45
  "chalk": "^5.4.1",
47
46
  "commander": "^13.1.0",
48
47
  "execa": "^9.5.2",
49
48
  "fs-extra": "^11.3.0",
50
49
  "gradient-string": "^3.0.0",
51
- "inquirer": "^12.4.2",
52
50
  "ora": "^8.2.0",
53
51
  "sort-package-json": "^3.0.0"
54
52
  },