create-lx2-app 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +20 -0
- package/dist/index.js +21 -21
- package/package.json +15 -15
- package/template/base/{next.config.mjs → next.config.ts} +4 -3
- package/template/packages/config/tsconfig/base.json +1 -7
- package/template/packages/config/tsconfig/with-payload.json +1 -7
- /package/template/base/src/{env.js → env.ts} +0 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Lasse Lammers
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import Ne from"path";import{execa as Pt}from"execa";import Fe from"fs-extra";import{confirm as V,input as be,select as j}from"@inquirer/prompts";import{Command as nt}from"commander";import ee from"path";import{fileURLToPath as He}from"url";var Ke=He(import.meta.url),Ye=ee.dirname(Ke),d=ee.join(Ye,"../"),te=` ___ ___ ___ _ _____ ___ _ ___ _ ___ ___
|
|
3
3
|
/ __| _ \\ __| /_\\_ _| __| | | __ __|_ ) /_\\ | _ \\ _ \\
|
|
4
4
|
| (__| / _| / _ \\| | | _| | |__\\ \\ / / / / _ \\| _/ _/
|
|
5
5
|
\\___|_|_\\___/_/ \\_\\_| |___| |____/_\\_\\/___| /_/ \\_\\_| |_|
|
|
6
|
-
`,C="my-lx2-app",
|
|
7
|
-
# When adding additional environment variables, the schema in "/src/env.
|
|
6
|
+
`,C="my-lx2-app",B="create-lx2-app";import w from"path";import T from"fs-extra";import se from"path";import ne from"fs-extra";import Qe from"sort-package-json";var ae={"next-auth":"^5.0.0-beta.25","@auth/prisma-adapter":"^2.8.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","@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 h=e=>{let{dependencies:a,devMode:s,projectDir:n}=e,t=ne.readJsonSync(se.join(n,"package.json"));a.forEach(i=>{let r=ae[i];s&&t.devDependencies?t.devDependencies[i]=r:t.dependencies&&(t.dependencies[i]=r)});let o=Qe(t);ne.writeJsonSync(se.join(n,"package.json"),o,{spaces:2})};var oe=({projectDir:e,packages:a,databaseProvider:s})=>{let n=a?.prisma.inUse,t=["better-auth"],o=[];n||t.push("better-sqlite3"),n||o.push("@types/better-sqlite3"),h({projectDir:e,dependencies:t,devMode:!1}),h({projectDir:e,dependencies:o,devMode:!0});let i=w.join(d,"template/packages"),r=w.join(i,"src/app/api/auth/[...betterauth]/route.ts"),p=w.join(e,"src/app/api/auth/[...all]/route.ts"),c=w.join(i,"src/server/auth/config",n?"better-auth-with-prisma.ts":"better-auth.ts"),g=T.readFileSync(c,"utf-8");n&&s!=="sqlite"&&(g=g.replace('provider: "sqlite",',`provider: "${{mysql:"mysql",postgresql:"postgresql"}[s]}",`));let f=w.join(e,"src/server/auth/index.ts");T.mkdirSync(w.dirname(f),{recursive:!0}),T.writeFileSync(f,g);let m=w.join(i,"src/lib/auth/better-auth-client.ts"),v=w.join(e,"src/lib/auth/client.ts");T.copySync(r,p),T.copySync(m,v)};import y from"path";import P from"fs-extra";var ie=({projectDir:e,packages:a,databaseProvider:s})=>{let n=[],t=[];if(a?.payload.inUse)switch(n.push("payload"),n.push("@payloadcms/next"),n.push("@payloadcms/payload-cloud"),n.push("@payloadcms/richtext-lexical"),n.push("graphql"),s){case"sqlite":t.push("@payloadcms/db-sqlite");break;case"postgresql":t.push("@payloadcms/db-vercel-postgres");break}h({projectDir:e,dependencies:n,devMode:!1}),h({projectDir:e,dependencies:t,devMode:!1});let o=y.join(d,"template/packages"),i=y.join(o,"config/payload",`${s==="postgresql"?"with-postgres":"with-sqlite"}.ts`),r=y.join(e,"payload.config.ts");P.copyFileSync(i,r);let p=y.join(o,"src/payload/collections"),c=y.join(e,"src/collections");P.mkdirSync(c,{recursive:!0}),P.copyFileSync(y.join(p,"Media.ts"),y.join(c,"Media.ts")),P.copyFileSync(y.join(p,"Users.ts"),y.join(c,"Users.ts"));let g=y.join(o,"src/app/(payload)"),f=y.join(e,"src/app/(payload)");P.mkdirSync(f,{recursive:!0}),P.copySync(g,f);let m=y.join(e,"package.json"),v=P.readJSONSync(m);v.scripts={...v.scripts,payload:"payload","generate:importmap":"payload generate:importmap","generate:types":"payload generate:types"},P.writeJSONSync(m,v,{spaces:2})};import re from"path";import Xe from"fs-extra";var le=({projectDir:e,packages:a})=>{let s=a?.typescript.inUse,n=a?.payload.inUse,t=[];s&&(t.push("typescript"),t.push("@types/node"),t.push("@types/react"),t.push("@types/react-dom")),h({projectDir:e,dependencies:t,devMode:!0});let o=re.join(d,"template/packages/config/tsconfig",`${n?"with-payload":"base"}.json`),i=re.join(e,"tsconfig.json");Xe.copyFileSync(o,i)};import _ from"path";import J from"fs-extra";var pe=({projectDir:e,packages:a})=>{let s=a?.prisma.inUse,n=["next-auth"];s&&n.push("@auth/prisma-adapter"),h({projectDir:e,dependencies:n,devMode:!1});let t=_.join(d,"template/packages"),o="src/app/api/auth/[...nextauth]/route.ts",i=_.join(t,o),r=_.join(e,o),p=_.join(t,"src/server/auth/config",s?"authjs-with-prisma.ts":"authjs.ts"),c=_.join(e,"src/server/auth/config.ts"),g=_.join(t,"src/server/auth/authjs.ts"),f=_.join(e,"src/server/auth/index.ts");J.copySync(i,r),J.copySync(p,c),J.copySync(g,f)};import U from"path";import W from"fs-extra";var ce=({projectDir:e,scopedAppName:a,packages:s,databaseProvider:n})=>{let t=s?.envVariables.inUse,o=s?.authjs.inUse,i=s?.betterAuth.inUse,r=s?.prisma.inUse,p=s?.payload.inUse,c=[];t&&(c.push("@t3-oss/env-nextjs"),c.push("zod")),h({projectDir:e,dependencies:c,devMode:!1});let g=r||p,f=Ze(!!o,!!i,!!r,!!p,a,n),m="";if(g?o?m="with-authjs-db.js":i?m="with-better-auth-db.js":p?m="with-payload.js":m="with-db.js":o?m="with-authjs.js":i&&(m="with-better-auth.js"),m!==""){let Ve=U.join(d,"template/packages/src/env",m),ze=U.join(e,"src/env.ts");W.copyFileSync(Ve,ze)}let v=U.join(e,".env"),Be=U.join(e,".env.example"),Je=et+f,F=Buffer.from(crypto.getRandomValues(new Uint8Array(32))).toString("base64"),We=f.replace('AUTH_SECRET=""',`AUTH_SECRET="${F}" # Generated by create-lx2-app`).replace('BETTER_AUTH_SECRET=""',`BETTER_AUTH_SECRET="${F}" # Generated by create-lx2-app`).replace('PAYLOAD_SECRET=""',`PAYLOAD_SECRET="${F}" # Generated by create-lx2-app`);W.writeFileSync(v,We,"utf-8"),W.writeFileSync(Be,Je,"utf-8")};function Ze(e,a,s,n,t,o){let i=`
|
|
7
|
+
# When adding additional environment variables, the schema in "/src/env.ts"
|
|
8
8
|
# should be updated accordingly.
|
|
9
9
|
`.trim().concat(`
|
|
10
10
|
`);return s&&(i+=`
|
|
11
11
|
# Prisma
|
|
12
12
|
# https://www.prisma.io/docs/reference/database-reference/connection-urls#env
|
|
13
|
-
`),s&&(
|
|
14
|
-
`),
|
|
13
|
+
`),s&&(o==="mysql"?i+=`DATABASE_URL="mysql://root:password@localhost:3306/${t}"`:o==="postgresql"?i+=`DATABASE_URL="postgresql://postgres:password@localhost:5432/${t}"`:o==="sqlite"&&(i+='DATABASE_URL="file:./db.sqlite"'),i+=`
|
|
14
|
+
`),n&&(i+=`
|
|
15
15
|
# Payload CMS
|
|
16
16
|
# https://payloadcms.com/docs/database/overview
|
|
17
17
|
`,i+=`PAYLOAD_SECRET=""
|
|
18
|
-
`,
|
|
18
|
+
`,o==="postgresql"?i+=`DATABASE_URL="postgresql://postgres:password@localhost:5432/${t}"`:o==="sqlite"&&(i+='DATABASE_URL="file:./db.sqlite"'),i+=`
|
|
19
19
|
`),e&&(i+=`
|
|
20
20
|
# Next Auth
|
|
21
21
|
# You can generate a new secret on the command line with:
|
|
@@ -36,11 +36,11 @@ NEXT_PUBLIC_BETTER_AUTH_URL="http://localhost:3000" # Base URL of your app
|
|
|
36
36
|
# Better Auth Discord Provider
|
|
37
37
|
DISCORD_CLIENT_ID=""
|
|
38
38
|
DISCORD_CLIENT_SECRET=""
|
|
39
|
-
`),!e&&!s&&!
|
|
39
|
+
`),!e&&!s&&!n&&(i+=`
|
|
40
40
|
# Example:
|
|
41
41
|
# SERVERVAR="foo"
|
|
42
42
|
# NEXT_PUBLIC_CLIENTVAR="bar"
|
|
43
|
-
`),i}var
|
|
43
|
+
`),i}var et=`
|
|
44
44
|
# Since the ".env" file is gitignored, you can use the ".env.example" file to
|
|
45
45
|
# build a new ".env" file when you clone the repo. Keep this file up-to-date
|
|
46
46
|
# when you add new variables to \`.env\`.
|
|
@@ -50,19 +50,19 @@ DISCORD_CLIENT_SECRET=""
|
|
|
50
50
|
# ".env" and populate it with your secrets.
|
|
51
51
|
`.trim().concat(`
|
|
52
52
|
|
|
53
|
-
`);import
|
|
53
|
+
`);import O from"path";import $ from"fs-extra";var de=({projectDir:e,packages:a})=>{let s=a?.["eslint/prettier"].inUse,n=[];s&&(n.push("eslint"),n.push("eslint-config-next"),n.push("@eslint/eslintrc"),n.push("prettier"),n.push("prettier-plugin-tailwindcss"),n.push("@ianvs/prettier-plugin-sort-imports")),h({projectDir:e,dependencies:n,devMode:!0});let t=O.join(d,"template/packages/config","eslint.config.mjs"),o=O.join(d,"template/packages/config","prettier.config.mjs"),i=O.join(e,"eslint.config.mjs"),r=O.join(e,"prettier.config.mjs"),p=O.join(e,"package.json"),c=$.readJSONSync(p);c.scripts={...c.scripts,lint:"next lint"},$.copyFileSync(t,i),$.writeJSONSync(p,c,{spaces:2}),$.copyFileSync(o,r)};import x from"path";import S from"fs-extra";var me=({projectDir:e,packages:a,databaseProvider:s})=>{let n=a?.authjs.inUse,t=a?.betterAuth.inUse;h({projectDir:e,dependencies:["prisma"],devMode:!0}),h({projectDir:e,dependencies:["@prisma/client"],devMode:!1});let o=x.join(d,"template/packages"),i=x.join(o,"prisma/schema",`${n?"with-authjs":t?"with-better-auth":"base"}.prisma`),r=S.readFileSync(i,"utf-8");s!=="sqlite"&&(r=r.replace('provider = "sqlite"',`provider = "${{mysql:"mysql",postgresql:"postgresql"}[s]}"`),["mysql"].includes(s)&&(r=r.replace("// @db.Text","@db.Text")));let p=x.join(e,"prisma/schema.prisma");S.mkdirSync(x.dirname(p),{recursive:!0}),S.writeFileSync(p,r);let c=x.join(o,"src/server/db/db-prisma.ts"),g=x.join(e,"src/server/db/index.ts");S.mkdirSync(x.dirname(g),{recursive:!0}),S.writeFileSync(g,S.readFileSync(c,"utf-8"));let f=x.join(e,"package.json"),m=S.readJSONSync(f);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"},S.writeJSONSync(f,m,{spaces:2})};var fe=["none","authjs","betterAuth"],ue=["none","prisma"],G=["sqlite","mysql","postgresql"];var ge=e=>({authjs:{inUse:e.includes("authjs"),installer:pe},betterAuth:{inUse:e.includes("betterAuth"),installer:oe},prisma:{inUse:e.includes("prisma"),installer:me},envVariables:{inUse:!0,installer:ce},"eslint/prettier":{inUse:e.includes("eslint/prettier"),installer:de},typescript:{inUse:!0,installer:le},payload:{inUse:e.includes("payload"),installer:ie}});import tt from"path";import at from"fs-extra";function I(){let e=tt.join(d,"package.json");return at.readJSONSync(e).version??"1.0.0"}var b=()=>{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 D=class extends Error{constructor(a){super(a)}};import L from"chalk";var l={error(...e){console.log(L.red(...e))},warn(...e){console.log(L.yellow(...e))},info(...e){console.log(L.cyan(...e))},success(...e){console.log(L.green(...e))}};var q=e=>(e.length>1&&e.endsWith("/")&&(e=e.slice(0,-1)),e);var st=/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/;function he(e){let a=q(e),s=a.split("/"),n=s.findIndex(o=>o.startsWith("@")),t=s[s.length-1];return s.findIndex(o=>o.startsWith("@"))!==-1&&(t=s.slice(n).join("/")),a=="."||st.test(t??"")?!0:"App name must consist of only lowercase alphanumeric characters, '-', and '_'"}var ye=e=>e.startsWith(".")||e.startsWith("/")?"Import alias can't start with '.' or '/'":!0;var u={appName:C,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 ve(){let e=u,a=new nt().name(B).description("CLI for scaffolding new web apps with the Lx2 stack").version(I(),"-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: ${u.flags.backend}`,u.flags.backend).option("--authProvider [provider]",`Choose an authentication provider to use. Possible values: ${fe.join(", ")}`,u.flags.authentication).option("--databaseORM [orm]",`Choose a database ORM to use. Possible values: ${ue.join(", ")}`,u.flags.orm).option("--linter [linter]",`Choose what linter and formatter to use. Possible values: ${u.flags.linter}`,u.flags.linter).option("-i, --import-alias [alias]","Explicitly tell the CLI to use a custom import alias",u.flags.importAlias).option("--dbProvider [provider]",`Choose a database provider to use. Possible values: ${G.join(", ")}`,u.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
54
|
and likely to result in a crash. Please run create-lx2-app with another
|
|
55
55
|
package manager such as pnpm, npm, or Yarn Classic.
|
|
56
|
-
See: https://github.com/t3-oss/create-t3-app/issues/57`);let s=a.args[0];if(s&&(e.appName=s),e.flags=a.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;default:break}switch(e.flags.
|
|
56
|
+
See: https://github.com/t3-oss/create-t3-app/issues/57`);let s=a.args[0];if(s&&(e.appName=s),e.flags=a.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;default:break}switch(e.flags.linter){case"eslint/prettier":e.packages.push("eslint/prettier");break;default:break}return G.includes(e.flags.dbProvider)===!1&&(l.warn(`Incompatible database provided. Use: ${G.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
57
|
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 H from"fs-extra";function
|
|
65
|
-
`).start(),s=Q(e),
|
|
66
|
-
`)}catch{a.fail(`${
|
|
67
|
-
`)}}import
|
|
68
|
-
`))};var
|
|
58
|
+
can provide the arguments from the CLI directly: https://create.lx2.dev/docs/getting-started#experimental-ci-flags to skip the prompts.`),new D("Non-interactive environment");let n=b(),t={};s||(t.name=await be({message:"What will your project be called?",default:C,validate:i=>he(i)})),t.backend=await j({message:"What backend framework would you like to use?",choices:[{value:"nextjs",name:"Next.js"},{value:"payload",name:"Payload CMS"}],default:!u.flags.backend}),t.backend==="payload"&&(t.databaseProvider=await j({message:"What database provider would you like to use?",choices:[{value:"sqlite",name:"SQLite"},{value:"postgresql",name:"PostgreSQL"}],default:!u.flags.dbProvider})),t.backend==="nextjs"&&(t.authentication=await j({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:!u.flags.authentication}),t.orm=await j({message:"What database ORM would you like to use?",choices:[{value:"none",name:"None"},{value:"prisma",name:"Prisma"}],default:!u.flags.orm}),t.orm!=="none"&&(t.databaseProvider=await j({message:"What database provider would you like to use?",choices:[{value:"sqlite",name:"SQLite"},{value:"mysql",name:"MySQL"},{value:"postgresql",name:"PostgreSQL"}],default:!u.flags.dbProvider}))),t.linter=await j({message:"What linter and formatter would you like to use?",choices:[{value:"eslint/prettier",name:"ESLint/Prettier"}],default:!u.flags.linter}),e.flags.noGit||(t.noGit=await V({message:"Should we initialize a Git repository and stage the changes?",default:!u.flags.noGit})),e.flags.noInstall||(t.noInstall=await V({message:`Should we run '${n}`+(n==="yarn"?"'?":" install' for you?"),default:!u.flags.noInstall})),t.importAlias=await be({message:"What import alias would you like to use?",default:u.flags.importAlias,validate:ye});let o=[];switch(t.backend){case"payload":o.push("payload");break;default:break}switch(t.authentication){case"authjs":o.push("authjs");break;case"betterAuth":o.push("betterAuth");break;default:break}switch(t.orm){case"prisma":o.push("prisma");break;default:break}switch(t.linter){case"eslint/prettier":o.push("eslint/prettier");break;default:break}return{appName:t.name??e.appName,packages:o,flags:{...e.flags,noGit:!t.noGit||e.flags.noGit,noInstall:!t.noInstall||e.flags.noInstall,importAlias:t.importAlias??e.flags.importAlias},databaseProvider:t.databaseProvider||"sqlite"}}catch(n){if(n instanceof D)l.warn(`${B} needs an interactive terminal to run.`),await V({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 n}return e}import pt from"path";import ke from"chalk";import ot from"ora";function we(e){let{packages:a}=e;l.info("Adding boilerplate...");for(let[s,n]of Object.entries(a))if(n.inUse){let t=ot(`Boilerplating ${s}...`).start();n.installer(e),t.succeed(ke.green(`${ke.green.bold(s)}`))}l.info("")}import z from"path";import{confirm as it,select as rt}from"@inquirer/prompts";import A from"chalk";import E from"fs-extra";import lt from"ora";async function Pe({projectName:e,projectDir:a,pkgManager:s,noInstall:n}){let t=z.join(d,"template/base");n?l.info(""):l.info(`
|
|
59
|
+
Using: ${A.cyan.bold(s)}
|
|
60
|
+
`);let o=lt(`Scaffolding in: ${a}...
|
|
61
|
+
`).start();if(E.existsSync(a))if(E.readdirSync(a).length===0)e!=="."&&o.info(`${A.cyan.bold(e)} exists but is empty, continuing...
|
|
62
|
+
`);else{o.stopAndPersist();let r=await rt({message:`${A.redBright.bold("Warning:")} ${A.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"&&(o.fail("Aborting installation..."),process.exit(1)),await it({message:`Are you sure you want to ${r==="clear"?"clear the directory":"overwrite conflicting files"}`,default:!1})||(o.fail("Aborting installation..."),process.exit(1)),r==="clear"&&(o.info(`Emptying ${A.cyan.bold(e)} and creating lx2 app...
|
|
63
|
+
`),E.emptyDirSync(a))}o.start(),E.copySync(t,a),E.renameSync(z.join(a,"_gitignore"),z.join(a,".gitignore"));let i=e==="."?"App":A.cyan.bold(e);o.succeed(`${i} ${A.green.bold("scaffolded successfully!")}
|
|
64
|
+
`)}import k from"path";import H from"fs-extra";function xe({packages:e,projectDir:a}){let s=k.join(d,"template/packages/src/app/layout"),n=e.payload.inUse,o=k.join(s,"base.tsx"),i=k.join(a,`src/app/${n?"(frontend)":""}/layout.tsx`);H.copySync(o,i)}function Se({packages:e,projectDir:a}){let s=k.join(d,"template/packages/src/app/page"),n=e.payload.inUse,t=e.authjs.inUse,o=e.betterAuth.inUse,i=e.prisma.inUse,r="base.tsx";n&&(r="with-payload.tsx"),t&&(r="with-authjs.tsx"),o&&(r="with-better-auth.tsx"),i&&(r="with-prisma.tsx"),t&&i&&(r="with-authjs-prisma.tsx"),o&&i&&(r="with-better-auth-prisma.tsx");let p=k.join(s,r),c=k.join(a,`src/app/${n?"(frontend)":""}/page.tsx`);H.copySync(p,c)}function _e({packages:e,projectDir:a}){let s=k.join(d,"template/packages/src/app/globals"),n=e.payload.inUse,o=k.join(s,"base.css"),i=k.join(a,`src/app/${n?"(frontend)":""}/globals.css`);H.copySync(o,i)}async function Ae({projectName:e,scopedAppName:a,packages:s,noInstall:n,databaseProvider:t}){let o=b(),i=pt.resolve(process.cwd(),e);return await Pe({projectName:e,projectDir:i,pkgManager:o,scopedAppName:a,noInstall:n,databaseProvider:t}),we({projectName:e,scopedAppName:a,projectDir:i,pkgManager:o,packages:s,noInstall:n,databaseProvider:t}),xe({packages:s,projectDir:i}),Se({packages:s,projectDir:i}),_e({packages:s,projectDir:i}),i}import{execSync as Y}from"child_process";import K from"path";import{confirm as Ie}from"@inquirer/prompts";import R from"chalk";import{execa as M}from"execa";import je from"fs-extra";import ct from"ora";function dt(e){try{return Y("git --version",{cwd:e}),!0}catch{return!1}}function Q(e){return je.existsSync(K.join(e,".git"))}async function X(e){try{return await M("git",["rev-parse","--is-inside-work-tree"],{cwd:e,stdout:"ignore"}),!0}catch{return!1}}function mt(){let a=Y("git --version").toString().trim().split(" ")[2],s=a?.split(".")[0],n=a?.split(".")[1];return{major:Number(s),minor:Number(n)}}function ft(){return Y("git config --global init.defaultBranch || echo main").toString().trim()}async function Ce(e){if(l.info("Initializing Git..."),!dt(e)){l.warn("Git is not installed. Skipping Git initialization.");return}let a=ct(`Creating a new git repo...
|
|
65
|
+
`).start(),s=Q(e),n=await X(e),t=K.parse(e).name;if(n&&s){if(a.stop(),!await Ie({message:`${R.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})){a.info("Skipping Git initialization.");return}je.removeSync(K.join(e,".git"))}else if(n&&!s&&(a.stop(),!await Ie({message:`${R.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}))){a.info("Skipping Git initialization.");return}try{let o=ft(),{major:i,minor:r}=mt();i<2||i==2&&r<28?(await M("git",["init"],{cwd:e}),await M("git",["symbolic-ref","HEAD",`refs/heads/${o}`],{cwd:e})):await M("git",["init",`--initial-branch=${o}`],{cwd:e}),await M("git",["add","."],{cwd:e}),a.succeed(`${R.green("Successfully initialized and staged")} ${R.green.bold("git")}
|
|
66
|
+
`)}catch{a.fail(`${R.bold.red("Failed:")} could not initialize git. Update git to the latest version!
|
|
67
|
+
`)}}import ut from"chalk";import{execa as Te}from"execa";import Oe from"ora";var Z=async(e,a,s)=>{let{onDataHandle:n,args:t=["install"],stdout:o="pipe"}=s,i=Oe(`Running ${a} install...`).start(),r=Te(a,t,{cwd:e,stdout:o});return await new Promise((p,c)=>{n&&r.stdout?.on("data",n(i)),r.on("error",g=>c(g)),r.on("close",()=>p())}),i},gt=async(e,a)=>{switch(e){case"npm":return await Te(e,["install"],{cwd:a,stderr:"inherit"}),null;case"pnpm":return Z(a,e,{onDataHandle:s=>n=>{let t=n.toString();t.includes("Progress")&&(s.text=t.includes("|")?t.split(" | ")[1]??"":t)}});case"yarn":return Z(a,e,{onDataHandle:s=>n=>{s.text=n.toString()}});case"bun":return Z(a,e,{stdout:"ignore"})}},De=async({projectDir:e})=>{l.info("Installing dependencies...");let a=b();(await gt(a,e)??Oe()).succeed(ut.green(`Successfully installed dependencies!
|
|
68
|
+
`))};var Ee=async({projectName:e=C,packages:a,noInstall:s,projectDir:n,databaseProvider:t})=>{let o=b();l.info("Next steps:"),e!=="."&&l.info(` cd ${e}`),s&&(o==="yarn"?l.info(` ${o}`):l.info(` ${o} install`)),["postgresql","mysql"].includes(t)&&l.info(" Add your database connection string to .env"),a?.authjs.inUse&&l.info(" Fill in your .env with necessary values. See https://create.lx2.dev/docs/first-steps for more info."),a?.betterAuth.inUse&&l.info(" Fill in your .env with necessary values. See https://create.lx2.dev/docs/first-steps for more info."),a?.prisma.inUse&&l.info(` Run "${o} db:push" to create you database tables.`),["npm"].includes(o)?l.info(` ${o} run dev`):l.info(` ${o} dev`),!await X(n)&&!Q(n)&&l.info(" git init"),l.info(' git commit -m "initial commit"')};import N from"fs";import ht from"path";function Re(e,a,s){N.readdirSync(e).forEach(t=>{let o=ht.join(e,t);if(N.statSync(o).isDirectory())Re(o,a,s);else{let r=N.readFileSync(o,"utf8").replace(new RegExp(a,"g"),s);N.writeFileSync(o,r,"utf8")}})}function Me(e,a){let s=a.replace(/\*/g,"").replace(/[^\/]$/,"$&/");Re(e,"@/",s)}import Ue from"path";function $e(e){let s=q(e).split("/"),n=s[s.length-1];if(n==="."){let i=Ue.resolve(process.cwd());n=Ue.basename(i)}let t=s.findIndex(i=>i.startsWith("@"));s.findIndex(i=>i.startsWith("@"))!==-1&&(n=s.slice(t).join("/"));let o=s.filter(i=>!i.startsWith("@")).join("/");return[n,o]}import yt from"gradient-string";var bt={primary:"#bf95f9",accent:"#6071a4",secondary:"#ff7ac5"};function Ge(){let e=yt(Object.values(bt)),a=b();(a==="yarn"||a==="pnpm")&&console.log(""),console.log(e.multiline(te))}import{execSync as vt}from"child_process";import kt from"https";function Le(e){let a=I();a.includes("beta")?(l.warn(" You are using a beta version of create-lx2-app."),l.warn(" Please report any bugs you encounter.")):a!==e&&(l.warn(" You are using an outdated version of create-lx2-app."),l.warn(" Your version:",a+".","Latest version in the npm registry:",e),l.warn(" Please run the CLI with @latest to get the latest updates.")),console.log("")}function wt(){return new Promise((e,a)=>{kt.get("https://registry.npmjs.org/-/package/create-lx2-app/dist-tags",s=>{if(s.statusCode===200){let n="";s.on("data",t=>n+=t),s.on("end",()=>{e(JSON.parse(n).latest)})}else a()}).on("error",()=>{a()})})}var qe=()=>wt().catch(()=>{try{return vt("npm view create-lx2-app version").toString().trim()}catch{return null}});async function xt(){let e=await qe(),a=b();Ge(),e&&Le(e);let{appName:s,packages:n,flags:{noGit:t,noInstall:o,importAlias:i},databaseProvider:r}=await ve(),p=ge(n),[c,g]=$e(s),f=await Ae({projectName:g,scopedAppName:c,packages:p,noInstall:o,databaseProvider:r}),m=Fe.readJsonSync(Ne.join(f,"package.json"));m.name=c,m.clx2aMetadata={initVersion:I()};let{stdout:v}=await Pt(a,["-v"],{cwd:f});m.packageManager=`${a}@${v.trim()}`,Fe.writeJSONSync(Ne.join(f,"package.json"),m,{spaces:2}),i!=="@/"&&Me(f,i),o||await De({projectDir:f}),t||await Ce(f),await Ee({projectDir:f,projectName:g,packages:p,noInstall:o,databaseProvider:r}),process.exit(0)}xt().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.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"description": "Create powerful full-stack web applications with the Lx2 stack",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -30,19 +30,6 @@
|
|
|
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
|
-
},
|
|
46
33
|
"dependencies": {
|
|
47
34
|
"@inquirer/prompts": "^7.4.0",
|
|
48
35
|
"better-auth": "^1.2.7",
|
|
@@ -88,5 +75,18 @@
|
|
|
88
75
|
"type-fest": "^4.37.0",
|
|
89
76
|
"typescript": "^5.8.2",
|
|
90
77
|
"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
91
|
}
|
|
92
|
-
}
|
|
92
|
+
}
|
|
@@ -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
|
|
|
@@ -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
|
}
|
|
File without changes
|