create-lx2-app 0.9.0 → 0.10.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 +22 -22
- package/package.json +1 -1
- package/template/packages/config/biome.jsonc +94 -0
package/dist/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import Ke from"path";import{execa as Tt}from"execa";import Ye from"fs-extra";import{confirm as Q,input as Ae,select as z}from"@inquirer/prompts";import{Command as gt}from"commander";import ne from"path";import{fileURLToPath as st}from"url";var at=st(import.meta.url),it=ne.dirname(at),p=ne.join(it,"../"),oe=` ___ ___ ___ _ _____ ___ _ ___ _ ___ ___
|
|
3
3
|
/ __| _ \\ __| /_\\_ _| __| | | __ __|_ ) /_\\ | _ \\ _ \\
|
|
4
4
|
| (__| / _| / _ \\| | | _| | |__\\ \\ / / / / _ \\| _/ _/
|
|
5
5
|
\\___|_|_\\___/_/ \\_\\_| |___| |____/_\\_\\/___| /_/ \\_\\_| |_|
|
|
6
|
-
`,
|
|
6
|
+
`,D="my-lx2-app",V="create-lx2-app";import w from"path";import T from"fs-extra";import le from"path";import ce from"fs-extra";import nt from"sort-package-json";var re={"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","@biomejs/biome":"2.2.4",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:t,devMode:i,projectDir:a}=e,s=ce.readJsonSync(le.join(a,"package.json"));t.forEach(o=>{let r=re[o];i&&s.devDependencies?s.devDependencies[o]=r:s.dependencies&&(s.dependencies[o]=r)});let n=nt(s);ce.writeJsonSync(le.join(a,"package.json"),n,{spaces:2})};var pe=({projectDir:e,packages:t,databaseProvider:i})=>{let a=t?.prisma.inUse,s=t?.drizzle.inUse,n=["better-auth"],o=[];(!a||!s)&&n.push("better-sqlite3"),(!a||!s)&&o.push("@types/better-sqlite3"),g({projectDir:e,dependencies:n,devMode:!1}),g({projectDir:e,dependencies:o,devMode:!0});let r=w.join(p,"template/packages"),c=w.join(r,"src/app/api/auth/[...betterauth]/route.ts"),d=w.join(e,"src/app/api/auth/[...all]/route.ts"),u=w.join(r,"src/server/auth/config",a?"better-auth-with-prisma.ts":s?"better-auth-with-drizzle.ts":"better-auth.ts"),m=T.readFileSync(u,"utf-8");(a||s)&&i!=="sqlite"&&(m=m.replace('provider: "sqlite",',`provider: "${{mysql:"mysql",postgresql:"postgresql"}[i]}",`));let f=w.join(e,"src/server/auth/index.ts");T.mkdirSync(w.dirname(f),{recursive:!0}),T.writeFileSync(f,m);let h=w.join(r,"src/lib/auth/better-auth-client.ts"),O=w.join(e,"src/lib/auth/client.ts");T.copySync(c,d),T.copySync(h,O)};import b from"path";import S from"fs-extra";var de=({projectDir:e,packages:t,databaseProvider:i})=>{let a=[],s=[];if(t?.payload.inUse)switch(a.push("payload"),a.push("@payloadcms/next"),a.push("@payloadcms/payload-cloud"),a.push("@payloadcms/richtext-lexical"),a.push("graphql"),i){case"sqlite":s.push("@payloadcms/db-sqlite");break;case"postgresql":s.push("@payloadcms/db-vercel-postgres");break}g({projectDir:e,dependencies:a,devMode:!1}),g({projectDir:e,dependencies:s,devMode:!1});let n=b.join(p,"template/packages"),o=b.join(n,"config/payload",`${i==="postgresql"?"with-postgres":"with-sqlite"}.ts`),r=b.join(e,"payload.config.ts");S.copyFileSync(o,r);let c=b.join(n,"src/payload/collections"),d=b.join(e,"src/collections");S.mkdirSync(d,{recursive:!0}),S.copyFileSync(b.join(c,"Media.ts"),b.join(d,"Media.ts")),S.copyFileSync(b.join(c,"Users.ts"),b.join(d,"Users.ts"));let u=b.join(n,"src/app/(payload)"),m=b.join(e,"src/app/(payload)");S.mkdirSync(m,{recursive:!0}),S.copySync(u,m);let f=b.join(e,"package.json"),h=S.readJSONSync(f);h.scripts={...h.scripts,payload:"payload","generate:importmap":"payload generate:importmap","generate:types":"payload generate:types"},S.writeJSONSync(f,h,{spaces:2})};import me from"path";import ot from"fs-extra";var fe=({projectDir:e,packages:t})=>{let i=t?.typescript.inUse,a=t?.payload.inUse,s=[];i&&(s.push("typescript"),s.push("@types/node"),s.push("@types/react"),s.push("@types/react-dom")),g({projectDir:e,dependencies:s,devMode:!0});let n=me.join(p,"template/packages/config/tsconfig",`${a?"with-payload":"base"}.json`),o=me.join(e,"tsconfig.json");ot.copyFileSync(n,o)};import A from"path";import H from"fs-extra";var ue=({projectDir:e,packages:t})=>{let i=t?.prisma.inUse,a=t?.drizzle.inUse,s=["next-auth"];i&&s.push("@auth/prisma-adapter"),a&&s.push("@auth/drizzle-adapter"),g({projectDir:e,dependencies:s,devMode:!1});let n=A.join(p,"template/packages"),o="src/app/api/auth/[...nextauth]/route.ts",r=A.join(n,o),c=A.join(e,o),d=A.join(n,"src/server/auth/config",i?"authjs-with-prisma.ts":a?"authjs-with-drizzle.ts":"authjs.ts"),u=A.join(e,"src/server/auth/config.ts"),m=A.join(n,"src/server/auth/authjs.ts"),f=A.join(e,"src/server/auth/index.ts");H.copySync(r,c),H.copySync(d,u),H.copySync(m,f)};import K from"path";import ct from"fs-extra";import rt from"path";import ge from"fs-extra";import{sortPackageJson as lt}from"sort-package-json";function q(e){let{scripts:t,projectDir:i}=e,a=rt.join(i,"package.json"),s=ge.readJSONSync(a);s.scripts={...s.scripts,...t};let n=lt(s);ge.writeJSONSync(a,n,{spaces:2})}var he=({projectDir:e})=>{g({projectDir:e,dependencies:["@biomejs/biome"],devMode:!0});let t=K.join(p,"template/packages"),i=K.join(t,"config/biome.jsonc"),a=K.join(e,"biome.jsonc");ct.copyFileSync(i,a),q({projectDir:e,scripts:{"lint:unsafe":"biome check --write --unsafe .","lint:write":"biome check --write .",lint:"biome check .",format:"biome format --write ."}})};import P from"path";import I from"fs-extra";var ye=({projectDir:e,packages:t,scopedAppName:i,databaseProvider:a})=>{let s=t?.authjs.inUse,n=t?.betterAuth.inUse;g({projectDir:e,dependencies:["drizzle-kit"],devMode:!0}),g({projectDir:e,dependencies:["drizzle-orm",{sqlite:"@libsql/client",mysql:"mysql2",postgresql:"postgres"}[a]],devMode:!1});let o=P.join(p,"template/packages"),r=P.join(o,"config/drizzle",{sqlite:"with-sqlite",mysql:"with-mysql",postgresql:"with-postgres"}[a]+".ts"),c=P.join(e,"drizzle.config.ts"),d=P.join(o,"src/server/db/schema-drizzle",s?`with-authjs-${a}.ts`:n?`with-better-auth-${a}.ts`:`base-${a}.ts`),u=P.join(e,"src/server/db/schema.ts"),m=I.readFileSync(d,"utf-8");m=m.replace("project1_${name}",`${i}_\${name}`);let f=I.readFileSync(r,"utf-8");f=f.replace("project1_*",`${i}_*`);let h=P.join(o,`src/server/db/index-drizzle/with-${a}.ts`),O=P.join(e,"src/server/db/index.ts");q({projectDir:e,scripts:{"db:generate":"drizzle-kit generate","db:migrate":"drizzle-kit migrate","db:push":"drizzle-kit push","db:studio":"drizzle-kit studio"}}),I.copySync(r,c),I.mkdirSync(P.dirname(u),{recursive:!0}),I.writeFileSync(u,m),I.writeFileSync(c,f),I.copySync(h,O)};import G from"path";import Y from"fs-extra";var be=({projectDir:e,scopedAppName:t,packages:i,databaseProvider:a})=>{let s=i?.envVariables.inUse,n=i?.authjs.inUse,o=i?.betterAuth.inUse,r=i?.prisma.inUse,c=i?.drizzle.inUse,d=i?.payload.inUse,u=[];s&&(u.push("@t3-oss/env-nextjs"),u.push("zod")),g({projectDir:e,dependencies:u,devMode:!1});let m=r||c||d,f=pt(!!n,!!o,!!r,!!c,!!d,t,a),h="";if(m?n?h="with-authjs-db.js":o?h="with-better-auth-db.js":d?h="with-payload.js":h="with-db.js":n?h="with-authjs.js":o&&(h="with-better-auth.js"),h!==""){let et=G.join(p,"template/packages/src/env",h),tt=G.join(e,"src/env.ts");Y.copyFileSync(et,tt)}let O=G.join(e,".env"),Qe=G.join(e,".env.example"),Xe=dt+f,W=Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("base64"),Ze=f.replace('AUTH_SECRET=""',`AUTH_SECRET="${W}" # Generated by create-lx2-app`).replace('BETTER_AUTH_SECRET=""',`BETTER_AUTH_SECRET="${W}" # Generated by create-lx2-app`).replace('PAYLOAD_SECRET=""',`PAYLOAD_SECRET="${W}" # Generated by create-lx2-app`);Y.writeFileSync(O,Ze,"utf-8"),Y.writeFileSync(Qe,Xe,"utf-8")};function pt(e,t,i,a,s,n,o){let r=`
|
|
7
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 i&&(r+=`
|
|
11
11
|
# Prisma
|
|
12
12
|
# https://www.prisma.io/docs/reference/database-reference/connection-urls#env
|
|
13
13
|
`),a&&(r+=`
|
|
14
14
|
# Drizzle ORM
|
|
15
15
|
# https://orm.drizzle.team/docs/connect-overview
|
|
16
|
-
`),(
|
|
17
|
-
`),
|
|
16
|
+
`),(i||a)&&(o==="mysql"?r+=`DATABASE_URL="mysql://root:password@localhost:3306/${n}"`:o==="postgresql"?r+=`DATABASE_URL="postgresql://postgres:password@localhost:5432/${n}"`:o==="sqlite"&&(r+='DATABASE_URL="file:./db.sqlite"'),r+=`
|
|
17
|
+
`),s&&(r+=`
|
|
18
18
|
# Payload CMS
|
|
19
19
|
# https://payloadcms.com/docs/database/overview
|
|
20
20
|
`,r+=`PAYLOAD_SECRET=""
|
|
21
|
-
`,o==="postgresql"?r+=`DATABASE_URL="postgresql://postgres:password@localhost:5432/${
|
|
21
|
+
`,o==="postgresql"?r+=`DATABASE_URL="postgresql://postgres:password@localhost:5432/${n}"`:o==="sqlite"&&(r+='DATABASE_URL="file:./db.sqlite"'),r+=`
|
|
22
22
|
`),e&&(r+=`
|
|
23
23
|
# Next Auth
|
|
24
24
|
# You can generate a new secret on the command line with:
|
|
@@ -29,7 +29,7 @@ AUTH_SECRET=""
|
|
|
29
29
|
# Next Auth Discord Provider
|
|
30
30
|
DISCORD_CLIENT_ID=""
|
|
31
31
|
DISCORD_CLIENT_SECRET=""
|
|
32
|
-
`),
|
|
32
|
+
`),t&&(r+=`
|
|
33
33
|
# Better Auth
|
|
34
34
|
# You can generate a new secret by going to the Better Auth docs:
|
|
35
35
|
# https://www.better-auth.com/docs/installation#set-environment-variables
|
|
@@ -39,11 +39,11 @@ NEXT_PUBLIC_BETTER_AUTH_URL="http://localhost:3000" # Base URL of your app
|
|
|
39
39
|
# Better Auth Discord Provider
|
|
40
40
|
DISCORD_CLIENT_ID=""
|
|
41
41
|
DISCORD_CLIENT_SECRET=""
|
|
42
|
-
`),!e&&!
|
|
42
|
+
`),!e&&!i&&!s&&(r+=`
|
|
43
43
|
# Example:
|
|
44
44
|
# SERVERVAR="foo"
|
|
45
45
|
# NEXT_PUBLIC_CLIENTVAR="bar"
|
|
46
|
-
`),r}var
|
|
46
|
+
`),r}var dt=`
|
|
47
47
|
# Since the ".env" file is gitignored, you can use the ".env.example" file to
|
|
48
48
|
# build a new ".env" file when you clone the repo. Keep this file up-to-date
|
|
49
49
|
# when you add new variables to \`.env\`.
|
|
@@ -53,19 +53,19 @@ DISCORD_CLIENT_SECRET=""
|
|
|
53
53
|
# ".env" and populate it with your secrets.
|
|
54
54
|
`.trim().concat(`
|
|
55
55
|
|
|
56
|
-
`);import
|
|
56
|
+
`);import R from"path";import L from"fs-extra";var ve=({projectDir:e,packages:t})=>{let i=t?.["eslint/prettier"].inUse,a=[];i&&(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 s=R.join(p,"template/packages/config","eslint.config.mjs"),n=R.join(p,"template/packages/config","prettier.config.mjs"),o=R.join(e,"eslint.config.mjs"),r=R.join(e,"prettier.config.mjs"),c=R.join(e,"package.json"),d=L.readJSONSync(c);d.scripts={...d.scripts,lint:"next lint"},L.copyFileSync(s,o),L.writeJSONSync(c,d,{spaces:2}),L.copyFileSync(n,r)};import x from"path";import _ from"fs-extra";var ke=({projectDir:e,packages:t,databaseProvider:i})=>{let a=t?.authjs.inUse,s=t?.betterAuth.inUse;g({projectDir:e,dependencies:["prisma"],devMode:!0}),g({projectDir:e,dependencies:["@prisma/client"],devMode:!1});let n=x.join(p,"template/packages"),o=x.join(n,"prisma/schema",`${a?"with-authjs":s?"with-better-auth":"base"}.prisma`),r=_.readFileSync(o,"utf-8");i!=="sqlite"&&(r=r.replace('provider = "sqlite"',`provider = "${{mysql:"mysql",postgresql:"postgresql"}[i]}"`),["mysql"].includes(i)&&(r=r.replace("// @db.Text","@db.Text")));let c=x.join(e,"prisma/schema.prisma");_.mkdirSync(x.dirname(c),{recursive:!0}),_.writeFileSync(c,r);let d=x.join(n,"src/server/db/db-prisma.ts"),u=x.join(e,"src/server/db/index.ts");_.mkdirSync(x.dirname(u),{recursive:!0}),_.writeFileSync(u,_.readFileSync(d,"utf-8"));let m=x.join(e,"package.json"),f=_.readJSONSync(m);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(m,f,{spaces:2})};var we=["none","authjs","betterAuth"],Se=["none","prisma","drizzle"],F=["sqlite","mysql","postgresql"];var Pe=e=>({authjs:{inUse:e.includes("authjs"),installer:ue},betterAuth:{inUse:e.includes("betterAuth"),installer:pe},prisma:{inUse:e.includes("prisma"),installer:ke},drizzle:{inUse:e.includes("drizzle"),installer:ye},envVariables:{inUse:!0,installer:be},"eslint/prettier":{inUse:e.includes("eslint/prettier"),installer:ve},biome:{inUse:e.includes("biome"),installer:he},typescript:{inUse:!0,installer:fe},payload:{inUse:e.includes("payload"),installer:de}});import mt from"path";import ft from"fs-extra";function C(){let e=mt.join(p,"package.json");return ft.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 E=class extends Error{constructor(t){super(t)}};import N from"chalk";var l={error(...e){console.log(N.red(...e))},warn(...e){console.log(N.yellow(...e))},info(...e){console.log(N.cyan(...e))},success(...e){console.log(N.green(...e))}};var J=e=>(e.length>1&&e.endsWith("/")&&(e=e.slice(0,-1)),e);var ut=/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;function xe(e){let t=J(e),i=t.split("/"),a=i.findIndex(n=>n.startsWith("@")),s=i[i.length-1];return i.findIndex(n=>n.startsWith("@"))!==-1&&(s=i.slice(a).join("/")),t=="."||ut.test(s??"")?!0:"App name must consist of only lowercase alphanumeric characters, '-', and '_'"}var _e=e=>e.startsWith(".")||e.startsWith("/")?"Import alias can't start with '.' or '/'":!0;var y={appName:D,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 Ie(){let e=y,t=new gt().name(V).description("CLI for scaffolding new web apps with the Lx2 stack").version(C(),"-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: ${we.join(", ")}`,y.flags.authentication).option("--databaseORM [orm]",`Choose a database ORM to use. Possible values: ${Se.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: ${F.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,
|
|
57
57
|
and likely to result in a crash. Please run create-lx2-app with another
|
|
58
58
|
package manager such as pnpm, npm, or Yarn Classic.
|
|
59
|
-
See: https://github.com/t3-oss/create-t3-app/issues/57`);let
|
|
59
|
+
See: https://github.com/t3-oss/create-t3-app/issues/57`);let i=t.args[0];if(i&&(e.appName=i),e.flags=t.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;case"biome":e.packages.push("biome");break;default:break}return F.includes(e.flags.dbProvider)===!1&&(l.warn(`Incompatible database provided. Use: ${F.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
|
|
60
60
|
using Git Bash. If that's that case, please use Git Bash from another terminal, such as Windows Terminal. Alternatively, you
|
|
61
|
-
can provide the arguments from the CLI directly: https://create.lx2.dev/docs/getting-started#experimental-ci-flags to skip the prompts.`),new
|
|
62
|
-
Using: ${j.cyan.bold(
|
|
63
|
-
`);let
|
|
64
|
-
`).start();if(M.existsSync(
|
|
65
|
-
`);else{
|
|
66
|
-
`),M.emptyDirSync(
|
|
67
|
-
`)}import k from"path";import
|
|
68
|
-
`).start(),
|
|
69
|
-
`)}catch{
|
|
70
|
-
`)}}import
|
|
71
|
-
`))};var
|
|
61
|
+
can provide the arguments from the CLI directly: https://create.lx2.dev/docs/getting-started#experimental-ci-flags to skip the prompts.`),new E("Non-interactive environment");let a=v(),s={};i||(s.name=await Ae({message:"What will your project be called?",default:D,validate:o=>xe(o)})),s.backend=await z({message:"What backend framework would you like to use?",choices:[{value:"nextjs",name:"Next.js"},{value:"payload",name:"Payload CMS"}],default:!y.flags.backend}),s.backend==="payload"&&(s.databaseProvider=await z({message:"What database provider would you like to use?",choices:[{value:"sqlite",name:"SQLite"},{value:"postgresql",name:"PostgreSQL"}],default:!y.flags.dbProvider})),s.backend==="nextjs"&&(s.authentication=await z({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}),s.orm=await z({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}),s.orm!=="none"&&(s.databaseProvider=await z({message:"What database provider would you like to use?",choices:[{value:"sqlite",name:"SQLite"},{value:"mysql",name:"MySQL"},{value:"postgresql",name:"PostgreSQL"}],default:!y.flags.dbProvider}))),s.linter=await z({message:"What linter and formatter would you like to use?",choices:[{value:"eslint/prettier",name:"ESLint/Prettier"},{value:"biome",name:"Biome"}],default:!y.flags.linter}),e.flags.noGit||(s.noGit=await Q({message:"Should we initialize a Git repository and stage the changes?",default:!y.flags.noGit})),e.flags.noInstall||(s.noInstall=await Q({message:`Should we run '${a}`+(a==="yarn"?"'?":" install' for you?"),default:!y.flags.noInstall})),s.importAlias=await Ae({message:"What import alias would you like to use?",default:y.flags.importAlias,validate:_e});let n=[];switch(s.backend){case"payload":n.push("payload");break;default:break}switch(s.authentication){case"authjs":n.push("authjs");break;case"betterAuth":n.push("betterAuth");break;default:break}switch(s.orm){case"prisma":n.push("prisma");break;case"drizzle":n.push("drizzle");break;default:break}switch(s.linter){case"eslint/prettier":n.push("eslint/prettier");break;case"biome":n.push("biome");break;default:break}return{appName:s.name??e.appName,packages:n,flags:{...e.flags,noGit:!s.noGit||e.flags.noGit,noInstall:!s.noInstall||e.flags.noInstall,importAlias:s.importAlias??e.flags.importAlias},databaseProvider:s.databaseProvider||"sqlite"}}catch(a){if(a instanceof E)l.warn(`${V} needs an interactive terminal to run.`),await Q({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 kt from"path";import je from"chalk";import ht from"ora";function Ce(e){let{packages:t}=e;l.info("Adding boilerplate...");for(let[i,a]of Object.entries(t))if(a.inUse){let s=ht(`Boilerplating ${i}...`).start();a.installer(e),s.succeed(je.green(`${je.green.bold(i)}`))}l.info("")}import X from"path";import{confirm as yt,select as bt}from"@inquirer/prompts";import j from"chalk";import M from"fs-extra";import vt from"ora";async function ze({projectName:e,projectDir:t,pkgManager:i,noInstall:a}){let s=X.join(p,"template/base");a?l.info(""):l.info(`
|
|
62
|
+
Using: ${j.cyan.bold(i)}
|
|
63
|
+
`);let n=vt(`Scaffolding in: ${t}...
|
|
64
|
+
`).start();if(M.existsSync(t))if(M.readdirSync(t).length===0)e!=="."&&n.info(`${j.cyan.bold(e)} exists but is empty, continuing...
|
|
65
|
+
`);else{n.stopAndPersist();let r=await bt({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"&&(n.fail("Aborting installation..."),process.exit(1)),await yt({message:`Are you sure you want to ${r==="clear"?"clear the directory":"overwrite conflicting files"}`,default:!1})||(n.fail("Aborting installation..."),process.exit(1)),r==="clear"&&(n.info(`Emptying ${j.cyan.bold(e)} and creating lx2 app...
|
|
66
|
+
`),M.emptyDirSync(t))}n.start(),M.copySync(s,t),M.renameSync(X.join(t,"_gitignore"),X.join(t,".gitignore"));let o=e==="."?"App":j.cyan.bold(e);n.succeed(`${o} ${j.green.bold("scaffolded successfully!")}
|
|
67
|
+
`)}import k from"path";import Z from"fs-extra";function Oe({packages:e,projectDir:t}){let i=k.join(p,"template/packages/src/app/layout"),a=e.payload.inUse,n=k.join(i,"base.tsx"),o=k.join(t,`src/app/${a?"(frontend)":""}/layout.tsx`);Z.copySync(n,o)}function De({packages:e,projectDir:t}){let i=k.join(p,"template/packages/src/app/page"),a=e.payload.inUse,s=e.authjs.inUse,n=e.betterAuth.inUse,o=e.prisma.inUse,r=e.drizzle.inUse,c="base.tsx";a&&(c="with-payload.tsx"),s&&(c="with-authjs.tsx"),n&&(c="with-better-auth.tsx"),o&&(c="with-prisma.tsx"),s&&o&&(c="with-authjs-prisma.tsx"),n&&o&&(c="with-better-auth-prisma.tsx"),r&&(c="with-drizzle.tsx"),s&&r&&(c="with-authjs-drizzle.tsx"),n&&r&&(c="with-better-auth-drizzle.tsx");let d=k.join(i,c),u=k.join(t,`src/app/${a?"(frontend)":""}/page.tsx`);Z.copySync(d,u)}function Te({packages:e,projectDir:t}){let i=k.join(p,"template/packages/src/app/globals"),a=e.payload.inUse,n=k.join(i,"base.css"),o=k.join(t,`src/app/${a?"(frontend)":""}/globals.css`);Z.copySync(n,o)}async function Re({projectName:e,scopedAppName:t,packages:i,noInstall:a,databaseProvider:s}){let n=v(),o=kt.resolve(process.cwd(),e);return await ze({projectName:e,projectDir:o,pkgManager:n,scopedAppName:t,noInstall:a,databaseProvider:s}),Ce({projectName:e,scopedAppName:t,projectDir:o,pkgManager:n,packages:i,noInstall:a,databaseProvider:s}),Oe({packages:i,projectDir:o}),De({packages:i,projectDir:o}),Te({packages:i,projectDir:o}),o}import{execSync as te}from"child_process";import ee from"path";import{confirm as Ee}from"@inquirer/prompts";import U from"chalk";import{execa as $}from"execa";import Me from"fs-extra";import wt from"ora";function St(e){try{return te("git --version",{cwd:e}),!0}catch{return!1}}function se(e){return Me.existsSync(ee.join(e,".git"))}async function ae(e){try{return await $("git",["rev-parse","--is-inside-work-tree"],{cwd:e,stdout:"ignore"}),!0}catch{return!1}}function Pt(){let t=te("git --version").toString().trim().split(" ")[2],i=t?.split(".")[0],a=t?.split(".")[1];return{major:Number(i),minor:Number(a)}}function xt(){return te("git config --global init.defaultBranch || echo main").toString().trim()}async function Ue(e){if(l.info("Initializing Git..."),!St(e)){l.warn("Git is not installed. Skipping Git initialization.");return}let t=wt(`Creating a new git repo...
|
|
68
|
+
`).start(),i=se(e),a=await ae(e),s=ee.parse(e).name;if(a&&i){if(t.stop(),!await Ee({message:`${U.redBright.bold("Warning:")} Git is already initialized in "${s}". Initializing a new git repository would delete the previous history. Would you like to continue anyways?`,default:!1})){t.info("Skipping Git initialization.");return}Me.removeSync(ee.join(e,".git"))}else if(a&&!i&&(t.stop(),!await Ee({message:`${U.redBright.bold("Warning:")} "${s}" 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 n=xt(),{major:o,minor:r}=Pt();o<2||o==2&&r<28?(await $("git",["init"],{cwd:e}),await $("git",["symbolic-ref","HEAD",`refs/heads/${n}`],{cwd:e})):await $("git",["init",`--initial-branch=${n}`],{cwd:e}),await $("git",["add","."],{cwd:e}),t.succeed(`${U.green("Successfully initialized and staged")} ${U.green.bold("git")}
|
|
69
|
+
`)}catch{t.fail(`${U.bold.red("Failed:")} could not initialize git. Update git to the latest version!
|
|
70
|
+
`)}}import _t from"chalk";import{execa as $e}from"execa";import qe from"ora";var ie=async(e,t,i)=>{let{onDataHandle:a,args:s=["install"],stdout:n="pipe"}=i,o=qe(`Running ${t} install...`).start(),r=$e(t,s,{cwd:e,stdout:n});return await new Promise((c,d)=>{a&&r.stdout?.on("data",a(o)),r.on("error",u=>d(u)),r.on("close",()=>c())}),o},At=async(e,t)=>{switch(e){case"npm":return await $e(e,["install"],{cwd:t,stderr:"inherit"}),null;case"pnpm":return ie(t,e,{onDataHandle:i=>a=>{let s=a.toString();s.includes("Progress")&&(i.text=s.includes("|")?s.split(" | ")[1]??"":s)}});case"yarn":return ie(t,e,{onDataHandle:i=>a=>{i.text=a.toString()}});case"bun":return ie(t,e,{stdout:"ignore"})}},Ge=async({projectDir:e})=>{l.info("Installing dependencies...");let t=v();(await At(t,e)??qe()).succeed(_t.green(`Successfully installed dependencies!
|
|
71
|
+
`))};var Le=async({projectName:e=D,packages:t,noInstall:i,projectDir:a,databaseProvider:s})=>{let n=v();l.info("Next steps:"),e!=="."&&l.info(` cd ${e}`),i&&(n==="yarn"?l.info(` ${n}`):l.info(` ${n} install`)),["postgresql","mysql"].includes(s)&&l.info(" Add your database connection string to .env"),t?.authjs.inUse&&l.info(" Fill in your .env with necessary values. See https://create.lx2.dev/docs/first-steps for more info."),t?.betterAuth.inUse&&l.info(" Fill in your .env with necessary values. See https://create.lx2.dev/docs/first-steps for more info."),t?.prisma.inUse&&l.info(` Run "${n} db:push" to create you database tables.`),["npm"].includes(n)?l.info(` ${n} run dev`):l.info(` ${n} dev`),!await ae(a)&&!se(a)&&l.info(" git init"),l.info(' git commit -m "initial commit"')};import B from"fs";import It from"path";function Fe(e,t,i){B.readdirSync(e).forEach(s=>{let n=It.join(e,s);if(B.statSync(n).isDirectory())Fe(n,t,i);else{let r=B.readFileSync(n,"utf8").replace(new RegExp(t,"g"),i);B.writeFileSync(n,r,"utf8")}})}function Ne(e,t){let i=t.replace(/\*/g,"").replace(/[^\/]$/,"$&/");Fe(e,"@/",i)}import Je from"path";function Be(e){let i=J(e).split("/"),a=i[i.length-1];if(a==="."){let o=Je.resolve(process.cwd());a=Je.basename(o)}let s=i.findIndex(o=>o.startsWith("@"));i.findIndex(o=>o.startsWith("@"))!==-1&&(a=i.slice(s).join("/"));let n=i.filter(o=>!o.startsWith("@")).join("/");return[a,n]}import jt from"gradient-string";var Ct={primary:"#bf95f9",accent:"#6071a4",secondary:"#ff7ac5"};function We(){let e=jt(Object.values(Ct)),t=v();(t==="yarn"||t==="pnpm")&&console.log(""),console.log(e.multiline(oe))}import{execSync as zt}from"child_process";import Ot from"https";function Ve(e){let t=C();t.includes("beta")?(l.warn(" You are using a beta version of create-lx2-app."),l.warn(" Please report any bugs you encounter.")):t!==e&&(l.warn(" You are using an outdated version of create-lx2-app."),l.warn(" Your version:",t+".","Latest version in the npm registry:",e),l.warn(" Please run the CLI with @latest to get the latest updates.")),console.log("")}function Dt(){return new Promise((e,t)=>{Ot.get("https://registry.npmjs.org/-/package/create-lx2-app/dist-tags",i=>{if(i.statusCode===200){let a="";i.on("data",s=>a+=s),i.on("end",()=>{e(JSON.parse(a).latest)})}else t()}).on("error",()=>{t()})})}var He=()=>Dt().catch(()=>{try{return zt("npm view create-lx2-app version").toString().trim()}catch{return null}});async function Rt(){let e=await He(),t=v();We(),e&&Ve(e);let{appName:i,packages:a,flags:{noGit:s,noInstall:n,importAlias:o},databaseProvider:r}=await Ie(),c=Pe(a),[d,u]=Be(i),m=await Re({projectName:u,scopedAppName:d,packages:c,noInstall:n,databaseProvider:r}),f=Ye.readJsonSync(Ke.join(m,"package.json"));f.name=d,f.clx2aMetadata={initVersion:C()};let{stdout:h}=await Tt(t,["-v"],{cwd:m});f.packageManager=`${t}@${h.trim()}`,Ye.writeJSONSync(Ke.join(m,"package.json"),f,{spaces:2}),o!=="@/"&&Ne(m,o),n||await Ge({projectDir:m}),s||await Ue(m),await Le({projectDir:m,projectName:u,packages:c,noInstall:n,databaseProvider:r}),process.exit(0)}Rt().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
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
|
|
3
|
+
"assist": {
|
|
4
|
+
"actions": {
|
|
5
|
+
"source": {
|
|
6
|
+
"organizeImports": {
|
|
7
|
+
"level": "on",
|
|
8
|
+
"options": {
|
|
9
|
+
"groups": [
|
|
10
|
+
[":PACKAGE:", ":PACKAGE_WITH_PROTOCOL:"],
|
|
11
|
+
":BLANK_LINE:",
|
|
12
|
+
":ALIAS:",
|
|
13
|
+
":BLANK_LINE:",
|
|
14
|
+
":PATH:",
|
|
15
|
+
],
|
|
16
|
+
"identifierOrder": "natural",
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
"useSortedAttributes": "on",
|
|
20
|
+
"useSortedKeys": "on",
|
|
21
|
+
"useSortedProperties": "on",
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
"enabled": true,
|
|
25
|
+
},
|
|
26
|
+
"files": {
|
|
27
|
+
"ignoreUnknown": true,
|
|
28
|
+
"includes": ["**", "!node_modules", "!.next", "!dist", "!build"],
|
|
29
|
+
},
|
|
30
|
+
"formatter": {
|
|
31
|
+
"bracketSpacing": true,
|
|
32
|
+
"enabled": true,
|
|
33
|
+
"expand": "auto",
|
|
34
|
+
"indentStyle": "space",
|
|
35
|
+
"indentWidth": 2,
|
|
36
|
+
"lineWidth": 80,
|
|
37
|
+
"useEditorconfig": true,
|
|
38
|
+
},
|
|
39
|
+
"javascript": {
|
|
40
|
+
"formatter": {
|
|
41
|
+
"arrowParentheses": "always",
|
|
42
|
+
"enabled": true,
|
|
43
|
+
"jsxQuoteStyle": "double",
|
|
44
|
+
"quoteStyle": "double",
|
|
45
|
+
"semicolons": "asNeeded",
|
|
46
|
+
"trailingCommas": "all",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
"linter": {
|
|
50
|
+
"domains": {
|
|
51
|
+
"next": "recommended",
|
|
52
|
+
"react": "recommended",
|
|
53
|
+
},
|
|
54
|
+
"enabled": true,
|
|
55
|
+
"rules": {
|
|
56
|
+
"complexity": {
|
|
57
|
+
"noExtraBooleanCast": "warn",
|
|
58
|
+
"noUselessFragments": "warn",
|
|
59
|
+
"noUselessTernary": "warn",
|
|
60
|
+
},
|
|
61
|
+
"nursery": {
|
|
62
|
+
"useSortedClasses": {
|
|
63
|
+
"fix": "safe",
|
|
64
|
+
"level": "warn",
|
|
65
|
+
"options": {
|
|
66
|
+
"attributes": ["className", "class"],
|
|
67
|
+
"functions": ["cn", "clsx", "classnames"],
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
"recommended": true,
|
|
72
|
+
"style": {
|
|
73
|
+
"useCollapsedElseIf": "error",
|
|
74
|
+
"useCollapsedIf": "error",
|
|
75
|
+
"useConst": "error",
|
|
76
|
+
"useImportType": {
|
|
77
|
+
"level": "warn",
|
|
78
|
+
"options": {
|
|
79
|
+
"style": "separatedType",
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
"useShorthandAssign": "error",
|
|
83
|
+
},
|
|
84
|
+
"suspicious": {
|
|
85
|
+
"noUnknownAtRules": "off",
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
"vcs": {
|
|
90
|
+
"clientKind": "git",
|
|
91
|
+
"enabled": true,
|
|
92
|
+
"useIgnoreFile": true,
|
|
93
|
+
},
|
|
94
|
+
}
|