create-lx2-app 0.7.1 → 0.8.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/index.js +29 -25
- package/package.json +23 -17
- package/template/base/{next.config.mjs → next.config.ts} +4 -3
- package/template/packages/config/drizzle/with-mysql.ts +12 -0
- package/template/packages/config/drizzle/with-postgres.ts +12 -0
- package/template/packages/config/drizzle/with-sqlite.ts +12 -0
- package/template/packages/config/tsconfig/base.json +1 -7
- package/template/packages/config/tsconfig/with-payload.json +1 -7
- package/template/packages/src/app/api/auth/[...betterauth]/route.ts +1 -1
- package/template/packages/src/app/page/with-authjs-drizzle.tsx +222 -0
- package/template/packages/src/app/page/with-authjs-prisma.tsx +21 -9
- package/template/packages/src/app/page/with-authjs.tsx +16 -8
- package/template/packages/src/app/page/with-better-auth-drizzle.tsx +234 -0
- package/template/packages/src/app/page/with-better-auth-prisma.tsx +7 -3
- package/template/packages/src/app/page/with-better-auth.tsx +2 -2
- package/template/packages/src/app/page/with-drizzle.tsx +172 -0
- package/template/packages/src/app/page/with-payload.tsx +2 -4
- package/template/packages/src/app/page/with-prisma.tsx +2 -2
- package/template/packages/src/server/auth/config/authjs-with-drizzle.ts +51 -0
- package/template/packages/src/server/auth/config/better-auth-with-drizzle.ts +20 -0
- package/template/packages/src/server/auth/config/better-auth-with-prisma.ts +1 -0
- package/template/packages/src/server/db/index-drizzle/with-mysql.ts +19 -0
- package/template/packages/src/server/db/index-drizzle/with-postgres.ts +19 -0
- package/template/packages/src/server/db/index-drizzle/with-sqlite.ts +20 -0
- package/template/packages/src/server/db/schema-drizzle/base-mysql.ts +27 -0
- package/template/packages/src/server/db/schema-drizzle/base-postgres.ts +27 -0
- package/template/packages/src/server/db/schema-drizzle/base-sqlite.ts +27 -0
- package/template/packages/src/server/db/schema-drizzle/with-authjs-mysql.ts +138 -0
- package/template/packages/src/server/db/schema-drizzle/with-authjs-postgres.ts +138 -0
- package/template/packages/src/server/db/schema-drizzle/with-authjs-sqlite.ts +138 -0
- package/template/packages/src/server/db/schema-drizzle/with-better-auth-mysql.ts +113 -0
- package/template/packages/src/server/db/schema-drizzle/with-better-auth-postgres.ts +113 -0
- package/template/packages/src/server/db/schema-drizzle/with-better-auth-sqlite.ts +113 -0
- package/LICENSE.md +0 -20
- /package/template/base/src/{env.js → env.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import Ve from"path";import{execa as Ct}from"execa";import He from"fs-extra";import{confirm as K,input as Pe,select as C}from"@inquirer/prompts";import{Command as mt}from"commander";import ae from"path";import{fileURLToPath as et}from"url";var tt=et(import.meta.url),st=ae.dirname(tt),m=ae.join(st,"../"),ne=` ___ ___ ___ _ _____ ___ _ ___ _ ___ ___
|
|
3
3
|
/ __| _ \\ __| /_\\_ _| __| | | __ __|_ ) /_\\ | _ \\ _ \\
|
|
4
4
|
| (__| / _| / _ \\| | | _| | |__\\ \\ / / / / _ \\| _/ _/
|
|
5
5
|
\\___|_|_\\___/_/ \\_\\_| |___| |____/_\\_\\/___| /_/ \\_\\_| |_|
|
|
6
|
-
`,
|
|
7
|
-
# When adding additional environment variables, the schema in "/src/env.
|
|
6
|
+
`,T="my-lx2-app",W="create-lx2-app";import w from"path";import O from"fs-extra";import oe from"path";import re from"fs-extra";import at from"sort-package-json";var ie={"next-auth":"^5.0.0-beta.25","@auth/prisma-adapter":"^2.8.0","@auth/drizzle-adapter":"^1.10.0","better-auth":"^1.2.7","better-sqlite3":"^11.9.1","@types/better-sqlite3":"^7.6.13",prisma:"^6.5.0","@prisma/client":"^6.5.0","drizzle-orm":"^0.44.4","drizzle-kit":"^0.31.4","@libsql/client":"^0.15.10",mysql2:"^3.14.3",postgres:"^3.4.7","@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 g=e=>{let{dependencies:s,devMode:n,projectDir:a}=e,t=re.readJsonSync(oe.join(a,"package.json"));s.forEach(o=>{let r=ie[o];n&&t.devDependencies?t.devDependencies[o]=r:t.dependencies&&(t.dependencies[o]=r)});let i=at(t);re.writeJsonSync(oe.join(a,"package.json"),i,{spaces:2})};var le=({projectDir:e,packages:s,databaseProvider:n})=>{let a=s?.prisma.inUse,t=s?.drizzle.inUse,i=["better-auth"],o=[];(!a||!t)&&i.push("better-sqlite3"),(!a||!t)&&o.push("@types/better-sqlite3"),g({projectDir:e,dependencies:i,devMode:!1}),g({projectDir:e,dependencies:o,devMode:!0});let r=w.join(m,"template/packages"),c=w.join(r,"src/app/api/auth/[...betterauth]/route.ts"),p=w.join(e,"src/app/api/auth/[...all]/route.ts"),u=w.join(r,"src/server/auth/config",a?"better-auth-with-prisma.ts":t?"better-auth-with-drizzle.ts":"better-auth.ts"),d=O.readFileSync(u,"utf-8");(a||t)&&n!=="sqlite"&&(d=d.replace('provider: "sqlite",',`provider: "${{mysql:"mysql",postgres:"pg"}[n]}",`));let f=w.join(e,"src/server/auth/index.ts");O.mkdirSync(w.dirname(f),{recursive:!0}),O.writeFileSync(f,d);let h=w.join(r,"src/lib/auth/better-auth-client.ts"),D=w.join(e,"src/lib/auth/client.ts");O.copySync(c,p),O.copySync(h,D)};import S from"path";import A from"fs-extra";import nt from"path";import ce from"fs-extra";import{sortPackageJson as it}from"sort-package-json";function pe(e){let{scripts:s,projectDir:n}=e,a=nt.join(n,"package.json"),t=ce.readJSONSync(a);t.scripts={...t.scripts,...s};let i=it(t);ce.writeJSONSync(a,i,{spaces:2})}var de=({projectDir:e,packages:s,scopedAppName:n,databaseProvider:a})=>{let t=s?.authjs.inUse,i=s?.betterAuth.inUse;g({projectDir:e,dependencies:["drizzle-kit"],devMode:!0}),g({projectDir:e,dependencies:["drizzle-orm",{sqlite:"@libsql/client",mysql:"mysql2",postgres:"postgres"}[a]],devMode:!1});let o=S.join(m,"template/packages"),r=S.join(o,"config/drizzle",{sqlite:"with-sqlite",mysql:"with-mysql",postgres:"with-postgres"}[a]+".ts"),c=S.join(e,"drizzle.config.ts"),p=S.join(o,"src/server/db/schema-drizzle",t?`with-authjs-${a}.ts`:i?`with-better-auth-${a}.ts`:`base-${a}.ts`),u=S.join(e,"src/server/db/schema.ts"),d=A.readFileSync(p,"utf-8");d=d.replace("project1_${name}",`${n}_\${name}`);let f=A.readFileSync(r,"utf-8");f=f.replace("project1_*",`${n}_*`);let h=S.join(o,`src/server/db/index-drizzle/with-${a}.ts`),D=S.join(e,"src/server/db/index.ts");pe({projectDir:e,scripts:{"db:generate":"drizzle-kit generate","db:migrate":"drizzle-kit migrate","db:push":"drizzle-kit push","db:studio":"drizzle-kit studio"}}),A.copySync(r,c),A.mkdirSync(S.dirname(u),{recursive:!0}),A.writeFileSync(u,d),A.writeFileSync(c,f),A.copySync(h,D)};import b from"path";import x from"fs-extra";var me=({projectDir:e,packages:s,databaseProvider:n})=>{let a=[],t=[];if(s?.payload.inUse)switch(a.push("payload"),a.push("@payloadcms/next"),a.push("@payloadcms/payload-cloud"),a.push("@payloadcms/richtext-lexical"),a.push("graphql"),n){case"sqlite":t.push("@payloadcms/db-sqlite");break;case"postgres":t.push("@payloadcms/db-vercel-postgres");break}g({projectDir:e,dependencies:a,devMode:!1}),g({projectDir:e,dependencies:t,devMode:!1});let i=b.join(m,"template/packages"),o=b.join(i,"config/payload",`${n==="postgres"?"with-postgres":"with-sqlite"}.ts`),r=b.join(e,"payload.config.ts");x.copyFileSync(o,r);let c=b.join(i,"src/payload/collections"),p=b.join(e,"src/collections");x.mkdirSync(p,{recursive:!0}),x.copyFileSync(b.join(c,"Media.ts"),b.join(p,"Media.ts")),x.copyFileSync(b.join(c,"Users.ts"),b.join(p,"Users.ts"));let u=b.join(i,"src/app/(payload)"),d=b.join(e,"src/app/(payload)");x.mkdirSync(d,{recursive:!0}),x.copySync(u,d);let f=b.join(e,"package.json"),h=x.readJSONSync(f);h.scripts={...h.scripts,payload:"payload","generate:importmap":"payload generate:importmap","generate:types":"payload generate:types"},x.writeJSONSync(f,h,{spaces:2})};import fe from"path";import ot from"fs-extra";var ue=({projectDir:e,packages:s})=>{let n=s?.typescript.inUse,a=s?.payload.inUse,t=[];n&&(t.push("typescript"),t.push("@types/node"),t.push("@types/react"),t.push("@types/react-dom")),g({projectDir:e,dependencies:t,devMode:!0});let i=fe.join(m,"template/packages/config/tsconfig",`${a?"with-payload":"base"}.json`),o=fe.join(e,"tsconfig.json");ot.copyFileSync(i,o)};import I from"path";import V from"fs-extra";var ge=({projectDir:e,packages:s})=>{let n=s?.prisma.inUse,a=s?.drizzle.inUse,t=["next-auth"];n&&t.push("@auth/prisma-adapter"),a&&t.push("@auth/drizzle-adapter"),g({projectDir:e,dependencies:t,devMode:!1});let i=I.join(m,"template/packages"),o="src/app/api/auth/[...nextauth]/route.ts",r=I.join(i,o),c=I.join(e,o),p=I.join(i,"src/server/auth/config",n?"authjs-with-prisma.ts":a?"authjs-with-drizzle.ts":"authjs.ts"),u=I.join(e,"src/server/auth/config.ts"),d=I.join(i,"src/server/auth/authjs.ts"),f=I.join(e,"src/server/auth/index.ts");V.copySync(r,c),V.copySync(p,u),V.copySync(d,f)};import L from"path";import H from"fs-extra";var he=({projectDir:e,scopedAppName:s,packages:n,databaseProvider:a})=>{let t=n?.envVariables.inUse,i=n?.authjs.inUse,o=n?.betterAuth.inUse,r=n?.prisma.inUse,c=n?.drizzle.inUse,p=n?.payload.inUse,u=[];t&&(u.push("@t3-oss/env-nextjs"),u.push("zod")),g({projectDir:e,dependencies:u,devMode:!1});let d=r||c||p,f=rt(!!i,!!o,!!r,!!c,!!p,s,a),h="";if(d?i?h="with-authjs-db.js":o?h="with-better-auth-db.js":p?h="with-payload.js":h="with-db.js":i?h="with-authjs.js":o&&(h="with-better-auth.js"),h!==""){let Xe=L.join(m,"template/packages/src/env",h),Ze=L.join(e,"src/env.ts");H.copyFileSync(Xe,Ze)}let D=L.join(e,".env"),Ke=L.join(e,".env.example"),Ye=lt+f,B=Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("base64"),Qe=f.replace('AUTH_SECRET=""',`AUTH_SECRET="${B}" # Generated by create-lx2-app`).replace('BETTER_AUTH_SECRET=""',`BETTER_AUTH_SECRET="${B}" # Generated by create-lx2-app`).replace('PAYLOAD_SECRET=""',`PAYLOAD_SECRET="${B}" # Generated by create-lx2-app`);H.writeFileSync(D,Qe,"utf-8"),H.writeFileSync(Ke,Ye,"utf-8")};function rt(e,s,n,a,t,i,o){let r=`
|
|
7
|
+
# When adding additional environment variables, the schema in "/src/env.ts"
|
|
8
8
|
# should be updated accordingly.
|
|
9
9
|
`.trim().concat(`
|
|
10
|
-
`);return
|
|
10
|
+
`);return n&&(r+=`
|
|
11
11
|
# Prisma
|
|
12
12
|
# https://www.prisma.io/docs/reference/database-reference/connection-urls#env
|
|
13
|
-
`),
|
|
14
|
-
`),
|
|
13
|
+
`),n&&(o==="mysql"?r+=`DATABASE_URL="mysql://root:password@localhost:3306/${i}"`:o==="postgres"?r+=`DATABASE_URL="postgresql://postgres:password@localhost:5432/${i}"`:o==="sqlite"&&(r+='DATABASE_URL="file:./db.sqlite"'),r+=`
|
|
14
|
+
`),a&&(r+=`
|
|
15
|
+
# Drizzle ORM
|
|
16
|
+
# https://orm.drizzle.team/docs/connect-overview
|
|
17
|
+
`),a&&(o==="mysql"?r+=`DATABASE_URL="mysql://root:password@localhost:3306/${i}"`:o==="postgres"?r+=`DATABASE_URL="postgresql://postgres:password@localhost:5432/${i}"`:o==="sqlite"&&(r+='DATABASE_URL="file:./db.sqlite"'),r+=`
|
|
18
|
+
`),t&&(r+=`
|
|
15
19
|
# Payload CMS
|
|
16
20
|
# https://payloadcms.com/docs/database/overview
|
|
17
|
-
`,
|
|
18
|
-
`,o==="
|
|
19
|
-
`),e&&(
|
|
21
|
+
`,r+=`PAYLOAD_SECRET=""
|
|
22
|
+
`,o==="postgres"?r+=`DATABASE_URL="postgresql://postgres:password@localhost:5432/${i}"`:o==="sqlite"&&(r+='DATABASE_URL="file:./db.sqlite"'),r+=`
|
|
23
|
+
`),e&&(r+=`
|
|
20
24
|
# Next Auth
|
|
21
25
|
# You can generate a new secret on the command line with:
|
|
22
26
|
# npx auth secret
|
|
@@ -26,7 +30,7 @@ AUTH_SECRET=""
|
|
|
26
30
|
# Next Auth Discord Provider
|
|
27
31
|
DISCORD_CLIENT_ID=""
|
|
28
32
|
DISCORD_CLIENT_SECRET=""
|
|
29
|
-
`),
|
|
33
|
+
`),s&&(r+=`
|
|
30
34
|
# Better Auth
|
|
31
35
|
# You can generate a new secret by going to the Better Auth docs:
|
|
32
36
|
# https://www.better-auth.com/docs/installation#set-environment-variables
|
|
@@ -36,11 +40,11 @@ NEXT_PUBLIC_BETTER_AUTH_URL="http://localhost:3000" # Base URL of your app
|
|
|
36
40
|
# Better Auth Discord Provider
|
|
37
41
|
DISCORD_CLIENT_ID=""
|
|
38
42
|
DISCORD_CLIENT_SECRET=""
|
|
39
|
-
`),!e&&!
|
|
43
|
+
`),!e&&!n&&!t&&(r+=`
|
|
40
44
|
# Example:
|
|
41
45
|
# SERVERVAR="foo"
|
|
42
46
|
# NEXT_PUBLIC_CLIENTVAR="bar"
|
|
43
|
-
`),
|
|
47
|
+
`),r}var lt=`
|
|
44
48
|
# Since the ".env" file is gitignored, you can use the ".env.example" file to
|
|
45
49
|
# build a new ".env" file when you clone the repo. Keep this file up-to-date
|
|
46
50
|
# when you add new variables to \`.env\`.
|
|
@@ -50,19 +54,19 @@ DISCORD_CLIENT_SECRET=""
|
|
|
50
54
|
# ".env" and populate it with your secrets.
|
|
51
55
|
`.trim().concat(`
|
|
52
56
|
|
|
53
|
-
`);import
|
|
57
|
+
`);import E from"path";import G from"fs-extra";var ye=({projectDir:e,packages:s})=>{let n=s?.["eslint/prettier"].inUse,a=[];n&&(a.push("eslint"),a.push("eslint-config-next"),a.push("@eslint/eslintrc"),a.push("prettier"),a.push("prettier-plugin-tailwindcss"),a.push("@ianvs/prettier-plugin-sort-imports")),g({projectDir:e,dependencies:a,devMode:!0});let t=E.join(m,"template/packages/config","eslint.config.mjs"),i=E.join(m,"template/packages/config","prettier.config.mjs"),o=E.join(e,"eslint.config.mjs"),r=E.join(e,"prettier.config.mjs"),c=E.join(e,"package.json"),p=G.readJSONSync(c);p.scripts={...p.scripts,lint:"next lint"},G.copyFileSync(t,o),G.writeJSONSync(c,p,{spaces:2}),G.copyFileSync(i,r)};import P from"path";import _ from"fs-extra";var be=({projectDir:e,packages:s,databaseProvider:n})=>{let a=s?.authjs.inUse,t=s?.betterAuth.inUse;g({projectDir:e,dependencies:["prisma"],devMode:!0}),g({projectDir:e,dependencies:["@prisma/client"],devMode:!1});let i=P.join(m,"template/packages"),o=P.join(i,"prisma/schema",`${a?"with-authjs":t?"with-better-auth":"base"}.prisma`),r=_.readFileSync(o,"utf-8");n!=="sqlite"&&(r=r.replace('provider = "sqlite"',`provider = "${{mysql:"mysql",postgres:"postgres"}[n]}"`),["mysql"].includes(n)&&(r=r.replace("// @db.Text","@db.Text")));let c=P.join(e,"prisma/schema.prisma");_.mkdirSync(P.dirname(c),{recursive:!0}),_.writeFileSync(c,r);let p=P.join(i,"src/server/db/db-prisma.ts"),u=P.join(e,"src/server/db/index.ts");_.mkdirSync(P.dirname(u),{recursive:!0}),_.writeFileSync(u,_.readFileSync(p,"utf-8"));let d=P.join(e,"package.json"),f=_.readJSONSync(d);f.scripts={...f.scripts,postinstall:"prisma generate","db:push":"prisma db push","db:studio":"prisma studio","db:generate":"prisma migrate dev","db:migrate":"prisma migrate deploy"},_.writeJSONSync(d,f,{spaces:2})};var ve=["none","authjs","betterAuth"],ke=["none","prisma","drizzle"],q=["sqlite","mysql","postgres"];var we=e=>({authjs:{inUse:e.includes("authjs"),installer:ge},betterAuth:{inUse:e.includes("betterAuth"),installer:le},prisma:{inUse:e.includes("prisma"),installer:be},drizzle:{inUse:e.includes("drizzle"),installer:de},envVariables:{inUse:!0,installer:he},"eslint/prettier":{inUse:e.includes("eslint/prettier"),installer:ye},typescript:{inUse:!0,installer:ue},payload:{inUse:e.includes("payload"),installer:me}});import ct from"path";import pt from"fs-extra";function z(){let e=ct.join(m,"package.json");return pt.readJSONSync(e).version??"1.0.0"}var v=()=>{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 R=class extends Error{constructor(s){super(s)}};import F from"chalk";var l={error(...e){console.log(F.red(...e))},warn(...e){console.log(F.yellow(...e))},info(...e){console.log(F.cyan(...e))},success(...e){console.log(F.green(...e))}};var N=e=>(e.length>1&&e.endsWith("/")&&(e=e.slice(0,-1)),e);var dt=/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;function Se(e){let s=N(e),n=s.split("/"),a=n.findIndex(i=>i.startsWith("@")),t=n[n.length-1];return n.findIndex(i=>i.startsWith("@"))!==-1&&(t=n.slice(a).join("/")),s=="."||dt.test(t??"")?!0:"App name must consist of only lowercase alphanumeric characters, '-', and '_'"}var xe=e=>e.startsWith(".")||e.startsWith("/")?"Import alias can't start with '.' or '/'":!0;var y={appName:T,packages:[],flags:{noGit:!1,noInstall:!1,default:!1,CI:!1,authentication:"none",orm:"none",linter:"eslint/prettier",importAlias:"@/",dbProvider:"sqlite",backend:"nextjs"},databaseProvider:"sqlite"};async function _e(){let e=y,s=new mt().name(W).description("CLI for scaffolding new web apps with the Lx2 stack").version(z(),"-v, --version","Output the current version of Create Lx2 App").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 lx2-app",!1).option("--CI","Boolean value if we're running in CI",!1).option("--backend [framework]",`Choose a backend framework to use. Possible values: ${y.flags.backend}`,y.flags.backend).option("--authProvider [provider]",`Choose an authentication provider to use. Possible values: ${ve.join(", ")}`,y.flags.authentication).option("--databaseORM [orm]",`Choose a database ORM to use. Possible values: ${ke.join(", ")}`,y.flags.orm).option("--linter [linter]",`Choose what linter and formatter to use. Possible values: ${y.flags.linter}`,y.flags.linter).option("-i, --import-alias [alias]","Explicitly tell the CLI to use a custom import alias",y.flags.importAlias).option("--dbProvider [provider]",`Choose a database provider to use. Possible values: ${q.join(", ")}`,y.flags.dbProvider).parse(process.argv);process.env.npm_config_user_agent?.startsWith("yarn/3")&&l.warn(` WARNING: It looks like you are using Yarn 3. This is currently not supported,
|
|
54
58
|
and likely to result in a crash. Please run create-lx2-app with another
|
|
55
59
|
package manager such as pnpm, npm, or Yarn Classic.
|
|
56
|
-
See: https://github.com/t3-oss/create-t3-app/issues/57`);let s
|
|
60
|
+
See: https://github.com/t3-oss/create-t3-app/issues/57`);let n=s.args[0];if(n&&(e.appName=n),e.flags=s.opts(),e.flags.CI){switch(e.packages=[],e.flags.backend){case"payload":e.packages.push("payload");break;default:break}switch(e.flags.authentication){case"authjs":e.packages.push("authjs");break;case"betterAuth":e.packages.push("betterAuth");break;default:break}switch(e.flags.orm){case"prisma":e.packages.push("prisma");break;case"drizzle":e.packages.push("drizzle");break;default:break}switch(e.flags.linter){case"eslint/prettier":e.packages.push("eslint/prettier");break;default:break}return q.includes(e.flags.dbProvider)===!1&&(l.warn(`Incompatible database provided. Use: ${q.join(", ")}. Exiting.`),process.exit(0)),e.flags.backend==="payload"&&e.flags.dbProvider==="mysql"&&(l.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 l.warn(` WARNING: It looks like you are using MinTTY, which is non-interactive. This is most likely because you are
|
|
57
61
|
using Git Bash. If that's that case, please use Git Bash from another terminal, such as Windows Terminal. Alternatively, you
|
|
58
|
-
can provide the arguments from the CLI directly: https://create.lx2.dev/docs/getting-started#experimental-ci-flags to skip the prompts.`),new
|
|
59
|
-
Using: ${
|
|
60
|
-
`);let
|
|
61
|
-
`).start();if(
|
|
62
|
-
`);else{
|
|
63
|
-
`),
|
|
64
|
-
`)}import k from"path";import
|
|
65
|
-
`).start(),
|
|
66
|
-
`)}catch{
|
|
67
|
-
`)}}import
|
|
68
|
-
`))};var
|
|
62
|
+
can provide the arguments from the CLI directly: https://create.lx2.dev/docs/getting-started#experimental-ci-flags to skip the prompts.`),new R("Non-interactive environment");let a=v(),t={};n||(t.name=await Pe({message:"What will your project be called?",default:T,validate:o=>Se(o)})),t.backend=await C({message:"What backend framework would you like to use?",choices:[{value:"nextjs",name:"Next.js"},{value:"payload",name:"Payload CMS"}],default:!y.flags.backend}),t.backend==="payload"&&(t.databaseProvider=await C({message:"What database provider would you like to use?",choices:[{value:"sqlite",name:"SQLite"},{value:"postgres",name:"PostgreSQL"}],default:!y.flags.dbProvider})),t.backend==="nextjs"&&(t.authentication=await C({message:"What authentication provider would you like to use?",choices:[{value:"none",name:"None"},{value:"authjs",name:"Auth.js"},{value:"betterAuth",name:"Better Auth"}],default:!y.flags.authentication}),t.orm=await C({message:"What database ORM would you like to use?",choices:[{value:"none",name:"None"},{value:"prisma",name:"Prisma"},{value:"drizzle",name:"Drizzle"}],default:!y.flags.orm}),t.orm!=="none"&&(t.databaseProvider=await C({message:"What database provider would you like to use?",choices:[{value:"sqlite",name:"SQLite"},{value:"mysql",name:"MySQL"},{value:"postgres",name:"PostgreSQL"}],default:!y.flags.dbProvider}))),t.linter=await C({message:"What linter and formatter would you like to use?",choices:[{value:"eslint/prettier",name:"ESLint/Prettier"}],default:!y.flags.linter}),e.flags.noGit||(t.noGit=await K({message:"Should we initialize a Git repository and stage the changes?",default:!y.flags.noGit})),e.flags.noInstall||(t.noInstall=await K({message:`Should we run '${a}`+(a==="yarn"?"'?":" install' for you?"),default:!y.flags.noInstall})),t.importAlias=await Pe({message:"What import alias would you like to use?",default:y.flags.importAlias,validate:xe});let i=[];switch(t.backend){case"payload":i.push("payload");break;default:break}switch(t.authentication){case"authjs":i.push("authjs");break;case"betterAuth":i.push("betterAuth");break;default:break}switch(t.orm){case"prisma":i.push("prisma");break;case"drizzle":i.push("drizzle");break;default:break}switch(t.linter){case"eslint/prettier":i.push("eslint/prettier");break;default:break}return{appName:t.name??e.appName,packages:i,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(a){if(a instanceof R)l.warn(`${W} needs an interactive terminal to run.`),await K({message:"Continue scaffolding with default options?",default:!0})||(l.info("Exiting..."),process.exit(0)),l.info(`Scaffolding default lx2 app in ./${e.appName}`);else throw a}return e}import yt from"path";import Ae from"chalk";import ft from"ora";function Ie(e){let{packages:s}=e;l.info("Adding boilerplate...");for(let[n,a]of Object.entries(s))if(a.inUse){let t=ft(`Boilerplating ${n}...`).start();a.installer(e),t.succeed(Ae.green(`${Ae.green.bold(n)}`))}l.info("")}import Y from"path";import{confirm as ut,select as gt}from"@inquirer/prompts";import j from"chalk";import U from"fs-extra";import ht from"ora";async function je({projectName:e,projectDir:s,pkgManager:n,noInstall:a}){let t=Y.join(m,"template/base");a?l.info(""):l.info(`
|
|
63
|
+
Using: ${j.cyan.bold(n)}
|
|
64
|
+
`);let i=ht(`Scaffolding in: ${s}...
|
|
65
|
+
`).start();if(U.existsSync(s))if(U.readdirSync(s).length===0)e!=="."&&i.info(`${j.cyan.bold(e)} exists but is empty, continuing...
|
|
66
|
+
`);else{i.stopAndPersist();let r=await gt({message:`${j.redBright.bold("Warning:")} ${j.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"});r==="abort"&&(i.fail("Aborting installation..."),process.exit(1)),await ut({message:`Are you sure you want to ${r==="clear"?"clear the directory":"overwrite conflicting files"}`,default:!1})||(i.fail("Aborting installation..."),process.exit(1)),r==="clear"&&(i.info(`Emptying ${j.cyan.bold(e)} and creating lx2 app...
|
|
67
|
+
`),U.emptyDirSync(s))}i.start(),U.copySync(t,s),U.renameSync(Y.join(s,"_gitignore"),Y.join(s,".gitignore"));let o=e==="."?"App":j.cyan.bold(e);i.succeed(`${o} ${j.green.bold("scaffolded successfully!")}
|
|
68
|
+
`)}import k from"path";import Q from"fs-extra";function ze({packages:e,projectDir:s}){let n=k.join(m,"template/packages/src/app/layout"),a=e.payload.inUse,i=k.join(n,"base.tsx"),o=k.join(s,`src/app/${a?"(frontend)":""}/layout.tsx`);Q.copySync(i,o)}function Ce({packages:e,projectDir:s}){let n=k.join(m,"template/packages/src/app/page"),a=e.payload.inUse,t=e.authjs.inUse,i=e.betterAuth.inUse,o=e.prisma.inUse,r=e.drizzle.inUse,c="base.tsx";a&&(c="with-payload.tsx"),t&&(c="with-authjs.tsx"),i&&(c="with-better-auth.tsx"),o&&(c="with-prisma.tsx"),t&&o&&(c="with-authjs-prisma.tsx"),i&&o&&(c="with-better-auth-prisma.tsx"),r&&(c="with-drizzle.tsx"),t&&r&&(c="with-authjs-drizzle.tsx"),i&&r&&(c="with-better-auth-drizzle.tsx");let p=k.join(n,c),u=k.join(s,`src/app/${a?"(frontend)":""}/page.tsx`);Q.copySync(p,u)}function De({packages:e,projectDir:s}){let n=k.join(m,"template/packages/src/app/globals"),a=e.payload.inUse,i=k.join(n,"base.css"),o=k.join(s,`src/app/${a?"(frontend)":""}/globals.css`);Q.copySync(i,o)}async function Te({projectName:e,scopedAppName:s,packages:n,noInstall:a,databaseProvider:t}){let i=v(),o=yt.resolve(process.cwd(),e);return await je({projectName:e,projectDir:o,pkgManager:i,scopedAppName:s,noInstall:a,databaseProvider:t}),Ie({projectName:e,scopedAppName:s,projectDir:o,pkgManager:i,packages:n,noInstall:a,databaseProvider:t}),ze({packages:n,projectDir:o}),Ce({packages:n,projectDir:o}),De({packages:n,projectDir:o}),o}import{execSync as Z}from"child_process";import X from"path";import{confirm as Oe}from"@inquirer/prompts";import M from"chalk";import{execa as $}from"execa";import Ee from"fs-extra";import bt from"ora";function vt(e){try{return Z("git --version",{cwd:e}),!0}catch{return!1}}function ee(e){return Ee.existsSync(X.join(e,".git"))}async function te(e){try{return await $("git",["rev-parse","--is-inside-work-tree"],{cwd:e,stdout:"ignore"}),!0}catch{return!1}}function kt(){let s=Z("git --version").toString().trim().split(" ")[2],n=s?.split(".")[0],a=s?.split(".")[1];return{major:Number(n),minor:Number(a)}}function wt(){return Z("git config --global init.defaultBranch || echo main").toString().trim()}async function Re(e){if(l.info("Initializing Git..."),!vt(e)){l.warn("Git is not installed. Skipping Git initialization.");return}let s=bt(`Creating a new git repo...
|
|
69
|
+
`).start(),n=ee(e),a=await te(e),t=X.parse(e).name;if(a&&n){if(s.stop(),!await Oe({message:`${M.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})){s.info("Skipping Git initialization.");return}Ee.removeSync(X.join(e,".git"))}else if(a&&!n&&(s.stop(),!await Oe({message:`${M.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}))){s.info("Skipping Git initialization.");return}try{let i=wt(),{major:o,minor:r}=kt();o<2||o==2&&r<28?(await $("git",["init"],{cwd:e}),await $("git",["symbolic-ref","HEAD",`refs/heads/${i}`],{cwd:e})):await $("git",["init",`--initial-branch=${i}`],{cwd:e}),await $("git",["add","."],{cwd:e}),s.succeed(`${M.green("Successfully initialized and staged")} ${M.green.bold("git")}
|
|
70
|
+
`)}catch{s.fail(`${M.bold.red("Failed:")} could not initialize git. Update git to the latest version!
|
|
71
|
+
`)}}import St from"chalk";import{execa as Ue}from"execa";import Me from"ora";var se=async(e,s,n)=>{let{onDataHandle:a,args:t=["install"],stdout:i="pipe"}=n,o=Me(`Running ${s} install...`).start(),r=Ue(s,t,{cwd:e,stdout:i});return await new Promise((c,p)=>{a&&r.stdout?.on("data",a(o)),r.on("error",u=>p(u)),r.on("close",()=>c())}),o},xt=async(e,s)=>{switch(e){case"npm":return await Ue(e,["install"],{cwd:s,stderr:"inherit"}),null;case"pnpm":return se(s,e,{onDataHandle:n=>a=>{let t=a.toString();t.includes("Progress")&&(n.text=t.includes("|")?t.split(" | ")[1]??"":t)}});case"yarn":return se(s,e,{onDataHandle:n=>a=>{n.text=a.toString()}});case"bun":return se(s,e,{stdout:"ignore"})}},$e=async({projectDir:e})=>{l.info("Installing dependencies...");let s=v();(await xt(s,e)??Me()).succeed(St.green(`Successfully installed dependencies!
|
|
72
|
+
`))};var Le=async({projectName:e=T,packages:s,noInstall:n,projectDir:a,databaseProvider:t})=>{let i=v();l.info("Next steps:"),e!=="."&&l.info(` cd ${e}`),n&&(i==="yarn"?l.info(` ${i}`):l.info(` ${i} install`)),["postgres","mysql"].includes(t)&&l.info(" Add your database connection string to .env"),s?.authjs.inUse&&l.info(" Fill in your .env with necessary values. See https://create.lx2.dev/docs/first-steps for more info."),s?.betterAuth.inUse&&l.info(" Fill in your .env with necessary values. See https://create.lx2.dev/docs/first-steps for more info."),s?.prisma.inUse&&l.info(` Run "${i} db:push" to create you database tables.`),["npm"].includes(i)?l.info(` ${i} run dev`):l.info(` ${i} dev`),!await te(a)&&!ee(a)&&l.info(" git init"),l.info(' git commit -m "initial commit"')};import J from"fs";import Pt from"path";function Ge(e,s,n){J.readdirSync(e).forEach(t=>{let i=Pt.join(e,t);if(J.statSync(i).isDirectory())Ge(i,s,n);else{let r=J.readFileSync(i,"utf8").replace(new RegExp(s,"g"),n);J.writeFileSync(i,r,"utf8")}})}function qe(e,s){let n=s.replace(/\*/g,"").replace(/[^\/]$/,"$&/");Ge(e,"@/",n)}import Fe from"path";function Ne(e){let n=N(e).split("/"),a=n[n.length-1];if(a==="."){let o=Fe.resolve(process.cwd());a=Fe.basename(o)}let t=n.findIndex(o=>o.startsWith("@"));n.findIndex(o=>o.startsWith("@"))!==-1&&(a=n.slice(t).join("/"));let i=n.filter(o=>!o.startsWith("@")).join("/");return[a,i]}import _t from"gradient-string";var At={primary:"#bf95f9",accent:"#6071a4",secondary:"#ff7ac5"};function Je(){let e=_t(Object.values(At)),s=v();(s==="yarn"||s==="pnpm")&&console.log(""),console.log(e.multiline(ne))}import{execSync as It}from"child_process";import jt from"https";function Be(e){let s=z();s.includes("beta")?(l.warn(" You are using a beta version of create-lx2-app."),l.warn(" Please report any bugs you encounter.")):s!==e&&(l.warn(" You are using an outdated version of create-lx2-app."),l.warn(" Your version:",s+".","Latest version in the npm registry:",e),l.warn(" Please run the CLI with @latest to get the latest updates.")),console.log("")}function zt(){return new Promise((e,s)=>{jt.get("https://registry.npmjs.org/-/package/create-lx2-app/dist-tags",n=>{if(n.statusCode===200){let a="";n.on("data",t=>a+=t),n.on("end",()=>{e(JSON.parse(a).latest)})}else s()}).on("error",()=>{s()})})}var We=()=>zt().catch(()=>{try{return It("npm view create-lx2-app version").toString().trim()}catch{return null}});async function Dt(){let e=await We(),s=v();Je(),e&&Be(e);let{appName:n,packages:a,flags:{noGit:t,noInstall:i,importAlias:o},databaseProvider:r}=await _e(),c=we(a),[p,u]=Ne(n),d=await Te({projectName:u,scopedAppName:p,packages:c,noInstall:i,databaseProvider:r}),f=He.readJsonSync(Ve.join(d,"package.json"));f.name=p,f.clx2aMetadata={initVersion:z()};let{stdout:h}=await Ct(s,["-v"],{cwd:d});f.packageManager=`${s}@${h.trim()}`,He.writeJSONSync(Ve.join(d,"package.json"),f,{spaces:2}),o!=="@/"&&qe(d,o),i||await $e({projectDir:d}),t||await Re(d),await Le({projectDir:d,projectName:u,packages:c,noInstall:i,databaseProvider:r}),process.exit(0)}Dt().catch(e=>{l.error("Aborting installation..."),e instanceof Error?l.error(e.message):(l.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-lx2-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Create powerful full-stack web applications with the Lx2 stack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -30,10 +30,21 @@
|
|
|
30
30
|
"engines": {
|
|
31
31
|
"node": ">=18"
|
|
32
32
|
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"dev": "tsup --watch",
|
|
35
|
+
"build": "tsup",
|
|
36
|
+
"start": "node dist/index.js",
|
|
37
|
+
"format": "prettier '**/*.{cjs,mjs,ts,tsx,md,json}' --ignore-path ../.gitignore --ignore-unknown --no-error-on-unmatched-pattern --write",
|
|
38
|
+
"format:check": "prettier '**/*.{cjs,mjs,ts,tsx,md,json}' --ignore-path ../.gitignore --ignore-unknown --no-error-on-unmatched-pattern --check",
|
|
39
|
+
"typecheck": "tsc",
|
|
40
|
+
"clean": "rm -rf dist .turbo node_modules",
|
|
41
|
+
"link": "pnpm run build && npm link",
|
|
42
|
+
"release": "changeset version",
|
|
43
|
+
"pub:beta": "pnpm run build && npm publish --tag beta",
|
|
44
|
+
"pub:release": "pnpm run build && npm publish"
|
|
45
|
+
},
|
|
33
46
|
"dependencies": {
|
|
34
47
|
"@inquirer/prompts": "^7.4.0",
|
|
35
|
-
"better-auth": "^1.2.7",
|
|
36
|
-
"better-sqlite3": "^11.9.1",
|
|
37
48
|
"chalk": "^5.4.1",
|
|
38
49
|
"commander": "^13.1.0",
|
|
39
50
|
"execa": "^9.5.2",
|
|
@@ -43,9 +54,11 @@
|
|
|
43
54
|
"sort-package-json": "^3.0.0"
|
|
44
55
|
},
|
|
45
56
|
"devDependencies": {
|
|
57
|
+
"@auth/drizzle-adapter": "^1.10.0",
|
|
46
58
|
"@auth/prisma-adapter": "^2.8.0",
|
|
47
59
|
"@eslint/eslintrc": "^3.3.1",
|
|
48
60
|
"@ianvs/prettier-plugin-sort-imports": "^4.4.1",
|
|
61
|
+
"@libsql/client": "^0.15.10",
|
|
49
62
|
"@payloadcms/db-sqlite": "^3.33.0",
|
|
50
63
|
"@payloadcms/db-vercel-postgres": "^3.33.0",
|
|
51
64
|
"@payloadcms/next": "^3.33.0",
|
|
@@ -58,12 +71,18 @@
|
|
|
58
71
|
"@types/node": "^22",
|
|
59
72
|
"@types/react": "^19",
|
|
60
73
|
"@types/react-dom": "^19",
|
|
74
|
+
"better-auth": "^1.3.4",
|
|
75
|
+
"better-sqlite3": "^12.2.0",
|
|
76
|
+
"drizzle-kit": "^0.31.4",
|
|
77
|
+
"drizzle-orm": "^0.44.4",
|
|
61
78
|
"eslint": "^9.22.0",
|
|
62
79
|
"eslint-config-next": "^15.2.4",
|
|
63
80
|
"graphql": "^16.10.0",
|
|
81
|
+
"mysql2": "^3.14.3",
|
|
64
82
|
"next": "^15.2.4",
|
|
65
83
|
"next-auth": "^5.0.0-beta.25",
|
|
66
84
|
"payload": "^3.33.0",
|
|
85
|
+
"postgres": "^3.4.7",
|
|
67
86
|
"prettier": "^3.5.3",
|
|
68
87
|
"prettier-plugin-tailwindcss": "^0.6.11",
|
|
69
88
|
"prisma": "^6.5.0",
|
|
@@ -75,18 +94,5 @@
|
|
|
75
94
|
"type-fest": "^4.37.0",
|
|
76
95
|
"typescript": "^5.8.2",
|
|
77
96
|
"zod": "^3.24.2"
|
|
78
|
-
},
|
|
79
|
-
"scripts": {
|
|
80
|
-
"dev": "tsup --watch",
|
|
81
|
-
"build": "tsup",
|
|
82
|
-
"start": "node dist/index.js",
|
|
83
|
-
"format": "prettier '**/*.{cjs,mjs,ts,tsx,md,json}' --ignore-path ../.gitignore --ignore-unknown --no-error-on-unmatched-pattern --write",
|
|
84
|
-
"format:check": "prettier '**/*.{cjs,mjs,ts,tsx,md,json}' --ignore-path ../.gitignore --ignore-unknown --no-error-on-unmatched-pattern --check",
|
|
85
|
-
"typecheck": "tsc",
|
|
86
|
-
"clean": "rm -rf dist .turbo node_modules",
|
|
87
|
-
"link": "pnpm run build && npm link",
|
|
88
|
-
"release": "changeset version",
|
|
89
|
-
"pub:beta": "pnpm run build && npm publish --tag beta",
|
|
90
|
-
"pub:release": "pnpm run build && npm publish"
|
|
91
97
|
}
|
|
92
|
-
}
|
|
98
|
+
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
+
import type { NextConfig } from "next"
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially useful
|
|
3
5
|
* for Docker builds.
|
|
4
6
|
*/
|
|
5
|
-
import "./src/env
|
|
7
|
+
import "./src/env"
|
|
6
8
|
|
|
7
|
-
|
|
8
|
-
const nextConfig = {
|
|
9
|
+
const nextConfig: NextConfig = {
|
|
9
10
|
/* config options here */
|
|
10
11
|
}
|
|
11
12
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineConfig } from "drizzle-kit"
|
|
2
|
+
|
|
3
|
+
import { env } from "@/env"
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
schema: "./src/server/db/schema.ts",
|
|
7
|
+
dialect: "postgresql",
|
|
8
|
+
dbCredentials: {
|
|
9
|
+
url: env.DATABASE_URL,
|
|
10
|
+
},
|
|
11
|
+
tablesFilter: ["project1_*"],
|
|
12
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { defineConfig } from "drizzle-kit"
|
|
2
|
+
|
|
3
|
+
import { env } from "@/env"
|
|
4
|
+
|
|
5
|
+
export default defineConfig({
|
|
6
|
+
schema: "./src/server/db/schema.ts",
|
|
7
|
+
dialect: "sqlite",
|
|
8
|
+
dbCredentials: {
|
|
9
|
+
url: env.DATABASE_URL,
|
|
10
|
+
},
|
|
11
|
+
tablesFilter: ["project1_*"],
|
|
12
|
+
})
|
|
@@ -31,12 +31,6 @@
|
|
|
31
31
|
"@/*": ["./src/*"]
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
|
-
"include": [
|
|
35
|
-
"next-env.d.ts",
|
|
36
|
-
"**/*.ts",
|
|
37
|
-
"**/*.tsx",
|
|
38
|
-
"**/*.js",
|
|
39
|
-
".next/types/**/*.ts"
|
|
40
|
-
],
|
|
34
|
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
|
41
35
|
"exclude": ["node_modules"]
|
|
42
36
|
}
|
|
@@ -32,12 +32,6 @@
|
|
|
32
32
|
"@payload-config": ["./payload.config.ts"]
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
|
-
"include": [
|
|
36
|
-
"next-env.d.ts",
|
|
37
|
-
"**/*.ts",
|
|
38
|
-
"**/*.tsx",
|
|
39
|
-
"**/*.js",
|
|
40
|
-
".next/types/**/*.ts"
|
|
41
|
-
],
|
|
35
|
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
|
42
36
|
"exclude": ["node_modules"]
|
|
43
37
|
}
|