UNPKG

create-w3-app

Version:
61 lines (52 loc) 27.9 kB
#!/usr/bin/env node import Ke from"path";import{execa as jt}from"execa";import Ye from"fs-extra";import*as f from"@clack/prompts";import ie from"chalk";import{Command as it}from"commander";import Q from"path";import{fileURLToPath as He}from"url";var Xe=He(import.meta.url),Qe=Q.dirname(Xe),c=Q.join(Qe,"../"),Z=` \u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D \u2588\u2588\u2551 \u2588\u2588\u2551\u255A\u2550\u2550\u2550\u2550\u2588\u2588\u2557 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u2588\u2557 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u255A\u2550\u2550\u2550\u2588\u2588\u2557 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551\u2588\u2588\u2554\u2550\u2550\u2550\u255D \u2588\u2588\u2554\u2550\u2550\u2550\u255D \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u255A\u2588\u2588\u2588\u2554\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u255A\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u255D\u255A\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D `,M="my-w3-app",F="create-w3-app";import Ze from"path";import et from"fs-extra";var S=()=>{let e=Ze.join(c,"package.json");return et.readJSONSync(e).version??"1.0.0"};var u=()=>{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 C=class extends Error{constructor(i){super(i)}};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 D=e=>(e.length>1&&e.endsWith("/")&&(e=e.slice(0,-1)),e);var tt=/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/,ee=e=>{if(!e)return"App name is required";let i=D(e),o=i.split("/"),t=o.findIndex(s=>s.startsWith("@")),n=o[o.length-1];if(o.findIndex(s=>s.startsWith("@"))!==-1&&(n=o.slice(t).join("/")),!(i==="."||tt.test(n??"")))return"App name must consist of only lowercase alphanumeric characters, '-', and '_'"};var te=e=>{if(!e)return"Import alias is required";if(e.startsWith(".")||e.startsWith("/"))return"Import alias can't start with '.' or '/'"};var I={appName:M,packages:["tailwind","privy","eslint"],flags:{noGit:!1,noInstall:!1,default:!1,CI:!1,tailwind:!1,shadcn:!1,privy:!1,rainbow:!1,importAlias:"@/",appRouter:!1,eslint:!1,biome:!1}},ne=async()=>{let e=I,i=new it().name(F).description("A CLI for creating dApps with the w3-app stack").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 w3-app app",!1).option("--CI","Boolean value if we're running in CI",!1).option("--tailwind [boolean]","Experimental: Boolean value if we should install Tailwind CSS. Must be used in conjunction with `--CI`.",t=>!!t&&t!=="false").option("--shadcn [boolean]","Experimental: Boolean value if we should install shadcn/ui. Must be used in conjunction with `--CI`.",t=>!!t&&t!=="false").option("-i, --import-alias","Explicitly tell the CLI to use a custom import alias",I.flags.importAlias).option("--appRouter [boolean]","Explicitly tell the CLI to use the new Next.js app router",t=>!!t&&t!=="false").option("--eslint [boolean]","Experimental: Boolean value if we should install eslint and prettier. Must be used in conjunction with `--CI`.",t=>!!t&&t!=="false").option("--biome [boolean]","Experimental: Boolean value if we should install biome. Must be used in conjunction with `--CI`.",t=>!!t&&t!=="false").version(S(),"-v, --version","Display the version number").addHelpText("afterAll",` The w3-app stack was inspired by ${ie.hex("#E8DCFF").bold("create-w3-app")} )} `).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, and likely to result in a crash. Please run create-w3-app with another package manager such as pnpm, npm, or Yarn Classic.`);let o=i.args[0];if(o&&(e.appName=o),e.flags=i.opts(),e.flags.CI)return e.packages=[],e.flags.tailwind&&e.packages.push("tailwind"),e.flags.shadcn&&e.packages.push("shadcn"),e.flags.privy&&e.packages.push("privy"),e.flags.rainbow&&e.packages.push("rainbow"),e.flags.eslint&&e.packages.push("eslint"),e.flags.biome&&e.packages.push("biome"),e.flags.biome&&e.flags.eslint&&(l.warn("Incompatible combination Biome + ESLint. Exiting."),process.exit(0)),!e.flags.tailwind&&e.flags.shadcn&&(l.warn("Cannot install Shadcn UI without Tailwind Css. 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 using Git Bash. If that's that case, please use Git Bash from another terminal, such as Windows Terminal. Alternatively, you can provide the arguments from the CLI directly to skip the prompts.`),new C("Non-interactive environment");let t=u(),n=await f.group({...!o&&{name:()=>f.text({message:"What will your project be called?",defaultValue:o,validate:ee})},language:()=>f.select({message:"Will you be using TypeScript or JavaScript?",options:[{value:"typescript",label:"TypeScript"},{value:"javascript",label:"JavaScript"}],initialValue:"typescript"}),_:({results:a})=>{a.language==="javascript"&&f.note(ie.redBright("Wrong answer, using TypeScript instead"))},styling:()=>f.confirm({message:"Will you be using Tailwind CSS for styling?"}),shadcn:()=>f.confirm({message:"Would you like to use Shadcn UI for component library?",initialValue:!0}),wallet:()=>f.select({message:"Which wallet authentication solution would you like to use?",options:[{value:"none",label:"None"},{value:"privy",label:"Privy"},{value:"rainbow",label:"Rainbow Kit"}],initialValue:"privy"}),viem:({results:a})=>{if(a.wallet==="privy"||a.wallet==="none")return f.confirm({message:"Would you like to install Wagmi (Viem + Tanstack React Query) for contract interactions?",initialValue:!0})},appRouter:()=>f.confirm({message:"Would you like to use Next.js App Router?",initialValue:!0}),linter:()=>f.select({message:"Would you like to use ESLint and Prettier or Biome for linting and formatting?",options:[{value:"eslint",label:"ESLint/Prettier"},{value:"biome",label:"Biome"}],initialValue:"eslint"}),...!e.flags.noGit&&{git:()=>f.confirm({message:"Should we initialize a Git repository and stage the changes?",initialValue:!I.flags.noGit})},...!e.flags.noInstall&&{install:()=>f.confirm({message:`Should we run '${t}`+(t==="yarn"?"'?":" install' for you?"),initialValue:!I.flags.noInstall})},importAlias:()=>f.text({message:"What import alias would you like to use?",defaultValue:I.flags.importAlias,placeholder:I.flags.importAlias,validate:te})},{onCancel(){process.exit(1)}}),s=[];return n.styling&&s.push("tailwind"),n.shadcn&&(s.push("shadcn"),s.includes("tailwind")||s.push("tailwind")),n.wallet==="privy"&&s.push("privy"),n.wallet==="rainbow"&&s.push("rainbow"),n.viem&&s.push("wagmi"),n.appRouter&&(e.flags.appRouter=n.appRouter),n.linter==="eslint"&&s.push("eslint"),n.linter==="biome"&&s.push("biome"),n.git!==void 0&&(e.flags.noGit=!n.git),{appName:n.name??e.appName,packages:s,flags:{...e.flags,appRouter:n.appRouter??e.flags.appRouter,noGit:!n.git||e.flags.noGit,noInstall:!n.install||e.flags.noInstall,importAlias:n.importAlias??e.flags.importAlias}}}catch(t){if(t instanceof C)l.warn(` ${F} needs an interactive terminal to provide options`),await f.confirm({message:"Continue scaffolding a default w3-app app?",initialValue:!0})||(l.info("Exiting..."),process.exit(0)),l.info(`Bootstrapping a default w3-app app in ./${e.appName}`);else throw t}return e};import ge from"fs";import R from"path";import oe from"chalk";import nt from"ora";var se=e=>{let{packages:i}=e;l.info("Adding boilerplate...");for(let[o,t]of Object.entries(i))if(t.inUse){let n=nt(`Boilerplating ${o}...`).start();t.installer(e),n.succeed(oe.green(`Successfully setup boilerplate for ${oe.green.bold(o)}`))}l.info("")};import $ from"path";import*as v from"@clack/prompts";import b from"chalk";import A from"fs-extra";import ot from"ora";var re=async({projectName:e,projectDir:i,pkgManager:o,noInstall:t})=>{let n=$.join(c,"template/base");t?l.info(""):l.info(` Using: ${b.cyan.bold(o)} `);let s=ot(`Scaffolding in: ${i}... `).start();if(A.existsSync(i))if(A.readdirSync(i).length===0)e!=="."&&s.info(`${b.cyan.bold(e)} exists but is empty, continuing... `);else{s.stopAndPersist();let r=await v.select({message:`${b.redBright.bold("Warning:")} ${b.cyan.bold(e)} already exists and isn't empty. How would you like to proceed?`,options:[{label:"Abort installation (recommended)",value:"abort"},{label:"Clear the directory and continue installation",value:"clear"},{label:"Continue installation and overwrite conflicting files",value:"overwrite"}],initialValue:"abort"});(v.isCancel(r)||r==="abort")&&(s.fail("Aborting installation..."),process.exit(1));let p=await v.confirm({message:`Are you sure you want to ${r==="clear"?"clear the directory":"overwrite conflicting files"}?`,initialValue:!1});(v.isCancel(p)||!p)&&(s.fail("Aborting installation..."),process.exit(1)),r==="clear"&&(s.info(`Emptying ${b.cyan.bold(e)} and creating w3-app.. `),A.emptyDirSync(i))}s.start(),A.copySync(n,i),A.renameSync($.join(i,"_gitignore"),$.join(i,".gitignore"));let a=e==="."?"App":b.cyan.bold(e);s.succeed(`${a} ${b.green("scaffolded successfully!")} `)};import g from"path";import k from"fs-extra";var ae=({projectDir:e,packages:i})=>{let o=g.join(c,"template/extras/src/pages/_app"),t=i.tailwind.inUse,n=i.privy.inUse,s=i.rainbow.inUse,a=i.wagmi.inUse,r="base.tsx";n&&t?r="with-privy-tw.tsx":n&&!t?r="with-privy.tsx":s&&t?r="with-rbow-tw.tsx":s&&!t?r="with-rbow.tsx":t&&!n&&!s?r="with-tw.tsx":(a&&!n&&!s||a&&!n&&!s&&!t)&&(r="with-wagmi.tsx");let p=g.join(o,r),m=g.join(e,"src/pages/_app.tsx");k.copySync(p,m)},le=({projectDir:e,packages:i})=>{let o=g.join(c,"template/extras/src/app/layout"),t=i.tailwind.inUse,n=i.privy.inUse,s=i.rainbow.inUse,a=i.wagmi.inUse,r="base.tsx";n&&t?r="with-privy-tw.tsx":n&&!t?r="with-privy.tsx":s&&t?r="with-rbow-tw.tsx":s&&!t?r="with-rbow.tsx":t&&!n&&!s?r="with-tw.tsx":(a&&!n&&!s||a&&!n&&!s&&!t)&&(r="with-wagmi.tsx");let p=g.join(o,r),m=g.join(e,"src/app/layout.tsx");k.copySync(p,m)},ce=({projectDir:e,packages:i})=>{let o=g.join(c,"template/extras/src/pages/index"),t=i.tailwind.inUse,n=i.privy.inUse,s=i.rainbow.inUse,a=i.wagmi.inUse,r="base.tsx";n&&t?r="with-privy-tw.tsx":n&&!t?r="with-privy.tsx":s&&t?r="with-rbow-tw.tsx":s&&!t?r="with-rbow.tsx":t&&!n&&!s?r="with-tw.tsx":a&&t&&!n&&!s?r="with-wagmi-tw.tsx":a&&!n&&!s&&!t&&(r="with-wagmi.tsx");let p=g.join(o,r),m=g.join(e,"src/pages/index.tsx");k.copySync(p,m)},pe=({projectDir:e,packages:i})=>{let o=g.join(c,"template/extras/src/app/page"),t=i.tailwind.inUse,n=i.privy.inUse,s=i.rainbow.inUse,a=i.wagmi.inUse,r="base.tsx";n&&t?r="with-privy-tw.tsx":n&&!t?r="with-privy.tsx":s&&t?r="with-rbow-tw.tsx":s&&!t?r="with-rbow.tsx":t&&!n&&!s?r="with-tw.tsx":a&&t&&!n&&!s?r="with-wagmi-tw.tsx":a&&!n&&!s&&!t&&(r="with-wagmi.tsx");let p=g.join(o,r),m=g.join(e,"src/app/page.tsx");k.copySync(p,m)},me=({projectDir:e,packages:i})=>{let o=g.join(c,"template/extras/src/app/components"),t=i.tailwind.inUse,n=i.privy.inUse,s=i.rainbow.inUse,a=i.wagmi.inUse,r="base.tsx";n&&t?r="with-privy-tw.tsx":n&&t&&a?r="with-privy-wagmi-tw.tsx":n&&a?r="with-privy-wagmi.tsx":s&&t?r="with-rbow-tw.tsx":s&&!t?r="with-rbow.tsx":t&&!n&&!s&&(r="with-tw.tsx");let p=g.join(o,r),m=g.join(e,"src/components/connect.tsx");k.copySync(p,m)},fe=({projectDir:e,packages:i})=>{let o=g.join(c,"template/extras/src/pages/components"),t=i.tailwind.inUse,n=i.privy.inUse,s=i.rainbow.inUse,a=i.wagmi.inUse,r="base.tsx";n&&t?r="with-privy-tw.tsx":n&&t&&a?r="with-privy-wagmi-tw.tsx":n&&a?r="with-privy-wagmi.tsx":s&&t?r="with-rbow-tw.tsx":s&&!t?r="with-rbow.tsx":t&&!n&&!s&&(r="with-tw.tsx");let p=g.join(o,r),m=g.join(e,"src/components/connect.tsx");k.copySync(p,m)};var de=async({projectName:e,scopedAppName:i,packages:o,noInstall:t,appRouter:n})=>{let s=u(),a=R.resolve(process.cwd(),e);if(await re({projectName:e,projectDir:a,pkgManager:s,scopedAppName:i,noInstall:t,appRouter:n}),se({projectName:e,scopedAppName:i,projectDir:a,pkgManager:s,packages:o,noInstall:t,appRouter:n}),n?(ge.copyFileSync(R.join(c,"template/extras/config/next-config-appdir.js"),R.join(a,"next.config.js")),le({projectDir:a,packages:o}),pe({projectDir:a,packages:o}),me({projectDir:a,packages:o})):(ae({projectDir:a,packages:o}),ce({projectDir:a,packages:o}),fe({projectDir:a,packages:o})),!o.tailwind.inUse){let r=R.join(c,"template/extras/src/index.module.css"),p=R.join(a,"src",n?"app":"pages","index.module.css");ge.copyFileSync(r,p)}return a};import{execSync as L}from"child_process";import B from"path";import*as J from"@clack/prompts";import T from"chalk";import{execa as O}from"execa";import ue from"fs-extra";import st from"ora";var rt=e=>{try{return L("git --version",{cwd:e}),!0}catch{return!1}},z=e=>ue.existsSync(B.join(e,".git")),K=async e=>{try{return await O("git",["rev-parse","--is-inside-work-tree"],{cwd:e,stdout:"ignore"}),!0}catch{return!1}},at=()=>{let i=L("git --version").toString().trim().split(" ")[2],o=i?.split(".")[0],t=i?.split(".")[1];return{major:Number(o),minor:Number(t)}},lt=()=>L("git config --global init.defaultBranch || echo main").toString().trim(),we=async e=>{if(l.info("Initializing Git..."),!rt(e)){l.warn("Git is not installed. Skipping Git initialization.");return}let i=st(`Creating a new git repo... `).start(),o=z(e),t=await K(e),n=B.parse(e).name;if(t&&o){if(i.stop(),!await J.confirm({message:`${T.redBright.bold("Warning:")} Git is already initialized in "${n}". Initializing a new git repository would delete the previous history. Would you like to continue anyways?`,initialValue:!1})){i.info("Skipping Git initialization.");return}ue.removeSync(B.join(e,".git"))}else if(t&&!o&&(i.stop(),!await J.confirm({message:`${T.redBright.bold("Warning:")} "${n}" is already in a git worktree. Would you still like to initialize a new git repository in this directory?`,initialValue:!1}))){i.info("Skipping Git initialization.");return}try{let s=lt(),{major:a,minor:r}=at();a<2||a==2&&r<28?(await O("git",["init"],{cwd:e}),await O("git",["symbolic-ref","HEAD",`refs/heads/${s}`],{cwd:e})):await O("git",["init",`--initial-branch=${s}`],{cwd:e}),await O("git",["add","."],{cwd:e}),i.succeed(`${T.green("Successfully initialized and staged")} ${T.green.bold("git")} `)}catch{i.fail(`${T.bold.red("Failed:")} could not initialize git. Update git to the latest version! `)}};var ye=async({projectName:e=M,noInstall:i,projectDir:o})=>{let t=u();l.info("Next steps:"),e!=="."&&l.info(` cd ${e}`),i&&(t==="yarn"?l.info(` ${t}`):l.info(` ${t} install`)),["npm","bun"].includes(t)?l.info(` ${t} run dev`):l.info(` ${t} dev`),!await K(o)&&!z(o)&&l.info(" git init"),l.info(' git commit -m "initial commit"')};import W from"fs";import ct from"path";function he(e,i,o){W.readdirSync(e).forEach(n=>{let s=ct.join(e,n);if(W.statSync(s).isDirectory())he(s,i,o);else{let r=W.readFileSync(s,"utf8").replace(new RegExp(i,"g"),o);W.writeFileSync(s,r,"utf8")}})}var xe=(e,i)=>{let o=i.replace(/\*/g,"").replace(/[^/]$/,"$&/");he(e,"~/",o)};import j from"path";import Se from"fs-extra";import ve from"path";import Pe from"fs-extra";import pt from"sort-package-json";var be={tailwindcss:"^4.0.15",postcss:"^8.5.3","@tailwindcss/postcss":"^4.0.15","class-variance-authority":"^0.7.1",clsx:"^2.1.1","lucide-react":"^0.515.0","tailwind-merge":"^3.3.1","tw-animate-css":"^1.3.4",prettier:"^3.5.3","@eslint/eslintrc":"^3.3.1","prettier-plugin-tailwindcss":"^0.6.11",eslint:"^9.23.0","eslint-config-next":"^15.2.3","eslint-plugin-drizzle":"^0.2.3","typescript-eslint":"^8.27.0","@biomejs/biome":"^1.9.4","@privy-io/react-auth":"^2.4.14","@privy-io/wagmi":"^1.0.5","@rainbow-me/rainbowkit":"^2.2.6","@tanstack/react-query":"^5.69.0",wagmi:"^2.15.6",viem:"^2.31.0"};var d=e=>{let{dependencies:i,devMode:o,projectDir:t}=e,n=Pe.readJSONSync(ve.join(t,"package.json"));i.forEach(a=>{let r=be[a];o&&n.devDependencies?n.devDependencies[a]=r:n.dependencies&&(n.dependencies[a]=r)});let s=pt(n);Pe.writeJSONSync(ve.join(t,"package.json"),s,{spaces:2})};var Ie=({projectDir:e,packages:i})=>{d({projectDir:e,dependencies:["@privy-io/react-auth"],devMode:!1});let o=i?.wagmi?.inUse===!0,t=j.join(c,"template/extras"),n=o?j.join(t,"src/provider/privy-wagmi-provider.tsx"):j.join(t,"src/provider/privy-provider.tsx"),s=j.join(e,"src/components/provider/privy-provider.tsx"),a=j.join(t,"config/privy.ts"),r=j.join(e,"src/config/privy.ts");Se.copySync(a,r),Se.copySync(n,s)};import E from"path";import ke from"fs-extra";var je=({projectDir:e})=>{d({projectDir:e,dependencies:["@rainbow-me/rainbowkit","wagmi","viem","@tanstack/react-query"],devMode:!1});let i=E.join(c,"template/extras"),o=E.join(i,"src/provider/rainbow-provider.tsx"),t=E.join(e,"src/components/provider/rainbow-provider.tsx"),n=E.join(i,"config/wagmi-rainbow.ts"),s=E.join(e,"src/config/wagmi.ts");ke.copySync(o,t),ke.copySync(n,s)};import P from"path";import Y from"fs-extra";var Ce=({projectDir:e})=>{d({projectDir:e,dependencies:["class-variance-authority","clsx","lucide-react","tailwind-merge"],devMode:!1}),d({projectDir:e,dependencies:["tw-animate-css"],devMode:!0});let i=P.join(c,"template/extras"),o=P.join(i,"config/components.json"),t=P.join(e,"components.json"),n=P.join(i,"src/lib/utils.ts"),s=P.join(e,"src/lib/utils.ts"),a=P.join(i,"src/styles/shadcn-globals.css"),r=P.join(e,"src/styles/globals.css");Y.copySync(o,t),Y.copySync(n,s),Y.copySync(a,r)};import _ from"path";import Ae from"fs-extra";var Re=({projectDir:e})=>{d({projectDir:e,dependencies:["tailwindcss","postcss","@tailwindcss/postcss"],devMode:!0});let i=_.join(c,"template/extras"),o=_.join(i,"config/postcss.config.js"),t=_.join(e,"postcss.config.js"),n=_.join(i,"src/styles/globals.css"),s=_.join(e,"src/styles/globals.css");Ae.copySync(o,t),Ae.copySync(n,s)};import w from"path";import G from"fs-extra";var Te=({projectDir:e,packages:i})=>{let o=i?.privy?.inUse===!0,t=i?.rainbow?.inUse===!0;o?d({projectDir:e,dependencies:["wagmi","@privy-io/wagmi","@tanstack/react-query"],devMode:!1}):d({projectDir:e,dependencies:["viem","wagmi","@tanstack/react-query"],devMode:!1});let n=w.join(c,"template/extras"),s=o?w.join(n,"config/wagmi-privy.ts"):w.join(n,"config/wagmi.ts"),a=w.join(e,"src/config/wagmi.ts"),r=w.join(n,"src/provider/wagmi-provider.tsx"),p=w.join(e,"src/components/provider/wagmi-provider.tsx");if(G.copySync(r,p),G.copySync(s,a),o){let m=w.join(n,"config/wagmi-privy.ts"),y=w.join(e,"src/config/wagmi.ts");G.copySync(m,y)}if(!t&&!o){let m=w.join(n,"src/provider/wagmi-provider.tsx"),y=w.join(e,"src/components/provider/wagmi-provider.tsx");G.copySync(m,y)}};import q from"path";import gt from"fs-extra";import mt from"path";import Oe from"fs-extra";import ft from"sort-package-json";var V=e=>{let{scripts:i,projectDir:o}=e,t=mt.join(o,"package.json"),n=Oe.readJSONSync(t);n.scripts={...n.scripts,...i};let s=ft(n);Oe.writeJSONSync(t,s,{spaces:2})};var Ee=({projectDir:e})=>{d({projectDir:e,dependencies:["@biomejs/biome"],devMode:!0});let i=q.join(c,"template/extras"),o=q.join(i,"config/biome.jsonc"),t=q.join(e,"biome.jsonc");gt.copySync(o,t),V({projectDir:e,scripts:{"biome:unsafe":"biome check --write --unsafe .","biome:write":"biome check --write .",biome:"biome check ."}})};import _e from"path";import Ue from"fs-extra";var Me=({projectDir:e,packages:i})=>{let o=i?.privy.inUse,t=i?.rainbow.inUse,n=_e.join(e,".env"),s=_e.join(e,".env.example"),a=dt(o,t),r=ut();Ue.writeFileSync(n,a,"utf-8"),Ue.writeFileSync(s,r,"utf-8")},dt=(e,i)=>{let o=` `.trim().concat(` `);return e&&(o+=`# Privy Configuration NODE_ENV="" NEXT_PUBLIC_PRIVY_APP_ID="" `),i&&(o+=`# Rainbow Kit Configuration NODE_ENV="" NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID="" `),!e&&!i&&(o+=`# Example: # NODE_ENV="" `),o},ut=()=>` # Since the ".env" file is gitignored, you can use the ".env.example" file to # build a new ".env" file when you clone the repo. Keep this file up-to-date # when you add new variables to \`.env\`. # This file will be committed to version control, so make sure not to have any # secrets in it. If you are cloning this repo, create a copy of this file named # ".env" and populate it with your secrets. NODE_ENV="" # Privy Configuration (if using Privy) NEXT_PUBLIC_PRIVY_APP_ID="" PRIVY_APP_SECRET="" # Rainbow Kit Configuration (if using Rainbow) NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID="" `.trim().concat(` `);import x from"path";import H from"fs-extra";var Ne=({projectDir:e,packages:i})=>{let o=["prettier","eslint","eslint-config-next","typescript-eslint","@eslint/eslintrc"];i?.tailwind.inUse&&o.push("prettier-plugin-tailwindcss"),d({projectDir:e,dependencies:o,devMode:!0});let t=x.join(c,"template/extras"),n;i?.tailwind.inUse?n=x.join(t,"config/_tailwind.prettier.config.js"):n=x.join(t,"config/_prettier.config.js");let s=x.join(e,"prettier.config.js");if(H.copySync(n,s),u()==="pnpm"){let m=x.join(t,"pnpm/_npmrc");H.copySync(m,x.join(e,".npmrc"))}V({projectDir:e,scripts:{lint:"next lint","lint:fix":"next lint --fix",check:"next lint && tsc --noEmit","format:write":'prettier --write "**/*.{ts,tsx,js,jsx,mdx}" --cache',"format:check":'prettier --check "**/*.{ts,tsx,js,jsx,mdx}" --cache'}});let r=x.join(t,"config/_eslint.base.js"),p=x.join(e,"eslint.config.js");H.copySync(r,p)};var De=e=>({tailwind:{inUse:e.includes("tailwind"),installer:Re},shadcn:{inUse:e.includes("shadcn"),installer:Ce},privy:{inUse:e.includes("privy"),installer:Ie},rainbow:{inUse:e.includes("rainbow"),installer:je},wagmi:{inUse:e.includes("wagmi"),installer:Te},envVariables:{inUse:!0,installer:Me},eslint:{inUse:e.includes("eslint"),installer:Ne},biome:{inUse:e.includes("biome"),installer:Ee}});import We from"path";var Ge=e=>{let o=D(e).split("/"),t=o[o.length-1];if(t==="."){let a=We.resolve(process.cwd());t=We.basename(a)}let n=o.findIndex(a=>a.startsWith("@"));o.findIndex(a=>a.startsWith("@"))!==-1&&(t=o.slice(n).join("/"));let s=o.filter(a=>!a.startsWith("@")).join("/");return[t,s]};import wt from"gradient-string";var yt={blue:"#add7ff",cyan:"#89ddff",green:"#5de4c7",magenta:"#fae4fc",red:"#d0679d",yellow:"#fffac2"},Ve=()=>{let e=wt(Object.values(yt)),i=u();(i==="yarn"||i==="pnpm")&&console.log(""),console.log(e.multiline(Z))};import ht from"chalk";import{execa as xt}from"execa";import bt from"ora";var Fe=async({pkgManager:e,projectDir:i,eslint:o})=>{l.info("Formatting project with eslint...");let t=bt(`Running format command `).start();o&&await xt(e,["run","format:write"],{cwd:i}),t.succeed(`${ht.green("Successfully formatted project")}`)};import vt from"chalk";import{execa as $e}from"execa";import Be from"ora";var X=async(e,i,o)=>{let{onDataHandle:t,args:n=["install"],stdout:s="pipe"}=o,a=Be(`Running ${i} install...`).start(),r=$e(i,n,{cwd:e,stdout:s});return await new Promise((p,m)=>{t&&r.stdout?.on("data",t(a)),r.on("error",y=>m(y)),r.on("close",()=>p())}),a},Pt=async(e,i)=>{switch(e){case"npm":return await $e(e,["install"],{cwd:i,stderr:"inherit"}),null;case"pnpm":return X(i,e,{onDataHandle:o=>t=>{let n=t.toString();n.includes("Progress")&&(o.text=n.includes("|")?n.split(" | ")[1]??"":n)}});case"yarn":return X(i,e,{onDataHandle:o=>t=>{o.text=t.toString()}});case"bun":return X(i,e,{stdout:"ignore"})}},Je=async({projectDir:e})=>{l.info("Installing dependencies...");let i=u();(await Pt(i,e)??Be()).succeed(vt.green(`Successfully installed dependencies! `))};import{execSync as St}from"child_process";import It from"https";var Le=e=>{let i=S();i.includes("beta")?(l.warn(" You are using a beta version of create-w3-app."),l.warn(" Please report any bugs you encounter.")):i.includes("next")?(l.warn(" You are running create-w3-app with the @next tag which is no longer maintained."),l.warn(" Please run the CLI with @latest instead.")):i!==e&&(l.warn(" You are using an outdated version of create-w3-app."),l.warn(" Your version:",i+".","Latest version in the npm registry:",e),l.warn(" Please run the CLI with @latest to get the latest updates.")),console.log("")};function kt(){return new Promise((e,i)=>{It.get("https://registry.npmjs.org/-/package/create-w3-app/dist-tags",o=>{if(o.statusCode===200){let t="";o.on("data",n=>t+=n),o.on("end",()=>{e(JSON.parse(t).latest)})}else i()}).on("error",()=>{i()})})}var ze=()=>kt().catch(()=>{try{return St("npm view create-w3-app version").toString().trim()}catch{return null}});var Ct=async()=>{let e=await ze(),i=u();Ve(),e&&Le(e);let{appName:o,packages:t,flags:{noGit:n,noInstall:s,importAlias:a,appRouter:r}}=await ne(),p=De(t),[m,y]=Ge(o),h=await de({projectName:y,scopedAppName:m,packages:p,importAlias:a,noInstall:s,appRouter:r}),U=Ye.readJSONSync(Ke.join(h,"package.json"));if(U.name=m,U.cweb3aMetadata={initVersion:S()},i!=="bun"){let{stdout:qe}=await jt(i,["-v"],{cwd:h});U.packageManager=`${i}@${qe.trim()}`}Ye.writeJSONSync(Ke.join(h,"package.json"),U,{spaces:2}),a!=="~/"&&xe(h,a),s||(await Je({projectDir:h}),await Fe({pkgManager:i,projectDir:h,eslint:t.includes("eslint")})),n||await we(h),await ye({projectName:y,appRouter:r,noInstall:s,projectDir:h}),process.exit(0)};Ct().catch(e=>{l.error("Aborting installation..."),e instanceof Error?l.error(e):(l.error("An unknown error has occurred. Please open an issue on github with the below:"),console.log(e)),process.exit(1)});