@teispace/next-maker 4.0.2 → 5.0.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/CHANGELOG.md +11 -0
- package/README.md +119 -875
- package/dist/index.js +779 -1045
- package/package.json +9 -4
package/dist/index.js
CHANGED
|
@@ -1,732 +1,537 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
`),t.
|
|
4
|
-
`),
|
|
5
|
-
|
|
6
|
-
`),r.
|
|
7
|
-
`),
|
|
8
|
-
`,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
`).filter(d=>d);for(let d of u){if(!l(d))continue;let f=await g(d),x=!1,I=new RegExp(`(import\\s*\\{[^}]*?)\\b${i}\\b([^}]*?\\}\\s*from\\s*['"][^'"]*?/http['"])`,"g");I.test(f)&&(f=f.replace(I,`$1${n}$2`),x=!0);let H=new RegExp(`import\\s+${i}\\s+from\\s+['"]([^'"]*?)/${o}['"]`,"g");H.test(f)&&(f=f.replace(H,`import ${n} from '$1/${s}'`),x=!0);let k=new RegExp(`\\b${i}\\b(?=\\.)`,"g");k.test(f)&&(f=f.replace(k,n),x=!0);let Z=new RegExp(`\\b${i}\\b(?![.\\w])`,"g");Z.test(f)&&(f=f.replace(Z,n),x=!0),x&&await h(d,f)}}catch(p){console.warn("Warning: Could not scan for HTTP client usages:",p)}},Lr=e=>{let t=D.join(e,a.LOCALE_LAYOUT);if(l(t))return t;let r=D.join(e,a.ROOT_LAYOUT);return l(r)?r:null},mc="// Regression sentinel \u2014 see file comment for what this guards.",Qi="import { HttpClientBundleSentinel } from '@/lib/utils/http/__bundle-sentinel__/client-bundle-sentinel';",en="<HttpClientBundleSentinel />",rn=e=>{if(e.includes(en))return e;let t=e;if(!t.includes(Qi)){let o=/(^import\s[^\n]*\n)+/m,s=t.match(o);if(!s)throw new Error("injectBundleSentinel: no `import` lines found \u2014 expected a layout file with at least one import.");let c=t.slice(0,(s.index??0)+s[0].length),p=t.slice((s.index??0)+s[0].length);t=`${c}${mc}
|
|
13
|
-
${Qi}
|
|
14
|
-
${p}`}let r=/(<RootProvider\b[^>]*>)\n([ \t]*)/,i=t.match(r);if(!i)throw new Error("injectBundleSentinel: could not locate `<RootProvider \u2026>` opening tag \u2014 layout shape unexpected.");let n=i[2];return t=t.replace(r,`$1
|
|
15
|
-
${n}${en}
|
|
16
|
-
${n}`),t},_t=e=>{let t=e,r=/@\/lib\/utils\/http\/__bundle-sentinel__\/client-bundle-sentinel/,i=new RegExp(`(?:^[ \\t]*//[^\\n]*\\n)?^[ \\t]*import[^\\n]*${r.source}[^\\n]*\\n`,"m");return t=t.replace(i,""),t=t.replace(/[ \t]*<HttpClientBundleSentinel\s*\/>\s*\n/,""),t},tt=async e=>{let t=Lr(e);if(!t)return;let r=await g(t),i=rn(r);i!==r&&await h(t,i)},rt=async e=>{let t=Lr(e);if(!t)return;let r=await g(t),i=_t(r);i!==r&&await h(t,i)},Mr=async e=>{let t=D.join(e,a.UTILS_INDEX);if(l(t)){let i=await g(t);i=i.replace(/^\s*export\s+\*\s+from\s+['"]\.\/http['"];?.*$/gm,""),await h(t,i)}let r=D.join(e,a.TYPES_INDEX);if(l(r)){let i=await g(r),n=D.join(e,a.COMMON_TYPES_DIR);if(!l(n))i=i.replace(/^\s*export\s+\*\s+from\s+['"]\.\/common['"];?.*$/gm,"");else{let o=D.join(n,"index.ts");if(l(o)){let s=await g(o);s=s.replace(/^\s*export\s+\*\s+from\s+['"]\.\/http\.types['"];?.*$/gm,""),await h(o,s)}}l(D.join(e,a.UTILITY_TYPES_DIR))||(i=i.replace(/^\s*export\s+\*\s+from\s+['"]\.\/utility['"];?.*$/gm,"")),await h(r,i)}},dc=async(e,t,r=[])=>{let i=D.join(e,"src"),o=`from ['"].*${t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}.*['"]`;try{let s=await Nr(o,i,["-r","-E"]);return s.trim()?s.trim().split(`
|
|
17
|
-
`).filter(u=>{let[d]=u.split(":"),f=D.resolve(e,d);return!r.some(x=>!!(f===x||f.startsWith(x+D.sep)))}).length>0:!1}catch(s){return console.warn(`Warning: Failed to check usage for ${t}:`,s),!0}},uc=async(e,t,r=[])=>{let i=D.join(e,"src");try{let n=await Nr(t,i,["-r","-F"]);return n.trim()?n.trim().split(`
|
|
18
|
-
`).filter(c=>{let[p]=c.split(":"),u=D.resolve(e,p);return!r.some(d=>!!(u===d||u.startsWith(d+D.sep)))}).length>0:!1}catch(n){return console.warn(`Warning: Failed to check usage for string ${t}:`,n),!0}},we=async(e,t)=>{let r=D.join(e,a.HTTP_BUNDLE_SENTINEL_FILE);if(!l(r))return;let i=await g(r),n=["toSearchParams"];if(t.includes("axios")&&n.unshift("axiosClient","createAxiosClient"),t.includes("fetch")){let c=n.indexOf("toSearchParams");n.splice(c,0,"createFetchClient","fetchClient")}n.sort();let o=`import {
|
|
19
|
-
${n.join(`,
|
|
20
|
-
`)},
|
|
21
|
-
} from '@/lib/utils/http';`;i=i.replace(/import\s*\{[^}]*\}\s*from\s*['"]@\/lib\/utils\/http['"];/,o);let s=n.map(c=>` ${c},`).join(`
|
|
22
|
-
`);i=i.replace(/const __sentinel__ = \{[\s\S]*?\};/,`const __sentinel__ = {
|
|
23
|
-
${s}
|
|
24
|
-
};`),await h(r,i)},Pe=async(e,t)=>{let r=D.join(e,a.HTTP_SERVER_FILE);if(!l(r)||t.length===0)return;let i=await g(r),n=o=>{i=i.replace(o,"")};t.includes("axios")||(n(/^import\s*\{\s*createAxiosClient\s*\}\s*from\s*['"]\.\/axios-client['"];\n?/m),n(/export const axiosClient = createAxiosClient\(\{[\s\S]*?\}\);\n?\n?/),i=tn(i,"createAxiosClient")),t.includes("fetch")||(n(/^import\s*\{\s*createFetchClient\s*\}\s*from\s*['"]\.\/fetch-client['"];\n?/m),n(/export const fetchClient = createFetchClient\(\{[\s\S]*?\}\);\n?\n?/),i=tn(i,"createFetchClient")),i=i.replace(/\n{3,}/g,`
|
|
25
|
-
|
|
26
|
-
`),await h(r,i)},tn=(e,t)=>{let r=/^export\s*\{([^}]*)\};\n?/m;return e.replace(r,(i,n)=>{let o=n.split(",").map(s=>s.trim()).filter(s=>s.length>0&&s!==t);return o.length===0?"":`export { ${o.join(", ")} };
|
|
27
|
-
`})}});import{existsSync as op}from"node:fs";import{access as sp}from"node:fs/promises";import Fn from"node:path";var Se,Ht,On=Ge(()=>{"use strict";Se=async(e,t,r)=>{try{return await sp(Fn.join(e,r,t)),!0}catch{return!1}},Ht=(e,t,r)=>op(Fn.join(e,t,r))});import{access as Ut,readFile as ap}from"node:fs/promises";import at from"node:path";var M,Dn=Ge(()=>{"use strict";M=async e=>{try{let t=at.join(e,"package.json"),r=await ap(t,"utf-8"),i=JSON.parse(r),n={...i.dependencies,...i.devDependencies},o=!!(n["@reduxjs/toolkit"]&&n["react-redux"]),s=!!n["next-intl"],c=!!n.axios,p=!1,u=at.join(e,"src","lib","utils","http","axios-client");try{await Ut(u)}catch{c=!1}let d=at.join(e,"src","lib","utils","http","fetch-client");try{await Ut(d),p=!0}catch{p=!1}let f;c&&p?f="both":c?f="axios":p?f="fetch":f="none";let x=!!n.vitest;if(!x)try{await Ut(at.join(e,"vitest.config.ts")),x=!0}catch{}let I="none";if(n["socket.io-client"])try{await Ut(at.join(e,"src","lib","utils","ws")),I="present"}catch{}return{hasRedux:o,httpClient:f,hasI18n:s,hasTests:x,ws:I}}catch(t){throw new Error(`Failed to detect project setup: ${t}`,{cause:t})}}});var ct={};Rr(ct,{detectProjectSetup:()=>M,directoryExists:()=>Se,fileExistsAt:()=>Ht});var q=Ge(()=>{"use strict";On();Dn()});import{Command as Cd}from"commander";var ji={name:"@teispace/next-maker",version:"4.0.2",description:"Create a new Teispace Next.js application with interactive setup.",keywords:["nextjs","react","typescript","tailwindcss","starter","template","redux"],type:"module",homepage:"https://github.com/teispace/npm-packages/tree/main/packages/next-maker#readme",bugs:{url:"https://github.com/teispace/npm-packages/issues"},license:"MIT",author:"Teispace",files:["dist","README.md","LICENSE","CHANGELOG.md"],bin:"dist/index.js",repository:{type:"git",url:"git+https://github.com/teispace/npm-packages.git",directory:"packages/next-maker"},scripts:{build:"tsx build.ts",start:"node dist/index.js",dev:"tsx --watch src/index.ts",test:"vitest run","test:watch":"vitest","test:cov":"vitest run --coverage","type-check":"tsc --noEmit",clean:"rm -rf dist",prepublishOnly:"yarn clean && yarn build"},dependencies:{commander:"^15.0.0",degit:"^3.8.0",enquirer:"^2.4.1",ora:"^9.4.1",picocolors:"^1.1.1","png-to-ico":"^3.0.2",sharp:"^0.35.3"},devDependencies:{"@types/degit":"^2.8.6","@types/node":"^26.2.0",esbuild:"^0.28.2",tsx:"^4.23.12",typescript:"^6.0.3",vitest:"^4.1.11"},engines:{node:">=24.0.0"},publishConfig:{access:"public",registry:"https://registry.npmjs.org/"}};import Ur from"node:path";import ee from"picocolors";var Ze=new Set;function Li(e){return Ze.add(e),()=>Ze.delete(e)}function Mi(e){let{logger:t=p=>console.error(p),exitOnCancel:r=process.env.NODE_ENV!=="test"}=e??{},i=!1,n=async()=>{let p=[...Ze];Ze.clear();for(let u of p)try{await u()}catch(d){t(`Cleanup failed: ${d instanceof Error?d.message:String(d)}`)}},o=()=>{if(i){r&&process.exit(130);return}i=!0;let p=Ze.size>0;n().then(()=>{console.log(""),t("Setup cancelled by user"),console.log(""),r&&process.exit(p?130:0)})},s=p=>{if(p!==null&&typeof p=="object"&&"code"in p&&p.code==="ERR_USE_AFTER_CLOSE"){o();return}if(p instanceof Error){t(`Uncaught exception: ${p.message}`);return}t(`Uncaught exception: ${String(p)}`)},c=p=>{if(p instanceof Error){t(`Unhandled promise rejection: ${p.message}`);return}t(`Unhandled promise rejection: ${String(p)}`)};return process.on("SIGINT",o),process.on("SIGTERM",o),process.on("uncaughtException",s),process.on("unhandledRejection",c),()=>{process.off("SIGINT",o),process.off("SIGTERM",o),process.off("uncaughtException",s),process.off("unhandledRejection",c)}}import ae from"picocolors";var _a={reset:e=>e,red:ae.red,green:ae.green,yellow:ae.yellow,blue:ae.blue,cyan:ae.cyan,magenta:ae.magenta,white:ae.white,gray:ae.gray,bright:ae.bold,dim:ae.dim};function xe(e,t="reset"){let r=_a[t]??(i=>i);console.log(r(e))}function Nt(e){xe(`\u2716 ${e}`,"red")}var E=Nt;function Gi(e){xe(`\u26A0 ${e}`,"yellow")}function m(e){xe(e)}function Hi(){console.log(""),xe("\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557","cyan"),xe("\u2551 \u2551","cyan"),xe("\u2551 \u{1F680} Create Teispace Next.js App \u{1F680} \u2551","cyan"),xe("\u2551 \u2551","cyan"),xe("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D","cyan"),console.log("")}import Fa from"ora";function S(e="",t){let r=Fa({text:e,...t});return r.start(),r}var Oa=e=>e.charAt(0).toUpperCase()+e.slice(1),G=e=>e.replace(/-([a-z])/g,(t,r)=>r.toUpperCase()),N=e=>Oa(G(e));import Da from"ora";var y=Da();w();import{execFile as ja}from"node:child_process";import{promisify as La}from"node:util";var Ma=La(ja),ue=(e,t)=>Ma("git",e,t?{cwd:t}:void 0);function Ga(e){let t=e.trim();if(!t||t.startsWith("-"))throw new Error(`Invalid git remote "${e}".`);if(!(/^https?:\/\/\S+$/.test(t)||/^git@[\w.-]+:\S+$/.test(t)||/^ssh:\/\/\S+$/.test(t)||/^[\w.-]+\/[\w.-]+$/.test(t)))throw new Error(`Invalid git remote "${e}". Expected an https/ssh URL or "owner/repo".`)}var Bi=async(e,t,r)=>{try{if(await ue(["init"],e),await ue(["add","."],e),await ue(["commit","-m","Initial commit from @teispace/next-maker"],e),t&&(Ga(t),await ue(["remote","add","origin",t],e),r)){await ue(["fetch","origin"],e);let i="main";try{await ue(["show-branch","origin/main"],e)}catch{try{await ue(["show-branch","origin/master"],e),i="master"}catch{i="main"}}await ue(["merge",`origin/${i}`,"--allow-unrelated-histories","-X","ours"],e),await ue(["push","origin",`HEAD:${i}`],e)}}catch(i){console.warn("Failed to initialize git repository",i)}};import{execFile as Ha}from"node:child_process";import{promisify as Ua}from"node:util";var Ba=Ua(Ha),Qe=(e,t,r)=>Ba(e,t,{cwd:r,maxBuffer:64*1024*1024}),Ir=e=>{let t=e;return(`${t.stdout??""}
|
|
2
|
+
import{Command as mp}from"commander";var Te={name:"@teispace/next-maker",version:"5.0.0",description:"Create and grow Next.js 16 applications from the Teispace starter: composable init, feature-aware setup and doctor, and generators for the server-first data layer.",keywords:["nextjs","react","typescript","tailwindcss","starter","template","redux","zustand","tanstack-query","server-actions","cli"],type:"module",homepage:"https://github.com/teispace/npm-packages/tree/main/packages/next-maker#readme",bugs:{url:"https://github.com/teispace/npm-packages/issues"},license:"MIT",author:"Teispace",files:["dist","README.md","LICENSE","CHANGELOG.md"],bin:"dist/index.js",repository:{type:"git",url:"git+https://github.com/teispace/npm-packages.git",directory:"packages/next-maker"},scripts:{build:"tsx build.ts",start:"node dist/index.js",dev:"tsx --watch src/index.ts",test:"vitest run","test:watch":"vitest","test:cov":"vitest run --coverage","type-check":"tsc --noEmit",clean:"rm -rf dist",prepublishOnly:"yarn clean && yarn build",smoke:"tsx scripts/smoke.ts"},dependencies:{commander:"^15.0.0",degit:"^3.8.0",enquirer:"^2.4.1",ora:"^9.4.1",picocolors:"^1.1.1","png-to-ico":"^3.0.2",sharp:"^0.35.3"},devDependencies:{"@types/degit":"^2.8.6","@types/node":"^26.2.0",esbuild:"^0.28.2",tsx:"^4.23.12",typescript:"^6.0.3",vitest:"^4.1.11"},engines:{node:">=24.0.0"},publishConfig:{access:"public",registry:"https://registry.npmjs.org/"}};import{copyFile as Ui}from"node:fs/promises";import Ct from"node:path";import A from"picocolors";var Xr=/@next-maker:([\w-]+)(?::(start|end))?/,Fs=/^\s*(?:\{\s*\/\*.*?\*\/\s*\}|\/\*.*?\*\/|\/\/.*|#.*)\s*$/,Ms=e=>e.replace(/\s*\{\s*\/\*[^*]*@next-maker:[^*]*\*\/\s*\}\s*$/,"").replace(/\s*\/\*[^*]*@next-maker:[^*]*\*\/\s*$/,"").replace(/\s*\/\/[^\n]*@next-maker:[^\n]*$/,"").replace(/\s*#[^\n]*@next-maker:[^\n]*$/,""),zt=(e,{off:t})=>{let r=e.split(`
|
|
3
|
+
`),n=[];for(let o=0;o<r.length;o++){let s=r[o],i=s.match(Xr);if(!i){n.push(s);continue}let[,a,p]=i,m=t.has(a);if(p==="start"){let d=_s(r,o+1,a);m&&(o=d);continue}if(p==="end")continue;let c=Fs.test(s);if(m){c&&o++;continue}c||n.push(Ms(s))}return n.join(`
|
|
4
|
+
`)},_s=(e,t,r)=>{for(let n=t;n<e.length;n++){let o=e[n].match(Xr);if(o&&o[1]===r&&o[2]==="end")return n}throw new Error(`Anchor @next-maker:${r}:start has no matching :end`)},Je=e=>e.includes("@next-maker:"),Yr=(e,t)=>{let r=e.split(`
|
|
5
|
+
`),n=[],o=new RegExp(`^import\\s+${t}\\s+from\\s+['"][^'"]+['"];?\\s*$`),s=/^(import\s+(?:type\s+)?)\{([^}]+)\}(\s+from\s+['"][^'"]+['"];?\s*)$/;for(let i of r){if(o.test(i))continue;let a=i.match(s);if(a){let p=a[2].split(",").map(c=>c.trim()).filter(Boolean),m=p.filter(c=>c.replace(/^type\s+/,"").split(/\s+as\s+/)[0]!==t);if(m.length===0)continue;if(m.length<p.length){n.push(`${a[1]}{ ${m.join(", ")} }${a[3]}`);continue}}n.push(i)}return n.join(`
|
|
6
|
+
`)},ze=(e,t)=>{let r=e.split(`
|
|
7
|
+
`),n=new RegExp(`^([ \\t]*)<${t}\\b`),o=-1,s="";for(let u=0;u<r.length;u++){let f=r[u].match(n);if(f){o=u,s=f[1];break}}if(o===-1)return e;let i=o;for(;i<r.length&&!/>\s*$/.test(r[i]);)i++;if(i>=r.length)throw new Error(`unwrapJsx: opening <${t}> never closes`);if(/\/>\s*$/.test(r[i]))return e;let a=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),p=new RegExp(`^${a}</${t}>\\s*$`),m=-1;for(let u=i+1;u<r.length;u++)if(p.test(r[u])){m=u;break}if(m===-1)throw new Error(`unwrapJsx: no closing </${t}> at the opening indent`);let c=r.slice(i+1,m).map(u=>u.startsWith(" ")?u.slice(2):u),d=[...r.slice(0,o),...c,...r.slice(m+1)].join(`
|
|
8
|
+
`);return Yr(d,t)},We=(e,t)=>{let r=new RegExp(`\\b${t}\\(`,"g"),n=e,o=r.exec(n);for(;o;){let s=o.index,i=0,a=s+o[0].length-1;for(;a<n.length;a++)if(n[a]==="(")i++;else if(n[a]===")"&&(i--,i===0))break;if(i!==0)throw new Error(`unwrapCall: unbalanced parentheses after ${t}(`);let p=n.slice(s+o[0].length,a);n=n.slice(0,s)+p+n.slice(a+1),r.lastIndex=s,o=r.exec(n)}return n};import{cp as on,mkdir as Js,mkdtemp as zs,readdir as rn,readFile as Oe,rm as Ht,rmdir as Ws,stat as Hs,writeFile as Ae}from"node:fs/promises";import{tmpdir as Ks}from"node:os";import N from"node:path";import{readdir as Ds}from"node:fs/promises";import gt from"node:path";var Qr=e=>{let t="^";for(let r=0;r<e.length;r++){let n=e[r];n==="*"?e[r+1]==="*"?(r++,e[r+1]==="/"?(r++,t+="(?:.*/)?"):t+=".*"):t+="[^/]*":t+=n.replace(/[.+?^${}()|[\]\\]/g,"\\$&")}return new RegExp(`${t}$`)},Ls=new Set(["node_modules",".git",".next","coverage","playwright-report","test-results"]),L=async(e,t=Ls)=>{let r=[],n=async o=>{let s;try{s=await Ds(o,{withFileTypes:!0})}catch{return}for(let i of s)if(i.isDirectory()){if(t.has(i.name))continue;await n(gt.join(o,i.name))}else i.isFile()&&r.push(gt.relative(e,gt.join(o,i.name)).split(gt.sep).join("/"))};return await n(e),r.sort()},se=(e,t)=>{let r=Qr(t);return e.filter(n=>r.test(n))};import{readFile as Us}from"node:fs/promises";import Gs from"node:path";var ht="next-maker.json",ge=".next-maker/overlays",Zr=1,G=e=>{throw new Error(`Invalid ${ht}: ${e}`)},tn=e=>{(typeof e!="object"||e===null)&&G("not an object");let t=e;t.manifestVersion!==Zr&&G(`manifestVersion ${String(t.manifestVersion)} is not supported by this CLI (expected ${Zr})`),(!t.starter?.name||!t.starter.version)&&G("starter.name and starter.version are required"),(!t.options||typeof t.options!="object")&&G("options is required"),(!t.features||typeof t.features!="object")&&G("features is required"),(!t.packageManagers||typeof t.packageManagers!="object")&&G("packageManagers is required");let r=t.options,n=t.features;for(let[o,s]of Object.entries(r))["choice","boolean","multi"].includes(s.type)||G(`option ${o} has unknown type ${String(s.type)}`),s.type!=="boolean"&&!Array.isArray(s.values)&&G(`option ${o} needs a values array`),s.default===void 0&&G(`option ${o} needs a default`);for(let[o,s]of Object.entries(n)){(!s.when||typeof s.when!="object")&&G(`feature ${o} needs a when`);for(let i of Object.keys(s.when))r[i]||G(`feature ${o} refers to unknown option ${i}`)}return{...t,always:{remove:t.always?.remove??[]}}},He=async e=>{let t=Gs.join(e,ht),r;try{r=await Us(t,"utf-8")}catch{throw new Error(`The starter at ${e} has no ${ht}. This CLI needs a starter that ships a composition manifest (nextjs-starter 2.x or later).`)}return tn(JSON.parse(r))},en=(e,t)=>e.some(r=>r===t),yt=(e,t,r)=>t===void 0?!1:e?.type==="multi"&&Array.isArray(t)?t.some(n=>en(r,n)):en(r,t),ie=(e,t,r)=>Object.entries(t.when).every(([n,o])=>yt(e.options[n],r[n],o)),Bs=e=>e.type==="boolean"?!1:e.type==="multi"?[]:e.default,Vs=(e,t,r)=>{if(e.type==="boolean"){if(typeof r=="boolean")return r;if(r==="true")return!0;if(r==="false")return!1;throw new Error(`Option ${t} expects true or false, got ${String(r)}`)}if(e.type==="multi"){let s=(Array.isArray(r)?r:String(r).split(",")).map(i=>String(i).trim()).filter(Boolean);for(let i of s)if(!e.values?.includes(i))throw new Error(`Option ${t} does not accept ${i}; valid: ${e.values?.join(", ")}`);return s}let n=String(r);if(!e.values?.includes(n))throw new Error(`Option ${t} does not accept ${n}; valid: ${e.values?.join(", ")}`);return n},Ke=(e,t={})=>{let r={},n=[],o=Object.keys(t).filter(s=>!e.options[s]);for(let[s,i]of Object.entries(e.options)){let a=t[s];r[s]=a===void 0?i.default:Vs(i,s,a)}for(let[s,i]of Object.entries(e.options))if(i.requires)for(let[a,p]of Object.entries(i.requires)){if(yt(e.options[a],r[a],p))continue;let m=Bs(i);r[s]!==m&&JSON.stringify(r[s])!==JSON.stringify(m)&&(n.push({option:s,value:m,reason:`${s} requires ${a} to be ${p.map(String).join(" or ")}`}),r[s]=m)}return{answers:r,forced:n,unknown:o}};var ae=(e,t)=>{switch(e){case"npm":return`npm run ${t}`;case"bun":return`bun run ${t}`;case"yarn":return`yarn ${t}`;default:return`pnpm ${t}`}},qs=e=>{switch(e){case"npm":return[[/\bpnpm install --frozen-lockfile\b/g,"npm ci"],[/\bpnpm install\b/g,"npm install"],[/\bpnpm add -D\b/g,"npm install --save-dev"],[/\bpnpm add\b/g,"npm install"],[/\bpnpm dlx\b/g,"npx"],[/\bpnpm exec\b/g,"npx --no --"],[/\bpnpm ([\w:.-]+)/g,"npm run $1"]];case"yarn":return[[/\bpnpm install --frozen-lockfile\b/g,"yarn install --immutable"],[/\bpnpm install\b/g,"yarn install"],[/\bpnpm add -D\b/g,"yarn add -D"],[/\bpnpm add\b/g,"yarn add"],[/\bpnpm dlx\b/g,"yarn dlx"],[/\bpnpm exec\b/g,"yarn"],[/\bpnpm ([\w:.-]+)/g,"yarn $1"]];case"bun":return[[/\bpnpm install --frozen-lockfile\b/g,"bun install --frozen-lockfile"],[/\bpnpm install\b/g,"bun install"],[/\bpnpm add -D\b/g,"bun add -d"],[/\bpnpm add\b/g,"bun add"],[/\bpnpm dlx\b/g,"bunx"],[/\bpnpm exec\b/g,"bunx"],[/\bpnpm ([\w:.-]+)/g,"bun run $1"]];default:return[]}},wt=(e,t)=>{if(t==="pnpm")return e;let r=e;for(let[n,o]of qs(t))r=r.replace(n,o);return r},Wt=e=>e==="package.json"||e.startsWith(".husky/")||e.endsWith(".md")||e===".lintstagedrc.mjs";var he=e=>[...new Set(e)],Xt=(e,t,r)=>{let n=e.packageManagers[r];if(!n)throw new Error(`This starter does not support ${r}; valid: ${Object.keys(e.packageManagers).join(", ")}`);let o=[],s=[],i=[],a=[],p=[];for(let[c,d]of Object.entries(e.features)){let u=ie(e,d,t);(u?o:s).push(c);let f=u?d.on:d.off;if(!f)continue;i.push(f);let h=Object.keys(d.when);f.overlay&&!a.some(w=>w.name===f.overlay)&&a.push({name:f.overlay,options:h}),f.remove?.length&&p.push({feature:c,options:h,patterns:f.remove})}let m=he([...e.always.remove,...n.remove??[]]);return{answers:t,packageManager:r,pmSpec:n,featuresOn:o,featuresOff:s,pmOverlays:n.overlay?[n.overlay]:[],featureOverlays:a,removePatterns:he([...m,...p.flatMap(c=>c.patterns)]),unconditionalRemovals:m,featureRemovals:p,anchorsOff:new Set(i.flatMap(c=>c.anchors??[])),unwrapJsx:i.flatMap(c=>c.unwrapJsx??[]),unwrapCall:i.flatMap(c=>c.unwrapCall??[]),packages:he(i.flatMap(c=>c.packages??[])),devPackages:he(i.flatMap(c=>c.devPackages??[])),scripts:he(i.flatMap(c=>c.scripts??[])),env:he(i.flatMap(c=>c.env??[])),packageJsonKeys:he(i.flatMap(c=>c.packageJsonKeys??[]))}},Xs=new Set([".ts",".tsx",".js",".mjs",".cjs",".css",".json",".yml",".yaml",".md",".sh",".example",".mdx"]),Ys=e=>Xs.has(N.extname(e))||e.startsWith(".husky/")||e==="Dockerfile",nn=async(e,t,r)=>{let n=N.join(e,r),o=await L(n,new Set);if(o.length===0)throw new Error(`Overlay "${r}" is missing or empty at ${ge}/${r}`);for(let s of o){let i=N.join(t,s);await Js(N.dirname(i),{recursive:!0}),await on(N.join(n,s),i,{force:!0})}return o},Yt=async(e,t=e)=>{let r;try{r=await rn(t,{withFileTypes:!0})}catch{return}for(let n of r)n.isDirectory()&&n.name!=="node_modules"&&n.name!==".git"&&await Yt(e,N.join(t,n.name));t!==e&&(await rn(t)).length===0&&await Ws(t)},sn=(e,t)=>{let r=t.split("."),n=e;for(let s of r.slice(0,-1)){let i=n?.[s];if(typeof i!="object"||i===null)return;n=i}let o=r[r.length-1];if(n&&o in n&&delete n[o],r.length>1){let s=r.slice(0,-1).join("."),i=r.slice(0,-1).reduce((a,p)=>a?.[p],e);i&&typeof i=="object"&&Object.keys(i).length===0&&sn(e,s)}},Qs=async(e,t,r)=>{let n=N.join(e,"package.json"),o=JSON.parse(await Oe(n,"utf-8"));for(let i of t.packages)delete o.dependencies?.[i];for(let i of t.devPackages)delete o.devDependencies?.[i];for(let i of t.scripts)delete o.scripts?.[i];for(let i of t.packageJsonKeys)sn(o,i);let s=r.validateScript;if(s&&o.scripts?.[s.name]){let i=s.steps.filter(a=>o.scripts[a]);o.scripts[s.name]=i.map(a=>ae(t.packageManager,a)).join(" && ")}if(o.scripts)for(let[i,a]of Object.entries(o.scripts))typeof a=="string"&&(o.scripts[i]=wt(a,t.packageManager));if(t.pmSpec.packageManager?o.packageManager=t.pmSpec.packageManager:delete o.packageManager,o.engines){for(let i of Object.keys(r.packageManagers))delete o.engines[i];Object.assign(o.engines,t.pmSpec.engines??{})}await Ae(n,`${JSON.stringify(o,null,2)}
|
|
9
|
+
`,"utf-8")},Zs=async(e,t)=>{let r=N.join(e,".env.example"),n;try{n=await Oe(r,"utf-8")}catch{return}for(let o of t)n=n.replace(new RegExp(`^${o}=.*\\n?`,"gm"),"");await Ae(r,n.replace(/\n{3,}/g,`
|
|
10
|
+
|
|
11
|
+
`),"utf-8")},Qt=async(e,t,r)=>{let n={removed:[],overlaid:[],anchored:[],unwrapped:[]},o=N.join(e,ge),s=await zs(N.join(Ks(),"next-maker-overlays-"));try{await Kt(o)&&await on(o,s,{recursive:!0});for(let m of r.pmOverlays)n.overlaid.push(...await nn(s,e,m));let a=await L(e),p=new Set(r.removePatterns.flatMap(m=>se(a,m)));for(let m of p)await Ht(N.join(e,m),{force:!0}),n.removed.push(m);for(let m of r.featureOverlays){let c=await nn(s,e,m.name),d=[...r.unconditionalRemovals,...r.featureRemovals.filter(f=>!f.options.some(h=>m.options.includes(h))).flatMap(f=>f.patterns)],u=new Set(d.flatMap(f=>se(c,f)));for(let f of u)await Ht(N.join(e,f),{force:!0}),n.removed.push(f);n.overlaid.push(...c.filter(f=>!u.has(f)))}}finally{await Ht(s,{recursive:!0,force:!0})}await Yt(e);let i=await L(e);for(let a of i){if(!Ys(a))continue;let p=N.join(e,a),m=await Oe(p,"utf-8");Je(m)&&(await Ae(p,zt(m,{off:r.anchorsOff}),"utf-8"),n.anchored.push(a))}for(let{file:a,tag:p}of r.unwrapJsx){let m=N.join(e,a);if(!await Kt(m))continue;let c=await Oe(m,"utf-8"),d=ze(c,p);d!==c&&(await Ae(m,d,"utf-8"),n.unwrapped.push(`${a}:<${p}>`))}for(let{file:a,name:p}of r.unwrapCall){let m=N.join(e,a);if(!await Kt(m))continue;let c=await Oe(m,"utf-8"),d=We(c,p);d!==c&&(await Ae(m,d,"utf-8"),n.unwrapped.push(`${a}:${p}()`))}if(await Qs(e,r,t),await Zs(e,r.env),r.packageManager!=="pnpm")for(let a of await L(e)){if(!Wt(a)||a==="package.json")continue;let p=N.join(e,a),m=await Oe(p,"utf-8"),c=wt(m,r.packageManager);c!==m&&await Ae(p,c,"utf-8")}return n},Kt=async e=>{try{return await Hs(e),!0}catch{return!1}};import{readFile as ei}from"node:fs/promises";import ti from"node:path";var Zt=async e=>{let t=ti.resolve(process.cwd(),e),r;try{r=await ei(t,"utf-8")}catch{throw new Error(`Config file not found: ${t}`)}let n=JSON.parse(r);if(typeof n!="object"||n===null||Array.isArray(n))throw new Error(`Config file ${t} must contain a JSON object`);if(n.options!==void 0&&(typeof n.options!="object"||n.options===null))throw new Error(`Config file ${t}: "options" must be an object`);return n},ye=e=>{let t={};for(let r of e??[]){let n=r.indexOf("=");if(n<=0)throw new Error(`--set expects key=value, got "${r}"`);t[r.slice(0,n).trim()]=r.slice(n+1).trim()}return t};var er={default:{description:"Manifest defaults: Redux, fetch, i18n, dark mode, unit + e2e tests, hooks",answers:{}},minimal:{description:"No state store, no i18n, no dark mode, no tests, no hooks",answers:{state:"none",i18n:!1,darkMode:!1,tests:!1,e2e:!1,hooks:!1,commitizen:!1}},full:{description:"Everything on: WebSocket, both HTTP adapters, Docker, CI, analyzer, OpenAPI, templates",answers:{ws:!0,http:"both",docker:!0,ci:!0,analyzer:!0,openapi:!0,githubTemplates:!0,communityFiles:["CODE_OF_CONDUCT.md","CONTRIBUTING.md","SECURITY.md"]}},zustand:{description:"Defaults with Zustand instead of Redux",answers:{state:"zustand"}},spa:{description:"Client-heavy app: Zustand, Axios, no i18n, Docker and CI on",answers:{state:"zustand",http:"axios",i18n:!1,docker:!0,ci:!0}}},Ie=()=>Object.keys(er),Ne=e=>{let t=er[e];if(!t)throw new Error(`Unknown preset "${e}". Valid: ${Ie().join(", ")}.`);return{...t.answers}};var Xe=new Set;function xt(e){return Xe.add(e),()=>Xe.delete(e)}function an(e){let{logger:t=p=>console.error(p),exitOnCancel:r=process.env.NODE_ENV!=="test"}=e??{},n=!1,o=async()=>{let p=[...Xe];Xe.clear();for(let m of p)try{await m()}catch(c){t(`Cleanup failed: ${c instanceof Error?c.message:String(c)}`)}},s=()=>{if(n){r&&process.exit(130);return}n=!0;let p=Xe.size>0;o().then(()=>{console.log(""),t("Setup cancelled by user"),console.log(""),r&&process.exit(p?130:0)})},i=p=>{if(p!==null&&typeof p=="object"&&"code"in p&&p.code==="ERR_USE_AFTER_CLOSE"){s();return}if(p instanceof Error){t(`Uncaught exception: ${p.message}`);return}t(`Uncaught exception: ${String(p)}`)},a=p=>{if(p instanceof Error){t(`Unhandled promise rejection: ${p.message}`);return}t(`Unhandled promise rejection: ${String(p)}`)};return process.on("SIGINT",s),process.on("SIGTERM",s),process.on("uncaughtException",i),process.on("unhandledRejection",a),()=>{process.off("SIGINT",s),process.off("SIGTERM",s),process.off("uncaughtException",i),process.off("unhandledRejection",a)}}import z from"picocolors";var ri={reset:e=>e,red:z.red,green:z.green,yellow:z.yellow,blue:z.blue,cyan:z.cyan,magenta:z.magenta,white:z.white,gray:z.gray,bright:z.bold,dim:z.dim};function ce(e,t="reset"){let r=ri[t]??(n=>n);console.log(r(e))}function bt(e){ce(`\u2716 ${e}`,"red")}var x=bt;function cn(e){ce(`\u26A0 ${e}`,"yellow")}function l(e){ce(e)}function vt(){console.log(""),ce("\u2554\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2557","cyan"),ce("\u2551 \u2551","cyan"),ce("\u2551 \u{1F680} Create Teispace Next.js App \u{1F680} \u2551","cyan"),ce("\u2551 \u2551","cyan"),ce("\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255D","cyan"),console.log("")}import ni from"ora";function $t(e="",t){let r=ni({text:e,...t});return r.start(),r}var oi=e=>e.charAt(0).toUpperCase()+e.slice(1),U=e=>e.replace(/-([a-z])/g,(t,r)=>r.toUpperCase()),$=e=>oi(U(e));import si from"ora";var g=si();import{execFile as ii}from"node:child_process";import{cp as pn,mkdir as ai,stat as ci}from"node:fs/promises";import Ye from"node:path";import{promisify as pi}from"node:util";import li from"degit";var mi=pi(ii),ln="teispace/nextjs-starter",Pt="v2.0.0-alpha.0",di="NEXT_MAKER_STARTER_PATH",ui=(e=Pt)=>e==="main"?ln:`${ln}#${e}`,B=(e={})=>{let t=e.starterPath??process.env[di];return t?{kind:"local",location:Ye.resolve(t)}:{kind:"remote",location:ui(e.ref)}},fi=new Set(["node_modules",".git",".next","coverage","playwright-report","test-results",".env"]),kt=async(e,t={})=>{let r=t.source??B();if(r.kind==="local"){try{if(!(await ci(r.location)).isDirectory())throw new Error("not a directory")}catch{throw new Error(`Starter path ${r.location} is not a directory`)}return await gi(r.location,e),r}return await li(r.location,{cache:!1,force:!0,verbose:t.verbose??!1}).clone(e),r},gi=async(e,t)=>{let r=null;try{let{stdout:n}=await mi("git",["-C",e,"ls-files","-z","--cached","--others","--exclude-standard"],{maxBuffer:67108864});r=n.split("\0").filter(Boolean)}catch{r=null}if(r===null){await pn(e,t,{recursive:!0,filter:n=>!fi.has(Ye.basename(n))});return}for(let n of r){let o=Ye.join(t,n);await ai(Ye.dirname(o),{recursive:!0});try{await pn(Ye.join(e,n),o)}catch{}}};import{existsSync as tr}from"node:fs";import Qe from"node:fs/promises";import hi from"node:path";var j=async e=>Qe.readFile(e,"utf-8"),k=async(e,t)=>{await Qe.mkdir(hi.dirname(e),{recursive:!0}),await Qe.writeFile(e,t,"utf-8")};var mn=async e=>{tr(e)&&await Qe.unlink(e)},Ze=async e=>{tr(e)&&await Qe.rm(e,{recursive:!0,force:!0})},dn=async(e,t)=>{let r=await j(e),n=JSON.parse(r),o=t(n);await k(e,JSON.stringify(o,null,2))},y=e=>tr(e);import{execFile as yi}from"node:child_process";import{promisify as wi}from"node:util";var xi=wi(yi),Z=(e,t)=>xi("git",e,t?{cwd:t}:void 0);function bi(e){let t=e.trim();if(!t||t.startsWith("-"))throw new Error(`Invalid git remote "${e}".`);if(!(/^https?:\/\/\S+$/.test(t)||/^git@[\w.-]+:\S+$/.test(t)||/^ssh:\/\/\S+$/.test(t)||/^[\w.-]+\/[\w.-]+$/.test(t)))throw new Error(`Invalid git remote "${e}". Expected an https/ssh URL or "owner/repo".`)}var St=async(e,t,r)=>{try{if(await Z(["init"],e),await Z(["add","."],e),await Z(["commit","-m","Initial commit from @teispace/next-maker"],e),t&&(bi(t),await Z(["remote","add","origin",t],e),r)){await Z(["fetch","origin"],e);let n="main";try{await Z(["show-branch","origin/main"],e)}catch{try{await Z(["show-branch","origin/master"],e),n="master"}catch{n="main"}}await Z(["merge",`origin/${n}`,"--allow-unrelated-histories","-X","ours"],e),await Z(["push","origin",`HEAD:${n}`],e)}}catch(n){console.warn("Failed to initialize git repository",n)}};import{execFile as vi}from"node:child_process";import{promisify as $i}from"node:util";var Pi=$i(vi),un=(e,t,r)=>Pi(e,t,{cwd:r,maxBuffer:64*1024*1024}),ki=e=>{let t=e;return(`${t.stdout??""}
|
|
28
12
|
${t.stderr??""}`.trim()||(t.message??String(e))).split(`
|
|
29
13
|
`).filter(Boolean).slice(-12).join(`
|
|
30
|
-
`)},
|
|
31
|
-
${
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
import type { ReactElement, ReactNode } from 'react';
|
|
36
|
-
import { Provider } from 'react-redux';
|
|
37
|
-
import { type AppState, type AppStore, makeStore } from '@/store';
|
|
38
|
-
import type { SupportedLocale } from '@/types/i18n';
|
|
39
|
-
|
|
40
|
-
type TestProvidersProps = {
|
|
41
|
-
children: ReactNode;
|
|
42
|
-
store?: AppStore;
|
|
43
|
-
preloadedState?: Partial<AppState>;
|
|
44
|
-
messages?: Record<string, unknown>;
|
|
45
|
-
locale?: SupportedLocale;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export function TestProviders({
|
|
49
|
-
children,
|
|
50
|
-
store,
|
|
51
|
-
preloadedState,
|
|
52
|
-
messages = {},
|
|
53
|
-
locale = 'en',
|
|
54
|
-
}: TestProvidersProps) {
|
|
55
|
-
const testStore = store ?? makeStore(preloadedState);
|
|
56
|
-
|
|
57
|
-
return (
|
|
58
|
-
<Provider store={testStore}>
|
|
59
|
-
<NextIntlClientProvider locale={locale} messages={messages} timeZone="UTC">
|
|
60
|
-
{children}
|
|
61
|
-
</NextIntlClientProvider>
|
|
62
|
-
</Provider>
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
type ExtendedRenderOptions = Omit<RenderOptions, 'wrapper'> & {
|
|
67
|
-
store?: AppStore;
|
|
68
|
-
preloadedState?: Partial<AppState>;
|
|
69
|
-
messages?: Record<string, unknown>;
|
|
70
|
-
locale?: SupportedLocale;
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export function renderWithProviders(
|
|
74
|
-
ui: ReactElement,
|
|
75
|
-
{ store, preloadedState, messages, locale, ...renderOptions }: ExtendedRenderOptions = {},
|
|
76
|
-
) {
|
|
77
|
-
const testStore = store ?? makeStore(preloadedState);
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
store: testStore,
|
|
81
|
-
...render(ui, {
|
|
82
|
-
wrapper: ({ children }) => (
|
|
83
|
-
<TestProviders store={testStore} messages={messages} locale={locale}>
|
|
84
|
-
{children}
|
|
85
|
-
</TestProviders>
|
|
86
|
-
),
|
|
87
|
-
...renderOptions,
|
|
88
|
-
}),
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export * from '@testing-library/react';
|
|
93
|
-
export { default as userEvent } from '@testing-library/user-event';
|
|
94
|
-
`,tc=`import { type RenderOptions, render } from '@testing-library/react';
|
|
95
|
-
import type { ReactElement, ReactNode } from 'react';
|
|
96
|
-
import { Provider } from 'react-redux';
|
|
97
|
-
import { type AppState, type AppStore, makeStore } from '@/store';
|
|
98
|
-
|
|
99
|
-
type TestProvidersProps = {
|
|
100
|
-
children: ReactNode;
|
|
101
|
-
store?: AppStore;
|
|
102
|
-
preloadedState?: Partial<AppState>;
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
export function TestProviders({ children, store, preloadedState }: TestProvidersProps) {
|
|
106
|
-
const testStore = store ?? makeStore(preloadedState);
|
|
107
|
-
|
|
108
|
-
return <Provider store={testStore}>{children}</Provider>;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
type ExtendedRenderOptions = Omit<RenderOptions, 'wrapper'> & {
|
|
112
|
-
store?: AppStore;
|
|
113
|
-
preloadedState?: Partial<AppState>;
|
|
114
|
-
};
|
|
14
|
+
`)},Si=e=>{switch(e){case"pnpm":return["install","--no-frozen-lockfile"];case"yarn":return["install","--no-immutable"];default:return["install"]}},pe=async(e,t)=>{try{await un(t,Si(t),e)}catch(r){throw new Error(`Failed to install dependencies with ${t}:
|
|
15
|
+
${ki(r)}`,{cause:r})}},Et=async(e,t,r)=>{let n=t==="npm"?["run",r]:[r];try{await un(t,n,e)}catch(o){console.warn(`Warning: Failed to run script '${r}': ${o}`)}};import Ei from"enquirer";var{prompt:fn}=Ei,Ri=/^[a-z0-9-_]+$/,ji=/^\d+\.\d+\.\d+$/,gn=e=>Ri.test(e),hn=e=>ji.test(e),et=e=>{if(!gn(e))throw new Error(`Invalid project name "${e}". Use lowercase letters, digits, hyphens, and underscores only \u2014 no slashes, "..", or absolute paths.`)},le=(e,t={})=>{let r=t.projectName??e??"my-app";et(r);let n=t.version??"0.1.0";if(!hn(n))throw new Error(`Invalid version "${n}". Expected semver (e.g. 0.1.0).`);return{projectName:r,description:t.description??"A Next.js application",author:t.author??"Teispace",version:n,email:t.email??"support@example.com",gitRemote:t.gitRemote??"",pushToRemote:t.pushToRemote??!1,gitIssues:t.gitIssues??"",gitHomepage:t.gitHomepage??"",readme:t.readme??!0,copyEnv:t.copyEnv??!0}},yn=e=>e.state?.answers??e.enquirer?.answers??{},wn=async e=>{e!==void 0&&et(e);let t=await fn([{type:"input",name:"projectName",message:"What is the project name?",initial:e||"my-app",skip:!!e,validate:r=>gn(r)||"Project name must be lowercase and contain only alphanumeric characters, hyphens, and underscores."},{type:"input",name:"description",message:"Project description:",initial:"A Next.js application"},{type:"input",name:"author",message:"Author:",initial:"Teispace"},{type:"input",name:"version",message:"Version:",initial:"0.1.0",validate:r=>hn(r)||"Version must be a valid semantic version (x.y.z)."},{type:"input",name:"email",message:"Support email:",initial:"support@example.com"},{type:"input",name:"gitRemote",message:"GitHub repository URL (optional):",initial:"",validate:r=>!r||/^(https:\/\/github\.com\/[\w-]+\/[\w.-]+(\.git)?|git@github\.com:[\w-]+\/[\w.-]+\.git)$/.test(r)||"Enter a GitHub URL (https://github.com/user/repo or git@github.com:user/repo.git)."},{type:"confirm",name:"pushToRemote",message:"Push the initial commit to the remote?",initial:!1,skip:function(){return!yn(this).gitRemote}},{type:"confirm",name:"readme",message:"Create a README.md?",initial:!0},{type:"confirm",name:"copyEnv",message:"Copy .env.example to .env?",initial:!0}]);return le(e,{...t,projectName:e??t.projectName})},Rt=async(e,t={})=>{let r=Object.entries(e.options).map(([s,i])=>{let a=t[s]??i.default,p={name:s,message:i.label??s,skip:function(){if(!i.requires)return!1;let c=yn(this);return!Object.entries(i.requires).every(([d,u])=>yt(e.options[d],c[d],u))}};if(i.type==="boolean")return{...p,type:"confirm",initial:!!a};if(i.type==="multi")return{...p,type:"multiselect",choices:(i.values??[]).map(c=>({name:c,value:c})),initial:Array.isArray(a)?a:[]};let m=i.values??[];return{...p,type:"select",choices:m,initial:Math.max(0,m.indexOf(String(a)))}}),n=await fn(r),o={};for(let[s,i]of Object.entries(e.options)){let a=n[s];a!==void 0&&(o[s]=i.type==="multi"&&!Array.isArray(a)?[]:a)}return o};import Ci from"node:path";var C={NEXT_CONFIG:"next.config.ts",POSTCSS_CONFIG:"postcss.config.mjs",BIOME_CONFIG:"biome.json",VITEST_CONFIG:"vitest.config.ts",TEST_DIR:"test",TS_CONFIG:"tsconfig.json",PACKAGE_JSON:"package.json",ENV_EXAMPLE:".env.example",GITIGNORE:".gitignore",README:"README.md",LICENSE:"LICENSE",CHANGELOG:"CHANGELOG.md",NVM_RC:".nvmrc",NPM_RC:".npmrc",AGENTS_MD:"AGENTS.md",CLAUDE_MD:"CLAUDE.md",SRC:"src",APP:"src/app",COMPONENTS:"src/components",LIB:"src/lib",PROVIDERS:"src/providers",STYLES:"src/styles",TYPES:"src/types",UTILS:"src/lib/utils",HOOKS:"src/hooks",SERVICES:"src/services",STORE:"src/store",I18N:"src/i18n",GLOBALS_CSS:"src/styles/globals.css",ROOT_LAYOUT:"src/app/layout.tsx",ROOT_PAGE:"src/app/page.tsx",ROOT_PROVIDER:"src/providers/RootProvider.tsx",PROVIDERS_INDEX:"src/providers/index.ts",COMPONENTS_INDEX:"src/components/index.ts",TYPES_INDEX:"src/types/index.ts",UTILS_INDEX:"src/lib/utils/index.ts",CONFIG_INDEX:"src/lib/config/index.ts",CONSTANTS:"src/lib/config/constants.ts",APP_LOCALES:"src/lib/config/app-locales.ts",SEO_FILE:"src/lib/config/seo.ts",SITEMAP_FILE:"src/app/sitemap.ts",MIDDLEWARE:"src/middleware.ts",PROXY:"src/proxy.ts",I18N_TYPES:"src/types/i18n.ts",HTTP_UTILS:"src/lib/utils/http",HTTP_SHARED:"src/lib/utils/http/shared",HTTP_SERVER_FILE:"src/lib/utils/http/server.ts",HTTP_BUNDLE_SENTINEL_DIR:"src/lib/utils/http/__bundle-sentinel__",HTTP_BUNDLE_SENTINEL_FILE:"src/lib/utils/http/__bundle-sentinel__/client-bundle-sentinel.tsx",WS_UTILS:"src/lib/utils/ws",WS_SLICE_FILE:"src/store/slices/ws.slice.ts",WS_SLICE_TEST_FILE:"src/store/slices/ws.slice.test.ts",ROOT_REDUCER:"src/store/rootReducer.ts",TEST_SETUP_FILE:"test/setup.ts",AXIOS_CLIENT:"src/lib/utils/http/axios-client",FETCH_CLIENT:"src/lib/utils/http/fetch-client",AXIOS_CLIENT_FILE:"src/lib/utils/http/axios-client/index.ts",FETCH_CLIENT_FILE:"src/lib/utils/http/fetch-client/index.ts",CLIENT_UTILS:"src/lib/utils/http/client-utils.ts",APP_APIS:"src/lib/config/app-apis.ts",API_URL_FILE:"src/lib/config/api-url.ts",STORAGE_SERVICE:"src/services/storage",COUNTER_FEATURE:"src/features/counter",I18N_DIR:"src/i18n",LOCALE_DIR:"src/app/[locale]",ERRORS_DIR:"src/lib/errors",UTILITY_TYPES_DIR:"src/types/utility",COMMON_TYPES_DIR:"src/types/common",HTTP_TYPES:"src/types/common/http.types.ts",GITHUB_DIR:".github",HUSKY_DIR:".husky",STORE_PROVIDER:"src/providers/StoreProvider.tsx",THEME_PROVIDER:"src/providers/CustomThemeProvider.tsx",COUNTER_COMPONENT:"src/features/counter/components/Counter.tsx",LOCALE_PAGE:"src/app/[locale]/page.tsx",LOCALE_LAYOUT:"src/app/[locale]/layout.tsx",COMMITLINT_CONFIG:"commitlint.config.mjs",LINTSTAGED_RC:".lintstagedrc.mjs",CZRC:".czrc",DOCKERIGNORE:".dockerignore",DOCKERFILE:"Dockerfile",DOCKER_COMPOSE:"docker-compose.yml",GITHUB_WORKFLOWS:".github/workflows",GITHUB_ISSUE_TEMPLATE:"ISSUE_TEMPLATE",GITHUB_PR_TEMPLATE:"PULL_REQUEST_TEMPLATE.md",CODE_OF_CONDUCT:"CODE_OF_CONDUCT.md",CONTRIBUTING:"CONTRIBUTING.md",SECURITY:"SECURITY.md",SCRIPTS_DIR:"scripts",DOCS_DIR:"docs",CLAUDE_DIR:".claude",VSCODE_DIR:".vscode"};var Ti=e=>{let t=e.gitRemote,r=e.gitHomepage,n=e.gitIssues;if(!t)return{remote:"",homepage:"",issues:""};t.startsWith("git@github.com:")&&(t=t.replace("git@github.com:","https://github.com/").replace(/\.git$/,""));let o=t.replace(/\.git$/,"");return r||=`${o}#readme`,n||=`${o}/issues`,t.endsWith(".git")||(t=`${t}.git`),{remote:t,homepage:r,issues:n}},xn=async(e,t)=>{let{remote:r,homepage:n,issues:o}=Ti(t);await dn(Ci.join(e,C.PACKAGE_JSON),s=>(s.name=t.projectName,s.version=t.version,s.description=t.description,s.author=t.author,delete s.keywords,r?(s.homepage=n,s.bugs={url:o},s.repository={type:"git",url:r}):(delete s.homepage,delete s.bugs,delete s.repository),s))};import{readdir as _i}from"node:fs/promises";import de from"node:path";import{cp as Oi,mkdir as Ai,mkdtemp as Ii,readFile as we,rm as $n,writeFile as jt}from"node:fs/promises";import{tmpdir as Ni}from"node:os";import O from"node:path";var Fe=".next-maker.json",me=async(e,t)=>{await jt(O.join(e,Fe),`${JSON.stringify(t,null,2)}
|
|
16
|
+
`,"utf-8")},ee=async e=>{let t=O.join(e,Fe);if(!y(t))throw new Error(`No ${Fe} in ${e}. Only projects created with next-maker 5+ can be reconfigured; run \`next-maker init\` for a new project.`);return JSON.parse(await we(t,"utf-8"))},Me=async(e,t={})=>{let r=e.starter.source.startsWith("/")&&y(e.starter.source)?e.starter.source:void 0,n=B({starterPath:t.starterPath??r}),o=await Ii(O.join(Ni(),"next-maker-starter-"));await kt(o,{source:n});let s=await He(o),i=await L(o);return{dir:o,source:n,manifest:s,files:i,dispose:()=>$n(o,{recursive:!0,force:!0})}},bn=(e,t)=>e[t]??{},Fi=e=>[...e.off?.anchors??[],...e.on?.anchors??[]],Mi=async(e,t)=>{if(t.length===0)return[];let r=[],n=new RegExp(`@next-maker:(?:${t.map(o=>o.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")})(?::(start|end))?`);for(let o of e.files){if(o.startsWith(".next-maker/"))continue;let s;try{s=await we(O.join(e.dir,o),"utf-8")}catch{continue}if(!Je(s))continue;let i=s.split(`
|
|
17
|
+
`),a=[];for(let p=0;p<i.length;p++){let m=i[p].match(n);if(m)if(m[1]==="start"){let c=p+1;for(;c<i.length&&!/@next-maker:[\w-]+:end/.test(i[c]);)a.push(i[c++]);p=c}else m[1]==="end"||(/^\s*(\{\s*\/\*|\/\*|\/\/|#)/.test(i[p])?i[p+1]!==void 0&&a.push(i[++p]):a.push(i[p].replace(/\s*(\{\s*\/\*|\/\*|\/\/|#).*$/,"")))}a.length&&r.push({file:o,lines:a})}return r},Pn=async(e,t)=>{let r=e.manifest.features[t];if(!r)throw new Error(`Unknown feature "${t}". Valid: ${Object.keys(e.manifest.features).join(", ")}.`);let n=bn(r,"off"),o=bn(r,"on"),s=new Set(e.manifest.always.remove.flatMap(p=>se(e.files,p))),i=[...new Set((n.remove??[]).flatMap(p=>se(e.files,p)))].filter(p=>!s.has(p)).sort(),a=o.overlay?(await L(O.join(e.dir,ge,o.overlay),new Set)).sort():[];return{id:t,feature:r,files:i,overlayFiles:a,packages:n.packages??[],devPackages:n.devPackages??[],scripts:n.scripts??[],env:n.env??[],snippets:await Mi(e,Fi(r))}},kn=e=>/\.(test|spec)\.tsx?$/.test(e)||e.startsWith("test/")||e.includes("__test-utils__"),rr=async(e,t,r)=>{let n=JSON.parse(await we(O.join(e,"package.json"),"utf-8")),o=t.answers.tests!==!1,s=[],i=Object.values(r.manifest.features).filter(p=>!ie(r.manifest,p,t.answers)).flatMap(p=>p.off?.remove??[]),a=new Set(i.flatMap(p=>se(r.files,p)));for(let[p,m]of Object.entries(r.manifest.features)){let c=ie(r.manifest,m,t.answers);if(!c){s.push({id:p,on:c,drift:[]});continue}let d=await Pn(r,p),u=[];for(let f of[...d.files,...d.overlayFiles])!o&&kn(f)||a.has(f)||y(O.join(e,f))||u.push({kind:"missingFile",file:f});for(let f of d.packages)n.dependencies?.[f]||u.push({kind:"missingPackage",name:f,dev:!1});for(let f of d.devPackages)n.devDependencies?.[f]||u.push({kind:"missingPackage",name:f,dev:!0});for(let f of d.scripts)n.scripts?.[f]||u.push({kind:"missingScript",name:f});s.push({id:p,on:c,drift:u})}return s},Sn=async(e,t,r,n)=>{let o=t.answers,s=JSON.parse(await we(O.join(r.dir,"package.json"),"utf-8")),i=[],a=[];for(let[c,d]of Object.entries(r.manifest.features)){let u=ie(r.manifest,d,o),f=ie(r.manifest,d,n);u!==f&&(f?i:a).push(await Pn(r,c))}let p=n.tests!==!1,m={before:o,after:n,turningOn:i,turningOff:a,copy:[],remove:[],addPackages:{},addDevPackages:{},removePackages:[],addScripts:{},removeScripts:[],unwrapJsx:[],unwrapCall:[],manual:[]};for(let c of a){for(let d of[...c.files,...c.overlayFiles])y(O.join(e,d))&&m.remove.push(d);m.removePackages.push(...c.packages,...c.devPackages),m.removeScripts.push(...c.scripts),m.unwrapJsx.push(...c.feature.off?.unwrapJsx??[]),m.unwrapCall.push(...c.feature.off?.unwrapCall??[]),c.snippets.length&&m.manual.push({feature:c.id,direction:"delete",snippets:c.snippets})}for(let c of i){for(let d of[...c.files,...c.overlayFiles])!p&&kn(d)||(!y(O.join(e,d))||c.overlayFiles.includes(d))&&m.copy.push(d);for(let d of c.packages)m.addPackages[d]=s.dependencies?.[d]??"latest";for(let d of c.devPackages)m.addDevPackages[d]=s.devDependencies?.[d]??"latest";for(let d of c.scripts)s.scripts?.[d]&&(m.addScripts[d]=s.scripts[d]);c.snippets.length&&m.manual.push({feature:c.id,direction:"add",snippets:c.snippets})}return m.copy=[...new Set(m.copy)].sort(),m.remove=[...new Set(m.remove)].sort(),m},En=async(e,t,r,n)=>{for(let i of r.remove)await $n(O.join(e,i),{force:!0});for(let i of r.copy){let a=r.turningOn.find(c=>c.overlayFiles.includes(i)),p=a?.feature.on?.overlay?O.join(t.dir,ge,a.feature.on.overlay,i):O.join(t.dir,i),m=O.join(e,i);await Ai(O.dirname(m),{recursive:!0}),await Oi(p,m,{force:!0})}for(let{file:i,tag:a}of r.unwrapJsx){let p=O.join(e,i);if(!y(p))continue;let m=await we(p,"utf-8"),c=ze(m,a);c!==m&&await jt(p,c,"utf-8")}for(let{file:i,name:a}of r.unwrapCall){let p=O.join(e,i);if(!y(p))continue;let m=await we(p,"utf-8"),c=We(m,a);c!==m&&await jt(p,c,"utf-8")}let o=O.join(e,"package.json"),s=JSON.parse(await we(o,"utf-8"));s.dependencies??={},s.devDependencies??={},s.scripts??={};for(let i of r.removePackages)delete s.dependencies[i],delete s.devDependencies[i];for(let i of r.removeScripts)delete s.scripts[i];Object.assign(s.dependencies,r.addPackages),Object.assign(s.devDependencies,r.addDevPackages),Object.assign(s.scripts,r.addScripts),s.dependencies=vn(s.dependencies),s.devDependencies=vn(s.devDependencies),await jt(o,`${JSON.stringify(s,null,2)}
|
|
18
|
+
`,"utf-8"),await me(e,{...n,answers:r.after})},vn=e=>Object.fromEntries(Object.entries(e).sort(([t],[r])=>t.localeCompare(r)));var Di=(e,t)=>e.replace(/support@teispace\.com/g,t.email).replace(/Next\.js Starter/g,t.projectName).replace(/\[AUTHOR\]/g,t.author).replace(/\[COMPANY\]/g,t.author).replace(/\[EMAIL\]/g,t.email),Rn=async(e,t)=>{let r=[de.join(e,C.GITHUB_DIR,C.GITHUB_PR_TEMPLATE),de.join(e,C.CODE_OF_CONDUCT),de.join(e,C.CONTRIBUTING),de.join(e,C.SECURITY)],n=de.join(e,C.GITHUB_DIR,C.GITHUB_ISSUE_TEMPLATE);if(y(n))for(let o of await _i(n))r.push(de.join(n,o));for(let o of r){if(!y(o))continue;let s=await j(o),i=Di(s,t);i!==s&&await k(o,i)}},jn=async(e,t)=>{let r=de.join(e,C.ENV_EXAMPLE);if(!y(r))return;let n=await j(r);n=n.replace(/^CONTAINER_NAME=.*$/m,`CONTAINER_NAME=${t.projectName} # -public`),n=n.replace(/^IMAGE_NAME=.*$/m,`IMAGE_NAME=${t.projectName} # -public`),await k(r,n)},Li=(e,t,r)=>{let n=e.options[t];if(!n)return null;let o=n.label??t;return n.type==="boolean"?r?o:null:Array.isArray(r)?r.length?`${o}: ${r.join(", ")}`:null:r==="none"?null:`${o}: ${String(r)}`},Cn=async(e,t,r,n,o)=>{let s=de.join(e,C.README);if(!t.readme){await mn(s);return}let i=Object.entries(n).filter(([m])=>m!=="packageManager").map(([m,c])=>Li(r,m,c)).filter(m=>m!==null),a=[["dev","development server"],["build","production build"],["start","serve the production build"],["lint:fix","lint, format, and sort imports"],["type-check","route types + tsc"],["check:deprecated","fail on deprecated API usage"],["validate","every gate CI runs"]];n.tests&&a.push(["test","unit and component tests"]),n.e2e&&a.push(["test:e2e","Playwright against a production build"]);let p=`# ${t.projectName}
|
|
115
19
|
|
|
116
|
-
|
|
117
|
-
ui: ReactElement,
|
|
118
|
-
{ store, preloadedState, ...renderOptions }: ExtendedRenderOptions = {},
|
|
119
|
-
) {
|
|
120
|
-
const testStore = store ?? makeStore(preloadedState);
|
|
121
|
-
|
|
122
|
-
return {
|
|
123
|
-
store: testStore,
|
|
124
|
-
...render(ui, {
|
|
125
|
-
wrapper: ({ children }) => <TestProviders store={testStore}>{children}</TestProviders>,
|
|
126
|
-
...renderOptions,
|
|
127
|
-
}),
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export * from '@testing-library/react';
|
|
132
|
-
export { default as userEvent } from '@testing-library/user-event';
|
|
133
|
-
`,rc=`import { type RenderOptions, render } from '@testing-library/react';
|
|
134
|
-
import { NextIntlClientProvider } from 'next-intl';
|
|
135
|
-
import type { ReactElement, ReactNode } from 'react';
|
|
136
|
-
import type { SupportedLocale } from '@/types/i18n';
|
|
137
|
-
|
|
138
|
-
type TestProvidersProps = {
|
|
139
|
-
children: ReactNode;
|
|
140
|
-
messages?: Record<string, unknown>;
|
|
141
|
-
locale?: SupportedLocale;
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
export function TestProviders({ children, messages = {}, locale = 'en' }: TestProvidersProps) {
|
|
145
|
-
return (
|
|
146
|
-
<NextIntlClientProvider locale={locale} messages={messages} timeZone="UTC">
|
|
147
|
-
{children}
|
|
148
|
-
</NextIntlClientProvider>
|
|
149
|
-
);
|
|
150
|
-
}
|
|
20
|
+
${t.description}
|
|
151
21
|
|
|
152
|
-
|
|
153
|
-
messages?: Record<string, unknown>;
|
|
154
|
-
locale?: SupportedLocale;
|
|
155
|
-
};
|
|
22
|
+
Generated from [@teispace/nextjs-starter](https://github.com/teispace/nextjs-starter) ${r.starter.version} with \`@teispace/next-maker\`.
|
|
156
23
|
|
|
157
|
-
|
|
158
|
-
ui: ReactElement,
|
|
159
|
-
{ messages, locale, ...renderOptions }: ExtendedRenderOptions = {},
|
|
160
|
-
) {
|
|
161
|
-
return render(ui, {
|
|
162
|
-
wrapper: ({ children }) => (
|
|
163
|
-
<TestProviders messages={messages} locale={locale}>
|
|
164
|
-
{children}
|
|
165
|
-
</TestProviders>
|
|
166
|
-
),
|
|
167
|
-
...renderOptions,
|
|
168
|
-
});
|
|
169
|
-
}
|
|
24
|
+
## Getting started
|
|
170
25
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
26
|
+
\`\`\`bash
|
|
27
|
+
${o} install
|
|
28
|
+
${ae(o,"dev")}
|
|
29
|
+
\`\`\`
|
|
175
30
|
|
|
176
|
-
|
|
177
|
-
children: ReactNode;
|
|
178
|
-
};
|
|
31
|
+
Open [http://localhost:3000](http://localhost:3000). Copy \`.env.example\` to \`.env\` and set \`NEXT_PUBLIC_API_URL\` to your API origin.
|
|
179
32
|
|
|
180
|
-
|
|
181
|
-
return <>{children}</>;
|
|
182
|
-
}
|
|
33
|
+
## What is included
|
|
183
34
|
|
|
184
|
-
|
|
35
|
+
${i.map(m=>`- ${m}`).join(`
|
|
36
|
+
`)}
|
|
185
37
|
|
|
186
|
-
|
|
187
|
-
return render(ui, {
|
|
188
|
-
wrapper: ({ children }) => <TestProviders>{children}</TestProviders>,
|
|
189
|
-
...options,
|
|
190
|
-
});
|
|
191
|
-
}
|
|
38
|
+
## Scripts
|
|
192
39
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
`)
|
|
40
|
+
| Script | Purpose |
|
|
41
|
+
| :-- | :-- |
|
|
42
|
+
${a.map(([m,c])=>`| \`${ae(o,m)}\` | ${c} |`).join(`
|
|
43
|
+
`)}
|
|
197
44
|
|
|
198
|
-
|
|
45
|
+
## Guides
|
|
199
46
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
47
|
+
- \`AGENTS.md\`: conventions and stack decisions (also read by coding agents)
|
|
48
|
+
- \`docs/data-layer.md\`: how reads, mutations, caching, and sessions fit together
|
|
49
|
+
- \`src/features/README.md\`: how to add a feature
|
|
50
|
+
- \`src/lib/http/README.md\`: the HTTP client
|
|
51
|
+
${n.ws?"- `src/lib/ws/README.md`: the WebSocket client\n":""}${n.i18n?"- `src/i18n/README.md`: internationalization\n":""}- \`docs/ui-libraries.md\`: adding shadcn/ui, Radix, MUI, Mantine, or HeroUI
|
|
204
52
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
path
|
|
209
|
-
image?: string;
|
|
210
|
-
noIndex?: boolean;
|
|
211
|
-
};
|
|
53
|
+
Generators: \`npx @teispace/next-maker feature <name>\`, \`page <name>\`, \`component <name>\`, \`env <NAME>\`${n.i18n?", `locale <code>`":""}.
|
|
54
|
+
`;await k(s,p)};var xe=async e=>{await kt(e.projectPath,{source:e.source});let t=await He(e.projectPath);return tt(t,e.supplied,e.packageManager)},tt=(e,t,r)=>{let{answers:n,forced:o,unknown:s}=Ke(e,t),i=n.packageManager??r??"pnpm";return{manifest:e,answers:n,forced:o,unknown:s,packageManager:i,plan:Xt(e,n,i)}},be=async(e,t,r,n)=>{let{manifest:o,answers:s,packageManager:i,plan:a}=r,p=await Qt(e,o,a);return await xn(e,t),await Rn(e,t),await jn(e,t),await Cn(e,t,o,s,i),await me(e,{cli:Te.version,starter:{name:o.starter.name,version:o.starter.version,source:n.location},packageManager:i,answers:s,identity:{projectName:t.projectName,description:t.description,author:t.author,version:t.version,email:t.email,gitRemote:t.gitRemote,readme:t.readme}}),p};var nr=["pnpm","npm","yarn","bun"],Gi=e=>{if(e!==void 0){if(!nr.includes(e))throw new Error(`Invalid --package-manager "${e}". Valid: ${nr.join(", ")}.`);return e}},Bi=(e,t=[])=>[...t,e],Tn=e=>{e.command("init").description("Create a new Next.js project from the Teispace starter").argument("[name]","Project name").option("-y, --yes","Skip every prompt and use the starter defaults").option("--preset <name>",`Start from a preset (${Ie().join(", ")})`).option("--config <file>","Read identity and options from a JSON file (non-interactive)").option("--set <key=value>","Override one starter option (repeatable), e.g. --set i18n=false",Bi).option("--package-manager <pm>",`Package manager (${nr.join(", ")})`).option("--starter-path <dir>","Compose from a local starter checkout instead of the pinned tag").option("--dry-run","Print the composition plan and create nothing").option("--no-install","Skip dependency installation").option("--no-git","Skip git init").action(async(t,r)=>{try{await zi(t,r)}catch(n){x(`${n instanceof Error?n.message:n}`),process.exit(1)}})},rt=async(e,t,r,n)=>{let o=$t(e);n.current=o;try{let s=await r();return o.succeed(t),s}finally{n.current===o&&(n.current=null)}},Vi=e=>Array.isArray(e)?e.length?e.join(", "):"none":String(e),qi=(e,t,r)=>{l(A.bold("Options"));for(let[n,o]of Object.entries(t.answers)){let s=e.options[n]?.label??n;l(` ${A.dim(s.padEnd(44))} ${Vi(o)}`)}for(let n of r)l(A.yellow(` ! ${n.reason}; ${n.option} turned off`));l(""),l(A.bold("Composition")),l(` ${A.green("keep")} ${t.featuresOn.join(", ")||"(none)"}`),l(` ${A.red("drop")} ${t.featuresOff.join(", ")||"(none)"}`),(t.featureOverlays.length||t.pmOverlays.length)&&l(` ${A.cyan("overlay")} ${[...t.pmOverlays,...t.featureOverlays].join(", ")}`),(t.packages.length||t.devPackages.length)&&l(` ${A.red("uninstall")} ${[...t.packages,...t.devPackages].join(", ")}`),l("")},Ji=async(e,t)=>{let r=t.config?await Zt(t.config):void 0,n=Gi(t.packageManager??r?.packageManager),s={...t.preset?Ne(t.preset):r?.preset?Ne(r.preset):{},...r?.options??{},...ye(t.set)};n&&(s.packageManager=n);let i=!(t.yes||r);return{identity:i?await wn(e):le(e,{projectName:r?.name,description:r?.description,author:r?.author,version:r?.version,email:r?.email,gitRemote:r?.gitRemote,readme:r?.readme,copyEnv:r?.copyEnv}),packageManager:n??"pnpm",suppliedOptions:s,interactive:i,install:t.install!==!1&&r?.install!==!1,git:t.git!==!1&&r?.git!==!1}},zi=async(e,t)=>{vt();let r=await Ji(e,t),{identity:n}=r,o=Ct.resolve(process.cwd(),n.projectName);if(y(o))throw new Error(`Directory ${n.projectName} already exists.`);let s={current:null},i=async()=>{y(o)&&(s.current?.stop(),s.current=null,l(A.yellow(`
|
|
55
|
+
Cleaning up ${n.projectName}...`)),await Ze(o))},a=xt(async()=>{l(A.red(`
|
|
56
|
+
Process interrupted.`)),await i()});try{let p=B({starterPath:t.starterPath}),m=await rt(`Fetching starter (${p.location})...`,"Starter fetched.",()=>xe({projectPath:o,source:p,supplied:r.suppliedOptions,packageManager:r.packageManager}),s);if(l(A.dim(` ${m.manifest.starter.name} ${m.manifest.starter.version}`)),l(""),r.interactive){let f={...r.suppliedOptions,...await Rt(m.manifest,m.answers)};t.packageManager&&(f.packageManager=t.packageManager),m=tt(m.manifest,f,r.packageManager),l("")}for(let f of m.unknown)l(A.yellow(` ! unknown option "${f}" ignored`));let{packageManager:c,plan:d,manifest:u}=m;if(qi(u,d,m.forced),t.dryRun){a(),await Ze(o),l(A.cyan("Dry run: nothing was created."));return}await rt("Composing project...","Project composed.",()=>be(o,n,m,p),s),r.install&&(await rt(`Installing dependencies with ${c}...`,"Dependencies installed.",()=>pe(o,c),s),await rt("Formatting...","Formatted.",()=>Et(o,c,"lint:fix"),s)),n.copyEnv&&y(Ct.join(o,".env.example"))&&await Ui(Ct.join(o,".env.example"),Ct.join(o,".env")),r.git&&await rt("Initializing git...","Git initialized.",()=>St(o,n.gitRemote,n.pushToRemote),s),a(),l(""),l(A.green(`\u2728 ${n.projectName} is ready.`)),l(""),l("Next:"),l(A.cyan(` cd ${n.projectName}`)),r.install||l(A.cyan(` ${c} install`)),l(A.cyan(` ${c==="pnpm"||c==="yarn"?`${c} dev`:`${c} run dev`}`)),l("")}catch(p){throw a(),s.current?.fail("Failed to create project."),s.current=null,await i(),p}};import Cr from"node:path";import K from"picocolors";import Tt from"node:path";var On=/^[A-Za-z][A-Za-z0-9-]*$/,Wi=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i;function An(e){return Wi.test(e)}function F(e,t="name"){let r=e?.trim();if(!r)throw new Error(`A ${t} is required.`);if(!On.test(r))throw new Error(`Invalid ${t} "${e}". Use letters, digits, and hyphens only \u2014 no slashes, spaces, "..", or absolute paths.`);if(An(r))throw new Error(`Invalid ${t} "${e}". That is a reserved name on Windows.`);return r}function W(e,t="path"){let r=e?.trim();if(!r)throw new Error(`A ${t} is required.`);let n=r.replace(/^\.\//,"");if(n.startsWith("/")||/^[a-zA-Z]:/.test(n))throw new Error(`Invalid ${t} "${e}". Must be a relative path inside the project (no leading "/" or drive letter).`);for(let o of n.split("/")){if(!On.test(o))throw new Error(`Invalid ${t} "${e}". Each segment must be kebab/camel-case (letters, digits, hyphens), separated by "/" \u2014 no "..", dots, or empty segments.`);if(An(o))throw new Error(`Invalid ${t} "${e}". Segment "${o}" is reserved on Windows.`)}return n}function te(e,...t){let r=Tt.resolve(e),n=Tt.resolve(r,...t),o=Tt.relative(r,n);if(o===""||o===".")return n;if(o.startsWith("..")||Tt.isAbsolute(o))throw new Error(`Refusing to write outside the project directory (resolved path escapes "${r}").`);return n}import{access as Hi}from"node:fs/promises";import Ki from"node:path";var ve=async(e,t,r)=>{try{return await Hi(Ki.join(e,r,t)),!0}catch{return!1}};import{access as Xi,readFile as Nn}from"node:fs/promises";import or from"node:path";var _e=async e=>{try{return await Xi(e),!0}catch{return!1}},In=async e=>{try{return JSON.parse(await Nn(e,"utf-8"))}catch{return null}},T=async e=>{let t=await In(or.join(e,"package.json"));if(!t)throw new Error(`Failed to detect project setup: no package.json in ${e}`);let r={...t.dependencies,...t.devDependencies},n=await In(or.join(e,Fe)),o=(...w)=>or.join(e,...w),s=await _e(o("src","store")),i=!!(r["@reduxjs/toolkit"]&&r["react-redux"])&&s,a=!!r.zustand&&s&&!i,p=i?"redux":a?"zustand":"none",m=await _e(o("src","lib","http","core","client.ts")),c=!!r.axios&&await _e(o("src","lib","http","adapters","axios.ts")),d="none";if(m)if(!c)d="fetch";else{let w="";try{w=await Nn(o("src","lib","http","client.ts"),"utf-8")}catch{}d=w.includes("axiosAdapter")?"axios":"both"}let u=!!r["next-intl"]&&await _e(o("src","i18n")),f=!!r.vitest||await _e(o("vitest.config.ts")),h=r["socket.io-client"]&&await _e(o("src","lib","ws"))?"present":"none";return{state:p,hasRedux:i,httpClient:d,hasI18n:u,hasTests:f,ws:h,hasQuery:!!r["@tanstack/react-query"],hasActions:!!r["next-safe-action"],record:n??void 0}};import{mkdir as Yi,writeFile as Qi}from"node:fs/promises";import sr from"node:path";var Fn=({pascalName:e,camelName:t})=>`import { z } from 'zod';
|
|
212
57
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
58
|
+
/**
|
|
59
|
+
* Wire contracts for the ${t} feature. Types are inferred from the
|
|
60
|
+
* schemas, so a response that drifts from the contract fails validation at
|
|
61
|
+
* the transport instead of surfacing as \`undefined\` in a component.
|
|
62
|
+
*/
|
|
63
|
+
export const ${t}Schema = z.object({
|
|
64
|
+
id: z.string(),
|
|
65
|
+
title: z.string(),
|
|
66
|
+
createdAt: z.string(),
|
|
67
|
+
});
|
|
68
|
+
export type ${e} = z.infer<typeof ${t}Schema>;
|
|
222
69
|
|
|
223
|
-
|
|
224
|
-
title,
|
|
225
|
-
description,
|
|
226
|
-
metadataBase: new URL(APP_URL),
|
|
227
|
-
alternates: {
|
|
228
|
-
canonical: url,
|
|
229
|
-
},
|
|
230
|
-
openGraph: {
|
|
231
|
-
type: 'website',
|
|
232
|
-
title,
|
|
233
|
-
description,
|
|
234
|
-
url,
|
|
235
|
-
siteName: APP_NAME,
|
|
236
|
-
images: [
|
|
237
|
-
{
|
|
238
|
-
url: ogImage,
|
|
239
|
-
width: 1200,
|
|
240
|
-
height: 630,
|
|
241
|
-
alt: title,
|
|
242
|
-
},
|
|
243
|
-
],
|
|
244
|
-
locale: 'en_US',
|
|
245
|
-
},
|
|
246
|
-
twitter: {
|
|
247
|
-
card: 'summary_large_image',
|
|
248
|
-
title,
|
|
249
|
-
description,
|
|
250
|
-
images: [ogImage],
|
|
251
|
-
},
|
|
252
|
-
robots: noIndex
|
|
253
|
-
? { index: false, follow: false }
|
|
254
|
-
: {
|
|
255
|
-
index: true,
|
|
256
|
-
follow: true,
|
|
257
|
-
'max-video-preview': -1,
|
|
258
|
-
'max-image-preview': 'large' as const,
|
|
259
|
-
'max-snippet': -1,
|
|
260
|
-
},
|
|
261
|
-
};
|
|
262
|
-
}
|
|
70
|
+
export const ${t}ListSchema = z.array(${t}Schema);
|
|
263
71
|
|
|
264
|
-
export {
|
|
265
|
-
|
|
72
|
+
export const create${e}InputSchema = z.object({
|
|
73
|
+
title: z.string().min(1).max(200),
|
|
74
|
+
});
|
|
75
|
+
export type Create${e}Input = z.infer<typeof create${e}InputSchema>;
|
|
266
76
|
|
|
267
|
-
|
|
77
|
+
export const update${e}InputSchema = create${e}InputSchema.partial().extend({
|
|
78
|
+
id: z.string(),
|
|
79
|
+
});
|
|
80
|
+
export type Update${e}Input = z.infer<typeof update${e}InputSchema>;
|
|
81
|
+
`,Mn=({kebabName:e,camelName:t})=>`/**
|
|
82
|
+
* Query keys owned by the feature. Everything under \`${t}Keys.all\` can
|
|
83
|
+
* be invalidated at once; narrower keys target one resource.
|
|
84
|
+
*/
|
|
85
|
+
export const ${t}Keys = {
|
|
86
|
+
all: ['${e}'] as const,
|
|
87
|
+
list: () => [...${t}Keys.all, 'list'] as const,
|
|
88
|
+
detail: (id: string) => [...${t}Keys.all, 'detail', id] as const,
|
|
89
|
+
} as const;
|
|
90
|
+
`,_n=({pascalName:e,camelName:t})=>`import 'server-only';
|
|
268
91
|
|
|
269
|
-
|
|
92
|
+
import { AppApis } from '@/lib/config/app-apis';
|
|
93
|
+
import { serverHttp } from '@/lib/http/server';
|
|
270
94
|
|
|
271
|
-
|
|
272
|
-
const paths = ['/'];
|
|
95
|
+
import { ${t}ListSchema, ${t}Schema } from './schema';
|
|
273
96
|
|
|
274
|
-
|
|
275
|
-
url: \`\${APP_URL}\${path}\`,
|
|
276
|
-
lastModified: new Date(),
|
|
277
|
-
changeFrequency: 'monthly' as const,
|
|
278
|
-
priority: path === '/' ? 1 : 0.8,
|
|
279
|
-
}));
|
|
280
|
-
}
|
|
281
|
-
`;import kc from"node:fs/promises";import it from"node:path";P();w();var Nc=[R.VITEST,R.JSDOM,R.VITE_PLUGIN_REACT,R.TESTING_LIBRARY_DOM,R.TESTING_LIBRARY_JEST_DOM,R.TESTING_LIBRARY_REACT,R.TESTING_LIBRARY_USER_EVENT],yn=async e=>{let t;try{t=await kc.readdir(e,{withFileTypes:!0})}catch{return}for(let r of t){let i=it.join(e,r.name);if(r.isDirectory()){if(r.name==="__test-utils__"||r.name==="__tests__"){await v(i);continue}await yn(i)}else r.isFile()&&/\.(test|spec)\.tsx?$/.test(r.name)&&await C(i)}},xn=async(e,t)=>{t.tests||(await C(it.join(e,a.VITEST_CONFIG)),await v(it.join(e,a.TEST_DIR)),await yn(it.join(e,a.SRC)),await _(it.join(e,a.PACKAGE_JSON),r=>{if(r.devDependencies)for(let i of Nc)delete r.devDependencies[i];return r.scripts&&(delete r.scripts.test,delete r.scripts["test:watch"],delete r.scripts["test:coverage"],typeof r.scripts.validate=="string"&&(r.scripts.validate=r.scripts.validate.replace(/\s*&&\s*yarn\s+test(?![:\w])/,"").replace(/\byarn\s+test(?![:\w])\s*&&\s*/,""))),r}))};P();w();import ze from"node:path";P();w();import wn from"node:path";import{readFile as Ac,writeFile as _c}from"node:fs/promises";import Fc from"node:path";var nt=(e,t)=>{let r=/import\s+.*\s+from\s+['"].*['"];?\n/g,i=e.match(r);if(i&&i.length>0){let n=i[i.length-1],o=e.lastIndexOf(n);return e.slice(0,o+n.length)+t+`
|
|
282
|
-
`+e.slice(o+n.length)}return`${t}
|
|
283
|
-
${e}`},Gr=(e,t,r)=>{let i=/combineReducers\(\{([^}]*)\}\)/s,n=e.match(i);if(!n)throw new Error("Could not find combineReducers in rootReducer.ts");let o=n[1],s=`
|
|
284
|
-
${t}: ${r},`,c=o.trimEnd()+s;return e.replace(i,`combineReducers({${c}
|
|
285
|
-
})`)},ot=(e,t)=>{let r=e.lastIndexOf("} as const;");if(r===-1)throw new Error("Could not find closing brace of AppApis object");let i=e.substring(0,r),n=e.substring(r);return`${i.trimEnd()}
|
|
286
|
-
${t}
|
|
287
|
-
${n}`};var ke=async e=>{let{projectPath:t,name:r,persist:i,importPath:n}=e,o=Fc.join(t,"src","store","rootReducer.ts");try{let s=await Ac(o,"utf-8"),c=G(r),p=`${c}Reducer`,u=`${c}PersistConfig`,d=n.replace(/^src\//,"@/"),f=i?`import { ${p}, ${u} } from '${d}';`:`import { ${p} } from '${d}';`;s=nt(s,f);let x=i?`persistReducer(${u}, ${p})`:p;s=Gr(s,c,x),await _c(o,s)}catch(s){throw new Error(`Failed to register reducer '${r}' in rootReducer: ${s}`,{cause:s})}};var Pn="import { attachWsBridge, wsClient } from '@/lib/utils/ws';",Oc=`
|
|
288
|
-
// Bridge the WS client's lifecycle into the Redux slice exactly once per
|
|
289
|
-
// store instance. The bridge does not open a connection \u2014 that happens
|
|
290
|
-
// lazily on first \`useWsEvent\` subscription or an explicit \`connect()\`.
|
|
291
|
-
// Effect runs in the browser only, so the SSR boundary is safe.
|
|
292
|
-
useEffect(() => {
|
|
293
|
-
const store = storeRef.current;
|
|
294
|
-
if (!store) return;
|
|
295
|
-
return attachWsBridge(wsClient, store.dispatch);
|
|
296
|
-
}, []);
|
|
297
|
-
`,Ft=async e=>{await ke({projectPath:e,name:"ws",persist:!1,importPath:"src/store/slices/ws.slice"})},Dc=e=>{if(e.includes("from '@/lib/utils/ws'"))return e;let t=e,r=/(^import\s[^\n]*\n)+/m,i=t.match(r);if(!i)throw new Error("injectBridgeMount: no `import` lines found \u2014 expected a StoreProvider with imports.");let n=(i.index??0)+i[0].length;t=`${t.slice(0,n)}${Pn}
|
|
298
|
-
${t.slice(n)}`,t=Gc(t);let o=/(if\s*\(\s*!storeRef\.current\s*\)\s*\{[\s\S]*?\n\s*\})/;if(!t.match(o))throw new Error("injectBridgeMount: could not locate `if (!storeRef.current) { ... }` initializer \u2014 StoreProvider shape unexpected.");return t=t.replace(o,`$1
|
|
299
|
-
${Oc.trimEnd()}
|
|
300
|
-
`),t},Ot=e=>{let t=e;return t=t.replace(new RegExp(`${Hc(Pn)}\\n?`),""),t=t.replace(/\n(?:[ \t]*\/\/[^\n]*\n)*[ \t]*useEffect\(\(\)\s*=>\s*\{[\s\S]*?attachWsBridge\(wsClient,\s*store\.dispatch\)[\s\S]*?\},\s*\[\]\);\n?/,`
|
|
301
|
-
`),/\buseEffect\s*\(/.test(t)||(t=jc(t)),t},jc=e=>{let t=/import\s*\{([^}]*)\}\s*from\s*['"]react['"];\n?/,r=e.match(t);if(!r)return e;let i=r[1].split(",").map(o=>o.trim()).filter(o=>o.length>0&&o!=="useEffect");if(i.length===0)return e.replace(t,"");let n=`import { ${i.join(", ")} } from 'react';
|
|
302
|
-
`;return e.replace(t,n)},Dt=async e=>{let t=wn.join(e,a.STORE_PROVIDER);if(!l(t))return;let r=await g(t),i=Dc(r);i!==r&&await h(t,i)};var jt=async e=>{let t=wn.join(e,a.TEST_SETUP_FILE);if(!l(t))return;let r=await g(t),i=!1;r.includes("vi.mock('react-secure-storage'")||(r+=Lc,i=!0),r.includes("vi.mock('server-only'")||(r+=Mc,i=!0),i&&await h(t,r)},Lc=`
|
|
303
|
-
// \`react-secure-storage\` constructs an \`EncryptionService\` at module load
|
|
304
|
-
// that fingerprints the browser via \`<canvas>.getContext\`. jsdom doesn't
|
|
305
|
-
// implement canvas, so the import explodes anywhere it's pulled in
|
|
306
|
-
// transitively (HTTP token store, WS auth carrier, etc.). Stub it globally \u2014
|
|
307
|
-
// tests that need real behaviour are integration tests, not unit tests.
|
|
308
|
-
vi.mock('react-secure-storage', () => {
|
|
309
|
-
const store = new Map<string, unknown>();
|
|
310
|
-
return {
|
|
311
|
-
default: {
|
|
312
|
-
setItem: (k: string, v: unknown) => store.set(k, v),
|
|
313
|
-
getItem: (k: string) => store.get(k) ?? null,
|
|
314
|
-
removeItem: (k: string) => store.delete(k),
|
|
315
|
-
clear: () => store.clear(),
|
|
316
|
-
},
|
|
317
|
-
};
|
|
318
|
-
});
|
|
319
|
-
`,Mc=`
|
|
320
|
-
// \`server-only\` throws at module load outside a Next.js server bundle \u2014
|
|
321
|
-
// the package relies on bundler-level redirect to a no-op file in server
|
|
322
|
-
// environments. Vitest doesn't do that redirect, so we stub it as a no-op
|
|
323
|
-
// to let unit tests reach the server-side modules. Production builds are
|
|
324
|
-
// unaffected; Next.js still routes \`server-only\` to its real implementation.
|
|
325
|
-
vi.mock('server-only', () => ({}));
|
|
326
|
-
`,Gc=e=>{let t=/import\s*\{([^}]*)\}\s*from\s*['"]react['"];/,r=e.match(t);if(!r)return e;let i=r[1];if(/\buseEffect\b/.test(i))return e;let n=i.split(",").map(s=>s.trim()).filter(Boolean);n.push("useEffect"),n.sort();let o=`import { ${n.join(", ")} } from 'react';`;return e.replace(t,o)},Hc=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),Lt=e=>{let t=e;return t=t.replace(/^import\s*\{\s*wsReducer\s*\}\s*from\s*['"][^'"]*ws\.slice['"];\n?/m,""),t=t.replace(/^\s*ws:\s*wsReducer,?\n/m,""),t=t.replace(/\/\*\*[^*]*(?:\*(?!\/)[^*]*)*\bws\b[^*]*(?:\*(?!\/)[^*]*)*\bpersistReducer\b[\s\S]*?\*\/\n?/,""),t};var vn=async(e,t)=>{t.ws||(await v(ze.join(e,a.WS_UTILS)),await C(ze.join(e,a.WS_SLICE_FILE)),await C(ze.join(e,a.WS_SLICE_TEST_FILE)),t.redux&&(await Uc(e),await Bc(e)),await zc(e))},Uc=async e=>{let t=ze.join(e,a.ROOT_REDUCER);if(!l(t))return;let r=await g(t),i=Lt(r);i!==r&&await h(t,i)},Bc=async e=>{let t=ze.join(e,a.STORE_PROVIDER);if(!l(t))return;let r=await g(t),i=Ot(r);i!==r&&await h(t,i)},zc=async e=>{let t=ze.join(e,a.PACKAGE_JSON);if(!l(t))return;let r=JSON.parse(await g(t));({...r.dependencies,...r.devDependencies})["socket.io-client"]&&await He(e,"socket.io-client")};var Sn=async(e,t)=>{let r=S("Customizing features...");try{await on(e,t),await an(e,t),await vn(e,t),await fn(e,t),await Zi(e,t),await Ki(e,t),await sn(e,t),await hn(e,t),await un(e,t),await xn(e,t),await cn(e),await pn(e),await ln(e),await mn(e),t.tests&&await ce(e,{redux:t.redux,i18n:t.i18n}),r.succeed("Features customized.")}catch(i){throw r.fail("Failed to customize features."),i}};import Vc from"node:path";P();w();var En=async(e,t)=>{let r=S("Configuring package.json...");try{let i=t.gitRemote,n=t.gitHomepage,o=t.gitIssues;t.gitRemote&&(t.gitRemote.startsWith("git@github.com:")&&(i=t.gitRemote.replace("git@github.com:","https://github.com/").replace(/\.git$/,"")),n||(n=`${i.replace(/\.git$/,"")}#readme`),o||(o=`${i.replace(/\.git$/,"")}/issues`),i.endsWith(".git")||(i=`${i}.git`)),await _(Vc.join(e,a.PACKAGE_JSON),s=>(s.name=t.projectName,s.version=t.version,s.description=t.description,s.author=t.author,delete s.packageManager,t.gitRemote?(n&&(s.homepage=n),o&&(s.bugs={url:o}),i&&(s.repository={type:"git",url:i})):(delete s.homepage,delete s.bugs,delete s.repository),t.redux||(delete s.dependencies[R.REDUX_TOOLKIT],delete s.dependencies[R.REACT_REDUX],delete s.dependencies[R.REDUX],delete s.dependencies[R.REDUX_PERSIST]),t.httpClient!=="none"||t.reactSecureStorage||delete s.dependencies[R.REACT_SECURE_STORAGE],t.i18n||delete s.dependencies[R.NEXT_INTL],t.darkMode||delete s.dependencies[R.NEXT_THEMES],t.httpClient==="none"?delete s.dependencies[R.AXIOS]:t.httpClient==="fetch"&&delete s.dependencies[R.AXIOS],s)),r.succeed("package.json configured.")}catch(i){throw r.fail("Failed to configure package.json."),i}};import{readdir as Tn}from"node:fs/promises";import L from"node:path";P();w();var Cn=async(e,t)=>{await Jc(e,t),await Wc(e,t),await qc(e,t),await Xc(e,t),await Yc(e,t),await Kc(e,t),await Zc(e,t)},Jc=async(e,t)=>{t.preCommitHooks||(await v(L.join(e,a.HUSKY_DIR)),await C(L.join(e,a.COMMITLINT_CONFIG)),await C(L.join(e,a.LINTSTAGED_RC)),await _(L.join(e,a.PACKAGE_JSON),r=>(delete r.devDependencies[R.HUSKY],delete r.devDependencies[R.COMMITLINT_CLI],delete r.devDependencies[R.COMMITLINT_CONFIG],delete r.devDependencies[R.LINT_STAGED],delete r.scripts.prepare,delete r.scripts.postinstall,delete r.commitlint,delete r["lint-staged"],r)))},Wc=async(e,t)=>{t.commitizen||(await C(L.join(e,a.CZRC)),await _(L.join(e,a.PACKAGE_JSON),r=>(delete r.devDependencies[R.COMMITIZEN],delete r.devDependencies[R.CZ_CONVENTIONAL_CHANGELOG],delete r.config?.commitizen,r.config&&Object.keys(r.config).length===0&&delete r.config,delete r.scripts.commit,r)))},qc=async(e,t)=>{t.ci||await v(L.join(e,a.GITHUB_WORKFLOWS))},Xc=async(e,t)=>{let r=L.join(e,a.GITHUB_DIR);if(!t.keepTemplates)await v(L.join(r,a.GITHUB_ISSUE_TEMPLATE)),await C(L.join(r,a.GITHUB_PR_TEMPLATE));else{let i=L.join(r,a.GITHUB_ISSUE_TEMPLATE),n=L.join(r,a.GITHUB_PR_TEMPLATE),o=s=>s.replace(/Teispace/g,t.company).replace(/support@teispace\.com/g,t.email).replace(/Next\.js Starter/g,t.projectName).replace(/\[AUTHOR\]/g,t.author).replace(/\[COMPANY\]/g,t.company).replace(/\[EMAIL\]/g,t.email);if(l(n)){let s=await g(n);s=o(s),await h(n,s)}try{if(l(i)){let s=await Tn(i);for(let c of s){let p=L.join(i,c),u=await g(p);u=o(u),await h(p,u)}}}catch{}}},Yc=async(e,t)=>{let r=[a.CODE_OF_CONDUCT,a.CONTRIBUTING,a.SECURITY];for(let i of r)t.communityFiles.includes(i)||await C(L.join(e,i))},Kc=async(e,t)=>{if(t.docker){let r=L.join(e,a.ENV_EXAMPLE);if(l(r)){let i=await g(r),n=(o,s)=>{let c=new RegExp(`${o}=.*`);c.test(i)?i=i.replace(c,`${o}=${s}`):i+=`${o}=${s}
|
|
327
|
-
`};n("CONTAINER_NAME",t.containerName||"next-app"),n("IMAGE_NAME",t.imageName||"nextjs-starter"),n("IMAGE_TAG",t.imageTag||"latest"),await h(r,i)}}else{await C(L.join(e,a.DOCKERFILE)),await C(L.join(e,a.DOCKER_COMPOSE)),await C(L.join(e,a.DOCKERIGNORE));let r=L.join(e,a.ENV_EXAMPLE);if(l(r)){let i=await g(r);i=i.replace(/# Docker Compose Configuration\n/,""),i=i.replace(/CONTAINER_NAME=.*\n/,""),i=i.replace(/IMAGE_NAME=.*\n/,""),i=i.replace(/IMAGE_TAG=.*\n/,""),await h(r,i)}}},Zc=async(e,t)=>{let r=async o=>{let s=await Tn(o,{withFileTypes:!0}),c=[];for(let p of s){let u=L.join(o,p.name);p.isDirectory()&&p.name!=="node_modules"&&p.name!==".git"?c.push(...await r(u)):p.isFile()&&p.name.toLowerCase()==="readme.md"&&c.push(u)}return c},i=await r(e),n=L.join(e,a.README);for(let o of i)o!==n&&await C(o);if(t.readme){let o=`# ${t.projectName}
|
|
97
|
+
export const ${t.toUpperCase()}_TAG = '${t}';
|
|
328
98
|
|
|
329
|
-
|
|
99
|
+
/**
|
|
100
|
+
* Data access for Server Components. These reads act as the signed-in user
|
|
101
|
+
* (\`serverHttp\` forwards the session cookie), so they must not be wrapped in
|
|
102
|
+
* \`use cache\` and the calling component must sit under \`<Suspense>\`.
|
|
103
|
+
*
|
|
104
|
+
* For public, user-independent data use \`publicServerHttp\` inside a
|
|
105
|
+
* \`'use cache'\` function with \`cacheTag(${t.toUpperCase()}_TAG)\` and a \`cacheLife\`.
|
|
106
|
+
*/
|
|
107
|
+
export const list${e}s = async () =>
|
|
108
|
+
serverHttp.get(AppApis.${t}.list, { schema: ${t}ListSchema });
|
|
330
109
|
|
|
331
|
-
|
|
110
|
+
export const get${e} = async (id: string) =>
|
|
111
|
+
serverHttp.get(AppApis.${t}.detail(id), { schema: ${t}Schema });
|
|
112
|
+
`,Dn=({pascalName:e,camelName:t})=>`'use server';
|
|
332
113
|
|
|
333
|
-
|
|
114
|
+
import { revalidateTag } from 'next/cache';
|
|
334
115
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
116
|
+
import { authActionClient } from '@/lib/actions';
|
|
117
|
+
import { AppApis } from '@/lib/config/app-apis';
|
|
118
|
+
import { serverHttp } from '@/lib/http/server';
|
|
338
119
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
${o}
|
|
342
|
-
</NextIntlClientProvider>`),t.darkMode&&(o=`<CustomThemeProvider>
|
|
343
|
-
${o}
|
|
344
|
-
</CustomThemeProvider>`),t.redux&&(o=`<StoreProvider preloadedState={preloadedState}>
|
|
345
|
-
${o}
|
|
346
|
-
</StoreProvider>`),o==="{children}"&&(o="<>{children}</>");let s=`type RootProviderProps = {
|
|
347
|
-
${i.join(`
|
|
348
|
-
`)}
|
|
349
|
-
};`,c=`'use client';
|
|
350
|
-
${r.join(`
|
|
351
|
-
`)}
|
|
120
|
+
import { create${e}InputSchema, ${t}Schema, update${e}InputSchema } from './schema';
|
|
121
|
+
import { ${t.toUpperCase()}_TAG } from './server';
|
|
352
122
|
|
|
353
|
-
|
|
123
|
+
/**
|
|
124
|
+
* Server Actions. \`authActionClient\` validates the input, loads the session
|
|
125
|
+
* (\`ctx.user\`), refuses anonymous callers, and turns thrown errors into a
|
|
126
|
+
* plain \`result.serverError\`.
|
|
127
|
+
*/
|
|
128
|
+
export const create${e} = authActionClient
|
|
129
|
+
.metadata({ name: '${t}.create' })
|
|
130
|
+
.inputSchema(create${e}InputSchema)
|
|
131
|
+
.action(async ({ parsedInput }) => {
|
|
132
|
+
const result = await serverHttp.post(AppApis.${t}.create, parsedInput, {
|
|
133
|
+
schema: ${t}Schema,
|
|
134
|
+
});
|
|
135
|
+
if (!result.ok) throw result.error;
|
|
136
|
+
revalidateTag(${t.toUpperCase()}_TAG, 'max');
|
|
137
|
+
return result.data;
|
|
138
|
+
});
|
|
354
139
|
|
|
355
|
-
export const
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
)
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
${o}import { RootProvider } from '@/providers';
|
|
367
|
-
|
|
368
|
-
const livvic = Livvic({
|
|
369
|
-
subsets: ['latin'],
|
|
370
|
-
variable: '--font-livvic',
|
|
371
|
-
weight: ['100', '200', '300', '400', '500', '600', '700', '900'],
|
|
372
|
-
display: 'swap',
|
|
373
|
-
});
|
|
140
|
+
export const update${e} = authActionClient
|
|
141
|
+
.metadata({ name: '${t}.update' })
|
|
142
|
+
.inputSchema(update${e}InputSchema)
|
|
143
|
+
.action(async ({ parsedInput: { id, ...changes } }) => {
|
|
144
|
+
const result = await serverHttp.patch(AppApis.${t}.update(id), changes, {
|
|
145
|
+
schema: ${t}Schema,
|
|
146
|
+
});
|
|
147
|
+
if (!result.ok) throw result.error;
|
|
148
|
+
revalidateTag(${t.toUpperCase()}_TAG, 'max');
|
|
149
|
+
return result.data;
|
|
150
|
+
});
|
|
374
151
|
|
|
375
|
-
export const
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
}
|
|
152
|
+
export const delete${e} = authActionClient
|
|
153
|
+
.metadata({ name: '${t}.delete' })
|
|
154
|
+
.inputSchema(${t}Schema.pick({ id: true }))
|
|
155
|
+
.action(async ({ parsedInput }) => {
|
|
156
|
+
const result = await serverHttp.delete<void>(AppApis.${t}.delete(parsedInput.id));
|
|
157
|
+
if (!result.ok) throw result.error;
|
|
158
|
+
revalidateTag(${t.toUpperCase()}_TAG, 'max');
|
|
159
|
+
return { deleted: true as const };
|
|
160
|
+
});
|
|
161
|
+
`,Ln=({pascalName:e,camelName:t})=>`import { queryOptions, useSuspenseQuery } from '@tanstack/react-query';
|
|
379
162
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
}
|
|
383
|
-
children: React.ReactNode;
|
|
384
|
-
}>) {
|
|
385
|
-
return (
|
|
386
|
-
<html lang="en"${t.darkMode?" suppressHydrationWarning={true}":""}>
|
|
387
|
-
<body className={${r}}>
|
|
388
|
-
<RootProvider${i}>${s}
|
|
389
|
-
{children}
|
|
390
|
-
</RootProvider>
|
|
391
|
-
</body>
|
|
392
|
-
</html>
|
|
393
|
-
);
|
|
394
|
-
}
|
|
395
|
-
`;await h(Hr.join(e,a.ROOT_LAYOUT),c);let p=t.redux?`import { Counter } from '@/features/counter';
|
|
163
|
+
import { AppApis } from '@/lib/config/app-apis';
|
|
164
|
+
import { http } from '@/lib/http';
|
|
165
|
+
import { unwrapForQuery } from '@/lib/query';
|
|
396
166
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
return (
|
|
400
|
-
<div className="flex min-h-screen flex-col items-center justify-center p-24">
|
|
401
|
-
<h1 className="text-4xl font-bold">Welcome to ${t.projectName}</h1>
|
|
402
|
-
<p className="mt-4 text-xl">Get started by editing src/app/page.tsx</p>${u}
|
|
403
|
-
</div>
|
|
404
|
-
);
|
|
405
|
-
}
|
|
406
|
-
`;await h(Hr.join(e,a.ROOT_PAGE),d)};import Qc from"degit";var In="teispace/nextjs-starter",$n="v1.1.1",ep=()=>$n==="main"?In:`${In}#${$n}`,J=async(e,t={})=>{await Qc(ep(),{cache:!1,force:!0,verbose:t.verbose??!1}).clone(e)};var kn=async e=>{let t=S("Downloading template...");try{await J(e,{verbose:!0}),t.succeed("Template downloaded successfully.")}catch(r){throw t.fail("Failed to download template."),r}};var Br=["npm","yarn","pnpm","bun"],tp=e=>{if(e!==void 0){if(!Br.includes(e))throw new Error(`Invalid --package-manager "${e}". Valid: ${Br.join(", ")}.`);return e}},Nn=e=>{e.command("init").description("Initialize a new Next.js project").argument("[name]","Project name").option("-y, --yes","Skip all prompts and use the recommended production defaults").option("--package-manager <pm>",`Override the package manager (one of: ${Br.join(", ")})`).action(async(t,r)=>{try{let i=tp(r.packageManager);await ip(t,{yes:r.yes??!1,packageManager:i})}catch(i){E(`${i instanceof Error?i.message:i}`),process.exit(1)}})},st=async(e,t,r,i)=>{let n=S(e);i.current=n;try{let o=await r();return n.succeed(t),o}finally{i.current===n&&(i.current=null)}},rp=e=>{let t=[];e.darkMode&&t.push("dark mode"),e.redux&&t.push("redux"),e.i18n&&t.push("i18n"),e.tests&&t.push("tests"),e.reactCompiler&&t.push("react-compiler"),e.preCommitHooks&&t.push("pre-commit hooks"),e.commitizen&&t.push("commitizen"),e.httpClient!=="none"&&t.push(`http (${e.httpClient})`),m(ee.dim("Defaults applied (run `next-maker remove <feature>` to undo any of them):")),m(ee.dim(` package manager : ${e.packageManager}`)),m(ee.dim(` features : ${t.join(", ")}`)),m("")},ip=async(e,t)=>{Hi();let r;t.yes?(r=Wi(e,{packageManager:t.packageManager}),m(ee.cyan(`\u2728 Bootstrapping ${r.projectName} with the recommended defaults`)),m(""),rp(r)):(m("Welcome to the Teispace Next.js App Creator!"),m(""),r=await qi(e),t.packageManager&&(r={...r,packageManager:t.packageManager}));let i=Ur.resolve(process.cwd(),r.projectName);l(i)&&(console.error(ee.red(`Error: Directory ${r.projectName} already exists.`)),process.exit(1));let n={current:null},o=async()=>{if(l(i)){n.current?.stop(),n.current=null,console.log(ee.yellow(`
|
|
407
|
-
Cleaning up: Deleting directory ${r.projectName}...`));try{await v(i),console.log(ee.green("Cleanup successful."))}catch(c){console.error(ee.red(`Failed to clean up directory ${r.projectName}:`),c)}}},s=Li(async()=>{console.log(ee.red(`
|
|
408
|
-
Process interrupted. Cleaning up...`)),await o()});try{if(await kn(i),await En(i,r),await Sn(i,r),await st("Generating providers and layout...","Providers and layout generated.",async()=>{await Rn(i,r),await bn(i,r)},n),await st("Setting up developer tools...","Developer tools configured.",()=>Cn(i,r),n),await st("Initializing Git...","Git initialized.",()=>Bi(i,r.gitRemote,r.pushToRemote),n),await st("Installing dependencies...","Dependencies installed.",()=>zi(i,r.packageManager),n),await st("Formatting and linting...","Formatted.",()=>K(i,r.packageManager,"lint:fix"),n),r.copyEnv){let c=Ur.join(i,".env.example"),p=Ur.join(i,".env");l(c)&&await(await import("node:fs/promises")).copyFile(c,p)}s(),m(""),m(ee.green(`\u2728 Project ${r.projectName} created successfully!`)),m(""),m("To get started:"),m(ee.cyan(` cd ${r.projectName}`)),m(ee.cyan(` ${r.packageManager==="npm"?"npm run dev":`${r.packageManager} dev`}`)),m("")}catch(c){s(),n.current?.fail("Failed to create project."),n.current=null,console.error(c),await o(),process.exit(1)}};import ii from"node:path";import le from"picocolors";import Mt from"node:path";var An=/^[A-Za-z][A-Za-z0-9-]*$/,np=/^(con|prn|aux|nul|com[1-9]|lpt[1-9])$/i;function _n(e){return np.test(e)}function W(e,t="name"){let r=e?.trim();if(!r)throw new Error(`A ${t} is required.`);if(!An.test(r))throw new Error(`Invalid ${t} "${e}". Use letters, digits, and hyphens only \u2014 no slashes, spaces, "..", or absolute paths.`);if(_n(r))throw new Error(`Invalid ${t} "${e}". That is a reserved name on Windows.`);return r}function pe(e,t="path"){let r=e?.trim();if(!r)throw new Error(`A ${t} is required.`);let i=r.replace(/^\.\//,"");if(i.startsWith("/")||/^[a-zA-Z]:/.test(i))throw new Error(`Invalid ${t} "${e}". Must be a relative path inside the project (no leading "/" or drive letter).`);for(let n of i.split("/")){if(!An.test(n))throw new Error(`Invalid ${t} "${e}". Each segment must be kebab/camel-case (letters, digits, hyphens), separated by "/" \u2014 no "..", dots, or empty segments.`);if(_n(n))throw new Error(`Invalid ${t} "${e}". Segment "${n}" is reserved on Windows.`)}return i}function Gt(e,...t){let r=Mt.resolve(e),i=Mt.resolve(r,...t),n=Mt.relative(r,i);if(n===""||n===".")return i;if(n.startsWith("..")||Mt.isAbsolute(n))throw new Error(`Refusing to write outside the project directory (resolved path escapes "${r}").`);return i}q();import{mkdir as Ln,writeFile as Vr}from"node:fs/promises";import Ne from"node:path";w();var zr=e=>{let{componentName:t,isClient:r,hasI18n:i}=e,n=e.translationNamespace||t,o=[];return(r||i)&&o.push("'use client';"),i&&o.push("import { useTranslations } from 'next-intl';"),o.push(""),o.push(`export function ${t}() {`),i?(o.push(` const t = useTranslations('${n}');`),o.push(""),o.push(" return ("),o.push(" <div>"),o.push(" <h2>{t('title')}</h2>"),o.push(" </div>"),o.push(" );")):(o.push(" return ("),o.push(" <div>"),o.push(` <h2>${t}</h2>`),o.push(" </div>"),o.push(" );")),o.push("}"),o.push(""),o.join(`
|
|
409
|
-
`)},jn=e=>`export { ${e.componentName} } from './${e.componentName}';
|
|
410
|
-
`;var Jr=async e=>{let{name:t,projectPath:r,isClient:i,hasI18n:n,featurePath:o}=e,s=N(t);o?await cp(s,r,o,i,n):await pp(s,t,r,i,n)},cp=async(e,t,r,i,n)=>{let o=Ne.join(t,r,"components");await Ln(o,{recursive:!0}),await Vr(Ne.join(o,`${e}.tsx`),zr({componentName:e,isClient:i,hasI18n:n}))},pp=async(e,t,r,i,n)=>{let o=Ne.join(r,"src","components","common",e);await Ln(o,{recursive:!0}),await Vr(Ne.join(o,`${e}.tsx`),zr({componentName:e,isClient:i,hasI18n:n})),await Vr(Ne.join(o,"index.ts"),jn({componentName:e}));let s=Ne.join(r,"src","components","common","index.ts");await lp(s,`export { ${e} } from './${e}';
|
|
411
|
-
`);let c=Ne.join(r,"src","components","index.ts");await mp(c)},lp=async(e,t)=>{let r="";l(e)&&(r=await g(e)),r.includes(t.trim())||(r+=t,await h(e,r))},mp=async e=>{let t="";l(e)&&(t=await g(e));let r=`export * from './common';
|
|
412
|
-
`;t.includes(r.trim())||(t+=r,await h(e,t))};import{writeFile as dp}from"node:fs/promises";import up from"node:path";var Mn=e=>{let{camelName:t,pascalName:r,httpClient:i}=e,n=i==="axios"?"import { axiosClient } from '@/lib/utils/http';":"import { fetchClient } from '@/lib/utils/http';",o=i==="axios"?"axiosClient":"fetchClient";return`import { AppApis } from '@/lib/config';
|
|
413
|
-
${n}
|
|
414
|
-
import type { ResultAsync } from '@/types';
|
|
167
|
+
import { ${t}Keys } from './keys';
|
|
168
|
+
import { ${t}ListSchema, ${t}Schema } from './schema';
|
|
415
169
|
|
|
416
170
|
/**
|
|
417
|
-
*
|
|
171
|
+
* Client-side reads. A Server Component can \`prefetchQuery(${t}ListQuery())\`
|
|
172
|
+
* inside \`<HydrateQueries>\` so the hook below renders with data on first paint.
|
|
418
173
|
*/
|
|
419
|
-
export
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
* Detail type used in single-item responses (e.g., detail page).
|
|
426
|
-
*/
|
|
427
|
-
export interface ${r}Detail extends ${r}Summary {
|
|
428
|
-
// Add detailed fields here (content, metadata, relations, etc.)
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
export interface Create${r}Dto {
|
|
432
|
-
// Add create fields here
|
|
433
|
-
}
|
|
174
|
+
export const ${t}ListQuery = () =>
|
|
175
|
+
queryOptions({
|
|
176
|
+
queryKey: ${t}Keys.list(),
|
|
177
|
+
queryFn: ({ signal }) =>
|
|
178
|
+
http.get(AppApis.${t}.list, { schema: ${t}ListSchema, signal }).then(unwrapForQuery),
|
|
179
|
+
});
|
|
434
180
|
|
|
435
|
-
export
|
|
436
|
-
|
|
437
|
-
}
|
|
181
|
+
export const ${t}Query = (id: string) =>
|
|
182
|
+
queryOptions({
|
|
183
|
+
queryKey: ${t}Keys.detail(id),
|
|
184
|
+
queryFn: ({ signal }) =>
|
|
185
|
+
http.get(AppApis.${t}.detail(id), { schema: ${t}Schema, signal }).then(unwrapForQuery),
|
|
186
|
+
});
|
|
438
187
|
|
|
439
|
-
export const ${
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
188
|
+
export const use${e}List = () => useSuspenseQuery(${t}ListQuery());
|
|
189
|
+
export const use${e} = (id: string) => useSuspenseQuery(${t}Query(id));
|
|
190
|
+
`,Un=({camelName:e,kebabName:t})=>` ${e}: {
|
|
191
|
+
list: '/${t}',
|
|
192
|
+
detail: (id: string) => \`/${t}/\${id}\`,
|
|
193
|
+
create: '/${t}',
|
|
194
|
+
update: (id: string) => \`/${t}/\${id}\`,
|
|
195
|
+
delete: (id: string) => \`/${t}/\${id}\`,
|
|
196
|
+
},`;var nt=async e=>{let{name:t,featurePath:r,withActions:n}=e,o={kebabName:t,camelName:U(t),pascalName:$(t)},s=sr.join(r,"api");await Yi(s,{recursive:!0});let i=[["schema.ts",Fn(o)],["keys.ts",Mn(o)],["server.ts",_n(o)],["queries.ts",Ln(o)]];return n&&i.push(["actions.ts",Dn(o)]),await Promise.all(i.map(([a,p])=>Qi(sr.join(s,a),p))),i.map(([a])=>sr.join("api",a))};import{mkdir as Bn,writeFile as ar}from"node:fs/promises";import $e from"node:path";var ir=e=>{let{componentName:t,isClient:r,hasI18n:n}=e,o=e.translationNamespace||t,s=[];return(r||n)&&s.push("'use client';"),n&&s.push("import { useTranslations } from 'next-intl';"),s.push(""),s.push(`export function ${t}() {`),n?(s.push(` const t = useTranslations('${o}');`),s.push(""),s.push(" return ("),s.push(" <div>"),s.push(" <h2>{t('title')}</h2>"),s.push(" </div>"),s.push(" );")):(s.push(" return ("),s.push(" <div>"),s.push(` <h2>${t}</h2>`),s.push(" </div>"),s.push(" );")),s.push("}"),s.push(""),s.join(`
|
|
197
|
+
`)},Gn=e=>`export { ${e.componentName} } from './${e.componentName}';
|
|
198
|
+
`;var cr=async e=>{let{name:t,projectPath:r,isClient:n,hasI18n:o,featurePath:s}=e,i=$(t);s?await Zi(i,r,s,n,o):await ea(i,t,r,n,o)},Zi=async(e,t,r,n,o)=>{let s=$e.join(t,r,"components");await Bn(s,{recursive:!0}),await ar($e.join(s,`${e}.tsx`),ir({componentName:e,isClient:n,hasI18n:o}))},ea=async(e,t,r,n,o)=>{let s=$e.join(r,"src","components","common",e);await Bn(s,{recursive:!0}),await ar($e.join(s,`${e}.tsx`),ir({componentName:e,isClient:n,hasI18n:o})),await ar($e.join(s,"index.ts"),Gn({componentName:e}));let i=$e.join(r,"src","components","common","index.ts");await ta(i,`export { ${e} } from './${e}';
|
|
199
|
+
`);let a=$e.join(r,"src","components","index.ts");await ra(a)},ta=async(e,t)=>{let r="";y(e)&&(r=await j(e)),r.includes(t.trim())||(r+=t,await k(e,r))},ra=async e=>{let t="";y(e)&&(t=await j(e));let r=`export * from './common';
|
|
200
|
+
`;t.includes(r.trim())||(t+=r,await k(e,t))};import{mkdir as mr,writeFile as De}from"node:fs/promises";import H from"node:path";import{mkdir as na,writeFile as Pe}from"node:fs/promises";import ke from"node:path";var lr=e=>{let{sliceName:t,withPersist:r,state:n="redux"}=e;return n==="zustand"?`export * from './${t}.store';
|
|
201
|
+
`:`export * from './${t}.selectors';
|
|
202
|
+
export * from './${t}.slice';${r?`
|
|
203
|
+
export * from './persist';`:""}
|
|
204
|
+
`},Vn=e=>{let{featureName:t,componentName:r,hookName:n,pascalName:o,withStore:s,withApi:i}=e,a=["/**"," * Client-safe public surface. Server-only pieces live in `./server`."," */"];return i&&(a.push(`export { create${o}, delete${o}, update${o} } from './api/actions';`),a.push(`export { ${pr(t)}Keys } from './api/keys';`),a.push(`export { ${pr(t)}ListQuery, ${pr(t)}Query, use${o}, use${o}List } from './api/queries';`),a.push("export * from './api/schema';")),a.push(`export { ${r} } from './components/${r}';`),i||a.push(`export { ${n} } from './hooks/${n}';`),a.push(`export * from './types/${t}.types';`),s&&a.push("export * from './store';"),`${a.join(`
|
|
205
|
+
`)}
|
|
206
|
+
`},qn=e=>`import 'server-only';
|
|
443
207
|
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
},
|
|
208
|
+
export { get${e.pascalName}, list${e.pascalName}s, ${e.pascalName.toUpperCase()}_TAG } from './api/server';
|
|
209
|
+
`,pr=e=>e.replace(/-([a-z])/g,(t,r)=>r.toUpperCase());var Jn=e=>{let{componentName:t,camelName:r,typesImportPath:n}=e,o=`${r.replace(/[A-Z]/g,s=>`_${s}`).toUpperCase()}_PERSIST_VERSION`;return`import { definePersistence } from '@/store/persistence';
|
|
447
210
|
|
|
448
|
-
|
|
449
|
-
return ${o}.post<${r}Detail>(AppApis.${t}.create, data);
|
|
450
|
-
},
|
|
211
|
+
import type { ${t}State } from '${n}';
|
|
451
212
|
|
|
452
|
-
|
|
453
|
-
return ${o}.patch<${r}Detail>(AppApis.${t}.update(id), data);
|
|
454
|
-
},
|
|
213
|
+
const ${o} = 1;
|
|
455
214
|
|
|
456
|
-
|
|
457
|
-
return ${o}.delete<void>(AppApis.${t}.delete(id));
|
|
458
|
-
},
|
|
459
|
-
};
|
|
460
|
-
`},Gn=e=>{let{camelName:t,kebabName:r}=e;return` ${t}: {
|
|
461
|
-
base: '/${r}',
|
|
462
|
-
getAll: '/${r}',
|
|
463
|
-
getById: (id: string) => \`/${r}/\${id}\`,
|
|
464
|
-
create: '/${r}',
|
|
465
|
-
update: (id: string) => \`/${r}/\${id}\`,
|
|
466
|
-
delete: (id: string) => \`/${r}/\${id}\`,
|
|
467
|
-
},`};var Wr=async e=>{let{name:t,outputPath:r,httpClient:i}=e,n=G(t),o=N(t);await dp(up.join(r,`${t}.service.ts`),Mn({camelName:n,pascalName:o,httpClient:i}))};import{mkdir as yp,writeFile as zt}from"node:fs/promises";import ie from"node:path";import{writeFile as fp}from"node:fs/promises";import gp from"node:path";var Hn=e=>{let{camelName:t,httpClient:r}=e;return`import { AppApis } from '@/lib/config';
|
|
468
|
-
${r==="axios"?"import { axiosClient } from '@/lib/utils/http';":"import { fetchClient } from '@/lib/utils/http';"}
|
|
469
|
-
import type { ResultAsync } from '@/types';
|
|
470
|
-
|
|
471
|
-
export const ${t}Service = {
|
|
472
|
-
getAll: (): ResultAsync<string> => {
|
|
473
|
-
return ${r==="axios"?"axiosClient":"fetchClient"}.get<string>(AppApis.${t}.getAll);
|
|
474
|
-
},
|
|
475
|
-
};
|
|
476
|
-
`};var pt=async e=>{let{name:t,outputPath:r,httpClient:i}=e,n=G(t);await fp(gp.join(r,`${t}.service.ts`),Hn({camelName:n,httpClient:i}))};import{mkdir as hp,writeFile as lt}from"node:fs/promises";import mt from"node:path";var Un=e=>{let{sliceName:t,withPersist:r}=e;return`export * from './${t}.slice';
|
|
477
|
-
export * from './${t}.selectors';
|
|
478
|
-
export * from './${t}.types';${r?`
|
|
479
|
-
export * from './persist';`:""}
|
|
480
|
-
`},Bn=e=>{let{featureName:t,componentName:r,hookName:i,withStore:n,withService:o}=e;return`export { default as ${r} } from './components/${r}';
|
|
481
|
-
export { ${i} } from './hooks/${i}';
|
|
482
|
-
export * from './types/${t}.types';${n?`
|
|
483
|
-
export * from './store';`:""}${o?`
|
|
484
|
-
export * from './services/${t}.service';`:""}
|
|
485
|
-
`};var zn=e=>{let{componentName:t,camelName:r,typesImportPath:i}=e,n=`${r.toUpperCase()}_PERSIST_VERSION`;return`import { createMigrate, type PersistConfig, type PersistedState } from 'redux-persist';
|
|
486
|
-
import storage from '@/store/storage';
|
|
487
|
-
import type { ${t}State } from '${i}';
|
|
488
|
-
|
|
489
|
-
const ${n} = 1;
|
|
490
|
-
|
|
491
|
-
const migrations = {
|
|
492
|
-
// Bump ${n} and add a migration here when ${t}State's
|
|
493
|
-
// shape changes. Receives the previously-persisted state, returns the new
|
|
494
|
-
// shape. Returning \`undefined\` discards stale state.
|
|
495
|
-
// 2: (state) => ({ ...state, newField: defaultValue }),
|
|
496
|
-
} satisfies Record<number, (state: PersistedState) => PersistedState>;
|
|
497
|
-
|
|
498
|
-
export const ${r}PersistConfig: PersistConfig<${t}State> = {
|
|
215
|
+
export const ${r}Persistence = definePersistence<${t}State>({
|
|
499
216
|
key: '${r}',
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
}
|
|
505
|
-
|
|
217
|
+
version: ${o},
|
|
218
|
+
// Fields that survive a reload. Transient status never should.
|
|
219
|
+
pick: [],
|
|
220
|
+
migrations: {
|
|
221
|
+
// Bump ${o} and add a step keyed by the new number when the
|
|
222
|
+
// persisted shape changes. Each step receives the previous version's data
|
|
223
|
+
// and returns the next; return \`undefined\` to discard.
|
|
224
|
+
// 2: (previous) => ({ ...(previous as ${t}State), newField: 0 }),
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
`};var zn=e=>{let{componentName:t,camelName:r}=e;return`import type { RootState } from '@/store/rootReducer';
|
|
506
228
|
|
|
507
229
|
export const select${t}State = (state: RootState) => state.${r};
|
|
508
|
-
export {
|
|
509
|
-
|
|
510
|
-
|
|
230
|
+
export const select${t}Status = (state: RootState) => state.${r}.status;
|
|
231
|
+
export const select${t}Error = (state: RootState) => state.${r}.error;
|
|
232
|
+
`};var Wn=e=>{let{componentName:t,camelName:r,typesImportPath:n}=e;return`import { createSlice, type PayloadAction } from '@reduxjs/toolkit';
|
|
233
|
+
|
|
234
|
+
import type { ${t}State } from '${n}';
|
|
511
235
|
|
|
512
236
|
const initialState: ${t}State = {
|
|
513
|
-
|
|
237
|
+
status: 'idle',
|
|
514
238
|
error: null,
|
|
515
|
-
// Add your initial state here
|
|
516
239
|
};
|
|
517
240
|
|
|
518
241
|
export const ${r}Slice = createSlice({
|
|
519
242
|
name: '${r}',
|
|
520
243
|
initialState,
|
|
521
244
|
reducers: {
|
|
522
|
-
|
|
523
|
-
state.
|
|
245
|
+
started: (state) => {
|
|
246
|
+
state.status = 'loading';
|
|
247
|
+
state.error = null;
|
|
524
248
|
},
|
|
525
|
-
|
|
249
|
+
failed: (state, action: PayloadAction<string>) => {
|
|
250
|
+
state.status = 'error';
|
|
526
251
|
state.error = action.payload;
|
|
527
252
|
},
|
|
528
|
-
|
|
529
|
-
state.loading = false;
|
|
530
|
-
state.error = null;
|
|
531
|
-
},
|
|
253
|
+
reset: () => initialState,
|
|
532
254
|
},
|
|
533
255
|
});
|
|
534
256
|
|
|
535
|
-
export const {
|
|
536
|
-
|
|
257
|
+
export const { started, failed, reset } = ${r}Slice.actions;
|
|
537
258
|
export const ${r}Reducer = ${r}Slice.reducer;
|
|
538
|
-
`};var
|
|
539
|
-
|
|
259
|
+
`};var Ot=e=>{let{componentName:t,withStore:r}=e;return r?`export type ${t}Status = 'idle' | 'loading' | 'error';
|
|
260
|
+
|
|
261
|
+
export interface ${t}State {
|
|
262
|
+
status: ${t}Status;
|
|
540
263
|
error: string | null;
|
|
541
|
-
// Add your state properties here`:`// Add your state properties here
|
|
542
|
-
// example: value: string;`}
|
|
543
264
|
}
|
|
544
|
-
|
|
545
|
-
|
|
265
|
+
`:`export interface ${t}Props {
|
|
266
|
+
// Props for the ${t} component
|
|
267
|
+
}
|
|
268
|
+
`};var Hn=e=>{let{componentName:t,camelName:r,typesImportPath:n}=e;return`import type { StateCreator } from 'zustand';
|
|
269
|
+
|
|
270
|
+
import type { ${t}State } from '${n}';
|
|
271
|
+
|
|
272
|
+
export interface ${t}Slice {
|
|
273
|
+
${r}: ${t}State;
|
|
274
|
+
${r}Started: () => void;
|
|
275
|
+
${r}Failed: (error: string) => void;
|
|
276
|
+
${r}Reset: () => void;
|
|
277
|
+
}
|
|
546
278
|
|
|
279
|
+
const initial: ${t}State = { status: 'idle', error: null };
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Slice creator. Compose it into the app store:
|
|
283
|
+
*
|
|
284
|
+
* // src/store/index.ts
|
|
285
|
+
* export type AppState = CounterSlice & ${t}Slice & { ... };
|
|
286
|
+
* ...create${t}Slice(set, get, api),
|
|
287
|
+
*/
|
|
288
|
+
// biome-ignore lint/suspicious/noExplicitAny: composed into the app store, whose full type is declared there
|
|
289
|
+
export const create${t}Slice: StateCreator<any, [], [], ${t}Slice> = (set) => ({
|
|
290
|
+
${r}: initial,
|
|
291
|
+
${r}Started: () => set({ ${r}: { status: 'loading', error: null } }),
|
|
292
|
+
${r}Failed: (error: string) => set({ ${r}: { status: 'error', error } }),
|
|
293
|
+
${r}Reset: () => set({ ${r}: initial }),
|
|
294
|
+
});
|
|
295
|
+
`};var ot=async e=>{let{name:t,outputPath:r,persist:n,state:o="redux",typesImportPath:s=`./${t}.types`}=e;await na(r,{recursive:!0});let i=$(t),a=U(t),p=[];s===`./${t}.types`&&p.push(Pe(ke.join(r,`${t}.types.ts`),Ot({componentName:i,withStore:!0}))),o==="zustand"?p.push(Pe(ke.join(r,`${t}.store.ts`),Hn({componentName:i,camelName:a,typesImportPath:s})),Pe(ke.join(r,"index.ts"),lr({sliceName:t,withPersist:!1,state:o}))):(p.push(Pe(ke.join(r,`${t}.slice.ts`),Wn({componentName:i,camelName:a,typesImportPath:s})),Pe(ke.join(r,`${t}.selectors.ts`),zn({componentName:i,camelName:a,sliceName:t})),Pe(ke.join(r,"index.ts"),lr({sliceName:t,withPersist:n,state:o}))),n&&p.push(Pe(ke.join(r,"persist.ts"),Jn({componentName:i,camelName:a,typesImportPath:s})))),await Promise.all(p)};var Kn=e=>{let{componentName:t,hookName:r,withApi:n,pascalName:o,hasI18n:s}=e,i=s?`import { useTranslations } from 'next-intl';
|
|
296
|
+
|
|
297
|
+
`:"",a=s?` const t = useTranslations('${o}');
|
|
298
|
+
`:"",p=s?"{t('title')}":t;return n?`'use client';
|
|
299
|
+
|
|
300
|
+
${i}import { use${o}List } from '../api/queries';
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Renders hydrated query data: prefetch \`${oa(o)}ListQuery()\` in the
|
|
304
|
+
* page and wrap this component in \`<HydrateQueries>\` for a no-spinner first paint.
|
|
305
|
+
*/
|
|
547
306
|
export function ${t}() {
|
|
548
|
-
const {} = ${
|
|
307
|
+
${a} const { data } = use${o}List();
|
|
549
308
|
|
|
550
309
|
return (
|
|
551
|
-
<
|
|
552
|
-
<h2>${
|
|
553
|
-
|
|
554
|
-
|
|
310
|
+
<section className="flex flex-col gap-2">
|
|
311
|
+
<h2 className="font-medium text-sm">${p}</h2>
|
|
312
|
+
<ul className="flex flex-col gap-1">
|
|
313
|
+
{data.map((item) => (
|
|
314
|
+
<li key={item.id}>{item.title}</li>
|
|
315
|
+
))}
|
|
316
|
+
</ul>
|
|
317
|
+
</section>
|
|
555
318
|
);
|
|
556
319
|
}
|
|
320
|
+
`:`'use client';
|
|
557
321
|
|
|
558
|
-
|
|
559
|
-
`};var qn=e=>{let{hookName:t,componentName:r,featureName:i}=e;return`'use client';
|
|
560
|
-
import { useAppDispatch, useAppSelector } from '@/store/hooks';
|
|
561
|
-
import { select${r}State, setLoading, setError } from '../store/${i}.selectors';
|
|
322
|
+
${i}import { ${r} } from '../hooks/${r}';
|
|
562
323
|
|
|
563
|
-
export
|
|
564
|
-
const
|
|
565
|
-
const state = useAppSelector(select${r}State);
|
|
324
|
+
export function ${t}() {
|
|
325
|
+
${a} const state = ${r}();
|
|
566
326
|
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
327
|
+
return (
|
|
328
|
+
<section className="flex flex-col gap-2">
|
|
329
|
+
<h2 className="font-medium text-sm">${p}</h2>
|
|
330
|
+
<pre className="text-xs">{JSON.stringify(state, null, 2)}</pre>
|
|
331
|
+
</section>
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
`},oa=e=>e.charAt(0).toLowerCase()+e.slice(1);var Xn=e=>{let{hookName:t,componentName:r,featureName:n,state:o}=e;return o==="zustand"?`'use client';
|
|
570
335
|
|
|
571
|
-
|
|
572
|
-
dispatch(setError(error));
|
|
573
|
-
};
|
|
336
|
+
import { useAppStore } from '@/store/hooks';
|
|
574
337
|
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
338
|
+
export const ${t} = () => {
|
|
339
|
+
const status = useAppStore((state) => state.${st(n)}.status);
|
|
340
|
+
const error = useAppStore((state) => state.${st(n)}.error);
|
|
341
|
+
const start = useAppStore((state) => state.${st(n)}Started);
|
|
342
|
+
const fail = useAppStore((state) => state.${st(n)}Failed);
|
|
343
|
+
const reset = useAppStore((state) => state.${st(n)}Reset);
|
|
344
|
+
|
|
345
|
+
return { status, error, start, fail, reset } as const;
|
|
580
346
|
};
|
|
581
|
-
|
|
582
|
-
|
|
347
|
+
`:`'use client';
|
|
348
|
+
|
|
349
|
+
import { useAppDispatch, useAppSelector } from '@/store/hooks';
|
|
350
|
+
|
|
351
|
+
import { failed, reset, started } from '../store/${n}.slice';
|
|
352
|
+
import { select${r}Error, select${r}Status } from '../store/${n}.selectors';
|
|
583
353
|
|
|
584
354
|
export const ${t} = () => {
|
|
585
|
-
|
|
586
|
-
const
|
|
355
|
+
const dispatch = useAppDispatch();
|
|
356
|
+
const status = useAppSelector(select${r}Status);
|
|
357
|
+
const error = useAppSelector(select${r}Error);
|
|
587
358
|
|
|
588
359
|
return {
|
|
589
|
-
|
|
590
|
-
|
|
360
|
+
status,
|
|
361
|
+
error,
|
|
362
|
+
start: () => dispatch(started()),
|
|
363
|
+
fail: (message: string) => dispatch(failed(message)),
|
|
364
|
+
reset: () => dispatch(reset()),
|
|
591
365
|
} as const;
|
|
592
366
|
};
|
|
593
|
-
`}
|
|
594
|
-
`)};var Yr=async e=>{let{name:t,projectPath:r,isClient:i,featurePath:n}=e,s=`use${N(t)}`,c;n?c=Xr.join(r,n,"hooks"):c=Xr.join(r,"src","hooks"),await xp(c,{recursive:!0}),await wp(Xr.join(c,`${s}.ts`),Yn({hookName:s,isClient:i}))};import{mkdir as Sp}from"node:fs/promises";import Vt from"node:path";w();var Pp=e=>`import { setRequestLocale } from 'next-intl/server';
|
|
595
|
-
import type { SupportedLocale } from '@/types/i18n';
|
|
367
|
+
`},st=e=>e.replace(/-([a-z])/g,(t,r)=>r.toUpperCase()),At=e=>{let{hookName:t}=e;return`'use client';
|
|
596
368
|
|
|
597
|
-
|
|
598
|
-
children: React.ReactNode;
|
|
599
|
-
params: Promise<{ locale: string }>;
|
|
600
|
-
};
|
|
369
|
+
import { useCallback, useState } from 'react';
|
|
601
370
|
|
|
602
|
-
export
|
|
603
|
-
const
|
|
604
|
-
|
|
371
|
+
export const ${t} = () => {
|
|
372
|
+
const [busy, setBusy] = useState(false);
|
|
373
|
+
|
|
374
|
+
const run = useCallback(async (task: () => Promise<void>) => {
|
|
375
|
+
setBusy(true);
|
|
376
|
+
try {
|
|
377
|
+
await task();
|
|
378
|
+
} finally {
|
|
379
|
+
setBusy(false);
|
|
380
|
+
}
|
|
381
|
+
}, []);
|
|
605
382
|
|
|
606
|
-
return
|
|
607
|
-
}
|
|
608
|
-
`,vp=e=>`type Props = {
|
|
609
|
-
children: React.ReactNode;
|
|
383
|
+
return { busy, run } as const;
|
|
610
384
|
};
|
|
385
|
+
`};var It=e=>{let{componentName:t,sourceImportPath:r,testUtilsImportPath:n,hasState:o,hasI18n:s,withQueryData:i}=e,a=[];if(s&&a.push("messages: {}"),o&&a.push("preloadedState: {}"),i)return`import { describe, expect, it } from 'vitest';
|
|
611
386
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
}
|
|
615
|
-
`,Kn=({componentName:e,hasI18n:t})=>t?Pp(e):vp(e);var Ep=/^[a-z][a-z0-9-]*$/,Tp=/^[a-z][a-z0-9-]*(\/[a-z][a-z0-9-]*)*$/,Cp=e=>{if(!Ep.test(e))throw new Error(`Invalid layout segment "${e}". Use kebab-case letters, digits, and hyphens. For route groups pass --group instead of wrapping in parens.`)},Rp=e=>{if(!Tp.test(e))throw new Error(`Invalid --at path "${e}". Use kebab-case segments separated by "/", e.g. "dashboard/settings".`)},Kr=async e=>{let{segment:t,at:r,projectPath:i,hasI18n:n,withGroup:o}=e;Cp(t),r&&Rp(r);let s=`${N(t)}Layout`,c=o?`(${t})`:t,p=["src","app"];n&&p.push("[locale]"),r&&p.push(...r.split("/")),p.push(c);let u=Vt.join(i,...p),d=Vt.join(u,"layout.tsx");if(l(d))throw new Error(`Layout already exists at ${Vt.relative(i,d)}.`);return await Sp(u,{recursive:!0}),await h(d,Kn({componentName:s,hasI18n:n})),{layoutFile:d,displayPath:Vt.relative(i,d),componentName:s}};w();import{copyFile as bp,readFile as Ip,writeFile as $p}from"node:fs/promises";import ut from"node:path";var Zr=async e=>{let{code:t,name:r,country:i,flag:n,projectPath:o,copyTranslations:s}=e;await kp(o,t,s),await Np(o,t),await Ap(o,t,r,i,n)},kp=async(e,t,r)=>{let i=ut.join(e,"src","i18n","translations"),n=ut.join(i,"en.json"),o=ut.join(i,`${t}.json`);if(r)await bp(n,o);else{let s=await Ip(n,"utf-8"),c=JSON.parse(s),p=Zn(c);await $p(o,`${JSON.stringify(p,null,2)}
|
|
616
|
-
`)}},Zn=e=>{let t={};for(let[r,i]of Object.entries(e))typeof i=="object"&&i!==null?t[r]=Zn(i):t[r]="";return t},Np=async(e,t)=>{let r=ut.join(e,"src","types","i18n.ts");if(!l(r))return;let i=await g(r),n=/export type SupportedLocale = (.*);/,o=i.match(n);if(o&&!o[1].includes(`'${t}'`)){let s=`${o[1]} | '${t}'`;i=i.replace(n,`export type SupportedLocale = ${s};`),await h(r,i)}},Ap=async(e,t,r,i,n)=>{let o=ut.join(e,"src","lib","config","app-locales.ts");if(!l(o))return;let s=await g(o);if(s.includes(`locale: '${t}'`))return;let c=s.lastIndexOf("];");if(c===-1)return;let p=` {
|
|
617
|
-
name: '${r}',
|
|
618
|
-
locale: '${t}',
|
|
619
|
-
flag: '${n}',
|
|
620
|
-
country: '${i}',
|
|
621
|
-
},
|
|
622
|
-
`;s=s.slice(0,c)+p+s.slice(c),await h(o,s)};import{mkdir as _p,writeFile as Qr}from"node:fs/promises";import ft from"node:path";var Qn=e=>{let{componentName:t,routePath:r,hasI18n:i}=e;return i?`import { generateSEOMetadata } from '@/lib/config/seo';
|
|
623
|
-
import type { Metadata } from 'next';
|
|
624
|
-
import { getTranslations, setRequestLocale } from 'next-intl/server';
|
|
625
|
-
import type { SupportedLocale } from '@/types/i18n';
|
|
387
|
+
import { makeTestQueryClient, renderWithProviders, screen } from '${n}';
|
|
388
|
+
import { ${i.keys} } from '${i.keysImport}';
|
|
389
|
+
import { ${t} } from '${r}';
|
|
626
390
|
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
391
|
+
describe('${t}', () => {
|
|
392
|
+
it('renders hydrated data', () => {
|
|
393
|
+
const queryClient = makeTestQueryClient();
|
|
394
|
+
queryClient.setQueryData(${i.keys}.${i.key}(), [
|
|
395
|
+
{ id: '1', title: 'First', createdAt: '2026-01-01T00:00:00.000Z' },
|
|
396
|
+
]);
|
|
397
|
+
renderWithProviders(<${t} />, { queryClient${a.length?`, ${a.join(", ")}`:""} });
|
|
398
|
+
expect(screen.getByText('First')).toBeInTheDocument();
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
`;let p=a.length?`, { ${a.join(", ")} }`:"";return`import { describe, expect, it } from 'vitest';
|
|
630
402
|
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
const t = await getTranslations({ locale, namespace: '${t}' });
|
|
403
|
+
import { renderWithProviders, screen } from '${n}';
|
|
404
|
+
import { ${t} } from '${r}';
|
|
634
405
|
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
406
|
+
describe('${t}', () => {
|
|
407
|
+
it('renders', () => {
|
|
408
|
+
renderWithProviders(<${t} />${p});
|
|
409
|
+
expect(screen.getByRole('heading')).toBeInTheDocument();
|
|
639
410
|
});
|
|
640
|
-
}
|
|
411
|
+
});
|
|
412
|
+
`},Yn=e=>{let{hookName:t,sourceImportPath:r,withStore:n,testUtilsImportPath:o}=e;return n?`// @vitest-environment jsdom
|
|
413
|
+
import { renderHook } from '@testing-library/react';
|
|
414
|
+
import { describe, expect, it } from 'vitest';
|
|
641
415
|
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
setRequestLocale(locale);
|
|
416
|
+
import { TestProviders } from '${o}';
|
|
417
|
+
import { ${t} } from '${r}';
|
|
645
418
|
|
|
646
|
-
|
|
419
|
+
describe('${t}', () => {
|
|
420
|
+
it('returns a defined value', () => {
|
|
421
|
+
const { result } = renderHook(() => ${t}(), { wrapper: TestProviders });
|
|
422
|
+
expect(result.current).toBeDefined();
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
`:`// @vitest-environment jsdom
|
|
426
|
+
import { renderHook } from '@testing-library/react';
|
|
427
|
+
import { describe, expect, it } from 'vitest';
|
|
647
428
|
|
|
648
|
-
|
|
649
|
-
<div>
|
|
650
|
-
<h1>{t('title')}</h1>
|
|
651
|
-
</div>
|
|
652
|
-
);
|
|
653
|
-
}
|
|
654
|
-
`:`import type { Metadata } from 'next';
|
|
429
|
+
import { ${t} } from '${r}';
|
|
655
430
|
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
431
|
+
describe('${t}', () => {
|
|
432
|
+
it('returns a defined value', () => {
|
|
433
|
+
const { result } = renderHook(() => ${t}());
|
|
434
|
+
expect(result.current).toBeDefined();
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
`},Qn=e=>{let{camelName:t,sourceImportPath:r}=e,n=`${t}Slice`;return`import { describe, expect, it } from 'vitest';
|
|
660
438
|
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
</div>
|
|
666
|
-
);
|
|
667
|
-
}
|
|
668
|
-
`},eo=e=>{let{componentName:t,paramName:r,routePath:i,hasI18n:n}=e;return n?`import { generateSEOMetadata } from '@/lib/config/seo';
|
|
669
|
-
import type { Metadata } from 'next';
|
|
670
|
-
import { getTranslations, setRequestLocale } from 'next-intl/server';
|
|
671
|
-
import type { SupportedLocale } from '@/types/i18n';
|
|
439
|
+
import { failed, reset, ${n}, started } from '${r}';
|
|
440
|
+
|
|
441
|
+
describe('${n}', () => {
|
|
442
|
+
const initialState = { status: 'idle', error: null } as const;
|
|
672
443
|
|
|
673
|
-
|
|
674
|
-
|
|
444
|
+
it('returns the initial state', () => {
|
|
445
|
+
expect(${n}.reducer(undefined, { type: '@@INIT' })).toEqual(initialState);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
it('tracks a start and a failure', () => {
|
|
449
|
+
const loading = ${n}.reducer(initialState, started());
|
|
450
|
+
expect(loading.status).toBe('loading');
|
|
451
|
+
const errored = ${n}.reducer(loading, failed('boom'));
|
|
452
|
+
expect(errored).toEqual({ status: 'error', error: 'boom' });
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it('resets', () => {
|
|
456
|
+
expect(${n}.reducer({ status: 'error', error: 'boom' }, reset())).toEqual(initialState);
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
`};var dr=async e=>{let{name:t,outputPath:r,createStore:n,persistStore:o,createApi:s,state:i,hasI18n:a,hasTests:p}=e,m=$(t),c=s?`${m}List`:m,d=`use${m}`,u=n&&i!=="none";await mr(H.join(r,"components"),{recursive:!0}),await mr(H.join(r,"types"),{recursive:!0}),s||await mr(H.join(r,"hooks"),{recursive:!0});let f=[De(H.join(r,"components",`${c}.tsx`),Kn({componentName:c,hookName:d,withApi:s,pascalName:m,hasI18n:a})),De(H.join(r,"types",`${t}.types.ts`),Ot({componentName:m,withStore:u})),De(H.join(r,"index.ts"),Vn({featureName:t,componentName:c,hookName:d,pascalName:m,withStore:u,withApi:s}))];s||f.push(De(H.join(r,"hooks",`${d}.ts`),u?Xn({hookName:d,componentName:m,featureName:t,state:i==="zustand"?"zustand":"redux"}):At({hookName:d}))),s&&(f.push(nt({name:t,featurePath:r,withActions:!0})),f.push(De(H.join(r,"server.ts"),qn({pascalName:m})))),p&&f.push(De(H.join(r,"components",`${c}.test.tsx`),It({componentName:c,sourceImportPath:`./${c}`,testUtilsImportPath:"../../../../test/test-utils",hasState:i!=="none",hasI18n:a,withQueryData:s?{keysImport:"../api/keys",keys:`${sa(t)}Keys`,key:"list"}:void 0}))),await Promise.all(f),u&&await ot({name:t,outputPath:H.join(r,"store"),persist:o,state:i==="zustand"?"zustand":"redux",typesImportPath:`../types/${t}.types`})},sa=e=>e.replace(/-([a-z])/g,(t,r)=>r.toUpperCase());import{mkdir as ia,writeFile as aa}from"node:fs/promises";import ur from"node:path";var fr=async e=>{let{name:t,projectPath:r,featurePath:n}=e,o=`use${$(t)}`,s=n?ur.join(r,n,"hooks"):ur.join(r,"src","hooks");await ia(s,{recursive:!0}),await aa(ur.join(s,`${o}.ts`),At({hookName:o}))};import{mkdir as ca}from"node:fs/promises";import Nt from"node:path";var Zn=({componentName:e})=>`type Props = {
|
|
460
|
+
children: React.ReactNode;
|
|
675
461
|
};
|
|
676
462
|
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
463
|
+
// Layouts do not re-run on client navigation: put session checks in pages
|
|
464
|
+
// (\`requireUser\`) and data reads in the components that render them.
|
|
465
|
+
export default function ${e}({ children }: Props) {
|
|
466
|
+
return <>{children}</>;
|
|
467
|
+
}
|
|
468
|
+
`;var pa=/^[a-z][a-z0-9-]*$/,la=/^[a-z][a-z0-9-]*(\/[a-z][a-z0-9-]*)*$/,ma=e=>{if(!pa.test(e))throw new Error(`Invalid layout segment "${e}". Use kebab-case letters, digits, and hyphens. For route groups pass --group instead of wrapping in parens.`)},da=e=>{if(!la.test(e))throw new Error(`Invalid --at path "${e}". Use kebab-case segments separated by "/", e.g. "dashboard/settings".`)},gr=async e=>{let{segment:t,at:r,projectPath:n,hasI18n:o,withGroup:s}=e;ma(t),r&&da(r);let i=`${$(t)}Layout`,a=s?`(${t})`:t,p=["src","app"];o&&p.push("[locale]"),r&&p.push(...r.split("/")),p.push(a);let m=Nt.join(n,...p),c=Nt.join(m,"layout.tsx");if(y(c))throw new Error(`Layout already exists at ${Nt.relative(n,c)}.`);return await ca(m,{recursive:!0}),await k(c,Zn({componentName:i,hasI18n:o})),{layoutFile:c,displayPath:Nt.relative(n,c),componentName:i}};import{copyFile as ua,readFile as fa,writeFile as ga}from"node:fs/promises";import it from"node:path";var hr=async e=>{let{code:t,name:r,country:n,flag:o,projectPath:s,copyTranslations:i}=e;await ha(s,t,i),await ya(s,t),await wa(s,t,r,n,o)},ha=async(e,t,r)=>{let n=it.join(e,"src","i18n","translations"),o=it.join(n,"en.json"),s=it.join(n,`${t}.json`);if(r)await ua(o,s);else{let i=await fa(o,"utf-8"),a=JSON.parse(i),p=eo(a);await ga(s,`${JSON.stringify(p,null,2)}
|
|
469
|
+
`)}},eo=e=>{let t={};for(let[r,n]of Object.entries(e))typeof n=="object"&&n!==null?t[r]=eo(n):t[r]="";return t},ya=async(e,t)=>{let r=it.join(e,"src","types","i18n.ts");if(!y(r))return;let n=await j(r),o=/export const SUPPORTED_LOCALES = \[([^\]]*)\] as const;/,s=n.match(o);if(s){if(s[1].includes(`'${t}'`))return;let p=s[1].split(",").map(m=>m.trim()).filter(Boolean);p.push(`'${t}'`),n=n.replace(o,`export const SUPPORTED_LOCALES = [${p.join(", ")}] as const;`),await k(r,n);return}let i=/export type SupportedLocale = (.*);/,a=n.match(i);a&&!a[1].includes(`'${t}'`)&&(n=n.replace(i,`export type SupportedLocale = ${a[1]} | '${t}';`),await k(r,n))},wa=async(e,t,r,n,o)=>{let s=it.join(e,"src","lib","config","app-locales.ts");if(!y(s))return;let i=await j(s);if(i.includes(`locale: '${t}'`))return;let a=i.lastIndexOf("];");if(a===-1)return;let p=` {
|
|
470
|
+
name: '${r}',
|
|
471
|
+
locale: '${t}',
|
|
472
|
+
flag: '${o}',
|
|
473
|
+
country: '${n}',
|
|
474
|
+
ogLocale: '${t}_${t.toUpperCase()}',
|
|
475
|
+
},
|
|
476
|
+
`;i=i.slice(0,a)+p+i.slice(a),await k(s,i)};import{mkdir as ba,writeFile as yr}from"node:fs/promises";import Ft from"node:path";var xa=({routePath:e,hasI18n:t,paramName:r})=>`${t?"/[locale]":""}${e}${r?`/[${r}]`:""}`,to=e=>{let{componentName:t,routePath:r,hasI18n:n,paramName:o}=e,s=xa(e);return n?`import type { Metadata } from 'next';
|
|
477
|
+
import { getLocale, getTranslations } from 'next-intl/server';
|
|
478
|
+
|
|
479
|
+
import { generateSEOMetadata } from '@/lib/config/seo';
|
|
680
480
|
|
|
481
|
+
export async function generateMetadata(): Promise<Metadata> {
|
|
482
|
+
const [locale, t] = await Promise.all([getLocale(), getTranslations('${t}')]);
|
|
681
483
|
return generateSEOMetadata({
|
|
682
484
|
title: t('title'),
|
|
683
485
|
description: t('description'),
|
|
684
|
-
path: '${
|
|
486
|
+
path: '${r}',
|
|
487
|
+
locale,
|
|
685
488
|
});
|
|
686
489
|
}
|
|
687
490
|
|
|
688
|
-
export default async function ${t}Page(
|
|
689
|
-
const { locale, ${r} } = await props.params;
|
|
690
|
-
setRequestLocale(locale);
|
|
691
|
-
|
|
491
|
+
export default async function ${t}Page(${o?`{ params }: PageProps<'${s}'>`:""}) {
|
|
692
492
|
const t = await getTranslations('${t}');
|
|
693
|
-
|
|
493
|
+
${o?` const { ${o} } = await params;
|
|
494
|
+
`:""}
|
|
694
495
|
return (
|
|
695
|
-
<div>
|
|
696
|
-
<h1>{t('title')}</h1>
|
|
697
|
-
<p
|
|
496
|
+
<div className="flex flex-col gap-2 p-6">
|
|
497
|
+
<h1 className="font-bold text-2xl">{t('title')}</h1>
|
|
498
|
+
<p className="text-gray-500 dark:text-gray-400">{t('description')}</p>${o?`
|
|
499
|
+
<p className="text-sm">${o}: {${o}}</p>`:""}
|
|
698
500
|
</div>
|
|
699
501
|
);
|
|
700
502
|
}
|
|
701
503
|
`:`import type { Metadata } from 'next';
|
|
702
504
|
|
|
703
|
-
|
|
505
|
+
import { generateSEOMetadata } from '@/lib/config/seo';
|
|
506
|
+
|
|
507
|
+
export const metadata: Metadata = generateSEOMetadata({
|
|
704
508
|
title: '${t}',
|
|
705
509
|
description: '${t} page',
|
|
706
|
-
}
|
|
707
|
-
|
|
708
|
-
type Props = {
|
|
709
|
-
params: Promise<{ ${r}: string }>;
|
|
710
|
-
};
|
|
510
|
+
path: '${r}',
|
|
511
|
+
});
|
|
711
512
|
|
|
712
|
-
export default async function ${t}Page(
|
|
713
|
-
const { ${
|
|
513
|
+
export default ${o?"async ":""}function ${t}Page(${o?`{ params }: PageProps<'${s}'>`:""}) {
|
|
514
|
+
${o?` const { ${o} } = await params;
|
|
714
515
|
|
|
715
|
-
return (
|
|
716
|
-
<div>
|
|
717
|
-
<h1>${t}</h1
|
|
718
|
-
<p>${
|
|
516
|
+
`:""} return (
|
|
517
|
+
<div className="flex flex-col gap-2 p-6">
|
|
518
|
+
<h1 className="font-bold text-2xl">${t}</h1>${o?`
|
|
519
|
+
<p className="text-sm">${o}: {${o}}</p>`:""}
|
|
719
520
|
</div>
|
|
720
521
|
);
|
|
721
522
|
}
|
|
722
|
-
`},
|
|
523
|
+
`},ro=e=>`export default function ${e.componentName}Loading() {
|
|
723
524
|
return (
|
|
724
|
-
<div className="flex h-full items-center justify-center">
|
|
725
|
-
<p>Loading
|
|
525
|
+
<div className="flex h-full items-center justify-center p-6">
|
|
526
|
+
<p className="text-gray-500 text-sm dark:text-gray-400">Loading\u2026</p>
|
|
726
527
|
</div>
|
|
727
528
|
);
|
|
728
529
|
}
|
|
729
|
-
`,
|
|
530
|
+
`,no=e=>`'use client';
|
|
531
|
+
|
|
532
|
+
import { useEffect } from 'react';
|
|
533
|
+
|
|
534
|
+
import { logger } from '@/lib/logger';
|
|
730
535
|
|
|
731
536
|
export default function ${e.componentName}Error({
|
|
732
537
|
error,
|
|
@@ -735,481 +540,410 @@ export default function ${e.componentName}Error({
|
|
|
735
540
|
error: Error & { digest?: string };
|
|
736
541
|
reset: () => void;
|
|
737
542
|
}) {
|
|
543
|
+
useEffect(() => {
|
|
544
|
+
logger.error({ err: error, digest: error.digest }, '${e.componentName} failed to render');
|
|
545
|
+
}, [error]);
|
|
546
|
+
|
|
738
547
|
return (
|
|
739
|
-
<div className="flex h-full flex-col items-center justify-center gap-4">
|
|
740
|
-
<h2>Something went wrong
|
|
741
|
-
<
|
|
742
|
-
|
|
548
|
+
<div className="flex h-full flex-col items-center justify-center gap-4 p-6 text-center">
|
|
549
|
+
<h2 className="font-semibold text-xl">Something went wrong</h2>
|
|
550
|
+
<button
|
|
551
|
+
type="button"
|
|
552
|
+
onClick={reset}
|
|
553
|
+
className="cursor-pointer rounded-md bg-dark px-6 py-2 text-light text-sm dark:bg-light dark:text-dark"
|
|
554
|
+
>
|
|
555
|
+
Try again
|
|
556
|
+
</button>
|
|
743
557
|
</div>
|
|
744
558
|
);
|
|
745
559
|
}
|
|
746
|
-
`;var
|
|
560
|
+
`;var wr=async e=>{let{name:t,projectPath:r,hasI18n:n,group:o,dynamic:s,withLoading:i=!1,withError:a=!1}=e,p=$(t),m=`/${t}`,c=[r,"src","app"];n&&c.push("[locale]"),o&&c.push(`(${o})`),c.push(t),s&&c.push(`[${s}]`);let d=Ft.join(...c);return await ba(d,{recursive:!0}),await yr(Ft.join(d,"page.tsx"),to({componentName:p,routePath:m,hasI18n:n,paramName:s})),i&&await yr(Ft.join(d,"loading.tsx"),ro({componentName:p})),a&&await yr(Ft.join(d,"error.tsx"),no({componentName:p})),{pageDir:d,routePath:s?`${m}/[${s}]`:m}};import{mkdir as va}from"node:fs/promises";import xr from"node:path";var oo=(e,t)=>e.endsWith(t)?e:`${e}${t}`,so=({baseName:e})=>{let t=oo(e,"Provider"),r=t.replace(/Provider$/,""),n=`${r}ContextValue`,o=`${r}Context`,s=`use${r}`;return`'use client';
|
|
747
561
|
import { createContext, useContext, useMemo } from 'react';
|
|
748
562
|
|
|
749
|
-
type ${
|
|
563
|
+
type ${n} = {
|
|
750
564
|
// TODO: declare context value fields
|
|
751
565
|
};
|
|
752
566
|
|
|
753
|
-
const ${
|
|
567
|
+
const ${o} = createContext<${n} | null>(null);
|
|
754
568
|
|
|
755
|
-
export const ${
|
|
756
|
-
const ctx = useContext(${
|
|
569
|
+
export const ${s} = (): ${n} => {
|
|
570
|
+
const ctx = useContext(${o});
|
|
757
571
|
if (!ctx) {
|
|
758
|
-
throw new Error('${
|
|
572
|
+
throw new Error('${s} must be used within ${t}');
|
|
759
573
|
}
|
|
760
574
|
return ctx;
|
|
761
575
|
};
|
|
762
576
|
|
|
763
577
|
export const ${t} = ({ children }: { children: React.ReactNode }) => {
|
|
764
|
-
const value = useMemo<${
|
|
765
|
-
return <${
|
|
578
|
+
const value = useMemo<${n}>(() => ({}), []);
|
|
579
|
+
return <${o}.Provider value={value}>{children}</${o}.Provider>;
|
|
766
580
|
};
|
|
767
|
-
`},
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
});
|
|
792
|
-
|
|
793
|
-
import { describe, expect, it } from 'vitest';
|
|
794
|
-
import { ${t} } from '${r}';
|
|
795
|
-
|
|
796
|
-
describe('${t}', () => {
|
|
797
|
-
it('returns a defined value', () => {
|
|
798
|
-
const { result } = renderHook(() => ${t}());
|
|
799
|
-
expect(result.current).toBeDefined();
|
|
800
|
-
});
|
|
801
|
-
});
|
|
802
|
-
`},co=e=>{let{camelName:t,sourceImportPath:r}=e,i=`${t}Slice`;return`import { describe, expect, it } from 'vitest';
|
|
803
|
-
import { ${i}, resetState, setError, setLoading } from '${r}';
|
|
804
|
-
|
|
805
|
-
describe('${i}', () => {
|
|
806
|
-
const initialState = { loading: false, error: null } as const;
|
|
807
|
-
|
|
808
|
-
it('returns the initial state', () => {
|
|
809
|
-
expect(${i}.reducer(undefined, { type: '@@INIT' })).toEqual(initialState);
|
|
810
|
-
});
|
|
811
|
-
|
|
812
|
-
it('handles setLoading', () => {
|
|
813
|
-
const next = ${i}.reducer(initialState, setLoading(true));
|
|
814
|
-
expect(next.loading).toBe(true);
|
|
815
|
-
});
|
|
816
|
-
|
|
817
|
-
it('handles setError', () => {
|
|
818
|
-
const next = ${i}.reducer(initialState, setError('boom'));
|
|
819
|
-
expect(next.error).toBe('boom');
|
|
820
|
-
});
|
|
821
|
-
|
|
822
|
-
it('handles resetState', () => {
|
|
823
|
-
const next = ${i}.reducer({ loading: true, error: 'boom' }, resetState());
|
|
824
|
-
expect(next).toEqual(initialState);
|
|
825
|
-
});
|
|
826
|
-
});
|
|
827
|
-
`};var ge=async e=>{let{projectPath:t,sourceFile:r,kind:i,symbolName:n}=e,o=gt.dirname(r),s=gt.basename(r).replace(/\.(tsx?|jsx?)$/i,""),c=i==="component"?".tsx":".ts",p=gt.join(o,`${s}.test${c}`),u=`./${s}`,d=jp(o,gt.join(t,"test","test-utils")),f;return i==="component"?f=so({componentName:n,sourceImportPath:u,testUtilsImportPath:d,hasRedux:!!e.hasRedux,hasI18n:!!e.hasI18n}):i==="hook"?f=ao({hookName:n,sourceImportPath:u,withStore:!!e.hookUsesStore,testUtilsImportPath:e.hookUsesStore?d:void 0}):f=co({camelName:n,sourceImportPath:u}),await h(p,f),p},jp=(e,t)=>{let r=gt.relative(e,t).replace(/\\/g,"/");return r.startsWith(".")?r:`./${r}`};import Lp from"enquirer";var{prompt:Mp}=Lp,po=async(e,t={})=>{let r=[];e||r.push({type:"input",name:"componentName",message:"Component name (kebab-case):",validate:n=>n?/^[a-z][a-z0-9-]*$/.test(n)?!0:"Use lowercase letters, numbers, and hyphens only":"Component name is required"}),t.client===void 0&&r.push({type:"confirm",name:"isClient",message:"Add 'use client' directive?",initial:!1});let i=r.length>0?await Mp(r):{};return{componentName:e??i.componentName,isClient:t.client??i.isClient??!1}};var lo=e=>{e.command("component [name]").description("Generate a shared component").option("--client","Add 'use client' directive").option("--i18n","Add useTranslations hook").option("--feature <path>","Generate in feature directory (e.g., src/features/auth)").option("--test","Also generate a sibling test file").option("--no-test","Skip test file generation").action(async(t,r)=>{try{let i=process.cwd();m(le.cyan(`
|
|
581
|
+
`},io=e=>oo(e,"Provider");var $a=/^[A-Za-z][A-Za-z0-9-]*$/,Pa=e=>e.includes("-")?$(e):e.charAt(0).toUpperCase()+e.slice(1),br=async e=>{let{name:t,projectPath:r}=e;if(!$a.test(t))throw new Error(`Invalid provider name "${t}". Use kebab-case or PascalCase letters and digits only.`);let n=Pa(t).replace(/Provider$/,""),o=io(n),s=o,i=xr.join(r,C.PROVIDERS),a=xr.join(i,`${s}.tsx`);if(y(a))throw new Error(`Provider already exists at ${xr.relative(r,a)}.`);return await va(i,{recursive:!0}),await k(a,so({baseName:n})),{componentName:o,fileBaseName:s,providerFile:a}};import at from"node:path";var re=async e=>{let{projectPath:t,sourceFile:r,kind:n,symbolName:o}=e,s=at.dirname(r),i=at.basename(r).replace(/\.(tsx?|jsx?)$/i,""),a=n==="component"?".tsx":".ts",p=at.join(s,`${i}.test${a}`),m=`./${i}`,c=ka(s,at.join(t,"test","test-utils")),d;return n==="component"?d=It({componentName:o,sourceImportPath:m,testUtilsImportPath:c,hasState:!!e.hasState,hasI18n:!!e.hasI18n}):n==="hook"?d=Yn({hookName:o,sourceImportPath:m,withStore:!!e.hookUsesStore,testUtilsImportPath:e.hookUsesStore?c:void 0}):d=Qn({camelName:o,sourceImportPath:m}),await k(p,d),p},ka=(e,t)=>{let r=at.relative(e,t).replace(/\\/g,"/");return r.startsWith(".")?r:`./${r}`};import{readFile as Sa,writeFile as Ea}from"node:fs/promises";import Ra from"node:path";var Le=(e,t)=>{let r=/import\s+.*\s+from\s+['"].*['"];?\n/g,n=e.match(r);if(n&&n.length>0){let o=n[n.length-1],s=e.lastIndexOf(o);return e.slice(0,s+o.length)+t+`
|
|
582
|
+
`+e.slice(s+o.length)}return`${t}
|
|
583
|
+
${e}`},vr=(e,t)=>{let r=/combineSlices\(([\s\S]*?)\)/,n=e.match(r);if(!n)throw new Error("Could not find combineSlices in rootReducer.ts");let o=n[1].split(",").map(p=>p.trim()).filter(Boolean);if(o.includes(t))return e;let s=o.indexOf("persistSlice");s===-1?o.push(t):o.splice(s,0,t);let i=`combineSlices(${o.join(", ")})`,a=`combineSlices(
|
|
584
|
+
${o.join(`,
|
|
585
|
+
`)},
|
|
586
|
+
)`;return e.replace(r,i.length<=100?i:a)},$r=(e,t)=>{let r=/entries:\s*\[([\s\S]*?)\]/,n=e.match(r);if(!n)throw new Error("Could not find `entries: [...]` in src/store/index.ts");let o=n[1].split(",").map(s=>s.trim()).filter(Boolean);return o.includes(t)?e:(o.push(t),e.replace(r,`entries: [${o.join(", ")}]`))},Pr=(e,t)=>{let r=e.lastIndexOf("} as const;");if(r===-1)throw new Error("Could not find closing brace of AppApis object");let n=e.substring(0,r),o=e.substring(r);return`${n.trimEnd()}
|
|
587
|
+
${t}
|
|
588
|
+
${o}`};var ct=async e=>{let{serviceName:t,projectPath:r}=e,n=U(t),o=Ra.join(r,"src","lib","config","app-apis.ts");try{let s=await Sa(o,"utf-8");if(s.includes(`${n}:`))return;if(!s.match(/export const AppApis = \{[\s\S]*?\} as const;/))throw new Error("Could not find AppApis object in app-apis.ts");s=Pr(s,Un({kebabName:t,camelName:n,pascalName:$(t)})),await Ea(o,s)}catch(s){throw new Error(`Failed to register API endpoints: ${s}`,{cause:s})}};import{readFile as ja,writeFile as Ca}from"node:fs/promises";import Ta from"node:path";var kr=async(e,t,r)=>{let n=Ta.join(e,"src","lib","config","app-paths.ts");if(!y(n))return;let o=await ja(n,"utf-8"),s=U(t);if(o.includes(`${s}:`))return;let i=o.lastIndexOf("} as const;");if(i===-1)return;let a=` ${s}: '${r}',
|
|
589
|
+
`;o=o.slice(0,i)+a+o.slice(i),await Ca(n,o)};import Sr from"node:path";var Oa=/^[A-Z][A-Z0-9_]*$/,po=e=>{if(!Oa.test(e))throw new Error(`Invalid env var name "${e}". Use UPPER_SNAKE_CASE (e.g. SENTRY_DSN, NEXT_PUBLIC_API_URL).`)},ne=(e,t)=>t?e.startsWith("NEXT_PUBLIC_")?e:`NEXT_PUBLIC_${e}`:e,Er=e=>e.public?"client":"server",Aa=e=>{if(e.default===void 0)return"";switch(e.type){case"number":return`.default(${Number(e.default)})`;case"boolean":return`.default(${e.default==="true"})`;default:return`.default('${e.default.replace(/'/g,"\\'")}')`}},Ia=e=>{switch(e.type){case"url":return"e.url()";case"number":return"e.number()";case"boolean":return"e.boolean()";case"enum":{let t=e.enumValues??[];if(t.length===0)throw new Error(`Enum env var "${e.name}" requires --enum values.`);return`e.enum([${t.map(n=>`'${n.replace(/'/g,"\\'")}'`).join(", ")}])`}default:return"e.string()"}},lo=e=>{let t=ne(e.name,e.public),r=Ia(e),n=e.default!==void 0,o=!e.required&&!n;if(n&&(r+=Aa(e)),o&&(r+=".optional()"),e.description){let s=e.description.replace(/'/g,"\\'");r+=`
|
|
590
|
+
.describe('${s}')`}return` ${t}: ${r},`},mo=e=>{let t=ne(e.name,e.public);return` ${t}: process.env.${t},`},Na=e=>new RegExp(`(${e}:\\s*\\{)([\\s\\S]*?)(\\n\\s*\\})`),ao=/(runtimeEnv:\s*\{)([\s\S]*?)(\n\s*\})/,co=(e,t,r,n)=>{let o=t.replace(/\s+$/,""),s=o.length===0||/,\s*$/.test(o)?o:`${o},`;return`${e}${s}
|
|
591
|
+
${n}
|
|
592
|
+
${r.replace(/^\n/,"")}`},uo=(e,t)=>{let r=ne(t.name,t.public),n=Er(t);if(new RegExp(`\\b${r}\\s*:`).test(e))return e;if(!/defineEnv\(\{/.test(e))throw new Error("Could not locate `defineEnv({ \u2026 })` in src/lib/env/index.ts. Is this a @teispace/env project?");let s=Na(n),i=e.match(s);if(!i)throw new Error(`Could not locate the \`${n}: { \u2026 }\` group in src/lib/env/index.ts.`);let[,a,p,m]=i,c=lo(t),d=e.replace(s,co(a,p,m,c)),u=d.match(ao);if(!u)throw new Error("Could not locate the `runtimeEnv: { \u2026 }` map in src/lib/env/index.ts.");let[,f,h,w]=u;return d=d.replace(ao,co(f,h,w,mo(t))),d},Fa="# -public",Ma=e=>{let t=ne(e.name,e.public),r=e.default??"",n=e.public?` ${Fa}`:"";return`${t}=${r}${n}`},fo=(e,t)=>{let r=ne(t.name,t.public);if(new RegExp(`^${r}=`,"m").test(e))return e;let o=e===""||e.endsWith(`
|
|
593
|
+
`)?"":`
|
|
594
|
+
`,s=e===""?"":`
|
|
595
|
+
`,i=t.description?`# ${t.description}
|
|
596
|
+
`:"";return`${e}${o}${s}${i}${Ma(t)}
|
|
597
|
+
`},go=(e,t)=>{let r=ne(t.name,t.public);if(new RegExp(`^${r}=`,"m").test(e))return e;let o=e===""||e.endsWith(`
|
|
598
|
+
`)?"":`
|
|
599
|
+
`,s=t.default??"";return`${e}${o}${r}=${s}
|
|
600
|
+
`},Rr=async(e,t)=>{po(t.name);let r=Sr.join(e,"src/lib/env/index.ts");if(!y(r))throw new Error("src/lib/env/index.ts not found \u2014 run `next-maker init` first.");let n=await j(r),o=uo(n,t),s=o!==n;s&&await k(r,o);let i=Sr.join(e,C.ENV_EXAMPLE),a=!1;if(y(i)){let c=await j(i),d=fo(c,t);a=d!==c,a&&await k(i,d)}let p=Sr.join(e,".env"),m=!1;if(y(p)){let c=await j(p),d=go(c,t);m=d!==c,m&&await k(p,d)}return{schemaUpdated:s,envExampleUpdated:a,envUpdated:m,group:Er(t)}};import Mt from"node:path";var _a=e=>new RegExp(`<\\s*${e}\\b`),ho=(e,t)=>{if(_a(t).test(e))return e;let r=/^(?<indent>[ \t]*)\{children\}\s*$/m,n=e.match(r);if(!n||n.index===void 0)throw new Error("Could not locate `{children}` line in RootProvider \u2014 expected a line containing only `{children}`.");let o=n.groups?.indent??"",s=`${o} `,i=`${o}<${t}>
|
|
601
|
+
${s}{children}
|
|
602
|
+
${o}</${t}>`;return e.replace(r,i)},yo=(e,t)=>{let r=`export * from './${t}';`;if(e.includes(r))return e;let n=e.split(`
|
|
603
|
+
`),o=[],s=[];for(let d of n)/^export \* from '\.\/.*';\s*$/.test(d)?o.push(d):s.push(d);let i=[...o,r].sort(),a=n.findIndex(d=>/^export \* from '\.\//.test(d));if(a===-1)return`${r}
|
|
604
|
+
${e.replace(/^\n+/,"")}`;let p=n.slice(0,a),m=n.findIndex((d,u)=>u>a&&!/^export \* from '\.\//.test(d)),c=m===-1?[]:n.slice(m);return[...p,...i,...c].join(`
|
|
605
|
+
`)},Da=C.PROVIDERS,La=C.ROOT_PROVIDER,Ua=C.PROVIDERS_INDEX,wo=async(e,t={fileExists:y,readFile:j})=>{let r=Mt.join(e,La);if(t.fileExists(r))return r;let n=Mt.join(e,Da);if(!t.fileExists(n))return null;let{readdir:o}=await import("node:fs/promises"),i=(await o(n).catch(()=>[])).filter(p=>p.endsWith(".tsx")),a=null;for(let p of i){let m=Mt.join(n,p),c=await t.readFile(m);if(!/\{children\}/.test(c))continue;let u=((c.split("{children}")[0]??"").match(/<[A-Z][A-Za-z0-9_]*\b/g)??[]).length;(!a||u>a.depth)&&(a={file:m,depth:u})}return a?.file??null},jr=async e=>{let{projectPath:t,componentName:r,fileBaseName:n}=e,o=await wo(t);if(o){let a=await j(o),p=a;(!/from '\.\//.test(a)||!a.includes(`{ ${r} }`))&&(p=Le(p,`import { ${r} } from './${n}';`)),p=ho(p,r),p!==a&&await k(o,p)}let s=Mt.join(t,Ua),i=null;if(y(s)){let a=await j(s),p=yo(a,n);p!==a&&await k(s,p),i=s}return{rootProviderFile:o,barrelFile:i}};import{readFile as xo,writeFile as bo}from"node:fs/promises";import vo from"node:path";var pt=async e=>{let{projectPath:t,name:r,persist:n,importPath:o}=e,s=vo.join(t,"src","store","rootReducer.ts"),i=vo.join(t,"src","store","index.ts"),a=U(r),p=o.replace(/^src\//,"@/");try{let m=await xo(s,"utf-8");if(m=Le(m,`import { ${a}Slice } from '${p}';`),m=vr(m,`${a}Slice`),await bo(s,m),n&&y(i)){let c=await xo(i,"utf-8");c=Le(c,`import { ${a}Persistence } from '${p}';`),c=$r(c,`${a}Persistence`),await bo(i,c)}}catch(m){throw new Error(`Failed to register slice '${r}': ${m}`,{cause:m})}};import{readFile as Ga,writeFile as Ba}from"node:fs/promises";import Va from"node:path";var Se=async(e,t)=>{let r=Va.join(e,"src","i18n","translations","en.json");if(!y(r))return;let n=await Ga(r,"utf-8"),o=JSON.parse(n);o[t]||(o[t]={title:t,description:`${t} page description`},await Ba(r,`${JSON.stringify(o,null,2)}
|
|
606
|
+
`))};import qa from"enquirer";var{prompt:Ja}=qa,$o=async(e,t={})=>{let r=[];e||r.push({type:"input",name:"componentName",message:"Component name (kebab-case):",validate:o=>o?/^[a-z][a-z0-9-]*$/.test(o)?!0:"Use lowercase letters, numbers, and hyphens only":"Component name is required"}),t.client===void 0&&r.push({type:"confirm",name:"isClient",message:"Add 'use client' directive?",initial:!1});let n=r.length>0?await Ja(r):{};return{componentName:e??n.componentName,isClient:t.client??n.isClient??!1}};var Po=e=>{e.command("component [name]").description("Generate a shared component").option("--client","Add 'use client' directive").option("--i18n","Add useTranslations hook").option("--feature <path>","Generate in feature directory (e.g., src/features/auth)").option("--test","Also generate a sibling test file").option("--no-test","Skip test file generation").action(async(t,r)=>{try{let n=process.cwd();l(K.cyan(`
|
|
828
607
|
\u{1F9E9} Component Generator
|
|
829
|
-
`)),
|
|
830
|
-
\u2728 Component '${
|
|
831
|
-
`)),
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
});
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
`)
|
|
838
|
-
`)
|
|
839
|
-
`),
|
|
840
|
-
|
|
841
|
-
`).
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
${r}
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
`),
|
|
853
|
-
${
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
--
|
|
860
|
-
}
|
|
861
|
-
`);let o=await
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
608
|
+
`)),g.start("Detecting project setup...");let o=await T(n);g.succeed("Project setup detected");let s=await $o(t,{client:r.client});F(s.componentName,"component name"),r.feature&&W(r.feature,"feature path");let i=$(s.componentName),a=s.isClient,p=r.i18n??!1,m=za(r,o.hasTests);g.start("Generating component..."),await cr({name:s.componentName,projectPath:n,isClient:a||p,hasI18n:p,featurePath:r.feature}),g.succeed("Component generated"),p&&await Se(n,i);let c=null;if(m){let u=r.feature?Cr.join(n,r.feature,"components",`${i}.tsx`):Cr.join(n,"src/components/common",i,`${i}.tsx`);g.start("Generating test..."),c=await re({projectPath:n,sourceFile:u,kind:"component",symbolName:i,hasState:o.state!=="none",hasI18n:o.hasI18n}),g.succeed("Test generated")}let d=r.feature?`${r.feature}/components/${i}.tsx`:`src/components/common/${i}/${i}.tsx`;l(K.green(`
|
|
609
|
+
\u2728 Component '${i}' created successfully!
|
|
610
|
+
`)),l(K.dim(` \u{1F4C4} ${d}`)),r.feature||(l(K.dim(` \u{1F4C4} src/components/common/${i}/index.ts`)),l(K.dim(" \u{1F4DD} Updated src/components/common/index.ts")),l(K.dim(" \u{1F4DD} Updated src/components/index.ts"))),c&&l(K.dim(` \u{1F9EA} ${Cr.relative(n,c)}`)),l(""),l(K.cyan("Usage:")),r.feature?l(K.dim(` import { ${i} } from '${r.feature.replace(/^src\//,"@/")}/components/${i}';`)):l(K.dim(` import { ${i} } from '@/components';`)),l("")}catch(n){g.fail("Component generation failed"),x(`${n}`),process.exit(1)}})},za=(e,t)=>e.test===!1?!1:e.test===!0?!0:t;import{spawnSync as Wa}from"node:child_process";import M from"picocolors";var Ha=e=>{switch(e.kind){case"missingFile":return`missing file: ${e.file}`;case"missingPackage":return`missing ${e.dev?"devDependency":"dependency"}: ${e.name}`;case"missingScript":return`missing script: ${e.name}`}},ko=e=>{e.command("doctor").description("Diagnose drift between the project and the starter features it was generated with").option("--fix","Restore missing files, packages, and scripts from the starter").option("--compile","Run the project type-check as part of the diagnosis").option("--json","Print machine-readable JSON").option("--starter-path <dir>","Compare against a local starter checkout").action(async t=>{let r=process.cwd(),n;try{let o=await ee(r),s=await Me(o,{starterPath:t.starterPath});n=s.dispose;let i=await rr(r,o,s),a=0;if(t.fix&&i.some(c=>c.drift.length)){let c=await Sn(r,{...o,answers:{}},s,o.answers),d=new Set(i.flatMap(h=>h.drift.filter(w=>w.kind==="missingFile").map(w=>w.file)));c.copy=c.copy.filter(h=>d.has(h)),c.remove=[],c.unwrapJsx=[],c.unwrapCall=[],c.removePackages=[],c.removeScripts=[],c.manual=[];let u=new Set(i.flatMap(h=>h.drift.filter(w=>w.kind==="missingPackage").map(w=>w.name)));for(let h of Object.keys(c.addPackages))u.has(h)||delete c.addPackages[h];for(let h of Object.keys(c.addDevPackages))u.has(h)||delete c.addDevPackages[h];let f=new Set(i.flatMap(h=>h.drift.filter(w=>w.kind==="missingScript").map(w=>w.name)));for(let h of Object.keys(c.addScripts))f.has(h)||delete c.addScripts[h];await En(r,s,c,o),a=c.copy.length+Object.keys(c.addPackages).length+Object.keys(c.addDevPackages).length+Object.keys(c.addScripts).length,i=await rr(r,o,s)}let p;if(t.compile){let[c,...d]=ae(o.packageManager,"type-check").split(" "),u=Wa(c,d,{cwd:r,encoding:"utf-8"});p={ok:u.status===0,output:`${u.stdout}${u.stderr}`.trim()}}let m=i.filter(c=>c.on&&c.drift.length);t.json&&(l(JSON.stringify({starter:o.starter,results:i,fixed:a,compile:p},null,2)),process.exit(m.length||p?.ok===!1?1:0)),l(M.cyan(`
|
|
611
|
+
\u{1FA7A} Project Doctor
|
|
612
|
+
`)),l(M.dim(` ${o.starter.name} ${o.starter.version} \xB7 ${s.source.location}
|
|
613
|
+
`));for(let c of i){if(!c.on){l(` ${M.dim("\u2014")} ${M.dim(c.id)} ${M.dim("(off)")}`);continue}if(c.drift.length===0){l(` ${M.green("\u2713")} ${c.id}`);continue}l(` ${M.yellow("!")} ${M.bold(c.id)} ${M.dim(`(${c.drift.length} issue${c.drift.length===1?"":"s"})`)}`);for(let d of c.drift)l(` ${M.yellow("\u2022")} ${Ha(d)}`)}a&&l(M.green(`
|
|
614
|
+
restored ${a} item(s) from the starter`)),p&&(l(""),l(p.ok?M.green(" \u2713 type-check passed"):M.red(" \u2717 type-check failed")),p.ok||l(M.dim(p.output.split(`
|
|
615
|
+
`).slice(-30).join(`
|
|
616
|
+
`)))),l(""),m.length===0&&p?.ok!==!1&&(l(M.green(`\u2713 No drift detected.
|
|
617
|
+
`)),process.exit(0)),m.length&&!t.fix&&l(M.dim(`Run with --fix to restore missing pieces from the starter.
|
|
618
|
+
`)),process.exit(1)}catch(o){x(`${o instanceof Error?o.message:o}`),process.exit(1)}finally{await n?.()}})};import Ue from"picocolors";var So=new Set(["string","url","number","boolean","enum"]),Ka=e=>{let t=(e??"string").toLowerCase();if(!So.has(t))throw new Error(`Invalid --type "${e}". Valid: ${Array.from(So).join(", ")}.`);return t},Xa=e=>{if(!e)return;let t=e.split(",").map(r=>r.trim()).filter(Boolean);return t.length===0?void 0:t},Eo=e=>{e.command("env <NAME>").description("Declare a new environment variable across src/lib/env/index.ts, .env.example, and .env").option("--type <type>","Coercer type (string|url|number|boolean|enum)","string").option("--required","Make the variable required (no .optional() / .default())").option("--default <value>","Set a default value (mutually exclusive with --required)").option("--public","Mark as public: place in the client group, auto-prefix NEXT_PUBLIC_, tag .env.example").option("--describe <text>","Description (rendered as .describe() and .env.example comment)").option("--enum <list>",'Comma-separated values when --type=enum (e.g. "dev,prod")').action(async(t,r)=>{try{let n=process.cwd();if(l(Ue.cyan(`
|
|
619
|
+
\u{1F510} Env Var Generator
|
|
620
|
+
`)),r.required&&r.default!==void 0)throw new Error("--required and --default are mutually exclusive.");let o=Ka(r.type),s=Xa(r.enum);if(o==="enum"&&(!s||s.length===0))throw new Error("--type=enum requires at least one value via --enum a,b,c.");let i={name:t,type:o,required:!!r.required,default:r.default,description:r.describe,enumValues:s,public:!!r.public};g.start("Updating src/lib/env/index.ts, .env.example, and .env...");let a=await Rr(n,i);g.succeed("Env var written");let p=ne(i.name,i.public);l(Ue.green(`
|
|
621
|
+
\u2728 ${p} declared in the ${a.group} group.
|
|
622
|
+
`)),l(Ue.dim("Touched:")),l(Ue.dim(` ${a.schemaUpdated?"\u270F\uFE0F ":"\u23ED "} src/lib/env/index.ts`)),l(Ue.dim(` ${a.envExampleUpdated?"\u270F\uFE0F ":"\u23ED "} .env.example`)),l(Ue.dim(` ${a.envUpdated?"\u270F\uFE0F ":"\u23ED "} .env`)),l("")}catch(n){g.fail("Env var declaration failed"),x(`${n instanceof Error?n.message:n}`),process.exit(1)}})};import Lt from"node:path";import Re from"picocolors";import Ya from"enquirer";var{prompt:Qa}=Ya,Ro=async(e={})=>e.source?{source:e.source}:{source:(await Qa({type:"input",name:"source",message:"Path to source image (PNG/JPG/JPEG/SVG/WebP/AVIF):",validate:r=>r?!0:"Source path is required"})).source};import{access as Za,readFile as ec,stat as tc}from"node:fs/promises";import Ee from"node:path";var jo=async e=>{try{return await Za(e),!0}catch{return!1}},rc=async e=>{try{return(await tc(e)).isDirectory()}catch{return!1}},_t=async e=>{let t=[Ee.join(e,"src","app"),Ee.join(e,"app")];for(let r of t)if(await rc(r))return r;return null},nc=["next-pwa","@ducanh2912/next-pwa","@serwist/next","serwist"],Tr=async e=>{let t={isPwa:!1},r=[Ee.join(e,"public","manifest.json"),Ee.join(e,"public","manifest.webmanifest"),Ee.join(e,"public","site.webmanifest")];for(let o of r)if(await jo(o)){t.publicManifestPath=o,t.isPwa=!0;break}let n=await _t(e);if(n)for(let o of["ts","tsx","js"]){let s=Ee.join(n,`manifest.${o}`);if(await jo(s)){t.appManifestPath=s,t.isPwa=!0;break}}try{let o=JSON.parse(await ec(Ee.join(e,"package.json"),"utf-8")),s={...o.dependencies,...o.devDependencies};for(let i of nc)if(s[i]){t.framework=i,t.isPwa=!0;break}}catch{}return t};import{mkdir as cc,readFile as Do,stat as pc,writeFile as lc}from"node:fs/promises";import X from"node:path";import mc from"sharp";import sc from"png-to-ico";import lt from"sharp";var Co=e=>e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<"),Or=(e,t,r)=>{switch(e){case"square":return`<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${t}"><rect width="${t}" height="${t}" fill="white"/></svg>`;case"circle":{let n=t/2;return`<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${t}"><circle cx="${n}" cy="${n}" r="${n}" fill="white"/></svg>`}case"rounded":{let n=Math.round(t*r/100);return`<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${t}"><rect width="${t}" height="${t}" rx="${n}" ry="${n}" fill="white"/></svg>`}case"squircle":return oc(t)}},oc=e=>{let t=e,r=t*.225,n=[`M 0 ${r}`,`C 0 0 0 0 ${r} 0`,`L ${t-r} 0`,`C ${t} 0 ${t} 0 ${t} ${r}`,`L ${t} ${t-r}`,`C ${t} ${t} ${t} ${t} ${t-r} ${t}`,`L ${r} ${t}`,`C 0 ${t} 0 ${t} 0 ${t-r}`,"Z"].join(" ");return`<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${t}"><path d="${Co(n)}" fill="white"/></svg>`},To=(e,t)=>`<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${e}"><rect width="${e}" height="${e}" fill="${Co(t)}"/></svg>`;var Ge=async e=>{let{size:t,paddingPercent:r,bg:n,fit:o,shape:s,radiusPercent:i,quality:a,forceSquare:p,sourceBuffer:m}=e,c=Math.max(1,Math.round(t*(1-r*2/100))),d=o==="cover"?"cover":"contain",u=await lt(m,{density:384}).resize(c,c,{fit:d,background:{r:0,g:0,b:0,alpha:0}}).png().toBuffer(),f=Math.round((t-c)/2),h=n==="transparent"?{r:0,g:0,b:0,alpha:0}:await Ar(n),w=await lt({create:{width:t,height:t,channels:4,background:h}}).composite([{input:u,left:f,top:f}]).png().toBuffer();if(!p&&(s!=="square"||o==="clip")){let b=s==="square"?"rounded":s,S=Buffer.from(Or(b,t,i));w=await lt(w).composite([{input:S,blend:"dest-in"}]).png({compressionLevel:Oo(a)}).toBuffer()}else w=await lt(w).png({compressionLevel:Oo(a)}).toBuffer();return w},Ar=async e=>{let t=await lt(Buffer.from(To(1,e))).raw().toBuffer({resolveWithObject:!0}),[r,n,o,s=255]=t.data;return{r,g:n,b:o,alpha:s/255}},Oo=e=>{let t=Math.round((100-e)/100*9);return Math.max(0,Math.min(9,t))},Ao=async e=>{if(e.length===0)throw new Error("No frames provided to encodeIco");return sc(e)};import{readFile as ic,writeFile as xf}from"node:fs/promises";var Io=e=>e.map(({src:t,size:r})=>({src:t,sizes:`${r}x${r}`,type:"image/png",purpose:"any maskable"})),No=async(e,t)=>{let r=await ic(e,"utf-8"),n=JSON.parse(r),o=Array.isArray(n.icons)?n.icons:[],s=new Map;for(let i of[...o,...t])i&&typeof i.src=="string"&&s.set(i.src,i);return n.icons=[...s.values()],`${JSON.stringify(n,null,2)}
|
|
623
|
+
`};var Fo=e=>`icons: [
|
|
624
|
+
${e.map(r=>` { src: '${r.src}', sizes: '${r.sizes}', type: '${r.type}'${r.purpose?`, purpose: '${r.purpose}'`:""} }`).join(`,
|
|
625
|
+
`)},
|
|
626
|
+
],`,Mo=(e,t,r)=>`${JSON.stringify({name:e,short_name:e,start_url:"/",display:"standalone",background_color:"#ffffff",theme_color:t,icons:r},null,2)}
|
|
627
|
+
`;import{stat as ac}from"node:fs/promises";import Ir from"node:path";var _o=[".png",".jpg",".jpeg",".webp",".svg",".avif"],Dt=async e=>{if(!e)throw new Error("Source image path is required (use --path).");let t=Ir.isAbsolute(e)?e:Ir.resolve(process.cwd(),e),r;try{r=await ac(t)}catch{throw new Error(`Source image not found: ${t}`)}if(!r.isFile())throw new Error(`Source is not a file: ${t}`);let n=Ir.extname(t).toLowerCase();if(!_o.includes(n))throw new Error(`Unsupported source format '${n}'. Use one of: ${_o.join(", ")}`);return{absolutePath:t,ext:n,bytes:r.size,isVector:n===".svg"}};var Nr=(e,t)=>{if(!e)return t;let r=e.split(",").map(n=>Number.parseInt(n.trim(),10)).filter(n=>Number.isFinite(n)&&n>0&&n<=1024);if(r.length===0)throw new Error(`Invalid --sizes value: '${e}'. Provide comma-separated positive integers.`);return r};var dc=async e=>{try{return await pc(e),!0}catch{return!1}},uc=async(e,t,r)=>{let n=[];for(let o of e){if(await dc(o.outPath)&&!t&&!o.alwaysWrite){n.push({path:o.outPath,bytes:o.bytes.length,skipped:!0});continue}r||(await cc(X.dirname(o.outPath),{recursive:!0}),await lc(o.outPath,o.bytes)),n.push({path:o.outPath,bytes:o.bytes.length})}return n},Fr=async(e,t)=>{let r=await Dt(t.source),n=await Do(r.absolutePath),o=t.ogSource?await Do((await Dt(t.ogSource)).absolutePath):n,s=[],i=[];for(let c of t.icoSizes)i.push(await Ge({sourceBuffer:n,size:c,shape:"square",radiusPercent:t.radius,bg:t.bg,paddingPercent:t.padding,fit:t.fit,quality:t.quality,forceSquare:!0}));let a=await Ao(i);if(s.push({outPath:X.join(t.outDir,"favicon.ico"),bytes:a}),t.emitIcon){let c=await Ge({sourceBuffer:n,size:512,shape:t.shape,radiusPercent:t.radius,bg:t.bg,paddingPercent:t.padding,fit:t.fit,quality:t.quality});s.push({outPath:X.join(t.outDir,"icon.png"),bytes:c})}if(t.emitApple){let c=t.bg==="transparent"?"#ffffff":t.bg,d=await Ge({sourceBuffer:n,size:180,shape:t.shape,radiusPercent:t.radius,bg:c,paddingPercent:t.padding,fit:t.fit,quality:t.quality});s.push({outPath:X.join(t.outDir,"apple-icon.png"),bytes:d})}if(t.emitOg){let c=await Lo(o,t,!1);s.push({outPath:X.join(t.outDir,"opengraph-image.png"),bytes:c})}if(t.emitTwitter){let c=await Lo(o,t,!0);s.push({outPath:X.join(t.outDir,"twitter-image.png"),bytes:c})}let p;if(t.pwa||t.pwaInit){let c=await Tr(e);if(t.pwa&&!c.isPwa)throw new Error("No PWA setup detected. Use --pwa-init to bootstrap a manifest, or set up next-pwa/serwist first.");let d=X.join(e,"public"),u=[192,512],f=[];for(let w of u){let P=await Ge({sourceBuffer:n,size:w,shape:t.shape,radiusPercent:t.radius,bg:t.bg,paddingPercent:t.padding,fit:t.fit,quality:t.quality}),b=`icon-${w}.png`;s.push({outPath:X.join(d,b),bytes:P}),f.push({src:`/${b}`,size:w})}let h=Io(f);if(c.publicManifestPath){let w=await No(c.publicManifestPath,h);s.push({outPath:c.publicManifestPath,bytes:Buffer.from(w,"utf-8"),alwaysWrite:!0})}else if(c.appManifestPath)p=Fo(h);else if(t.pwaInit){let w=X.join(d,"manifest.webmanifest"),P=Mo(X.basename(e)||"App","#000000",h);s.push({outPath:w,bytes:Buffer.from(P,"utf-8")})}}return{outputs:await uc(s,t.force,t.dryRun),pwaSnippet:p}},Lo=async(e,t,r)=>{let o=r?600:630,s=Math.round(Math.min(1200,o)*(1-t.padding*2/100)),i=await Ge({sourceBuffer:e,size:s,shape:t.shape,radiusPercent:t.radius,bg:"transparent",paddingPercent:0,fit:t.fit,quality:t.quality}),a=t.bg==="transparent"?"#ffffff":t.bg,p=await Ar(a),m=Math.round((1200-s)/2),c=Math.round((o-s)/2);return mc({create:{width:1200,height:o,channels:4,background:p}}).composite([{input:i,left:m,top:c}]).png().toBuffer()};var Uo=new Set(["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"]);var fc=["square","rounded","circle","squircle"],gc=["contain","cover","clip"],Go=(e,t,r,n)=>{if(!e)return r;if(!t.includes(e))throw new Error(`Invalid value for --${n}: '${e}'. Allowed: ${t.join(", ")}`);return e},Mr=(e,t,r,n,o)=>{if(e===void 0)return t;let s=Number(e);if(!Number.isFinite(s)||s<n||s>o)throw new Error(`Invalid value for --${r}: '${e}'. Must be a number between ${n}\u2013${o}.`);return s},Vo=e=>{e.command("favicon").description("Generate favicon.ico (and optionally icons, OG image, PWA manifest icons)").option("--path <file>","Path to source image (PNG, JPG, JPEG, WebP, SVG, AVIF)").option("--out <dir>","Output dir (default: src/app or app)").option("--force","Overwrite existing files without prompt",!1).option("--dry-run","Show what would be written without writing",!1).option("--icon","Also emit icon.png (512\xD7512)",!1).option("--apple","Also emit apple-icon.png (180\xD7180)",!1).option("--og","Also emit opengraph-image.png (1200\xD7630)",!1).option("--og-source <file>","Use a separate image for the OG/Twitter card").option("--twitter","Also emit twitter-image.png (1200\xD7600)",!1).option("--all","Shorthand for --icon --apple --og",!1).option("--pwa","Detect PWA setup and emit manifest icons (192/512); errors if not detected",!1).option("--pwa-init","Bootstrap public/manifest.webmanifest with icons",!1).option("--shape <shape>","square | rounded | circle | squircle","square").option("--radius <percent>","Corner radius % when shape=rounded (0-50)","20").option("--bg <color>",'Background color (hex, css name, or "transparent")',"transparent").option("--padding <percent>","Padding around source content (0-30)","0").option("--fit <fit>","How source fits target: contain | cover | clip","contain").option("--sizes <list>","Comma-separated ICO sizes (default: 16,32,48)").option("--quality <n>","PNG compression 1-100 (higher = smaller file; PNG is lossless, default: 90)","90").action(async t=>{try{let r=process.cwd();l(Re.cyan(`
|
|
628
|
+
\u{1F3A8} Favicon Generator
|
|
629
|
+
`));let n=await Ro({source:t.path}),o=await hc(r,t.out),s=Go(t.shape,fc,"square","shape"),i=Go(t.fit,gc,"contain","fit"),a=Mr(t.radius,20,"radius",0,50),p=Mr(t.padding,0,"padding",0,30),m=Mr(t.quality,90,"quality",1,100),c=Nr(t.sizes,[16,32,48]),d=t.bg??"transparent";xc(d);let u=t.all===!0,f={source:n.source,outDir:o,force:!!t.force,dryRun:!!t.dryRun,emitIcon:!!t.icon||u,emitApple:!!t.apple||u,emitOg:!!t.og||u,emitTwitter:!!t.twitter,ogSource:t.ogSource,pwa:!!t.pwa,pwaInit:!!t.pwaInit,shape:s,radius:a,bg:d,padding:p,fit:i,icoSizes:c,quality:m};g.start("Generating favicon assets...");let h=await Fr(r,f);g.succeed(f.dryRun?"Favicon plan ready":"Favicon assets generated"),l("");for(let w of h.outputs){let P=Lt.relative(r,w.path);w.skipped?l(Re.yellow(` \u21B7 skipped ${P} (exists; use --force to overwrite)`)):f.dryRun?l(Re.dim(` \u{1F4C4} would write ${P} (${Bo(w.bytes)})`)):l(Re.green(` \u2713 ${P} `)+Re.dim(`(${Bo(w.bytes)})`))}h.pwaSnippet&&(l(""),l(Re.cyan("Add this to your typed manifest (src/app/manifest.ts):")),l(Re.dim(h.pwaSnippet))),l("")}catch(r){g.fail("Favicon generation failed");let n=r instanceof Error?r.message:String(r);x(n),process.exit(1)}})},hc=async(e,t)=>{if(t)return Lt.isAbsolute(t)?t:Lt.resolve(e,t);let r=await _t(e);return r||(cn("Could not detect app/ or src/app/ \u2014 falling back to src/app"),Lt.join(e,"src","app"))},yc=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/,wc=/^(?:rgb|rgba|hsl|hsla)\(\s*[\d.,%\s/]+\)$/i,xc=e=>{if(e!=="transparent"&&!yc.test(e)&&!wc.test(e)&&!Uo.has(e.toLowerCase()))throw new Error(`Invalid value for --bg: '${e}'. Use 'transparent', a hex code (e.g. #0f172a), a CSS color name, or rgb()/rgba()/hsl()/hsla().`)},Bo=e=>e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(2)} MB`;import _r from"node:path";import _ from"picocolors";import bc from"enquirer";var{prompt:vc}=bc,qo=async(e,t,r={})=>{let n=[];e||n.push({type:"input",name:"featureName",message:"Feature name (kebab-case):",initial:"my-feature",validate:s=>/^[a-z][a-z0-9-]*$/.test(s)||"Use lowercase letters, digits, and hyphens only."}),r.api===void 0&&n.push({type:"confirm",name:"createApi",message:"Generate the api/ layer (schema, DAL, Server Actions, queries)?",initial:!0}),t!=="none"&&r.store===void 0&&(n.push({type:"confirm",name:"createStore",message:`Generate a ${t==="zustand"?"Zustand":"Redux"} slice for client-only state?`,initial:!1}),t==="redux"&&r.persist===void 0&&n.push({type:"confirm",name:"persistStore",message:"Persist the slice across reloads?",initial:!1,skip(){return!this.state.answers.createStore}}));let o=n.length>0?await vc(n):{};return{featureName:e??o.featureName,createApi:r.api??o.createApi??!0,createStore:t!=="none"&&(r.store??o.createStore??!1),persistStore:t==="redux"&&(r.persist??o.persistStore??!1)}};var zo=e=>{e.command("feature [name]").description("Generate a feature module (api/, components/, store/, index.ts, server.ts)").option("--api","Generate the api/ layer: schema, DAL, Server Actions, queries").option("--no-api","Skip the api/ layer").option("--store","Generate a client-state slice (Redux or Zustand, whichever the project uses)").option("--no-store","Skip the slice").option("--persist","Persist the Redux slice across reloads").option("--no-persist","Do not persist the slice").option("--path <path>","Base directory (default: src/features)").action(async(t,r)=>{try{let n=process.cwd();l(_.cyan(`
|
|
630
|
+
\u{1F3AF} Feature Generator
|
|
631
|
+
`)),g.start("Detecting project setup...");let o=await T(n);g.succeed("Project setup detected"),l(_.dim(` state: ${o.state} i18n: ${o.hasI18n?"\u2713":"\u2717"} tests: ${o.hasTests?"\u2713":"\u2717"}
|
|
632
|
+
`));let s=await qo(t,o.state,{api:r.api,store:r.store,persist:r.persist});F(s.featureName,"feature name"),r.path&&W(r.path,"path");let i=r.path||_r.join("src","features"),a=te(n,i,s.featureName);await ve(n,s.featureName,i)&&(x(`Feature '${s.featureName}' already exists at ${i}.`),process.exit(1)),g.start("Generating feature files..."),await dr({name:s.featureName,outputPath:a,createStore:s.createStore,persistStore:s.persistStore,createApi:s.createApi,state:o.state,hasI18n:o.hasI18n,hasTests:o.hasTests}),g.succeed("Feature files generated"),o.hasI18n&&await Se(n,$(s.featureName)),s.createApi&&(g.start("Registering API endpoints..."),await ct({serviceName:s.featureName,projectPath:n}),g.succeed("API endpoints registered")),s.createStore&&o.state==="redux"&&(g.start("Registering slice in the store..."),await pt({projectPath:n,name:s.featureName,persist:s.persistStore,importPath:_r.join(i,s.featureName,"store")}),g.succeed("Slice registered")),$c(s,i,o.state)}catch(n){g.fail("Feature generation failed"),x(`${n instanceof Error?n.message:n}`),process.exit(1)}})},$c=(e,t,r)=>{let n=_r.join(t,e.featureName);l(_.green(`
|
|
633
|
+
\u2728 Feature '${e.featureName}' created.
|
|
634
|
+
`)),l(_.dim(` ${n}/`)),e.createApi&&l(_.dim(" api/ schema, keys, server (DAL), actions, queries")),l(_.dim(" components/")),e.createApi||l(_.dim(" hooks/")),e.createStore&&l(_.dim(" store/")),l(_.dim(" types/")),l(_.dim(" index.ts client-safe barrel")),e.createApi&&l(_.dim(" server.ts server-only barrel")),l(""),l(_.cyan("Next:")),e.createApi&&(l(_.dim(` 1. Adjust the contracts in ${n}/api/schema.ts and the paths in src/lib/config/app-apis.ts`)),l(_.dim(` 2. Read in a Server Component: import { list${Jo(e.featureName)}s } from '@/features/${e.featureName}/server'`)),l(_.dim(` 3. Prefetch + hydrate for the client list: prefetchQuery(${Pc(e.featureName)}ListQuery())`))),e.createStore&&r==="zustand"&&l(_.yellow(` ! Compose create${Jo(e.featureName)}Slice into AppState in src/store/index.ts`)),l("")},Pc=e=>e.replace(/-([a-z])/g,(t,r)=>r.toUpperCase()),Jo=$;import Dr from"node:path";import Be from"picocolors";import kc from"enquirer";var{prompt:Sc}=kc,Wo=async e=>e?{hookName:e}:await Sc({type:"input",name:"hookName",message:'Hook name (kebab-case, without "use" prefix):',validate:r=>r?/^[a-z][a-z0-9-]*$/.test(r)?!0:"Use lowercase letters, numbers, and hyphens only":"Hook name is required"});var Ho=e=>{e.command("hook [name]").description("Generate a custom React hook").option("--client","Add 'use client' directive (default: true)",!0).option("--feature <path>","Generate in feature directory (e.g., src/features/auth)").option("--test","Also generate a sibling test file").option("--no-test","Skip test file generation").action(async(t,r)=>{try{let n=process.cwd();l(Be.cyan(`
|
|
635
|
+
\u{1FA9D} Hook Generator
|
|
636
|
+
`));let o=await T(n),s=await Wo(t);F(s.hookName,"hook name"),r.feature&&W(r.feature,"feature path");let a=`use${$(s.hookName)}`,p=Ec(r,o.hasTests);g.start("Generating hook..."),await fr({name:s.hookName,projectPath:n,isClient:r.client??!0,featurePath:r.feature}),g.succeed("Hook generated");let m=r.feature?Dr.join(n,r.feature,"hooks",`${a}.ts`):Dr.join(n,"src/hooks",`${a}.ts`),c=null;p&&(g.start("Generating test..."),c=await re({projectPath:n,sourceFile:m,kind:"hook",symbolName:a,hookUsesStore:o.state!=="none"&&!!r.feature}),g.succeed("Test generated"));let d=r.feature?`${r.feature}/hooks/${a}.ts`:`src/hooks/${a}.ts`;l(Be.green(`
|
|
637
|
+
\u2728 Hook '${a}' created successfully!
|
|
638
|
+
`)),l(Be.dim(` \u{1F4C4} ${d}`)),c&&l(Be.dim(` \u{1F9EA} ${Dr.relative(n,c)}`)),l(""),l(Be.cyan("Usage:"));let u=r.feature?`${r.feature.replace(/^src\//,"@/")}/hooks/${a}`:`@/hooks/${a}`;l(Be.dim(` import { ${a} } from '${u}';`)),l("")}catch(n){g.fail("Hook generation failed"),x(`${n}`),process.exit(1)}})},Ec=(e,t)=>e.test===!1?!1:e.test===!0?!0:t;import Ut from"picocolors";var Ko=e=>{e.command("layout <segment>").description("Generate a nested layout.tsx (locale-aware when i18n is detected)").option("--group","Treat the segment as a route group (wraps it in parens)").option("--at <path>","Place the layout under this nested path (kebab-case, slash-separated)").option("--no-locale","Skip the locale wrapper even if i18n is detected").action(async(t,r)=>{try{let n=process.cwd();l(Ut.cyan(`
|
|
639
|
+
\u{1F4D0} Layout Generator
|
|
640
|
+
`)),g.start("Detecting project setup...");let o=await T(n);g.succeed("Project setup detected");let s=o.hasI18n&&r.locale!==!1;l(Ut.dim(` i18n: ${s?"\u2713":"\u2717"}
|
|
641
|
+
`)),g.start("Generating layout...");let i=await gr({segment:t,at:r.at,projectPath:n,hasI18n:s,withGroup:!!r.group});g.succeed("Layout generated"),l(Ut.green(`
|
|
642
|
+
\u2728 ${i.componentName} created!
|
|
643
|
+
`)),l(Ut.dim(` \u{1F4C4} ${i.displayPath}`)),l("")}catch(n){g.fail("Layout generation failed"),x(`${n instanceof Error?n.message:n}`),process.exit(1)}})};import Y from"picocolors";import Rc from"enquirer";var{prompt:jc}=Rc,Xo=async(e,t={})=>{let r=[];e||r.push({type:"input",name:"code",message:"Locale code (e.g., es, fr, de):",validate:o=>o?/^[a-z]{2}(-[A-Z]{2})?$/.test(o)?!0:"Use format: xx or xx-XX (e.g., es, pt-BR)":"Locale code is required"}),t.name||r.push({type:"input",name:"name",message:"Language name (e.g., Spanish, French):",validate:o=>o?!0:"Language name is required"}),t.country||r.push({type:"input",name:"country",message:"Country (e.g., Spain, France):",validate:o=>o?!0:"Country is required"}),t.flag||r.push({type:"input",name:"flag",message:"Flag emoji (e.g., \u{1F1EA}\u{1F1F8}, \u{1F1EB}\u{1F1F7}):",validate:o=>o?!0:"Flag emoji is required"}),t.copyTranslations===void 0&&r.push({type:"confirm",name:"copyTranslations",message:"Copy translations from English? (No = empty values)",initial:!1});let n=r.length>0?await jc(r):{};return{code:e??n.code,name:t.name??n.name,country:t.country??n.country,flag:t.flag??n.flag,copyTranslations:t.copyTranslations??n.copyTranslations??!1}};var Yo=e=>{e.command("locale [code]").description("Add a new locale/language").option("--copy-translations","Copy translations from English instead of empty values").option("--name <name>","Language name, e.g. Spanish").option("--country <country>","Country, e.g. Spain").option("--flag <emoji>","Flag emoji, e.g. \u{1F1EA}\u{1F1F8}").action(async(t,r)=>{try{let n=process.cwd();l(Y.cyan(`
|
|
644
|
+
\u{1F30D} Locale Generator
|
|
645
|
+
`)),g.start("Detecting project setup...");let o=await T(n);g.succeed("Project setup detected"),o.hasI18n||(g.fail("i18n is not set up in this project"),x("Please set up internationalization first"),l(Y.dim(`
|
|
646
|
+
Run: npx @teispace/next-maker setup --i18n
|
|
647
|
+
`)),process.exit(1));let s=await Xo(t,{copyTranslations:r.copyTranslations,name:r.name,country:r.country,flag:r.flag});F(s.code,"locale code");let i=te(n,"src","i18n","translations",`${s.code}.json`);y(i)&&(x(`Locale '${s.code}' already exists!`),process.exit(1)),g.start("Adding locale..."),await hr({...s,projectPath:n}),g.succeed("Locale added"),l(Y.green(`
|
|
648
|
+
\u2728 Locale '${s.code}' (${s.name}) added successfully!
|
|
649
|
+
`)),l(Y.dim("Updated files:")),l(Y.dim(` \u{1F4C4} src/i18n/translations/${s.code}.json`)),l(Y.dim(" \u{1F4DD} src/types/i18n.ts (SupportedLocale type)")),l(Y.dim(" \u{1F4DD} src/lib/config/app-locales.ts")),l(""),l(Y.cyan("Next steps:")),l(Y.dim(` 1. Translate: src/i18n/translations/${s.code}.json`)),l(Y.dim(` 2. Visit: http://localhost:3000/${s.code}`)),l("")}catch(n){g.fail("Locale generation failed"),x(`${n}`),process.exit(1)}})};import Cc from"node:path";import mt from"picocolors";var Qo=e=>{e.command("options").description("List the starter's options and this project's current values").option("--starter-path <dir>","Read the manifest from a local starter checkout").action(async t=>{let r;try{let n=process.cwd(),o=y(Cc.join(n,".next-maker.json")),s=o?await ee(n):{cli:"",starter:{name:"",version:"",source:""},packageManager:"pnpm",answers:{}},i=await Me(s,{starterPath:t.starterPath});r=i.dispose,l(mt.cyan(`
|
|
650
|
+
${i.manifest.starter.name} ${i.manifest.starter.version}
|
|
651
|
+
`));for(let[a,p]of Object.entries(i.manifest.options)){let m=o?s.answers[a]:p.default,c=p.type==="boolean"?"true | false":(p.values??[]).join(" | ");l(` ${mt.bold(a.padEnd(18))} ${String(Array.isArray(m)?m.join(",")||"none":m).padEnd(10)} ${mt.dim(c)}`),p.label&&l(` ${"".padEnd(18)} ${mt.dim(p.label)}`)}l(""),l(mt.dim(o?"Change with: next-maker setup --set <option>=<value>":"Use with: next-maker init --set <option>=<value>")),l("")}catch(n){x(`${n instanceof Error?n.message:n}`),process.exit(1)}finally{await r?.()}})};import Lr from"node:path";import V from"picocolors";import Tc from"enquirer";var{prompt:Oc}=Tc,Zo=async(e,t={})=>{let r=[];e||r.push({type:"input",name:"pageName",message:"Page name (kebab-case):",validate:o=>o?/^[a-z][a-z0-9-]*$/.test(o)?!0:"Use lowercase letters, numbers, and hyphens only":"Page name is required"}),t.loading===void 0&&r.push({type:"confirm",name:"withLoading",message:"Generate loading.tsx?",initial:!0}),t.error===void 0&&r.push({type:"confirm",name:"withError",message:"Generate error.tsx?",initial:!0});let n=r.length>0?await Oc(r):{};return{pageName:e??n.pageName,withLoading:t.loading??n.withLoading??!0,withError:t.error??n.withError??!0}};var es=e=>{e.command("page [name]").description("Generate a new page/route").option("--dynamic <param>","Create dynamic route with parameter (e.g., id)").option("--group <name>","Route group to place the page in, e.g. app or marketing").option("--loading","Generate loading.tsx").option("--no-loading","Skip loading.tsx").option("--error","Generate error.tsx").option("--no-error","Skip error.tsx").action(async(t,r)=>{try{let n=process.cwd();l(V.cyan(`
|
|
652
|
+
\u{1F4C4} Page Generator
|
|
653
|
+
`)),g.start("Detecting project setup...");let o=await T(n);g.succeed("Project setup detected"),l(V.dim(` i18n: ${o.hasI18n?"\u2713":"\u2717"}
|
|
654
|
+
`));let s=await Zo(t,{loading:r.loading,error:r.error}),i=s.pageName;F(i,"page name"),r.dynamic&&F(r.dynamic,"dynamic param"),r.group&&F(r.group,"route group");let a=$(i),p=Lr.join(o.hasI18n?"src/app/[locale]":"src/app",r.group?`(${r.group})`:"");await ve(n,i,p)&&(x(`Page '${i}' already exists at ${p}/${i}!`),process.exit(1)),g.start("Generating page files..."),await wr({name:i,projectPath:n,hasI18n:o.hasI18n,group:r.group,dynamic:r.dynamic,withLoading:r.loading??s.withLoading,withError:r.error??s.withError}),g.succeed("Page files generated"),g.start("Registering route...");let c=r.dynamic?`/${i}/[${r.dynamic}]`:`/${i}`;await kr(n,i,c),g.succeed("Route registered"),o.hasI18n&&(g.start("Adding translation namespace..."),await Se(n,a),g.succeed("Translation namespace added"));let d=r.dynamic?Lr.join(p,i,`[${r.dynamic}]`):Lr.join(p,i);l(V.green(`
|
|
655
|
+
\u2728 Page '${i}' created successfully!
|
|
656
|
+
`)),l(V.dim("Generated files:")),l(V.dim(` \u{1F4C2} ${d}/`)),l(V.dim(" \u251C\u2500\u2500 page.tsx")),(r.loading??s.withLoading)&&l(V.dim(" \u251C\u2500\u2500 loading.tsx")),(r.error??s.withError)&&l(V.dim(" \u2514\u2500\u2500 error.tsx")),l(""),o.hasI18n&&(l(V.cyan("Next steps:")),l(V.dim(` 1. Add translations in: src/i18n/translations/en.json \u2192 "${a}"`)),l(V.dim(` 2. Visit: http://localhost:3000/${i}`)),l(""))}catch(n){g.fail("Page generation failed"),x(`${n}`),process.exit(1)}})};import Ur from"node:path";import ue from"picocolors";var ts=e=>{e.command("provider <name>").description("Generate a context provider in src/providers/ and wire it into RootProvider").action(async t=>{try{let r=process.cwd();l(ue.cyan(`
|
|
657
|
+
\u{1F50C} Provider Generator
|
|
658
|
+
`)),g.start("Generating provider...");let{componentName:n,fileBaseName:o,providerFile:s}=await br({name:t,projectPath:r});g.succeed("Provider generated"),g.start("Registering provider in RootProvider and barrel...");let{rootProviderFile:i,barrelFile:a}=await jr({projectPath:r,componentName:n,fileBaseName:o});g.succeed("Provider registered"),l(ue.green(`
|
|
659
|
+
\u2728 ${n} created!
|
|
660
|
+
`)),l(ue.dim("Generated files:")),l(ue.dim(` \u{1F4C4} ${Ur.relative(r,s)}`)),i?l(ue.dim(` \u270F\uFE0F ${Ur.relative(r,i)} \u2014 wrapped {children}`)):(l(ue.yellow(`
|
|
661
|
+
\u26A0\uFE0F Could not locate a RootProvider file. Wire the new provider manually:`)),l(ue.dim(` <${n}>{children}</${n}>`))),a&&l(ue.dim(` \u270F\uFE0F ${Ur.relative(r,a)} \u2014 added re-export`)),l("")}catch(r){g.fail("Provider generation failed"),x(`${r instanceof Error?r.message:r}`),process.exit(1)}})};import Ac from"picocolors";var rs=e=>{e.command("remove <feature>").alias("uninstall").description("Turn a boolean starter feature off (shorthand for `setup --set <feature>=false`)").option("-y, --yes","Skip the confirmation prompt").option("--dry-run","Print the plan without writing").option("--no-install","Skip dependency installation after the change").action(async(t,r)=>{try{let n=["setup","--set",`${t}=false`];r.yes&&n.push("--yes"),r.dryRun&&n.push("--dry-run"),r.install===!1&&n.push("--no-install"),await e.parseAsync([process.argv[0],process.argv[1],...n])}catch(n){x(`${n instanceof Error?n.message:n}`),process.exit(1)}}).addHelpText("after",`
|
|
662
|
+
${Ac.dim("Example: next-maker remove ws")}
|
|
663
|
+
`)};import Gr from"node:path";import Br from"picocolors";var ns=e=>{e.command("api [name]").alias("service").description("Generate api/{schema,keys,server,queries,actions}.ts for a resource inside a feature").option("--feature <path>","Feature directory (default: src/features/<name>)").option("--no-actions","Skip actions.ts (read-only resource)").action(async(t,r)=>{try{let n=process.cwd();if(l(Br.cyan(`
|
|
664
|
+
\u{1F50C} API Layer Generator
|
|
665
|
+
`)),!t)throw new Error("Pass the resource name, e.g. `next-maker api invoice`.");F(t,"resource name"),r.feature&&W(r.feature,"feature path");let o=await T(n);if(!o.hasQuery||!o.hasActions)throw new Error("This generator needs @tanstack/react-query and next-safe-action (starter 2.x).");let s=r.feature?te(n,r.feature):te(n,"src","features",t);if(y(Gr.join(s,"api","schema.ts")))throw new Error(`${Gr.relative(n,s)}/api already exists.`);g.start("Generating api/ files...");let i=await nt({name:t,featurePath:s,withActions:r.actions!==!1});g.succeed("api/ generated"),g.start("Registering API endpoints..."),await ct({serviceName:t,projectPath:n}),g.succeed("Endpoints registered in src/lib/config/app-apis.ts"),l(Br.green(`
|
|
666
|
+
\u2728 ${Gr.relative(n,s)}/api ready.
|
|
667
|
+
`));for(let a of i)l(Br.dim(` ${a}`));l("")}catch(n){g.fail("API generation failed"),x(`${n instanceof Error?n.message:n}`),process.exit(1)}})};import Xc from"enquirer";import q from"picocolors";import{execFile as Ic}from"node:child_process";import{cp as gh,mkdir as is,readFile as Nc,rm as as,stat as hh,writeFile as Gt}from"node:fs/promises";import Q from"node:path";import{promisify as Fc}from"node:util";var Mc=Fc(Ic),_c=new Set(["pnpm-lock.yaml","package-lock.json","yarn.lock","bun.lock","bun.lockb",".env",".next-maker.json","next-env.d.ts","tsconfig.tsbuildinfo"]),Dc=e=>_c.has(e)||e.startsWith(".env.")||e.endsWith(".log"),Lc=new Set([".png",".jpg",".jpeg",".gif",".webp",".avif",".ico",".woff",".woff2",".ttf",".otf",".pdf",".zip",".gz"]),Vr=(e,t)=>Lc.has(Q.extname(e))||t.subarray(0,8e3).includes(0),qr=async e=>{try{return await Nc(e)}catch{return null}},dt=async(e,t,r)=>{r||(await is(Q.dirname(e),{recursive:!0}),await Gt(e,t))},os=async(e,t,r,n={ours:"project",base:"starter (previous)",theirs:"starter (new)"})=>{let o=Q.join(process.env.TMPDIR??"/tmp",`next-maker-merge-${process.pid}-${Math.random().toString(36).slice(2)}`);await is(o,{recursive:!0});try{await Gt(Q.join(o,"ours"),e),await Gt(Q.join(o,"base"),t),await Gt(Q.join(o,"theirs"),r);try{let{stdout:s}=await Mc("git",["merge-file","-p","-L",n.ours,"-L",n.base,"-L",n.theirs,"ours","base","theirs"],{cwd:o,maxBuffer:67108864});return{content:s,conflicts:0}}catch(s){let i=s;if(typeof i.code=="number"&&i.code>0&&i.code<128&&typeof i.stdout=="string")return{content:i.stdout,conflicts:i.code};throw i.code==="ENOENT"?new Error("git is required for merges but was not found on PATH."):s}}finally{await as(o,{recursive:!0,force:!0})}},ss=["scripts","dependencies","devDependencies","peerDependencies","optionalDependencies","engines"],Uc=(e,t,r)=>{let n=structuredClone(e),o=[],s=(a,p)=>JSON.stringify(a)===JSON.stringify(p),i=(a,p,m,c,d,u)=>{let f=m[d],h=c[d],w=p[d];if(!s(f,h)){if(s(w,f)||s(w,h)){h===void 0?delete a[d]:a[d]=h;return}o.push(u)}};for(let a of ss){let p=t[a]??{},m=r[a]??{},c=e[a]??{};n[a]||(n[a]={});let d=n[a];for(let u of new Set([...Object.keys(p),...Object.keys(m)]))i(d,c,p,m,u,`${a}.${u}`);Object.keys(d).length===0&&!(a in r)?delete n[a]:a!=="scripts"&&a!=="engines"&&(n[a]=Object.fromEntries(Object.entries(d).sort(([u],[f])=>u.localeCompare(f))))}for(let a of new Set([...Object.keys(t),...Object.keys(r)]))ss.includes(a)||i(n,e,t,r,a,a);return{result:n,conflicts:o}},Ve=async({base:e,theirs:t,ours:r},n={})=>{let o=n.dryRun??!1,s=n.skip??Dc,[i,a,p]=await Promise.all([L(e),L(t),L(r)]),m=new Set(p),c=new Set(i),d=new Set(a),u={entries:[],conflicts:[]},f=(h,w,P)=>{u.entries.push({file:h,outcome:w,note:P}),w==="conflict"&&u.conflicts.push(h)};for(let h of[...new Set([...i,...a])].sort()){if(s(h))continue;let w=c.has(h),P=d.has(h),b=m.has(h),[S,R,D]=await Promise.all([w?qr(Q.join(e,h)):null,P?qr(Q.join(t,h)):null,b?qr(Q.join(r,h)):null]),Ce=Q.join(r,h);if(P&&!w){if(!b)await dt(Ce,R,o),f(h,"added");else if(D.equals(R))f(h,"unchanged");else if(Vr(h,R))f(h,"kept","starter added a binary the project also has");else{let ut=await os(D.toString("utf8"),"",R.toString("utf8"));await dt(Ce,ut.content,o),f(h,ut.conflicts?"conflict":"merged")}continue}if(w&&!P){if(!b)continue;D.equals(S)?(o||await as(Ce,{force:!0}),f(h,"deleted")):f(h,"kept","starter removed it, but the project changed it");continue}if(!b){f(h,"kept","deleted in the project");continue}if(S.equals(R)||D.equals(R)){f(h,"unchanged");continue}if(D.equals(S)){await dt(Ce,R,o),f(h,"updated");continue}if(Vr(h,D)||Vr(h,R)){f(h,"kept","binary changed on both sides");continue}if(h==="package.json"){let{result:ut,conflicts:ft}=Uc(JSON.parse(D.toString("utf8")),JSON.parse(S.toString("utf8")),JSON.parse(R.toString("utf8")));await dt(Ce,`${JSON.stringify(ut,null,2)}
|
|
668
|
+
`,o),f(h,ft.length?"conflict":"merged",ft.length?`project kept: ${ft.join(", ")}`:void 0),ft.length&&u.conflicts.pop();continue}let Kr=await os(D.toString("utf8"),S.toString("utf8"),R.toString("utf8"));await dt(Ce,Kr.content,o),f(h,Kr.conflicts?"conflict":"merged")}return u};import{execFile as Gc}from"node:child_process";import{mkdtemp as Bc,readFile as Vc,rm as cs}from"node:fs/promises";import{tmpdir as qc}from"node:os";import oe from"node:path";import{promisify as Jc}from"node:util";var zc=Jc(Gc),Bt=async(e,t)=>{if(t.identity)return le(t.identity.projectName,{...t.identity,copyEnv:!1});let r=JSON.parse(await Vc(oe.join(e,"package.json"),"utf-8"));return le(oe.basename(e),{projectName:r.name??oe.basename(e),description:r.description,author:typeof r.author=="string"?r.author:void 0,version:r.version,readme:y(oe.join(e,"README.md")),copyEnv:!1})},ps=e=>{let t=e.starter.source;if(t.startsWith("/")||t.startsWith(".")){if(!y(t))throw new Error(`The starter this project was generated from is a local path that no longer exists (${t}). Pass --from <ref|dir>.`);return{kind:"local",location:oe.resolve(t)}}return{kind:"remote",location:t}},Jr=e=>e.startsWith("/")||e.startsWith(".")||y(e)?{kind:"local",location:oe.resolve(e)}:B({ref:e.includes("#")?e.split("#")[1]:e,starterPath:void 0}),qe=async(e,t,r,n,o)=>{let s=await Bc(oe.join(qc(),"next-maker-ref-")),i=oe.join(s,r.projectName);try{let a=await xe({projectPath:i,source:e,supplied:t,packageManager:n});await be(i,r,a,e);let p=o?oe.join(o,"node_modules",".bin","biome"):void 0;if(p&&y(p))try{await zc(p,["check","--write","--no-errors-on-unmatched","."],{cwd:i,maxBuffer:64*1024*1024})}catch{}return{dir:i,scaffold:a,dispose:()=>cs(s,{recursive:!0,force:!0})}}catch(a){throw await cs(s,{recursive:!0,force:!0}),a}};import Wc from"enquirer";import E from"picocolors";var{prompt:Hc}=Wc,Kc={added:E.green("+"),updated:E.cyan("\u2191"),merged:E.cyan("\u21C4"),deleted:E.red("-"),conflict:E.red("\u2717"),kept:E.yellow("\xB7"),skipped:E.dim("\xB7")},zr=e=>{let t=e.entries.filter(n=>n.outcome!=="unchanged");if(t.length===0){l(E.dim(" no file changes"));return}for(let n of t)l(` ${Kc[n.outcome]??" "} ${n.outcome.padEnd(8)} ${n.file}${n.note?E.dim(` (${n.note})`):""}`);let r={};for(let n of t)r[n.outcome]=(r[n.outcome]??0)+1;if(l(""),l(E.dim(` ${Object.entries(r).map(([n,o])=>`${o} ${n}`).join(", ")}`)),e.conflicts.length){l(""),l(E.red(` ${e.conflicts.length} file(s) need attention; look for <<<<<<< markers:`));for(let n of e.conflicts)l(E.red(` ${n}`))}},ls=e=>{e.command("upgrade").description(`Merge starter changes into this project (default target: ${Pt})`).option("--to <ref|dir>","Starter tag or local checkout to upgrade to").option("--from <ref|dir>","Starter the project was generated from (default: recorded at init)").option("--starter-path <dir>","Alias for --to with a local checkout").option("-y, --yes","Skip the confirmation prompt").option("--dry-run","Report what would change without writing").option("--no-install","Skip dependency installation afterwards").action(async t=>{let r=process.cwd(),n=[];try{let o=await ee(r),s=await Bt(r,o),i=t.from?Jr(t.from):ps(o),a=t.to?Jr(t.to):B({starterPath:t.starterPath,ref:Pt});if(i.location===a.location){l(E.dim(`Already on ${a.location}; nothing to upgrade.`));return}l(E.cyan(`
|
|
669
|
+
\u2B06 Upgrade
|
|
670
|
+
`)),l(` ${E.dim("from")} ${i.location}`),l(` ${E.dim("to ")} ${a.location}
|
|
671
|
+
`);let p=await qe(i,o.answers,s,o.packageManager,r);n.push(p.dispose);let m=await qe(a,o.answers,s,o.packageManager,r);n.push(m.dispose);for(let u of m.scaffold.forced)l(E.yellow(` ! ${u.reason}; ${u.option} turned off`));for(let u of m.scaffold.unknown)l(E.yellow(` ! option "${u}" no longer exists in the new starter`));let c=await Ve({base:p.dir,theirs:m.dir,ours:r},{dryRun:!0});if(zr(c),t.dryRun){l(E.dim(`
|
|
672
|
+
Dry run: nothing was written.
|
|
673
|
+
`));return}if(!t.yes){let{confirm:u}=await Hc({type:"confirm",name:"confirm",message:"Apply these changes?",initial:!1});if(!u){l(E.yellow(`Aborted.
|
|
674
|
+
`));return}}let d=await Ve({base:p.dir,theirs:m.dir,ours:r});await me(r,{...o,cli:Te.version,starter:{...m.scaffold.manifest.starter,source:a.location},answers:m.scaffold.answers,identity:o.identity??{projectName:s.projectName,description:s.description,author:s.author,version:s.version,email:s.email,gitRemote:s.gitRemote,readme:s.readme}}),t.install!==!1&&(l(E.dim(`
|
|
675
|
+
Installing with ${o.packageManager}...`)),await pe(r,o.packageManager)),l(E.green(`
|
|
676
|
+
\u2713 Upgraded to ${m.scaffold.manifest.starter.version}.`)),d.conflicts.length?l(E.yellow(" Resolve the conflicts above, then run `next-maker doctor --compile`.")):l(E.dim(" Run `next-maker doctor --compile` to confirm.")),l("")}catch(o){x(`${o instanceof Error?o.message:o}`),process.exit(1)}finally{for(let o of n)await o()}})};var{prompt:Yc}=Xc,Qc=(e,t=[])=>[...t,e],ms=e=>{e.command("setup").description("Turn starter features on or off in an existing project (e.g. --set ws=true)").option("--set <key=value>","Option to change (repeatable), e.g. --set i18n=false --set state=zustand",Qc).option("-y, --yes","Skip the confirmation prompt").option("--dry-run","Print the plan without writing").option("--no-install","Skip dependency installation after the change").option("--starter-path <dir>","Use a local starter checkout").action(async t=>{let r=process.cwd(),n=[];try{let o=await ee(r),s=ye(t.set);if(Object.keys(s).length===0)throw new Error("Nothing to change. Pass at least one --set key=value (run `next-maker options` to list them).");let i=await Me(o,{starterPath:t.starterPath});n.push(i.dispose);let{answers:a,forced:p,unknown:m}=Ke(i.manifest,{...o.answers,...s});for(let P of m)l(q.yellow(` ! unknown option "${P}" ignored`));for(let P of p)l(q.yellow(` ! ${P.reason}; ${P.option} turned off`));let c=Object.keys(a).filter(P=>JSON.stringify(a[P])!==JSON.stringify(o.answers[P]));if(l(q.cyan(`
|
|
677
|
+
\u{1F527} Setup
|
|
678
|
+
`)),c.length===0){l(q.dim(`No option changes; the project already has these values.
|
|
679
|
+
`));return}for(let P of c)l(` ${q.dim(P.padEnd(18))} ${String(o.answers[P])} ${q.dim("\u2192")} ${String(a[P])}`);l("");let d=await Bt(r,o),u=await qe(i.source,o.answers,d,o.packageManager,r);n.push(u.dispose);let f=await qe(i.source,a,d,o.packageManager,r);n.push(f.dispose);let h=await Ve({base:u.dir,theirs:f.dir,ours:r},{dryRun:!0});if(zr(h),t.dryRun){l(q.dim(`
|
|
680
|
+
Dry run: nothing was written.
|
|
681
|
+
`));return}if(!t.yes){let{confirm:P}=await Yc({type:"confirm",name:"confirm",message:"Apply these changes?",initial:!1});if(!P){l(q.yellow(`Aborted.
|
|
682
|
+
`));return}}let w=await Ve({base:u.dir,theirs:f.dir,ours:r});await me(r,{...o,answers:a}),t.install!==!1&&(l(q.dim(`
|
|
683
|
+
Installing with ${o.packageManager}...`)),await pe(r,o.packageManager)),l(q.green(`
|
|
684
|
+
\u2713 Applied.`)),w.conflicts.length&&l(q.yellow(" Resolve the conflicts above, then run `next-maker doctor --compile`.")),l("")}catch(o){x(`${o instanceof Error?o.message:o}`),process.exit(1)}finally{for(let o of n)await o()}})};import Wr from"node:path";import Vt from"picocolors";import Zc from"enquirer";var{prompt:ep}=Zc,ds=async(e,t)=>{let r=[];e||r.push({type:"input",name:"sliceName",message:"What is the slice name?",initial:"my-slice",validate:o=>/^[a-z0-9-]+$/.test(o)?!0:"Slice name must be lowercase and contain only alphanumeric characters and hyphens."}),t===void 0&&r.push({type:"confirm",name:"persistSlice",message:"Enable persistence for this slice?",initial:!1});let n=r.length>0?await ep(r):{};return{sliceName:e||n.sliceName,persistSlice:t===void 0?n.persistSlice||!1:t}};var us=e=>{e.command("slice [name]").description("Generate a store slice (Redux or Zustand, whichever the project uses)").option("--path <path>","Directory for the slice (default: src/store/slices/<name>)").option("--persist","Persist the slice across reloads (Redux)").option("--no-persist","Do not persist the slice").option("--test","Also generate a sibling test file (Redux)").option("--no-test","Skip test file generation").action(async(t,r)=>{try{let n=process.cwd();l(Vt.cyan(`
|
|
685
|
+
\u{1F527} Slice Generator
|
|
686
|
+
`)),g.start("Detecting project setup...");let o=await T(n);if(g.succeed("Project setup detected"),o.state==="none")throw new Error("This project has no client store. Re-run init with a state store, or add one with `next-maker setup --set state=redux`.");l(Vt.dim(` state: ${o.state}
|
|
687
|
+
`));let s=await ds(t,o.state==="zustand"?!1:r.persist);F(s.sliceName,"slice name"),r.path&&W(r.path,"path");let i=r.path??Wr.join("src","store","slices"),a=te(n,i,s.sliceName);if(await ve(n,s.sliceName,i))throw new Error(`Slice '${s.sliceName}' already exists at ${i}.`);g.start("Generating slice files..."),await ot({name:s.sliceName,outputPath:a,persist:s.persistSlice,state:o.state}),g.succeed("Slice files generated"),o.state==="redux"&&(g.start("Registering slice in the store..."),await pt({projectPath:n,name:s.sliceName,persist:s.persistSlice,importPath:Wr.join(i,s.sliceName)}),g.succeed("Slice registered"),(r.test??o.hasTests)&&(g.start("Generating test..."),await re({projectPath:n,sourceFile:Wr.join(a,`${s.sliceName}.slice.ts`),kind:"slice",symbolName:s.sliceName.replace(/-([a-z])/g,(p,m)=>m.toUpperCase())}),g.succeed("Test generated"))),l(Vt.green(`
|
|
688
|
+
\u2728 Slice '${s.sliceName}' created in ${i}/${s.sliceName}/.
|
|
689
|
+
`)),o.state==="zustand"&&(l(Vt.yellow(` ! Compose create${$(s.sliceName)}Slice into AppState in src/store/index.ts`)),l(""))}catch(n){g.fail("Slice generation failed"),x(`${n instanceof Error?n.message:n}`),process.exit(1)}})};import J from"node:path";import Hr from"picocolors";var fs=e=>{e.command("test <file>").description(`Generate a sibling test file for an existing component, hook, or slice.
|
|
690
|
+
Infers the kind from filename/content; pass --kind to override.`).option("--kind <kind>","Override inferred kind: component | hook | slice").option("--force","Overwrite an existing test file").action(async(t,r)=>{try{let n=process.cwd(),o=J.isAbsolute(t)?t:J.join(n,t);l(Hr.cyan(`
|
|
691
|
+
\u{1F9EA} Test Generator
|
|
692
|
+
`)),y(o)||(x(`Source file not found: ${t}`),process.exit(1));let s=await T(n);s.hasTests||(x("Testing is not installed in this project. Run `next-maker setup --tests` first."),process.exit(1));let i=await j(o),a=tp(r.kind)??rp(o,i);a||(x(`Could not infer test kind for ${J.basename(o)}. Pass --kind component|hook|slice.`),process.exit(1));let p=np(o,a),m=op(o,a);y(m)&&!r.force&&(x(`Test file already exists: ${J.relative(n,m)}. Use --force to overwrite.`),process.exit(1)),g.start(`Generating ${a} test...`);let c=await re({projectPath:n,sourceFile:o,kind:a,symbolName:p,hasState:s.state!=="none",hasI18n:s.hasI18n,hookUsesStore:a==="hook"&&s.state!=="none"&&i.includes("useAppSelector")});g.succeed("Test generated"),l(Hr.green(`
|
|
693
|
+
\u2728 Test '${J.basename(c)}' created.
|
|
694
|
+
`)),l(Hr.dim(` \u{1F9EA} ${J.relative(n,c)}`)),l("")}catch(n){g.fail("Test generation failed"),x(`${n}`),process.exit(1)}})},tp=e=>{if(!e)return null;if(e==="component"||e==="hook"||e==="slice")return e;throw new Error(`Invalid --kind: ${e}. Use component | hook | slice.`)},rp=(e,t)=>{let r=J.basename(e);return/\.slice\.ts$/.test(r)?"slice":/^use[A-Z]/.test(r.replace(/\.tsx?$/,""))?"hook":r.endsWith(".tsx")?"component":/createSlice\s*\(/.test(t)?"slice":/^export\s+(const|function)\s+use[A-Z]/m.test(t)?"hook":null},np=(e,t)=>{let r=J.basename(e).replace(/\.(tsx?|jsx?)$/i,"");return t==="slice"?U(r.replace(/\.slice$/,"")):t==="hook"?/^use[A-Z]/.test(r)?r:`use${$(r.replace(/^use-?/,""))}`:$(r)},op=(e,t)=>{let r=J.dirname(e),n=J.basename(e).replace(/\.(tsx?|jsx?)$/i,""),o=t==="component"?".tsx":".ts";return J.join(r,`${n}.test${o}`)};import{chmod as sp,cp as ip,mkdir as qt,readFile as Jt,rm as ap,writeFile as I}from"node:fs/promises";import v from"node:path";import fe from"picocolors";var gs=e=>{let t={"@biomejs/biome":e.biomeVersion,turbo:e.turboVersion};e.hooks&&(e.huskyVersion&&(t.husky=e.huskyVersion),e.lintStagedVersion&&(t["lint-staged"]=e.lintStagedVersion),e.commitlintCliVersion&&(t["@commitlint/cli"]=e.commitlintCliVersion),e.commitlintConfigVersion&&(t["@commitlint/config-conventional"]=e.commitlintConfigVersion));let r={name:e.name,version:"0.1.0",description:e.description,author:e.author,private:!0,type:"module",packageManager:e.packageManagerPin,engines:{node:e.nodeEngine,pnpm:">=11.0.0"},scripts:{dev:"turbo run dev",build:"turbo run build",start:"turbo run start",lint:"turbo run lint","lint:fix":"biome check --write . && turbo run lint:fix","ci:check":"biome ci . && turbo run ci:check","type-check":"turbo run type-check","check:deprecated":"turbo run check:deprecated",test:"turbo run test","test:e2e":"turbo run test:e2e",validate:"pnpm ci:check && pnpm type-check && pnpm check:deprecated && pnpm test && pnpm build",...e.hooks?{prepare:"husky","lint-staged":"lint-staged"}:{}},devDependencies:Object.fromEntries(Object.entries(t).sort())};return`${JSON.stringify(r,null,2)}
|
|
695
|
+
`},hs=e=>`packages:
|
|
696
|
+
- 'apps/*'
|
|
697
|
+
- 'packages/*'
|
|
698
|
+
|
|
699
|
+
${e.split(`
|
|
700
|
+
`).filter(r=>!r.startsWith("packages:")&&!r.startsWith("# Single-package")&&!r.startsWith("# Monorepo mode")).join(`
|
|
868
701
|
`).trim()}
|
|
869
|
-
`,
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
${s}
|
|
903
|
-
</NextIntlClientProvider>
|
|
904
|
-
);`)}}await h(t,r)}},Uo=async e=>{let t=he.join(e,a.ROOT_LAYOUT),r=he.join(e,a.ROOT_PAGE),i=he.join(e,"src/app/[locale]");if(await pl.mkdir(i,{recursive:!0}),l(t)){let n=he.join(i,"layout.tsx"),o=await g(t);if(o.includes("next-intl")||(o=`import { routing } from '@/i18n/routing';
|
|
905
|
-
import { hasLocale } from 'next-intl';
|
|
906
|
-
import { notFound } from 'next/navigation';
|
|
907
|
-
import { getMessages, getTimeZone, setRequestLocale } from 'next-intl/server';
|
|
908
|
-
import { getLocaleDirection } from '@/lib/config/app-locales';
|
|
909
|
-
${o}`),!o.includes("generateStaticParams")){let p=o.indexOf("};",o.indexOf("export const metadata"));if(p!==-1){let u=p+2;o=o.slice(0,u)+`
|
|
910
|
-
|
|
911
|
-
export function generateStaticParams() {
|
|
912
|
-
return routing.locales.map((locale) => ({ locale }));
|
|
913
|
-
}`+o.slice(u)}}o=o.replace(/Readonly<\{\s*children:\s*React\.ReactNode;\s*}>/,`Readonly<{
|
|
914
|
-
children: React.ReactNode;
|
|
915
|
-
params: Promise<{ locale: string }>;
|
|
916
|
-
}>`);let s=/export default (async )?function RootLayout\(\{\s*children,?\s*\}\s*:/,c=o.match(s);if(c){c[1]||(o=o.replace("export default function","export default async function")),o=o.replace(/export default (async )?function RootLayout\(\{\s*children,?\s*\}\s*:/,"export default async function RootLayout({ children, params }:");let u=/export default async function RootLayout[\s\S]*?\)\s*\{/,d=o.match(u);if(d&&d.index!==void 0){let f=d.index+d[0].length-1;o=o.slice(0,f+1)+`
|
|
917
|
-
const { locale } = await params;
|
|
918
|
-
|
|
919
|
-
if (!hasLocale(routing.locales, locale)) {
|
|
920
|
-
notFound();
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
setRequestLocale(locale);
|
|
702
|
+
`,ys=()=>`${JSON.stringify({$schema:"https://turborepo.com/schema.json",ui:"tui",globalEnv:["NODE_ENV","CI"],globalPassThroughEnv:["NEXT_PUBLIC_*","API_INTERNAL_URL","CSP_MODE","BUILD_STANDALONE","DEFAULT_TIMEZONE","DEFAULT_LOCALE","NEXT_TELEMETRY_DISABLED"],tasks:{build:{dependsOn:["^build"],inputs:["$TURBO_DEFAULT$",".env.production",".env"],outputs:[".next/**","!.next/cache/**"]},dev:{cache:!1,persistent:!0},start:{cache:!1,persistent:!0,dependsOn:["build"]},lint:{},"lint:fix":{cache:!1},"ci:check":{},"type-check":{dependsOn:["^build"]},"check:deprecated":{dependsOn:["^build"]},test:{dependsOn:["^build"],outputs:["coverage/**"]},"test:e2e":{dependsOn:["build"],cache:!1}}},null,2)}
|
|
703
|
+
`,ws=e=>`${JSON.stringify({$schema:`https://biomejs.dev/schemas/${e.replace(/^[\^~]/,"")}/schema.json`,vcs:{enabled:!0,clientKind:"git",useIgnoreFile:!0},files:{includes:["*.json","*.mjs","*.ts",".github/**","!apps","!packages"]},formatter:{enabled:!0,indentStyle:"space",indentWidth:2,lineWidth:100,lineEnding:"lf"},javascript:{formatter:{quoteStyle:"single",semicolons:"always",trailingCommas:"all"}},json:{formatter:{trailingCommas:"none"}},linter:{enabled:!0,rules:{preset:"recommended"}}},null,2)}
|
|
704
|
+
`,xs=()=>`# dependencies
|
|
705
|
+
node_modules
|
|
706
|
+
.pnpm-store
|
|
707
|
+
|
|
708
|
+
# turborepo
|
|
709
|
+
.turbo
|
|
710
|
+
|
|
711
|
+
# build and test output
|
|
712
|
+
.next
|
|
713
|
+
out
|
|
714
|
+
coverage
|
|
715
|
+
test-results
|
|
716
|
+
playwright-report
|
|
717
|
+
.vitest
|
|
718
|
+
*.tsbuildinfo
|
|
719
|
+
next-env.d.ts
|
|
720
|
+
|
|
721
|
+
# env
|
|
722
|
+
.env
|
|
723
|
+
.env.*.local
|
|
724
|
+
|
|
725
|
+
# misc
|
|
726
|
+
.DS_Store
|
|
727
|
+
*.pem
|
|
728
|
+
npm-debug.log*
|
|
729
|
+
.pnpm-debug.log*
|
|
730
|
+
`,bs=(e,t)=>`# ${e.name}
|
|
731
|
+
|
|
732
|
+
${e.description}
|
|
733
|
+
|
|
734
|
+
A pnpm + Turborepo workspace. Each app under \`apps/\` was generated from [@teispace/nextjs-starter](https://github.com/teispace/nextjs-starter) ${t} with \`@teispace/next-maker\`; shared code goes under \`packages/\`.
|
|
924
735
|
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
${
|
|
929
|
-
params: Promise<{ locale: string }>;
|
|
930
|
-
};
|
|
931
|
-
|
|
932
|
-
export default async function Home(props: Props)`);let s=o.indexOf("export default async function Home(props: Props) {");if(s!==-1){let c=`
|
|
933
|
-
const locale = (await props.params).locale as SupportedLocale;
|
|
934
|
-
setRequestLocale(locale);
|
|
935
|
-
`,p=o.indexOf("{",s);o=o.slice(0,p+1)+c+o.slice(p+1)}await h(n,o),await C(r)}};var mr=async e=>{let t=S("Setting up Internationalization (next-intl)..."),r=pi.join(e,".next-maker-temp-i18n");try{let{isSetup:i,reason:n}=await Go(e);if(i){t.fail(`i18n is already set up (${n}).`);return}await Ho(e),await Lo(r,t),t.text="Copying i18n files...",await Mo(e,r),t.text="Configuring project structure...",await ar(e),await cr(e),await pr(e),await lr(e),t.text="Migrating to [locale] structure...",await Uo(e),t.text="Installing dependencies...",await z(e,"next-intl");let o=pi.join(e,a.VITEST_CONFIG);if(l(o)){let c=JSON.parse(await g(pi.join(e,a.PACKAGE_JSON))),p={...c.dependencies,...c.devDependencies},u=!!(p["@reduxjs/toolkit"]&&p["react-redux"]);await ce(e,{redux:u,i18n:!0})}t.text="Formatting code...";let s=await A(e);await K(e,s,"lint:fix"),t.succeed(ll.green("Internationalization setup successfully!"))}catch(i){throw t.fail("Failed to setup Internationalization."),i}finally{await v(r)}};P();import ml from"node:fs/promises";import Pt from"node:path";import Bo from"picocolors";w();var dl="src/providers/RootProvider.tsx",zo=async(e,t)=>{let r=S("Repairing Internationalization..."),i=Pt.join(e,".next-maker-temp-i18n-repair");try{let n=Pt.join(e,a.I18N_DIR),o=Pt.join(e,a.PROXY),s=F(t,a.I18N_DIR)&&!l(n),c=F(t,a.PROXY)&&!l(o),p=[];(s||c)&&(r.text="Fetching assets from starter repo...",await te(i,async x=>{s&&(await ml.cp(Pt.join(x,a.I18N_DIR),n,{recursive:!0}),p.push(a.I18N_DIR)),c&&(await b(Pt.join(x,a.PROXY),o),p.push(a.PROXY))})),U(t,a.NEXT_CONFIG)&&(r.text="Restoring the next-intl plugin wrap...",await ar(e),p.push("createNextIntlPlugin wrap")),U(t,dl)&&(r.text="Restoring <NextIntlClientProvider>...",await lr(e),p.push("<NextIntlClientProvider> wrap")),p.length>0&&(await cr(e),await pr(e)),r.text="Restoring dependencies...";let u=await B(e,t),d=F(t,a.LOCALE_DIR),f=[p.length>0?`restored ${p.join(", ")}`:null,u.length>0?`reinstalled ${u.join(", ")}`:null].filter(Boolean);r.succeed(Bo.green(f.length>0?`Internationalization repaired (${f.join("; ")}).`:"Internationalization repaired.")),d&&console.log(Bo.yellow(` \u26A0\uFE0F ${a.LOCALE_DIR} is missing. Recreating it means moving your app-router pages, so it is left for you: run \`next-maker setup --i18n\` on a clean tree, or move your pages under ${a.LOCALE_DIR}/ by hand.`))}catch(n){throw r.fail("Failed to repair Internationalization."),n}};var Vo={id:"i18n",name:"Internationalization",description:"next-intl with [locale] routing, RootProvider, and proxy.ts",detect:async e=>{let{detectProjectSetup:t}=await Promise.resolve().then(()=>(q(),ct));return(await t(e)).hasI18n},files:[{path:"src/i18n",generated:!0,isDir:!0,containsUserContent:!0,removeHint:"holds your translation JSON files \u2014 copy any you want to keep, then delete by hand"},{path:"src/proxy.ts",generated:!0},{path:"src/app/[locale]",generated:!0,isDir:!0,containsUserContent:!0,removeHint:"holds every page you generated under the locale segment \u2014 move them to src/app/ before deleting"}],packages:[{name:"next-intl",kind:"dependency"}],scripts:[],injections:[{file:"next.config.ts",description:"createNextIntlPlugin wrap in next.config.ts",presence:/next-intl\/plugin/,removePattern:go},{file:"src/providers/RootProvider.tsx",description:"<NextIntlClientProvider> wrap",presence:/NextIntlClientProvider/,removePattern:Ve("NextIntlClientProvider")}],apply:O(mr,zo)};P();w();import yl from"node:path";P();import ul from"node:path";import fl from"picocolors";w();var Jo=/(const\s+nextConfig\s*:\s*NextConfig\s*=\s*\{)/,dr=e=>/reactCompiler\s*:/.test(e),vt=e=>{if(dr(e))return e;if(!Jo.test(e))throw new Error("Could not locate `const nextConfig: NextConfig = {` in next.config.ts.");return e.replace(Jo,`$1
|
|
936
|
-
reactCompiler: true,`)};var ur=async e=>{let t=S("Enabling React Compiler...");try{let r=ul.join(e,a.NEXT_CONFIG);if(!l(r))throw new Error(`${a.NEXT_CONFIG} not found.`);let i=await g(r);if(dr(i)){t.fail("React Compiler is already configured in next.config.ts.");return}await h(r,vt(i)),t.text="Installing babel-plugin-react-compiler...",await At(e,"babel-plugin-react-compiler"),t.succeed(fl.green("React Compiler enabled."))}catch(r){throw t.fail("Failed to enable React Compiler."),r}};P();import gl from"node:path";import hl from"picocolors";w();var Wo=async(e,t)=>{let r=S("Repairing React Compiler...");try{if(U(t,a.NEXT_CONFIG)){let n=gl.join(e,a.NEXT_CONFIG);if(l(n)){let o=await g(n),s=vt(o);s!==o&&await h(n,s)}}let i=await B(e,t);r.succeed(hl.green(i.length>0?`React Compiler repaired (reinstalled ${i.join(", ")}).`:"React Compiler repaired."))}catch(i){throw r.fail("Failed to repair React Compiler."),i}};var qo={id:"react-compiler",name:"React Compiler",description:"reactCompiler: true in next.config.ts + babel-plugin-react-compiler",detect:async e=>{let t=yl.join(e,a.NEXT_CONFIG);return l(t)?/reactCompiler\s*:\s*true/.test(await g(t)):!1},files:[],packages:[{name:"babel-plugin-react-compiler",kind:"devDependency"}],scripts:[],injections:[{file:a.NEXT_CONFIG,description:"`reactCompiler: true` flag",presence:/reactCompiler\s*:\s*true/,removePattern:/\n\s*reactCompiler:\s*true,?/}],apply:O(ur,Wo)};P();import di from"node:path";import xl from"picocolors";w();P();import Xo from"node:fs/promises";import _e from"node:path";w();var Yo=async(e,t)=>{t.text="Fetching assets from starter repo...",await J(e)},Ko=async(e,t)=>{let r=_e.join(t,"src/providers/StoreProvider.tsx"),i=_e.join(e,a.STORE_PROVIDER);await b(r,i);let n=_e.join(t,"src/store"),o=_e.join(e,a.STORE);await Xo.cp(n,o,{recursive:!0})},Zo=async(e,t)=>{let r=_e.join(t,"src/features/counter"),i=_e.join(e,a.COUNTER_FEATURE);await Xo.cp(r,i,{recursive:!0});let n=_e.join(i,"components/Counter.tsx");if(await l(n)){let o=await g(n);o=o.replace(/import \{ useTranslations \} from 'next-intl';\n?/,""),o=o.replace(/const t = useTranslations\('Count'\);\n?/,""),o=o.replace(/\{t\('currentCount', \{ count: value \}\)\}/g,"Current Count: {value}"),o=o.replace(/\{t\('increment'\)\}/g,"Increment"),o=o.replace(/\{t\('decrement'\)\}/g,"Decrement"),o=o.replace(/\{t\('reset'\)\}/g,"Reset"),await h(n,o)}};P();w();import li from"node:path";var Qo=async e=>{let t=li.join(e,a.STORE),r=li.join(e,"package.json");if(l(t))return{isSetup:!0,reason:"src/store directory exists"};if(l(r)){let i=JSON.parse(await g(r));if(i.dependencies?.["@reduxjs/toolkit"]||i.devDependencies?.["@reduxjs/toolkit"])return{isSetup:!0,reason:"@reduxjs/toolkit is installed"}}return{isSetup:!1,reason:""}},es=async e=>{let t=li.join(e,a.PROVIDERS_INDEX);if(!await Yt(e)||!l(t))throw new Error("Project structure mismatch. Ensure src/app/layout.tsx (or src/app/[locale]/layout.tsx) and src/providers/index.ts exist.")};P();w();import mi from"node:path";var ts=async e=>{},fr=async e=>{let t=mi.join(e,"src/providers/RootProvider.tsx");if(!l(t))return;let r=await g(t),i="'use client';",n=r.includes(i);if(n&&(r=r.replace(i,"").trim()),r.includes("from '@/store'")||(r=`import type { AppState } from '@/store';
|
|
937
|
-
${r}`),r.includes("from './StoreProvider'")||(r=`${r.includes("from '@/store'"),""}import { StoreProvider } from './StoreProvider';
|
|
938
|
-
${r}`),n&&(r=`${i}
|
|
939
|
-
${r}`),r.includes("preloadedState")||(r=r.replace(/children:\s*React\.ReactNode;/,`children: React.ReactNode;
|
|
940
|
-
preloadedState?: Partial<AppState>;`),r=r.replace(/export const RootProvider = \(\{([\s\S]*?)\}:/,(o,s)=>`export const RootProvider = ({${s}, preloadedState }:`),r=r.replace(/,\s*,/g,",").replace(/\{\s*,/g,"{ ").replace(/,\s*\}/g," }")),!r.includes("<StoreProvider")){let o=r.match(/return\s*\(\s*([\s\S]*?)\s*\);/);if(o){let s=o[1];r=r.replace(o[0],`return (
|
|
941
|
-
<StoreProvider preloadedState={preloadedState}>
|
|
942
|
-
${s}
|
|
943
|
-
</StoreProvider>
|
|
944
|
-
);`)}}await h(t,r)},rs=async e=>{let t=[mi.join(e,a.ROOT_PAGE),mi.join(e,"src/app/[locale]/page.tsx")],r="";for(let n of t)if(l(n)){r=n;break}if(!r)return;let i=await g(r);if(i.includes("Counter")||(i=`import { Counter } from '@/features/counter';
|
|
945
|
-
${i}`),!i.includes("<Counter />")){let n=i.lastIndexOf("</div>"),o=i.lastIndexOf("</main>"),s=o!==-1?o:n;s!==-1&&(i=i.slice(0,s)+`
|
|
946
|
-
<div className="mt-8">
|
|
947
|
-
<h2 className="mb-4 text-2xl font-bold">Redux Counter</h2>
|
|
948
|
-
<Counter />
|
|
949
|
-
</div>
|
|
950
|
-
`+i.slice(s),await h(r,i))}};var gr=async e=>{let t=S("Setting up Redux Toolkit..."),r=di.join(e,".next-maker-temp-redux");try{let{isSetup:i,reason:n}=await Qo(e);if(i){t.fail(`Redux is already set up (${n}).`);return}await es(e),await Yo(r,t),t.text="Copying Redux files...",await Ko(e,r),t.text="Creating Counter feature...",await Zo(e,r),t.text="Updating providers and pages...",await ts(e),await fr(e),await rs(e),t.text="Installing dependencies...",await z(e,"@reduxjs/toolkit"),await z(e,"react-redux"),await z(e,"redux-persist"),await z(e,"react-secure-storage");let o=di.join(e,a.VITEST_CONFIG);if(l(o)){let c=JSON.parse(await g(di.join(e,a.PACKAGE_JSON))),p={...c.dependencies,...c.devDependencies};await ce(e,{redux:!0,i18n:!!p["next-intl"]})}t.text="Formatting code...";let s=await A(e);await K(e,s,"lint:fix"),t.succeed(xl.green("Redux Toolkit setup successfully!"))}catch(i){throw t.fail("Failed to setup Redux Toolkit."),i}finally{await v(r)}};P();import wl from"node:fs/promises";import St from"node:path";import Pl from"picocolors";w();var vl="src/providers/RootProvider.tsx",is=async(e,t)=>{let r=S("Repairing Redux Toolkit..."),i=St.join(e,".next-maker-temp-redux-repair");try{let n=St.join(e,a.STORE),o=St.join(e,a.STORE_PROVIDER),s=F(t,a.STORE)&&!l(n),c=F(t,a.STORE_PROVIDER)&&!l(o),p=[];(s||c)&&(r.text="Fetching assets from starter repo...",await te(i,async f=>{s&&(await wl.cp(St.join(f,a.STORE),n,{recursive:!0}),p.push(a.STORE)),c&&(await b(St.join(f,a.STORE_PROVIDER),o),p.push(a.STORE_PROVIDER))})),U(t,vl)&&(r.text="Restoring <StoreProvider> wrap...",await fr(e),p.push("<StoreProvider> wrap")),r.text="Restoring dependencies...";let u=await B(e,t),d=[p.length>0?`restored ${p.join(", ")}`:null,u.length>0?`reinstalled ${u.join(", ")}`:null].filter(Boolean);r.succeed(Pl.green(d.length>0?`Redux Toolkit repaired (${d.join("; ")}).`:"Redux Toolkit repaired."))}catch(n){throw r.fail("Failed to repair Redux Toolkit."),n}};var ns={id:"redux",name:"Redux Toolkit",description:"Redux Toolkit + react-redux + redux-persist + StoreProvider",detect:async e=>{let{detectProjectSetup:t}=await Promise.resolve().then(()=>(q(),ct));return(await t(e)).hasRedux},files:[{path:"src/store",generated:!0,isDir:!0,containsUserContent:!0,removeHint:"holds the rootReducer and any slices you registered \u2014 review before deleting"},{path:"src/providers/StoreProvider.tsx",generated:!0}],packages:[{name:"@reduxjs/toolkit",kind:"dependency"},{name:"react-redux",kind:"dependency"},{name:"redux-persist",kind:"dependency"}],scripts:[],injections:[{file:"src/providers/RootProvider.tsx",description:"<StoreProvider> wrap in RootProvider",presence:/<StoreProvider/,removePattern:Ve("StoreProvider")}],apply:O(gr,is)};P();w();import Il from"node:path";P();import Tl from"node:path";import Cl from"picocolors";w();var ss=[{key:"X-DNS-Prefetch-Control",value:"on"},{key:"Strict-Transport-Security",value:"max-age=63072000; includeSubDomains; preload"},{key:"X-XSS-Protection",value:"1; mode=block"},{key:"X-Frame-Options",value:"SAMEORIGIN"},{key:"X-Content-Type-Options",value:"nosniff"},{key:"Referrer-Policy",value:"origin-when-cross-origin"}],os=/(const\s+nextConfig\s*:\s*NextConfig\s*=\s*\{)/,Sl=/^\s+headers\s*:/m,El=e=>`
|
|
951
|
-
headers: async () => {
|
|
952
|
-
return [
|
|
953
|
-
{
|
|
954
|
-
source: '/:path*',
|
|
955
|
-
headers: [
|
|
956
|
-
${e.map(({key:r,value:i})=>` { key: '${r}', value: '${i}' },`).join(`
|
|
736
|
+
\`\`\`
|
|
737
|
+
${e.name}/
|
|
738
|
+
apps/
|
|
739
|
+
${e.apps.map(r=>` ${r}/`).join(`
|
|
957
740
|
`)}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
import * as path from 'node:path';
|
|
963
|
-
|
|
964
|
-
const checkOnly = process.argv.includes('--check');
|
|
965
|
-
|
|
966
|
-
const envPath = path.join(process.cwd(), '.env');
|
|
967
|
-
const examplePath = path.join(process.cwd(), '.env.example');
|
|
968
|
-
|
|
969
|
-
if (!fs.existsSync(envPath)) {
|
|
970
|
-
console.log('\u26A0\uFE0F No .env file found. Skipping sync.');
|
|
971
|
-
process.exit(0);
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
const envContent = fs.readFileSync(envPath, 'utf-8');
|
|
975
|
-
const lines = envContent.split('\\n');
|
|
976
|
-
|
|
977
|
-
let isPublicBlock = false;
|
|
978
|
-
|
|
979
|
-
const exampleLines = lines.map((line) => {
|
|
980
|
-
const trimmed = line.trim();
|
|
981
|
-
|
|
982
|
-
// Preserve empty lines and reset public block state
|
|
983
|
-
if (!trimmed) {
|
|
984
|
-
isPublicBlock = false;
|
|
985
|
-
return line;
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
// Preserve comments
|
|
989
|
-
if (trimmed.startsWith('#')) {
|
|
990
|
-
if (line.toLowerCase().includes('-public')) {
|
|
991
|
-
isPublicBlock = true;
|
|
992
|
-
}
|
|
993
|
-
return line;
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
// Parse KEY=VALUE
|
|
997
|
-
const match = line.match(/^([^=]+)=(.*)$/);
|
|
998
|
-
|
|
999
|
-
if (match) {
|
|
1000
|
-
const key = match[1];
|
|
741
|
+
packages/ shared libraries (see below)
|
|
742
|
+
turbo.json task graph and caching
|
|
743
|
+
pnpm-workspace.yaml workspace members and install policy
|
|
744
|
+
\`\`\`
|
|
1001
745
|
|
|
1002
|
-
|
|
1003
|
-
if (isPublicBlock || line.toLowerCase().includes('-public')) {
|
|
1004
|
-
isPublicBlock = false;
|
|
1005
|
-
return line;
|
|
1006
|
-
}
|
|
746
|
+
## Getting started
|
|
1007
747
|
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
748
|
+
\`\`\`bash
|
|
749
|
+
pnpm install
|
|
750
|
+
pnpm dev # every app
|
|
751
|
+
pnpm --filter ${e.apps[0]} dev # one app
|
|
752
|
+
\`\`\`
|
|
1011
753
|
|
|
1012
|
-
|
|
1013
|
-
return line;
|
|
1014
|
-
});
|
|
754
|
+
Each app reads its own \`.env\` (copy \`apps/<app>/.env.example\`). Ports: set \`PORT\` per app (\`PORT=3001 pnpm --filter ${e.apps[1]??e.apps[0]} dev\`).
|
|
1015
755
|
|
|
1016
|
-
|
|
756
|
+
## Scripts
|
|
1017
757
|
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
758
|
+
| Script | Purpose |
|
|
759
|
+
| :-- | :-- |
|
|
760
|
+
| \`pnpm build\` | build every app (Turborepo caches unchanged apps) |
|
|
761
|
+
| \`pnpm lint\` / \`pnpm ci:check\` | Biome per app and at the root |
|
|
762
|
+
| \`pnpm type-check\`, \`pnpm check:deprecated\`, \`pnpm test\`, \`pnpm test:e2e\` | per-app gates through Turborepo |
|
|
763
|
+
| \`pnpm validate\` | everything CI runs |
|
|
1022
764
|
|
|
1023
|
-
|
|
1024
|
-
console.log('\u2728 .env.example is already up to date');
|
|
1025
|
-
process.exit(0);
|
|
1026
|
-
}
|
|
765
|
+
## Adding a shared package
|
|
1027
766
|
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
}
|
|
767
|
+
\`\`\`bash
|
|
768
|
+
mkdir -p packages/ui && cd packages/ui
|
|
769
|
+
pnpm init # name it @${e.name}/ui, "type": "module"
|
|
770
|
+
cd ../../apps/${e.apps[0]} && pnpm add @${e.name}/ui --workspace
|
|
771
|
+
\`\`\`
|
|
1032
772
|
|
|
1033
|
-
|
|
1034
|
-
console.log('\u2705 Synchronized .env.example with .env');
|
|
1035
|
-
`,ds=`/**
|
|
1036
|
-
* Walks every identifier in the project and flags any whose resolved TypeScript
|
|
1037
|
-
* symbol carries a \`@deprecated\` JSDoc tag. Catches deprecated API usage that
|
|
1038
|
-
* \`tsc --noEmit\` does not surface (deprecations are "suggestion"-level, not
|
|
1039
|
-
* errors) and that Biome does not yet detect.
|
|
1040
|
-
*
|
|
1041
|
-
* Exits 1 if any deprecated usage is found (so it can gate CI).
|
|
1042
|
-
*/
|
|
1043
|
-
import path from 'node:path';
|
|
1044
|
-
import ts from 'typescript';
|
|
773
|
+
Give the package a \`build\` script (or point \`exports\` at TypeScript sources and add it to \`transpilePackages\` in the app's \`next.config.ts\`). Turborepo runs \`^build\` before an app builds.
|
|
1045
774
|
|
|
1046
|
-
|
|
1047
|
-
const configPath = ts.findConfigFile(cwd, ts.sys.fileExists, 'tsconfig.json');
|
|
775
|
+
## Adding an app
|
|
1048
776
|
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
}
|
|
777
|
+
\`\`\`bash
|
|
778
|
+
cd apps && npx @teispace/next-maker init <name> --yes --set hooks=false --set commitizen=false --set ci=false --set docker=false --no-git
|
|
779
|
+
\`\`\`
|
|
1053
780
|
|
|
1054
|
-
|
|
1055
|
-
const parsed = ts.parseJsonConfigFileContent(raw, ts.sys, path.dirname(configPath));
|
|
781
|
+
Git hooks, CI, and Docker live at the workspace root; apps keep their own tests, lint, and type-check.
|
|
1056
782
|
|
|
1057
|
-
|
|
1058
|
-
rootNames: parsed.fileNames,
|
|
1059
|
-
options: parsed.options,
|
|
1060
|
-
});
|
|
783
|
+
## Docker
|
|
1061
784
|
|
|
1062
|
-
|
|
785
|
+
\`apps/<app>/Dockerfile\` (generated with \`--docker\`; add later by copying one) builds from the workspace root with \`turbo prune\`, so an image contains only that app and its workspace dependencies:
|
|
1063
786
|
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
787
|
+
\`\`\`bash
|
|
788
|
+
docker build -f apps/${e.apps[0]}/Dockerfile -t ${e.apps[0]} .
|
|
789
|
+
docker compose up --build
|
|
790
|
+
\`\`\`
|
|
1068
791
|
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
792
|
+
## Dependencies
|
|
793
|
+
|
|
794
|
+
Ranges shared by every app live in the \`catalog:\` section of \`pnpm-workspace.yaml\`; apps reference them as \`"next": "catalog:"\`. Bump a shared version there once. Add an app-specific dependency the normal way (\`pnpm --filter ${e.apps[0]} add <pkg>\`).
|
|
795
|
+
|
|
796
|
+
## Maintenance
|
|
797
|
+
|
|
798
|
+
\`cd apps/<app> && npx @teispace/next-maker doctor --compile\` checks an app against the starter; \`setup --set <option>=<value>\` changes its features.
|
|
799
|
+
`,vs=()=>`name: CI
|
|
800
|
+
|
|
801
|
+
on:
|
|
802
|
+
push:
|
|
803
|
+
branches: [main]
|
|
804
|
+
pull_request:
|
|
805
|
+
branches: [main]
|
|
806
|
+
|
|
807
|
+
concurrency:
|
|
808
|
+
group: \${{ github.workflow }}-\${{ github.ref }}
|
|
809
|
+
cancel-in-progress: \${{ github.ref != 'refs/heads/main' }}
|
|
810
|
+
|
|
811
|
+
env:
|
|
812
|
+
NEXT_PUBLIC_APP_URL: https://ci.example.com
|
|
813
|
+
NEXT_TELEMETRY_DISABLED: 1
|
|
814
|
+
TURBO_TELEMETRY_DISABLED: 1
|
|
815
|
+
|
|
816
|
+
jobs:
|
|
817
|
+
validate:
|
|
818
|
+
name: Lint, types, tests, build
|
|
819
|
+
runs-on: ubuntu-latest
|
|
820
|
+
timeout-minutes: 20
|
|
821
|
+
steps:
|
|
822
|
+
- uses: actions/checkout@v6
|
|
823
|
+
- uses: pnpm/action-setup@v4
|
|
824
|
+
- uses: actions/setup-node@v6
|
|
825
|
+
with:
|
|
826
|
+
node-version-file: .nvmrc
|
|
827
|
+
cache: pnpm
|
|
828
|
+
- run: pnpm install --frozen-lockfile
|
|
829
|
+
- name: Restore Turborepo cache
|
|
830
|
+
uses: actions/cache@v4
|
|
831
|
+
with:
|
|
832
|
+
path: .turbo
|
|
833
|
+
key: turbo-\${{ runner.os }}-\${{ github.sha }}
|
|
834
|
+
restore-keys: |
|
|
835
|
+
turbo-\${{ runner.os }}-
|
|
836
|
+
- run: pnpm ci:check
|
|
837
|
+
- run: pnpm type-check
|
|
838
|
+
- run: pnpm check:deprecated
|
|
839
|
+
- run: pnpm test
|
|
840
|
+
- run: pnpm build
|
|
841
|
+
`,$s=()=>`const config = {
|
|
842
|
+
'*': ['biome check --write --no-errors-on-unmatched --files-ignore-unknown=true'],
|
|
843
|
+
};
|
|
1088
844
|
|
|
1089
|
-
|
|
1090
|
-
|
|
845
|
+
export default config;
|
|
846
|
+
`,Ps=()=>`const config = {
|
|
847
|
+
extends: ['@commitlint/config-conventional'],
|
|
848
|
+
rules: {
|
|
849
|
+
'header-max-length': [2, 'always', 150],
|
|
850
|
+
'scope-enum': [0],
|
|
851
|
+
},
|
|
852
|
+
};
|
|
1091
853
|
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
854
|
+
export default config;
|
|
855
|
+
`,ks=()=>({"pre-commit":`#!/usr/bin/env sh
|
|
856
|
+
pnpm lint-staged
|
|
857
|
+
`,"commit-msg":`#!/usr/bin/env sh
|
|
858
|
+
pnpm exec commitlint --edit "$1"
|
|
859
|
+
`,"pre-push":`#!/usr/bin/env sh
|
|
860
|
+
pnpm ci:check && pnpm type-check && pnpm check:deprecated && pnpm test
|
|
861
|
+
`}),Ss=(e,t="24")=>`# syntax=docker.io/docker/dockerfile:1
|
|
862
|
+
# Build from the workspace root:
|
|
863
|
+
# docker build -f apps/${e}/Dockerfile -t ${e} .
|
|
864
|
+
|
|
865
|
+
FROM node:${t}-alpine AS base
|
|
866
|
+
ENV PNPM_HOME=/pnpm
|
|
867
|
+
ENV PATH=$PNPM_HOME:$PATH
|
|
868
|
+
RUN corepack enable && apk add --no-cache libc6-compat
|
|
869
|
+
|
|
870
|
+
# Prune the workspace down to this app and its dependencies.
|
|
871
|
+
FROM base AS pruner
|
|
872
|
+
WORKDIR /app
|
|
873
|
+
RUN pnpm add -g turbo@2
|
|
874
|
+
COPY . .
|
|
875
|
+
RUN turbo prune ${e} --docker
|
|
876
|
+
|
|
877
|
+
# Install with only the pruned lockfile so dependency layers cache well.
|
|
878
|
+
FROM base AS installer
|
|
879
|
+
WORKDIR /app
|
|
880
|
+
COPY --from=pruner /app/out/json/ ./
|
|
881
|
+
COPY --from=pruner /app/pnpm-workspace.yaml ./
|
|
882
|
+
COPY --from=pruner /app/.npmrc ./
|
|
883
|
+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
|
|
884
|
+
|
|
885
|
+
# Build with the full pruned source.
|
|
886
|
+
FROM base AS builder
|
|
887
|
+
WORKDIR /app
|
|
888
|
+
ARG NEXT_PUBLIC_API_URL
|
|
889
|
+
ARG NEXT_PUBLIC_APP_URL
|
|
890
|
+
ENV NEXT_PUBLIC_API_URL=$NEXT_PUBLIC_API_URL
|
|
891
|
+
ENV NEXT_PUBLIC_APP_URL=$NEXT_PUBLIC_APP_URL
|
|
892
|
+
ENV NEXT_TELEMETRY_DISABLED=1
|
|
893
|
+
ENV TURBO_TELEMETRY_DISABLED=1
|
|
894
|
+
ENV BUILD_STANDALONE=true
|
|
895
|
+
COPY --from=installer /app/ ./
|
|
896
|
+
COPY --from=pruner /app/out/full/ ./
|
|
897
|
+
RUN pnpm turbo run build --filter=${e}
|
|
898
|
+
|
|
899
|
+
FROM base AS runner
|
|
900
|
+
WORKDIR /app
|
|
901
|
+
ENV NODE_ENV=production
|
|
902
|
+
ENV NEXT_TELEMETRY_DISABLED=1
|
|
903
|
+
ENV PORT=3000
|
|
904
|
+
ENV HOSTNAME=0.0.0.0
|
|
905
|
+
RUN addgroup --system --gid 1001 nodejs && adduser --system --uid 1001 nextjs
|
|
906
|
+
COPY --from=builder --chown=nextjs:nodejs /app/apps/${e}/public ./apps/${e}/public
|
|
907
|
+
COPY --from=builder --chown=nextjs:nodejs /app/apps/${e}/.next/standalone ./
|
|
908
|
+
COPY --from=builder --chown=nextjs:nodejs /app/apps/${e}/.next/static ./apps/${e}/.next/static
|
|
909
|
+
USER nextjs
|
|
910
|
+
EXPOSE 3000
|
|
911
|
+
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \\
|
|
912
|
+
CMD wget -qO- http://127.0.0.1:3000/robots.txt >/dev/null || exit 1
|
|
913
|
+
CMD ["node", "apps/${e}/server.js"]
|
|
914
|
+
`,Es=e=>`services:
|
|
915
|
+
${e.map((r,n)=>` ${r}:
|
|
916
|
+
build:
|
|
917
|
+
context: .
|
|
918
|
+
dockerfile: apps/${r}/Dockerfile
|
|
919
|
+
args:
|
|
920
|
+
NEXT_PUBLIC_API_URL: \${NEXT_PUBLIC_API_URL}
|
|
921
|
+
NEXT_PUBLIC_APP_URL: \${${r.toUpperCase().replace(/-/g,"_")}_URL:-http://localhost:${3e3+n}}
|
|
922
|
+
restart: unless-stopped
|
|
923
|
+
ports:
|
|
924
|
+
- "${3e3+n}:3000"
|
|
925
|
+
environment:
|
|
926
|
+
NODE_ENV: production
|
|
927
|
+
NEXT_PUBLIC_API_URL: \${NEXT_PUBLIC_API_URL}
|
|
928
|
+
API_INTERNAL_URL: \${API_INTERNAL_URL}`).join(`
|
|
1096
929
|
|
|
1097
|
-
console.log(\`\\n\${hits} deprecated symbol use(s) found.\`);
|
|
1098
|
-
process.exit(1);
|
|
1099
|
-
`,Ct=[{relative:"scripts/sync-env.ts",content:ms},{relative:"scripts/check-deprecated.ts",content:ds}];var xr=async e=>{let t=S("Adding validation scripts...");try{let r=!1;for(let{relative:o,content:s}of Ct){let c=us.join(e,o);l(c)||(await h(c,s),r=!0)}let i=await A(e),n=!1;await _(us.join(e,a.PACKAGE_JSON),o=>{let s=o.devDependencies?.tsx,c=Tt(o,i);return n=!s&&!!c.devDependencies?.tsx,c}),n&&(t.text="Installing tsx...",await fe(e,i,["tsx"])),t.succeed(Dl.green(r?"Validation scripts added (env:sync, check:deprecated, validate).":"Validation scripts already present \u2014 refreshed package.json."))}catch(r){throw t.fail("Failed to add validation scripts."),r}};P();import fs from"node:path";import jl from"picocolors";w();var gs=async(e,t)=>{let r=S("Repairing validation scripts...");try{let i=[];for(let{relative:p,content:u}of Ct){if(!F(t,p))continue;let d=fs.join(e,p);l(d)||(await h(d,u),i.push(p))}let n=await B(e,t),o=fs.join(e,a.PACKAGE_JSON);if(l(o)){let p=await A(e);await _(o,u=>Tt(u,p))}let s=await Ee(e,t),c=[i.length>0?`rewrote ${i.join(", ")}`:null,n.length>0?`reinstalled ${n.join(", ")}`:null,s.length>0?`reset ${s.join(", ")}`:null].filter(Boolean);r.succeed(jl.green(c.length>0?`Validation scripts repaired (${c.join("; ")}).`:"Validation scripts repaired."))}catch(i){throw r.fail("Failed to repair validation scripts."),i}};var hs=["scripts/sync-env.ts","scripts/check-deprecated.ts"],ys={id:"validate-scripts",name:"Validation Scripts",description:"sync-env, check-deprecated, and the validate chain",detect:async e=>hs.every(t=>l(Ll.join(e,t))),files:hs.map(e=>({path:e,generated:!0})),packages:[{name:"tsx",kind:"devDependency"}],scripts:[{name:"env:sync",expectedValue:"tsx scripts/sync-env.ts"},{name:"check:deprecated",expectedValue:"tsx scripts/check-deprecated.ts"},{name:"type-check",expectedValue:"tsc --noEmit"},{name:"validate"}],injections:[],apply:O(xr,gs)};import{access as Bl,readFile as zl}from"node:fs/promises";import Ts from"node:path";P();import gi from"node:path";import Ml from"picocolors";w();P();import ui from"node:fs/promises";import Rt from"node:path";w();var xs=async(e,t)=>{t.text="Downloading assets from starter repository...",await J(e)},ws=async(e,t,r)=>{let i=Rt.join(e,a.WS_UTILS);await ui.cp(Rt.join(t,a.WS_UTILS),i,{recursive:!0,force:!0});let n=Rt.join(e,a.WS_SLICE_FILE);await b(Rt.join(t,a.WS_SLICE_FILE),n),r.keepTests||await fi(i)},fi=async e=>{let t=async r=>{let i=await ui.readdir(r,{withFileTypes:!0});for(let n of i){let o=Rt.join(r,n.name);if(n.isDirectory()){if(n.name==="__test-utils__"){await v(o);continue}await t(o)}else n.isFile()&&/\.test\.tsx?$/.test(n.name)&&await ui.unlink(o)}};await t(e)};P();w();import Ps from"node:path";var vs=async e=>{let t=Ps.join(e,a.WS_UTILS);return l(t)?{isSetup:!0,reason:"src/lib/utils/ws/ already exists"}:{isSetup:!1}},Ss=async e=>{let t=[],r=[{rel:"src/lib",label:"src/lib"},{rel:"src/store",label:"src/store (Redux Toolkit not installed?)"},{rel:a.ROOT_REDUCER,label:"src/store/rootReducer.ts (Redux not initialised?)"},{rel:a.STORE_PROVIDER,label:"src/providers/StoreProvider.tsx (Redux not initialised?)"}];for(let{rel:i,label:n}of r)l(Ps.join(e,i))||t.push(`- ${n}`);if(t.length>0)throw new Error(`WebSocket setup requires Redux Toolkit. Missing:
|
|
1100
|
-
${t.join(`
|
|
1101
930
|
`)}
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
${
|
|
1119
|
-
|
|
1120
|
-
`)
|
|
1121
|
-
`,o=e===""?"":`
|
|
1122
|
-
`,s=t.description?`# ${t.description}
|
|
1123
|
-
`:"";return`${e}${n}${o}${s}${rm(t)}
|
|
1124
|
-
`},Ms=(e,t)=>{let r=ye(t.name,t.public);if(new RegExp(`^${r}=`,"m").test(e))return e;let n=e===""||e.endsWith(`
|
|
1125
|
-
`)?"":`
|
|
1126
|
-
`,o=t.default??"";return`${e}${n}${r}=${o}
|
|
1127
|
-
`},xi=async(e,t)=>{Fs(t.name);let r=hi.join(e,"src/lib/env/index.ts");if(!l(r))throw new Error("src/lib/env/index.ts not found \u2014 run `next-maker init` first.");let i=await g(r),n=js(i,t),o=n!==i;o&&await h(r,n);let s=hi.join(e,a.ENV_EXAMPLE),c=!1;if(l(s)){let d=await g(s),f=Ls(d,t);c=f!==d,c&&await h(s,f)}let p=hi.join(e,".env"),u=!1;if(l(p)){let d=await g(p),f=Ms(d,t);u=f!==d,u&&await h(p,f)}return{schemaUpdated:o,envExampleUpdated:c,envUpdated:u,group:yi(t)}};var Gs=new Set(["string","url","number","boolean","enum"]),im=e=>{let t=(e??"string").toLowerCase();if(!Gs.has(t))throw new Error(`Invalid --type "${e}". Valid: ${Array.from(Gs).join(", ")}.`);return t},nm=e=>{if(!e)return;let t=e.split(",").map(r=>r.trim()).filter(Boolean);return t.length===0?void 0:t},Hs=e=>{e.command("env <NAME>").description("Declare a new environment variable across src/lib/env/index.ts, .env.example, and .env").option("--type <type>","Coercer type (string|url|number|boolean|enum)","string").option("--required","Make the variable required (no .optional() / .default())").option("--default <value>","Set a default value (mutually exclusive with --required)").option("--public","Mark as public: place in the client group, auto-prefix NEXT_PUBLIC_, tag .env.example").option("--describe <text>","Description (rendered as .describe() and .env.example comment)").option("--enum <list>",'Comma-separated values when --type=enum (e.g. "dev,prod")').action(async(t,r)=>{try{let i=process.cwd();if(m(Xe.cyan(`
|
|
1128
|
-
\u{1F510} Env Var Generator
|
|
1129
|
-
`)),r.required&&r.default!==void 0)throw new Error("--required and --default are mutually exclusive.");let n=im(r.type),o=nm(r.enum);if(n==="enum"&&(!o||o.length===0))throw new Error("--type=enum requires at least one value via --enum a,b,c.");let s={name:t,type:n,required:!!r.required,default:r.default,description:r.describe,enumValues:o,public:!!r.public};y.start("Updating src/lib/env/index.ts, .env.example, and .env...");let c=await xi(i,s);y.succeed("Env var written");let p=ye(s.name,s.public);m(Xe.green(`
|
|
1130
|
-
\u2728 ${p} declared in the ${c.group} group.
|
|
1131
|
-
`)),m(Xe.dim("Touched:")),m(Xe.dim(` ${c.schemaUpdated?"\u270F\uFE0F ":"\u23ED "} src/lib/env/index.ts`)),m(Xe.dim(` ${c.envExampleUpdated?"\u270F\uFE0F ":"\u23ED "} .env.example`)),m(Xe.dim(` ${c.envUpdated?"\u270F\uFE0F ":"\u23ED "} .env`)),m("")}catch(i){y.fail("Env var declaration failed"),E(`${i instanceof Error?i.message:i}`),process.exit(1)}})};import Er from"node:path";import Le from"picocolors";import om from"enquirer";var{prompt:sm}=om,Us=async(e={})=>e.source?{source:e.source}:{source:(await sm({type:"input",name:"source",message:"Path to source image (PNG/JPG/JPEG/SVG/WebP/AVIF):",validate:r=>r?!0:"Source path is required"})).source};import{access as am,readFile as cm,stat as pm}from"node:fs/promises";import je from"node:path";var Bs=async e=>{try{return await am(e),!0}catch{return!1}},lm=async e=>{try{return(await pm(e)).isDirectory()}catch{return!1}},vr=async e=>{let t=[je.join(e,"src","app"),je.join(e,"app")];for(let r of t)if(await lm(r))return r;return null},mm=["next-pwa","@ducanh2912/next-pwa","@serwist/next","serwist"],wi=async e=>{let t={isPwa:!1},r=[je.join(e,"public","manifest.json"),je.join(e,"public","manifest.webmanifest"),je.join(e,"public","site.webmanifest")];for(let n of r)if(await Bs(n)){t.publicManifestPath=n,t.isPwa=!0;break}let i=await vr(e);if(i)for(let n of["ts","tsx","js"]){let o=je.join(i,`manifest.${n}`);if(await Bs(o)){t.appManifestPath=o,t.isPwa=!0;break}}try{let n=JSON.parse(await cm(je.join(e,"package.json"),"utf-8")),o={...n.dependencies,...n.devDependencies};for(let s of mm)if(o[s]){t.framework=s,t.isPwa=!0;break}}catch{}return t};import{mkdir as hm,readFile as Qs,stat as ym,writeFile as xm}from"node:fs/promises";import me from"node:path";import wm from"sharp";import um from"png-to-ico";import bt from"sharp";var zs=e=>e.replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<"),Pi=(e,t,r)=>{switch(e){case"square":return`<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${t}"><rect width="${t}" height="${t}" fill="white"/></svg>`;case"circle":{let i=t/2;return`<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${t}"><circle cx="${i}" cy="${i}" r="${i}" fill="white"/></svg>`}case"rounded":{let i=Math.round(t*r/100);return`<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${t}"><rect width="${t}" height="${t}" rx="${i}" ry="${i}" fill="white"/></svg>`}case"squircle":return dm(t)}},dm=e=>{let t=e,r=t*.225,i=[`M 0 ${r}`,`C 0 0 0 0 ${r} 0`,`L ${t-r} 0`,`C ${t} 0 ${t} 0 ${t} ${r}`,`L ${t} ${t-r}`,`C ${t} ${t} ${t} ${t} ${t-r} ${t}`,`L ${r} ${t}`,`C 0 ${t} 0 ${t} 0 ${t-r}`,"Z"].join(" ");return`<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${t}"><path d="${zs(i)}" fill="white"/></svg>`},Vs=(e,t)=>`<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${e}"><rect width="${e}" height="${e}" fill="${zs(t)}"/></svg>`;var Ye=async e=>{let{size:t,paddingPercent:r,bg:i,fit:n,shape:o,radiusPercent:s,quality:c,forceSquare:p,sourceBuffer:u}=e,d=Math.max(1,Math.round(t*(1-r*2/100))),f=n==="cover"?"cover":"contain",x=await bt(u,{density:384}).resize(d,d,{fit:f,background:{r:0,g:0,b:0,alpha:0}}).png().toBuffer(),I=Math.round((t-d)/2),H=i==="transparent"?{r:0,g:0,b:0,alpha:0}:await vi(i),k=await bt({create:{width:t,height:t,channels:4,background:H}}).composite([{input:x,left:I,top:I}]).png().toBuffer();if(!p&&(o!=="square"||n==="clip")){let kt=o==="square"?"rounded":o,ka=Buffer.from(Pi(kt,t,s));k=await bt(k).composite([{input:ka,blend:"dest-in"}]).png({compressionLevel:Js(c)}).toBuffer()}else k=await bt(k).png({compressionLevel:Js(c)}).toBuffer();return k},vi=async e=>{let t=await bt(Buffer.from(Vs(1,e))).raw().toBuffer({resolveWithObject:!0}),[r,i,n,o=255]=t.data;return{r,g:i,b:n,alpha:o/255}},Js=e=>{let t=Math.round((100-e)/100*9);return Math.max(0,Math.min(9,t))},Ws=async e=>{if(e.length===0)throw new Error("No frames provided to encodeIco");return um(e)};import{readFile as fm,writeFile as VT}from"node:fs/promises";var qs=e=>e.map(({src:t,size:r})=>({src:t,sizes:`${r}x${r}`,type:"image/png",purpose:"any maskable"})),Xs=async(e,t)=>{let r=await fm(e,"utf-8"),i=JSON.parse(r),n=Array.isArray(i.icons)?i.icons:[],o=new Map;for(let s of[...n,...t])s&&typeof s.src=="string"&&o.set(s.src,s);return i.icons=[...o.values()],`${JSON.stringify(i,null,2)}
|
|
1132
|
-
`};var Ys=e=>`icons: [
|
|
1133
|
-
${e.map(r=>` { src: '${r.src}', sizes: '${r.sizes}', type: '${r.type}'${r.purpose?`, purpose: '${r.purpose}'`:""} }`).join(`,
|
|
1134
|
-
`)},
|
|
1135
|
-
],`,Ks=(e,t,r)=>`${JSON.stringify({name:e,short_name:e,start_url:"/",display:"standalone",background_color:"#ffffff",theme_color:t,icons:r},null,2)}
|
|
1136
|
-
`;import{stat as gm}from"node:fs/promises";import Si from"node:path";var Zs=[".png",".jpg",".jpeg",".webp",".svg",".avif"],Sr=async e=>{if(!e)throw new Error("Source image path is required (use --path).");let t=Si.isAbsolute(e)?e:Si.resolve(process.cwd(),e),r;try{r=await gm(t)}catch{throw new Error(`Source image not found: ${t}`)}if(!r.isFile())throw new Error(`Source is not a file: ${t}`);let i=Si.extname(t).toLowerCase();if(!Zs.includes(i))throw new Error(`Unsupported source format '${i}'. Use one of: ${Zs.join(", ")}`);return{absolutePath:t,ext:i,bytes:r.size,isVector:i===".svg"}};var Ei=(e,t)=>{if(!e)return t;let r=e.split(",").map(i=>Number.parseInt(i.trim(),10)).filter(i=>Number.isFinite(i)&&i>0&&i<=1024);if(r.length===0)throw new Error(`Invalid --sizes value: '${e}'. Provide comma-separated positive integers.`);return r};var Pm=async e=>{try{return await ym(e),!0}catch{return!1}},vm=async(e,t,r)=>{let i=[];for(let n of e){if(await Pm(n.outPath)&&!t&&!n.alwaysWrite){i.push({path:n.outPath,bytes:n.bytes.length,skipped:!0});continue}r||(await hm(me.dirname(n.outPath),{recursive:!0}),await xm(n.outPath,n.bytes)),i.push({path:n.outPath,bytes:n.bytes.length})}return i},Ti=async(e,t)=>{let r=await Sr(t.source),i=await Qs(r.absolutePath),n=t.ogSource?await Qs((await Sr(t.ogSource)).absolutePath):i,o=[],s=[];for(let d of t.icoSizes)s.push(await Ye({sourceBuffer:i,size:d,shape:"square",radiusPercent:t.radius,bg:t.bg,paddingPercent:t.padding,fit:t.fit,quality:t.quality,forceSquare:!0}));let c=await Ws(s);if(o.push({outPath:me.join(t.outDir,"favicon.ico"),bytes:c}),t.emitIcon){let d=await Ye({sourceBuffer:i,size:512,shape:t.shape,radiusPercent:t.radius,bg:t.bg,paddingPercent:t.padding,fit:t.fit,quality:t.quality});o.push({outPath:me.join(t.outDir,"icon.png"),bytes:d})}if(t.emitApple){let d=t.bg==="transparent"?"#ffffff":t.bg,f=await Ye({sourceBuffer:i,size:180,shape:t.shape,radiusPercent:t.radius,bg:d,paddingPercent:t.padding,fit:t.fit,quality:t.quality});o.push({outPath:me.join(t.outDir,"apple-icon.png"),bytes:f})}if(t.emitOg){let d=await ea(n,t,!1);o.push({outPath:me.join(t.outDir,"opengraph-image.png"),bytes:d})}if(t.emitTwitter){let d=await ea(n,t,!0);o.push({outPath:me.join(t.outDir,"twitter-image.png"),bytes:d})}let p;if(t.pwa||t.pwaInit){let d=await wi(e);if(t.pwa&&!d.isPwa)throw new Error("No PWA setup detected. Use --pwa-init to bootstrap a manifest, or set up next-pwa/serwist first.");let f=me.join(e,"public"),x=[192,512],I=[];for(let k of x){let Z=await Ye({sourceBuffer:i,size:k,shape:t.shape,radiusPercent:t.radius,bg:t.bg,paddingPercent:t.padding,fit:t.fit,quality:t.quality}),kt=`icon-${k}.png`;o.push({outPath:me.join(f,kt),bytes:Z}),I.push({src:`/${kt}`,size:k})}let H=qs(I);if(d.publicManifestPath){let k=await Xs(d.publicManifestPath,H);o.push({outPath:d.publicManifestPath,bytes:Buffer.from(k,"utf-8"),alwaysWrite:!0})}else if(d.appManifestPath)p=Ys(H);else if(t.pwaInit){let k=me.join(f,"manifest.webmanifest"),Z=Ks(me.basename(e)||"App","#000000",H);o.push({outPath:k,bytes:Buffer.from(Z,"utf-8")})}}return{outputs:await vm(o,t.force,t.dryRun),pwaSnippet:p}},ea=async(e,t,r)=>{let n=r?600:630,o=Math.round(Math.min(1200,n)*(1-t.padding*2/100)),s=await Ye({sourceBuffer:e,size:o,shape:t.shape,radiusPercent:t.radius,bg:"transparent",paddingPercent:0,fit:t.fit,quality:t.quality}),c=t.bg==="transparent"?"#ffffff":t.bg,p=await vi(c),u=Math.round((1200-o)/2),d=Math.round((n-o)/2);return wm({create:{width:1200,height:n,channels:4,background:p}}).composite([{input:s,left:u,top:d}]).png().toBuffer()};var ta=new Set(["aliceblue","antiquewhite","aqua","aquamarine","azure","beige","bisque","black","blanchedalmond","blue","blueviolet","brown","burlywood","cadetblue","chartreuse","chocolate","coral","cornflowerblue","cornsilk","crimson","cyan","darkblue","darkcyan","darkgoldenrod","darkgray","darkgreen","darkgrey","darkkhaki","darkmagenta","darkolivegreen","darkorange","darkorchid","darkred","darksalmon","darkseagreen","darkslateblue","darkslategray","darkslategrey","darkturquoise","darkviolet","deeppink","deepskyblue","dimgray","dimgrey","dodgerblue","firebrick","floralwhite","forestgreen","fuchsia","gainsboro","ghostwhite","gold","goldenrod","gray","green","greenyellow","grey","honeydew","hotpink","indianred","indigo","ivory","khaki","lavender","lavenderblush","lawngreen","lemonchiffon","lightblue","lightcoral","lightcyan","lightgoldenrodyellow","lightgray","lightgreen","lightgrey","lightpink","lightsalmon","lightseagreen","lightskyblue","lightslategray","lightslategrey","lightsteelblue","lightyellow","lime","limegreen","linen","magenta","maroon","mediumaquamarine","mediumblue","mediumorchid","mediumpurple","mediumseagreen","mediumslateblue","mediumspringgreen","mediumturquoise","mediumvioletred","midnightblue","mintcream","mistyrose","moccasin","navajowhite","navy","oldlace","olive","olivedrab","orange","orangered","orchid","palegoldenrod","palegreen","paleturquoise","palevioletred","papayawhip","peachpuff","peru","pink","plum","powderblue","purple","rebeccapurple","red","rosybrown","royalblue","saddlebrown","salmon","sandybrown","seagreen","seashell","sienna","silver","skyblue","slateblue","slategray","slategrey","snow","springgreen","steelblue","tan","teal","thistle","tomato","turquoise","violet","wheat","white","whitesmoke","yellow","yellowgreen"]);var Sm=["square","rounded","circle","squircle"],Em=["contain","cover","clip"],ra=(e,t,r,i)=>{if(!e)return r;if(!t.includes(e))throw new Error(`Invalid value for --${i}: '${e}'. Allowed: ${t.join(", ")}`);return e},Ci=(e,t,r,i,n)=>{if(e===void 0)return t;let o=Number(e);if(!Number.isFinite(o)||o<i||o>n)throw new Error(`Invalid value for --${r}: '${e}'. Must be a number between ${i}\u2013${n}.`);return o},na=e=>{e.command("favicon").description("Generate favicon.ico (and optionally icons, OG image, PWA manifest icons)").option("--path <file>","Path to source image (PNG, JPG, JPEG, WebP, SVG, AVIF)").option("--out <dir>","Output dir (default: src/app or app)").option("--force","Overwrite existing files without prompt",!1).option("--dry-run","Show what would be written without writing",!1).option("--icon","Also emit icon.png (512\xD7512)",!1).option("--apple","Also emit apple-icon.png (180\xD7180)",!1).option("--og","Also emit opengraph-image.png (1200\xD7630)",!1).option("--og-source <file>","Use a separate image for the OG/Twitter card").option("--twitter","Also emit twitter-image.png (1200\xD7600)",!1).option("--all","Shorthand for --icon --apple --og",!1).option("--pwa","Detect PWA setup and emit manifest icons (192/512); errors if not detected",!1).option("--pwa-init","Bootstrap public/manifest.webmanifest with icons",!1).option("--shape <shape>","square | rounded | circle | squircle","square").option("--radius <percent>","Corner radius % when shape=rounded (0-50)","20").option("--bg <color>",'Background color (hex, css name, or "transparent")',"transparent").option("--padding <percent>","Padding around source content (0-30)","0").option("--fit <fit>","How source fits target: contain | cover | clip","contain").option("--sizes <list>","Comma-separated ICO sizes (default: 16,32,48)").option("--quality <n>","PNG compression 1-100 (higher = smaller file; PNG is lossless, default: 90)","90").action(async t=>{try{let r=process.cwd();m(Le.cyan(`
|
|
1137
|
-
\u{1F3A8} Favicon Generator
|
|
1138
|
-
`));let i=await Us({source:t.path}),n=await Tm(r,t.out),o=ra(t.shape,Sm,"square","shape"),s=ra(t.fit,Em,"contain","fit"),c=Ci(t.radius,20,"radius",0,50),p=Ci(t.padding,0,"padding",0,30),u=Ci(t.quality,90,"quality",1,100),d=Ei(t.sizes,[16,32,48]),f=t.bg??"transparent";bm(f);let x=t.all===!0,I={source:i.source,outDir:n,force:!!t.force,dryRun:!!t.dryRun,emitIcon:!!t.icon||x,emitApple:!!t.apple||x,emitOg:!!t.og||x,emitTwitter:!!t.twitter,ogSource:t.ogSource,pwa:!!t.pwa,pwaInit:!!t.pwaInit,shape:o,radius:c,bg:f,padding:p,fit:s,icoSizes:d,quality:u};y.start("Generating favicon assets...");let H=await Ti(r,I);y.succeed(I.dryRun?"Favicon plan ready":"Favicon assets generated"),m("");for(let k of H.outputs){let Z=Er.relative(r,k.path);k.skipped?m(Le.yellow(` \u21B7 skipped ${Z} (exists; use --force to overwrite)`)):I.dryRun?m(Le.dim(` \u{1F4C4} would write ${Z} (${ia(k.bytes)})`)):m(Le.green(` \u2713 ${Z} `)+Le.dim(`(${ia(k.bytes)})`))}H.pwaSnippet&&(m(""),m(Le.cyan("Add this to your typed manifest (src/app/manifest.ts):")),m(Le.dim(H.pwaSnippet))),m("")}catch(r){y.fail("Favicon generation failed");let i=r instanceof Error?r.message:String(r);E(i),process.exit(1)}})},Tm=async(e,t)=>{if(t)return Er.isAbsolute(t)?t:Er.resolve(e,t);let r=await vr(e);return r||(Gi("Could not detect app/ or src/app/ \u2014 falling back to src/app"),Er.join(e,"src","app"))},Cm=/^#([0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/,Rm=/^(?:rgb|rgba|hsl|hsla)\(\s*[\d.,%\s/]+\)$/i,bm=e=>{if(e!=="transparent"&&!Cm.test(e)&&!Rm.test(e)&&!ta.has(e.toLowerCase()))throw new Error(`Invalid value for --bg: '${e}'. Use 'transparent', a hex code (e.g. #0f172a), a CSS color name, or rgb()/rgba()/hsl()/hsla().`)},ia=e=>e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(2)} MB`;import pa from"node:path";import V from"picocolors";q();q();import Hm from"node:path";import{readFile as Im,writeFile as $m}from"node:fs/promises";import km from"node:path";var It=async e=>{let{serviceName:t,projectPath:r}=e,i=G(t),n=km.join(r,"src","lib","config","app-apis.ts");try{let o=await Im(n,"utf-8");if(o.includes(`${i}:`))return;if(!o.match(/export const AppApis = \{[\s\S]*?\} as const;/))throw new Error("Could not find AppApis object in app-apis.ts");let s=` ${i}: {
|
|
1139
|
-
base: '/${t}',
|
|
1140
|
-
getAll: '/${t}',
|
|
1141
|
-
},`;o=ot(o,s),await $m(n,o)}catch(o){throw new Error(`Failed to register API endpoints: ${o}`,{cause:o})}};import{readFile as Nm,writeFile as Am}from"node:fs/promises";import _m from"node:path";w();var Ri=async(e,t,r)=>{let i=_m.join(e,"src","lib","config","app-paths.ts");if(!l(i))return;let n=await Nm(i,"utf-8"),o=G(t);if(n.includes(`${o}:`))return;let s=n.lastIndexOf("} as const;");if(s===-1)return;let c=` ${o}: '${r}',
|
|
1142
|
-
`;n=n.slice(0,s)+c+n.slice(s),await Am(i,n)};P();w();import Tr from"node:path";var Fm=e=>new RegExp(`<\\s*${e}\\b`),oa=(e,t)=>{if(Fm(t).test(e))return e;let r=/^(?<indent>[ \t]*)\{children\}\s*$/m,i=e.match(r);if(!i||i.index===void 0)throw new Error("Could not locate `{children}` line in RootProvider \u2014 expected a line containing only `{children}`.");let n=i.groups?.indent??"",o=`${n} `,s=`${n}<${t}>
|
|
1143
|
-
${o}{children}
|
|
1144
|
-
${n}</${t}>`;return e.replace(r,s)},sa=(e,t)=>{let r=`export * from './${t}';`;if(e.includes(r))return e;let i=e.split(`
|
|
1145
|
-
`),n=[],o=[];for(let f of i)/^export \* from '\.\/.*';\s*$/.test(f)?n.push(f):o.push(f);let s=[...n,r].sort(),c=i.findIndex(f=>/^export \* from '\.\//.test(f));if(c===-1)return`${r}
|
|
1146
|
-
${e.replace(/^\n+/,"")}`;let p=i.slice(0,c),u=i.findIndex((f,x)=>x>c&&!/^export \* from '\.\//.test(f)),d=u===-1?[]:i.slice(u);return[...p,...s,...d].join(`
|
|
1147
|
-
`)},Om=a.PROVIDERS,Dm=a.ROOT_PROVIDER,jm=a.PROVIDERS_INDEX,aa=async(e,t={fileExists:l,readFile:g})=>{let r=Tr.join(e,Dm);if(t.fileExists(r))return r;let i=Tr.join(e,Om);if(!t.fileExists(i))return null;let{readdir:n}=await import("node:fs/promises"),s=(await n(i).catch(()=>[])).filter(p=>p.endsWith(".tsx")),c=null;for(let p of s){let u=Tr.join(i,p),d=await t.readFile(u);if(!/\{children\}/.test(d))continue;let x=((d.split("{children}")[0]??"").match(/<[A-Z][A-Za-z0-9_]*\b/g)??[]).length;(!c||x>c.depth)&&(c={file:u,depth:x})}return c?.file??null},bi=async e=>{let{projectPath:t,componentName:r,fileBaseName:i}=e,n=await aa(t);if(n){let c=await g(n),p=c;(!/from '\.\//.test(c)||!c.includes(`{ ${r} }`))&&(p=nt(p,`import { ${r} } from './${i}';`)),p=oa(p,r),p!==c&&await h(n,p)}let o=Tr.join(t,jm),s=null;if(l(o)){let c=await g(o),p=sa(c,i);p!==c&&await h(o,p),s=o}return{rootProviderFile:n,barrelFile:s}};w();import{readFile as Lm,writeFile as Mm}from"node:fs/promises";import Gm from"node:path";var Ii=async(e,t)=>{let r=Gm.join(e,"src","i18n","translations","en.json");if(!l(r))return;let i=await Lm(r,"utf-8"),n=JSON.parse(i);n[t]||(n[t]={title:t,description:`${t} page description`},await Mm(r,`${JSON.stringify(n,null,2)}
|
|
1148
|
-
`))};var $i=()=>[{name:"Project setup detected",spinnerText:"Detecting project setup...",execute:async e=>{e.detection=await M(e.projectPath)}},{name:"Feature files generated",spinnerText:"Generating feature files...",execute:async e=>{await qr({name:e.featureName,outputPath:e.featurePath,createStore:e.createStore,persistStore:e.persistStore,createService:e.createService,httpClient:e.httpClient})}},{name:"API endpoints registered",spinnerText:"Registering API endpoints...",shouldSkip:e=>!e.createService,execute:async e=>{await It({serviceName:e.featureName,projectPath:e.projectPath})}},{name:"Feature registered in rootReducer",spinnerText:"Registering feature in rootReducer...",shouldSkip:e=>!e.createStore||!e.detection.hasRedux,execute:async e=>{await ke({projectPath:e.projectPath,name:e.featureName,persist:e.persistStore,importPath:Hm.join(e.basePath,e.featureName,"store")})}}];var Me=async(e,t)=>{for(let r of e)if(!r.shouldSkip?.(t)){t.spinner.start(r.spinnerText);try{await r.execute(t),t.spinner.succeed(r.name)}catch(i){throw t.spinner.fail(r.name),i}}};var ki=()=>[{name:"Service files generated",spinnerText:"Generating service files...",execute:async e=>{await pt({name:e.serviceName,outputPath:e.servicePath,httpClient:e.httpClient})}},{name:"API endpoints registered",spinnerText:"Registering API endpoints...",execute:async e=>{await It({serviceName:e.serviceName,projectPath:e.projectPath})}}];import Um from"node:path";var Ni=()=>[{name:"Slice files generated",spinnerText:"Generating slice files...",execute:async e=>{await dt({name:e.sliceName,outputPath:e.slicePath,persist:e.persistSlice})}},{name:"Slice registered in rootReducer",spinnerText:"Registering slice in rootReducer...",execute:async e=>{await ke({projectPath:e.projectPath,name:e.sliceName,persist:e.persistSlice,importPath:Um.join(e.basePath,e.sliceName)})}}];import Bm from"enquirer";var{prompt:zm}=Bm,ca=async(e,t,r,i,n,o,s)=>{let c=[];e||c.push({type:"input",name:"featureName",message:"What is the feature name?",initial:"my-feature",validate:u=>/^[a-z0-9-]+$/.test(u)?!0:"Feature name must be lowercase and contain only alphanumeric characters and hyphens."}),t&&i===void 0&&n===void 0&&(c.push({type:"confirm",name:"createStore",message:"Generate Redux store for this feature?",initial:!0}),c.push({type:"confirm",name:"persistStore",message:"Enable persistence for this store?",initial:!1,skip(){return!this.state.answers.createStore}})),r&&r!=="none"&&o===void 0&&s===void 0&&(c.push({type:"confirm",name:"createService",message:"Generate API service for this feature?",initial:!0}),r==="both"&&c.push({type:"select",name:"selectedHttpClient",message:"Which HTTP client to use for the service?",choices:["fetch","axios"],initial:0,skip(){return!this.state.answers.createService}}));let p=c.length>0?await zm(c):{};return{featureName:e||p.featureName,hasRedux:t||!1,createStore:i===!0?!1:n!==void 0?!0:p.createStore||!1,persistStore:n==="persist"?!0:n==="no-persist"?!1:p.persistStore||!1,httpClient:r||"none",createService:o===!0?!1:s!==void 0?!0:p.createService||!1,selectedHttpClient:s||p.selectedHttpClient||(r==="both"?"fetch":r!=="none"?r:void 0)}};var la=e=>{e.command("feature [name]").description("Generate a new feature module").option("--skip-store","Skip Redux store generation").option("--store <type>","Generate Redux store with persistence option (persist|no-persist)").option("--skip-service","Skip API service generation").option("--service <client>","Generate API service with specific HTTP client (axios|fetch)").option("--path <path>","Custom path for feature generation (default: src/features)").action(async(t,r)=>{try{let i=process.cwd();Vm(r),m(V.cyan(`
|
|
1149
|
-
\u{1F3AF} Feature Generator
|
|
1150
|
-
`));let n=$i();y.start("Detecting project setup...");let{detectProjectSetup:o}=await Promise.resolve().then(()=>(q(),ct)),s=await o(i);y.succeed("Project setup detected"),m(V.dim(` Redux: ${s.hasRedux?"\u2713":"\u2717"}`)),m(V.dim(` HTTP Client: ${s.httpClient}`)),m(V.dim(` i18n: ${s.hasI18n?"\u2713":"\u2717"}
|
|
1151
|
-
`));let c=await ca(t,s.hasRedux,s.httpClient,r.skipStore,r.store,r.skipService,r.service);W(c.featureName,"feature name"),r.path&&pe(r.path,"path");let p=r.path||pa.join("src","features"),u=Gt(i,p,c.featureName);await Se(i,c.featureName,p)&&(E(`Feature '${c.featureName}' already exists at ${p}!`),process.exit(1)),await Me(n.slice(1),{projectPath:i,spinner:y,featureName:c.featureName,basePath:p,featurePath:u,createStore:c.createStore,persistStore:c.persistStore,createService:c.createService,httpClient:c.selectedHttpClient,detection:s}),Jm(c,p)}catch(i){y.fail("Feature generation failed"),E(`${i}`),process.exit(1)}})},Vm=e=>{e.store&&!["persist","no-persist"].includes(e.store)&&(E("Invalid --store option. Use: persist or no-persist"),process.exit(1)),e.service&&!["axios","fetch"].includes(e.service)&&(E("Invalid --service option. Use: axios or fetch"),process.exit(1)),e.skipStore&&e.store&&(E("Cannot use --skip-store and --store together"),process.exit(1)),e.skipService&&e.service&&(E("Cannot use --skip-service and --service together"),process.exit(1))},Jm=(e,t)=>{let r=pa.join(t,e.featureName);m(V.green(`
|
|
1152
|
-
\u2728 Feature '${e.featureName}' created successfully!
|
|
1153
|
-
`)),m(V.dim("Generated files:")),m(V.dim(` \u{1F4C2} ${r}/`)),m(V.dim(" \u251C\u2500\u2500 components/")),m(V.dim(" \u251C\u2500\u2500 hooks/")),m(V.dim(" \u251C\u2500\u2500 types/")),e.createStore&&m(V.dim(" \u251C\u2500\u2500 store/")),e.createService&&m(V.dim(" \u251C\u2500\u2500 services/")),m(V.dim(` \u2514\u2500\u2500 index.ts
|
|
1154
|
-
`)),m(V.cyan("Next steps:"));let i=t.replace(/^src\//,"@/");m(V.dim(` 1. Import and use the feature: import { ${e.featureName} } from '${i}/${e.featureName}'`)),e.createStore&&m(V.dim(` 2. Customize your Redux slice in: ${r}/store/`)),e.createService&&m(V.dim(` 3. Add API methods in: ${r}/services/${e.featureName}.service.ts`)),m("")};import Ai from"node:path";import Ke from"picocolors";q();import Wm from"enquirer";var{prompt:qm}=Wm,ma=async e=>e?{hookName:e}:await qm({type:"input",name:"hookName",message:'Hook name (kebab-case, without "use" prefix):',validate:r=>r?/^[a-z][a-z0-9-]*$/.test(r)?!0:"Use lowercase letters, numbers, and hyphens only":"Hook name is required"});var da=e=>{e.command("hook [name]").description("Generate a custom React hook").option("--client","Add 'use client' directive (default: true)",!0).option("--feature <path>","Generate in feature directory (e.g., src/features/auth)").option("--test","Also generate a sibling test file").option("--no-test","Skip test file generation").action(async(t,r)=>{try{let i=process.cwd();m(Ke.cyan(`
|
|
1155
|
-
\u{1FA9D} Hook Generator
|
|
1156
|
-
`));let n=await M(i),o=await ma(t);W(o.hookName,"hook name"),r.feature&&pe(r.feature,"feature path");let c=`use${N(o.hookName)}`,p=Xm(r,n.hasTests);y.start("Generating hook..."),await Yr({name:o.hookName,projectPath:i,isClient:r.client??!0,featurePath:r.feature}),y.succeed("Hook generated");let u=r.feature?Ai.join(i,r.feature,"hooks",`${c}.ts`):Ai.join(i,"src/hooks",`${c}.ts`),d=null;p&&(y.start("Generating test..."),d=await ge({projectPath:i,sourceFile:u,kind:"hook",symbolName:c,hookUsesStore:n.hasRedux&&!!r.feature}),y.succeed("Test generated"));let f=r.feature?`${r.feature}/hooks/${c}.ts`:`src/hooks/${c}.ts`;m(Ke.green(`
|
|
1157
|
-
\u2728 Hook '${c}' created successfully!
|
|
1158
|
-
`)),m(Ke.dim(` \u{1F4C4} ${f}`)),d&&m(Ke.dim(` \u{1F9EA} ${Ai.relative(i,d)}`)),m(""),m(Ke.cyan("Usage:"));let x=r.feature?`${r.feature.replace(/^src\//,"@/")}/hooks/${c}`:`@/hooks/${c}`;m(Ke.dim(` import { ${c} } from '${x}';`)),m("")}catch(i){y.fail("Hook generation failed"),E(`${i}`),process.exit(1)}})},Xm=(e,t)=>e.test===!1?!1:e.test===!0?!0:t;import Cr from"picocolors";q();var ua=e=>{e.command("layout <segment>").description("Generate a nested layout.tsx (locale-aware when i18n is detected)").option("--group","Treat the segment as a route group (wraps it in parens)").option("--at <path>","Place the layout under this nested path (kebab-case, slash-separated)").option("--no-locale","Skip the locale wrapper even if i18n is detected").action(async(t,r)=>{try{let i=process.cwd();m(Cr.cyan(`
|
|
1159
|
-
\u{1F4D0} Layout Generator
|
|
1160
|
-
`)),y.start("Detecting project setup...");let n=await M(i);y.succeed("Project setup detected");let o=n.hasI18n&&r.locale!==!1;m(Cr.dim(` i18n: ${o?"\u2713":"\u2717"}
|
|
1161
|
-
`)),y.start("Generating layout...");let s=await Kr({segment:t,at:r.at,projectPath:i,hasI18n:o,withGroup:!!r.group});y.succeed("Layout generated"),m(Cr.green(`
|
|
1162
|
-
\u2728 ${s.componentName} created!
|
|
1163
|
-
`)),m(Cr.dim(` \u{1F4C4} ${s.displayPath}`)),m("")}catch(i){y.fail("Layout generation failed"),E(`${i instanceof Error?i.message:i}`),process.exit(1)}})};import de from"picocolors";w();q();import Ym from"enquirer";var{prompt:Km}=Ym,fa=async(e,t={})=>{let r=[];e||r.push({type:"input",name:"code",message:"Locale code (e.g., es, fr, de):",validate:n=>n?/^[a-z]{2}(-[A-Z]{2})?$/.test(n)?!0:"Use format: xx or xx-XX (e.g., es, pt-BR)":"Locale code is required"}),r.push({type:"input",name:"name",message:"Language name (e.g., Spanish, French):",validate:n=>n?!0:"Language name is required"},{type:"input",name:"country",message:"Country (e.g., Spain, France):",validate:n=>n?!0:"Country is required"},{type:"input",name:"flag",message:"Flag emoji (e.g., \u{1F1EA}\u{1F1F8}, \u{1F1EB}\u{1F1F7}):",validate:n=>n?!0:"Flag emoji is required"}),t.copyTranslations===void 0&&r.push({type:"confirm",name:"copyTranslations",message:"Copy translations from English? (No = empty values)",initial:!1});let i=await Km(r);return{code:e??i.code,name:i.name,country:i.country,flag:i.flag,copyTranslations:t.copyTranslations??i.copyTranslations??!1}};var ga=e=>{e.command("locale [code]").description("Add a new locale/language").option("--copy-translations","Copy translations from English instead of empty values").action(async(t,r)=>{try{let i=process.cwd();m(de.cyan(`
|
|
1164
|
-
\u{1F30D} Locale Generator
|
|
1165
|
-
`)),y.start("Detecting project setup...");let n=await M(i);y.succeed("Project setup detected"),n.hasI18n||(y.fail("i18n is not set up in this project"),E("Please set up internationalization first"),m(de.dim(`
|
|
1166
|
-
Run: npx @teispace/next-maker setup --i18n
|
|
1167
|
-
`)),process.exit(1));let o=await fa(t,{copyTranslations:r.copyTranslations});W(o.code,"locale code");let s=Gt(i,"src","i18n","translations",`${o.code}.json`);l(s)&&(E(`Locale '${o.code}' already exists!`),process.exit(1)),y.start("Adding locale..."),await Zr({...o,projectPath:i}),y.succeed("Locale added"),m(de.green(`
|
|
1168
|
-
\u2728 Locale '${o.code}' (${o.name}) added successfully!
|
|
1169
|
-
`)),m(de.dim("Updated files:")),m(de.dim(` \u{1F4C4} src/i18n/translations/${o.code}.json`)),m(de.dim(" \u{1F4DD} src/types/i18n.ts (SupportedLocale type)")),m(de.dim(" \u{1F4DD} src/lib/config/app-locales.ts")),m(""),m(de.cyan("Next steps:")),m(de.dim(` 1. Translate: src/i18n/translations/${o.code}.json`)),m(de.dim(` 2. Visit: http://localhost:3000/${o.code}`)),m("")}catch(i){y.fail("Locale generation failed"),E(`${i}`),process.exit(1)}})};import ya from"node:path";import ne from"picocolors";q();import Zm from"enquirer";var{prompt:Qm}=Zm,ha=async(e,t={})=>{let r=[];e||r.push({type:"input",name:"pageName",message:"Page name (kebab-case):",validate:n=>n?/^[a-z][a-z0-9-]*$/.test(n)?!0:"Use lowercase letters, numbers, and hyphens only":"Page name is required"}),t.loading===void 0&&r.push({type:"confirm",name:"withLoading",message:"Generate loading.tsx?",initial:!0}),t.error===void 0&&r.push({type:"confirm",name:"withError",message:"Generate error.tsx?",initial:!0});let i=r.length>0?await Qm(r):{};return{pageName:e??i.pageName,withLoading:t.loading??i.withLoading??!0,withError:t.error??i.withError??!0}};var xa=e=>{e.command("page [name]").description("Generate a new page/route").option("--dynamic <param>","Create dynamic route with parameter (e.g., id)").option("--loading","Generate loading.tsx").option("--error","Generate error.tsx").action(async(t,r)=>{try{let i=process.cwd();m(ne.cyan(`
|
|
1170
|
-
\u{1F4C4} Page Generator
|
|
1171
|
-
`)),y.start("Detecting project setup...");let n=await M(i);y.succeed("Project setup detected"),m(ne.dim(` i18n: ${n.hasI18n?"\u2713":"\u2717"}
|
|
1172
|
-
`));let o=await ha(t,{loading:r.loading,error:r.error}),s=o.pageName;W(s,"page name"),r.dynamic&&W(r.dynamic,"dynamic param");let c=N(s),p=n.hasI18n?"src/app/[locale]":"src/app";await Se(i,s,p)&&(E(`Page '${s}' already exists at ${p}/${s}!`),process.exit(1)),y.start("Generating page files..."),await ei({name:s,projectPath:i,hasI18n:n.hasI18n,dynamic:r.dynamic,withLoading:r.loading??o.withLoading,withError:r.error??o.withError}),y.succeed("Page files generated"),y.start("Registering route...");let d=r.dynamic?`/${s}/[${r.dynamic}]`:`/${s}`;await Ri(i,s,d),y.succeed("Route registered"),n.hasI18n&&(y.start("Adding translation namespace..."),await Ii(i,c),y.succeed("Translation namespace added"));let f=r.dynamic?ya.join(p,s,`[${r.dynamic}]`):ya.join(p,s);m(ne.green(`
|
|
1173
|
-
\u2728 Page '${s}' created successfully!
|
|
1174
|
-
`)),m(ne.dim("Generated files:")),m(ne.dim(` \u{1F4C2} ${f}/`)),m(ne.dim(" \u251C\u2500\u2500 page.tsx")),(r.loading??o.withLoading)&&m(ne.dim(" \u251C\u2500\u2500 loading.tsx")),(r.error??o.withError)&&m(ne.dim(" \u2514\u2500\u2500 error.tsx")),m(""),n.hasI18n&&(m(ne.cyan("Next steps:")),m(ne.dim(` 1. Add translations in: src/i18n/translations/en.json \u2192 "${c}"`)),m(ne.dim(` 2. Visit: http://localhost:3000/${s}`)),m(""))}catch(i){y.fail("Page generation failed"),E(`${i}`),process.exit(1)}})};import _i from"node:path";import Re from"picocolors";var wa=e=>{e.command("provider <name>").description("Generate a context provider in src/providers/ and wire it into RootProvider").action(async t=>{try{let r=process.cwd();m(Re.cyan(`
|
|
1175
|
-
\u{1F50C} Provider Generator
|
|
1176
|
-
`)),y.start("Generating provider...");let{componentName:i,fileBaseName:n,providerFile:o}=await ri({name:t,projectPath:r});y.succeed("Provider generated"),y.start("Registering provider in RootProvider and barrel...");let{rootProviderFile:s,barrelFile:c}=await bi({projectPath:r,componentName:i,fileBaseName:n});y.succeed("Provider registered"),m(Re.green(`
|
|
1177
|
-
\u2728 ${i} created!
|
|
1178
|
-
`)),m(Re.dim("Generated files:")),m(Re.dim(` \u{1F4C4} ${_i.relative(r,o)}`)),s?m(Re.dim(` \u270F\uFE0F ${_i.relative(r,s)} \u2014 wrapped {children}`)):(m(Re.yellow(`
|
|
1179
|
-
\u26A0\uFE0F Could not locate a RootProvider file. Wire the new provider manually:`)),m(Re.dim(` <${i}>{children}</${i}>`))),c&&m(Re.dim(` \u270F\uFE0F ${_i.relative(r,c)} \u2014 added re-export`)),m("")}catch(r){y.fail("Provider generation failed"),E(`${r instanceof Error?r.message:r}`),process.exit(1)}})};import ed from"enquirer";import X from"picocolors";var{prompt:td}=ed,rd=e=>{let t=[];for(let r of e.filesRemoved)t.push(` ${X.red("-")} delete: ${r}`);for(let r of e.blocksStripped)t.push(` ${X.red("-")} strip block: ${r.description} ${X.dim(`(${r.file})`)}`);for(let r of e.scriptsRemoved)t.push(` ${X.red("-")} remove script: ${r}`);for(let r of e.packagesUninstalled)t.push(` ${X.red("-")} uninstall: ${r}`);for(let r of e.manualCleanup)t.push(` ${X.yellow("?")} manual cleanup: ${r.description} ${X.dim(`(${r.file})`)}`);return t},id=e=>e.filesRemoved.length===0&&e.blocksStripped.length===0&&e.scriptsRemoved.length===0&&e.packagesUninstalled.length===0&&e.manualCleanup.length===0,Pa=e=>{e.command("remove <feature>").alias("uninstall").description("Reverse a feature install (uses the feature manifest)").option("-y, --yes","Skip confirmation prompt").option("--dry-run","Show what would change without writing").action(async(t,r)=>{try{let i=process.cwd(),n=$s(t);if(!n)throw new Error(`Unknown feature "${t}". Valid: ${De.map(p=>p.id).join(", ")}.`);if(m(X.cyan(`
|
|
1180
|
-
\u{1F5D1} Remove ${n.name}
|
|
1181
|
-
`)),!(await qe(n,i)).installed){m(X.dim(`${n.name} is not installed \u2014 nothing to remove.`));return}y.start("Computing changes...");let s=await Pr(n,i,{dryRun:!0});if(y.succeed("Computed plan"),id(s)){m(X.yellow(`
|
|
1182
|
-
\u26A0\uFE0F Manifest had no removable artifacts. Nothing to do.
|
|
1183
|
-
`));return}m(X.bold(`
|
|
1184
|
-
Planned changes:
|
|
1185
|
-
`));for(let p of rd(s))m(p);if(m(""),r.dryRun){m(X.dim(`--dry-run set \u2014 exiting without writing.
|
|
1186
|
-
`));return}if(!r.yes){let{confirm:p}=await td({type:"confirm",name:"confirm",message:`Apply the changes above to remove ${n.name}?`,initial:!1});if(!p){m(X.yellow(`
|
|
1187
|
-
Aborted.
|
|
1188
|
-
`));return}}y.start(`Removing ${n.name}...`);let c;if(n.remove?(await n.remove(i),c=s):c=await Pr(n,i),y.succeed(`${n.name} removed`),m(X.green(`
|
|
1189
|
-
\u2713 ${n.name} removed.`)),c.manualCleanup.length>0){m(X.yellow(`
|
|
1190
|
-
\u26A0\uFE0F Manual cleanup still required:`));for(let p of c.manualCleanup)m(` - ${p.description} (${p.file})`)}m("")}catch(i){y.fail("Remove failed"),E(`${i instanceof Error?i.message:i}`),process.exit(1)}})};import{existsSync as ad}from"node:fs";import{mkdir as cd}from"node:fs/promises";import $t from"node:path";import oe from"picocolors";q();import{readFile as nd,writeFile as od}from"node:fs/promises";import sd from"node:path";var va=async(e,t)=>{let r=G(t),i=sd.join(e,"src","lib","config","app-apis.ts");try{let n=await nd(i,"utf-8");if(n.includes(`${r}:`))return;if(!n.match(/export const AppApis = \{[\s\S]*?\} as const;/))throw new Error("Could not find AppApis object in app-apis.ts");let o=Gn({camelName:r,kebabName:t});n=ot(n,o),await od(i,n)}catch(n){throw new Error(`Failed to register CRUD API endpoints: ${n}`,{cause:n})}};import Sa from"enquirer";var Ea=async(e,t,r,i)=>{let n=e||(await Sa.prompt({type:"input",name:"serviceName",message:"Service name (kebab-case):",validate:s=>s?/^[a-z0-9-]+$/.test(s)?!0:"Service name must be lowercase with hyphens only":"Service name is required"})).serviceName,o;return t!==void 0?o="axios":r!==void 0?o="fetch":i==="axios"?o="axios":i==="fetch"?o="fetch":i==="both"?o=(await Sa.prompt({type:"select",name:"httpClient",message:"Choose HTTP client:",choices:["axios","fetch"]})).httpClient:o="axios",{serviceName:n,httpClient:o}};var Ta=e=>{e.command("service [name]").description("Generate an API service").option("--path <path>","Custom path for service generation (default: create new feature)").option("--axios","Use Axios HTTP client").option("--fetch","Use Fetch HTTP client").option("--crud","Generate full CRUD service (getAll, getById, create, update, delete)").action(async(t,r)=>{try{let i=process.cwd();r.axios&&r.fetch&&(E("Cannot use --axios and --fetch together"),process.exit(1)),m(oe.cyan(`
|
|
1191
|
-
\u{1F527} Service Generator
|
|
1192
|
-
`)),y.start("Detecting project setup...");let n=await M(i);y.succeed("Project setup detected"),n.httpClient==="none"&&(y.fail("No HTTP client is setup in this project"),E("Please setup either AxiosClient or FetchClient first"),m(oe.dim(`
|
|
1193
|
-
Check: lib/utils/http/axios-client or lib/utils/http/fetch-client
|
|
1194
|
-
`)),process.exit(1));let o=[];(n.httpClient==="axios"||n.httpClient==="both")&&o.push("Axios \u2713"),(n.httpClient==="fetch"||n.httpClient==="both")&&o.push("Fetch \u2713"),m(oe.dim(` HTTP Clients: ${o.join(", ")}
|
|
1195
|
-
`));let s=await Ea(t,r.axios,r.fetch,n.httpClient);W(s.serviceName,"service name"),r.path&&pe(r.path,"path");let{basePath:c,servicePath:p}=pd(i,s.serviceName,r.path);ad(p)||await cd(p,{recursive:!0}),Ht(i,c,`${s.serviceName}.service.ts`)&&(E(`Service '${s.serviceName}' already exists at ${c}!`),process.exit(1)),r.crud?(y.start("Generating CRUD service files..."),await Wr({name:s.serviceName,outputPath:p,httpClient:s.httpClient}),y.succeed("CRUD service files generated"),y.start("Registering CRUD API endpoints..."),await va(i,s.serviceName),y.succeed("CRUD API endpoints registered")):await Me(ki(),{projectPath:i,spinner:y,serviceName:s.serviceName,servicePath:p,httpClient:s.httpClient}),ld(s,c,!!r.crud)}catch(i){y.fail("Service generation failed"),E(`${i}`),process.exit(1)}})},pd=(e,t,r)=>{let i;if(r){let n=r.replace(/^src\//,"");if(n.startsWith("features/")){let o=n.split("/")[1];i=$t.join("src","features",o,"services")}else i=$t.join("src",n)}else i=$t.join("src","features",t,"services");return{basePath:i,servicePath:$t.join(e,i)}},ld=(e,t,r=!1)=>{let i=$t.join(t,`${e.serviceName}.service.ts`);m(oe.green(`
|
|
1196
|
-
\u2728 ${r?"CRUD ":""}Service '${e.serviceName}' created successfully!
|
|
1197
|
-
`)),m(oe.dim("Generated files:")),m(oe.dim(` \u{1F4C4} ${i}
|
|
1198
|
-
`)),m(oe.cyan("Next steps:"));let n=t.replace(/^src\//,"@/");m(oe.dim(` 1. Import service: import { ${e.serviceName}Service } from '${n}/${e.serviceName}.service'`)),r?(m(oe.dim(" 2. Available methods: getAll, getById, create, update, delete")),m(oe.dim(" 3. Update DTO types in the service file"))):m(oe.dim(` 2. Use in component: const data = await ${e.serviceName}Service.getAll()`)),m("")};import md from"enquirer";import Fi from"picocolors";var{prompt:dd}=md,Oi=[{key:"http-client",label:"HTTP Client (Axios/Fetch)",flag:"httpClient",handler:or},{key:"dark-theme",label:"Dark Theme",flag:"darkTheme",handler:er},{key:"redux",label:"Redux Toolkit",flag:"redux",handler:gr},{key:"ws",label:"WebSocket Client (requires Redux)",flag:"ws",handler:wr},{key:"i18n",label:"Internationalization (next-intl)",flag:"i18n",handler:mr},{key:"tests",label:"Testing (Vitest + RTL)",flag:"tests",handler:yr},{key:"react-compiler",label:"React Compiler",flag:"reactCompiler",handler:ur},{key:"bundle-analyzer",label:"Bundle Analyzer",flag:"bundleAnalyzer",handler:Wt},{key:"security-headers",label:"Security Headers",flag:"securityHeaders",handler:hr},{key:"validate-scripts",label:"Validation Scripts",flag:"validateScripts",handler:xr},{key:"commitizen",label:"Commitizen",flag:"commitizen",handler:Xt}],ud=async(e,t={})=>{let r=t.promptFn??dd,i=t.cwd??(()=>process.cwd());m(Fi.cyan(`
|
|
1199
|
-
\u{1F527} Setup Wizard
|
|
1200
|
-
`));let n=Oi.filter(p=>!!e[p.flag]);if(n.length>0){for(let p of n)await p.handler(i());return n.length===1?n[0].key:"multiple"}let s=(await r([{type:"select",name:"feature",message:"What would you like to setup?",choices:[...Oi.map(p=>({name:p.key,message:p.label})),{name:"cancel",message:"Cancel"}]}])).feature;if(s==="cancel")return m(Fi.yellow("Setup cancelled.")),null;let c=Oi.find(p=>p.key===s);return c?(await c.handler(i()),c.key):(m(Fi.yellow(`
|
|
1201
|
-
\u26A0\uFE0F ${s} setup is not implemented yet.`)),null)},Ca=e=>{e.command("setup").description("Setup features in an existing Next.js project").option("--http-client","Setup HTTP client (axios|fetch)").option("--dark-theme","Setup Dark Theme (Tailwind + @teispace/next-themes)").option("--redux","Setup Redux Toolkit").option("--ws","Setup WebSocket client (socket.io-client + Redux bridge; requires --redux)").option("--i18n","Setup next-intl for internationalization").option("--tests","Setup testing (Vitest + React Testing Library)").option("--react-compiler","Enable the React Compiler").option("--bundle-analyzer","Add @next/bundle-analyzer").option("--security-headers","Add hardened HTTP headers to next.config.ts").option("--validate-scripts","Add scripts/sync-env.ts, scripts/check-deprecated.ts, and the validate chain").option("--commitizen","Add Commitizen with the conventional-changelog adapter").action(async t=>{try{await ud(t)}catch(r){y.fail("Setup failed"),E(`${r}`),process.exit(1)}})};import{existsSync as hd}from"node:fs";import{mkdir as yd}from"node:fs/promises";import be from"node:path";import Y from"picocolors";q();import fd from"enquirer";var{prompt:gd}=fd,Ra=async(e,t)=>{let r=[];e||r.push({type:"input",name:"sliceName",message:"What is the slice name?",initial:"my-slice",validate:n=>/^[a-z0-9-]+$/.test(n)?!0:"Slice name must be lowercase and contain only alphanumeric characters and hyphens."}),t===void 0&&r.push({type:"confirm",name:"persistSlice",message:"Enable persistence for this slice?",initial:!1});let i=r.length>0?await gd(r):{};return{sliceName:e||i.sliceName,persistSlice:t===void 0?i.persistSlice||!1:t}};var ba=e=>{e.command("slice [name]").description("Generate a Redux slice").option("--path <path>","Custom path for slice generation (default: create new feature)").option("--persist","Enable persistence for this slice").option("--no-persist","Disable persistence for this slice").option("--test","Also generate a sibling test file").option("--no-test","Skip test file generation").action(async(t,r)=>{try{let i=process.cwd();m(Y.cyan(`
|
|
1202
|
-
\u{1F527} Slice Generator
|
|
1203
|
-
`)),y.start("Detecting project setup...");let n=await M(i);y.succeed("Project setup detected"),n.hasRedux||(y.fail("Redux is not setup in this project"),E("Please install @reduxjs/toolkit and react-redux first"),m(Y.dim(`
|
|
1204
|
-
Run: npm install @reduxjs/toolkit react-redux
|
|
1205
|
-
`)),process.exit(1)),m(Y.dim(` Redux: \u2713
|
|
1206
|
-
`));let o=await Ra(t,r.persist);W(o.sliceName,"slice name"),r.path&&pe(r.path,"path");let{basePath:s,slicePath:c}=xd(i,o.sliceName,r.path),p=be.join(i,s);hd(p)||await yd(p,{recursive:!0}),await Se(i,o.sliceName,s)&&(E(`Slice '${o.sliceName}' already exists at ${s}!`),process.exit(1)),await Me(Ni(),{projectPath:i,spinner:y,sliceName:o.sliceName,basePath:s,slicePath:c,persistSlice:o.persistSlice});let d=null;if(wd(r,n.hasTests)){let x=be.join(c,`${o.sliceName}.slice.ts`);y.start("Generating test..."),d=await ge({projectPath:i,sourceFile:x,kind:"slice",symbolName:G(o.sliceName)}),y.succeed("Test generated")}Pd(o,s,d,i)}catch(i){y.fail("Slice generation failed"),E(`${i}`),process.exit(1)}})},xd=(e,t,r)=>{let i;if(r){let n=r.replace(/^src\//,"");if(n.startsWith("features/")){let o=n.split("/")[1];i=be.join("src","features",o,"store")}else i=be.join("src",n)}else i=be.join("src","features",t,"store");return{basePath:i,slicePath:be.join(e,i,t)}},wd=(e,t)=>e.test===!1?!1:e.test===!0?!0:t,Pd=(e,t,r,i)=>{let n=be.join(t,e.sliceName);m(Y.green(`
|
|
1207
|
-
\u2728 Slice '${e.sliceName}' created successfully!
|
|
1208
|
-
`)),m(Y.dim("Generated files:")),m(Y.dim(` \u{1F4C2} ${n}/`)),m(Y.dim(` \u251C\u2500\u2500 ${e.sliceName}.slice.ts`)),m(Y.dim(` \u251C\u2500\u2500 ${e.sliceName}.selectors.ts`)),e.persistSlice&&m(Y.dim(" \u251C\u2500\u2500 persist.ts")),m(Y.dim(` \u251C\u2500\u2500 ${e.sliceName}.types.ts`)),m(Y.dim(` \u2514\u2500\u2500 index.ts
|
|
1209
|
-
`)),r&&m(Y.dim(` \u{1F9EA} ${be.relative(i,r)}
|
|
1210
|
-
`)),m(Y.cyan("Next steps:"));let o=t.replace(/^src\//,"@/");m(Y.dim(` 1. Import actions: import { setLoading, setError } from '${o}/${e.sliceName}'`)),m(Y.dim(" 2. Use in component: dispatch(setLoading(true))")),m("")};import se from"node:path";import Di from"picocolors";w();q();var Ia=e=>{e.command("test <file>").description(`Generate a sibling test file for an existing component, hook, or slice.
|
|
1211
|
-
Infers the kind from filename/content; pass --kind to override.`).option("--kind <kind>","Override inferred kind: component | hook | slice").option("--force","Overwrite an existing test file").action(async(t,r)=>{try{let i=process.cwd(),n=se.isAbsolute(t)?t:se.join(i,t);m(Di.cyan(`
|
|
1212
|
-
\u{1F9EA} Test Generator
|
|
1213
|
-
`)),l(n)||(E(`Source file not found: ${t}`),process.exit(1));let o=await M(i);o.hasTests||(E("Testing is not installed in this project. Run `next-maker setup --tests` first."),process.exit(1));let s=await g(n),c=vd(r.kind)??Sd(n,s);c||(E(`Could not infer test kind for ${se.basename(n)}. Pass --kind component|hook|slice.`),process.exit(1));let p=Ed(n,c),u=Td(n,c);l(u)&&!r.force&&(E(`Test file already exists: ${se.relative(i,u)}. Use --force to overwrite.`),process.exit(1)),y.start(`Generating ${c} test...`);let d=await ge({projectPath:i,sourceFile:n,kind:c,symbolName:p,hasRedux:o.hasRedux,hasI18n:o.hasI18n,hookUsesStore:c==="hook"&&o.hasRedux&&s.includes("useAppSelector")});y.succeed("Test generated"),m(Di.green(`
|
|
1214
|
-
\u2728 Test '${se.basename(d)}' created.
|
|
1215
|
-
`)),m(Di.dim(` \u{1F9EA} ${se.relative(i,d)}`)),m("")}catch(i){y.fail("Test generation failed"),E(`${i}`),process.exit(1)}})},vd=e=>{if(!e)return null;if(e==="component"||e==="hook"||e==="slice")return e;throw new Error(`Invalid --kind: ${e}. Use component | hook | slice.`)},Sd=(e,t)=>{let r=se.basename(e);return/\.slice\.ts$/.test(r)?"slice":/^use[A-Z]/.test(r.replace(/\.tsx?$/,""))?"hook":r.endsWith(".tsx")?"component":/createSlice\s*\(/.test(t)?"slice":/^export\s+(const|function)\s+use[A-Z]/m.test(t)?"hook":null},Ed=(e,t)=>{let r=se.basename(e).replace(/\.(tsx?|jsx?)$/i,"");return t==="slice"?G(r.replace(/\.slice$/,"")):t==="hook"?/^use[A-Z]/.test(r)?r:`use${N(r.replace(/^use-?/,""))}`:N(r)},Td=(e,t)=>{let r=se.dirname(e),i=se.basename(e).replace(/\.(tsx?|jsx?)$/i,""),n=t==="component"?".tsx":".ts";return se.join(r,`${i}.test${n}`)};var $a=e=>{Nn(e),Ca(e),la(e),ba(e),Ta(e),xa(e),ua(e),lo(e),ga(e),da(e),wa(e),Hs(e),na(e),Ns(e),Pa(e),Ia(e)};var Rd=process.emitWarning;process.emitWarning=function(e,t,r,i){if(!(typeof e=="string"&&e.includes("--localstorage-file")&&e.includes("was provided without a valid path")))return Rd.apply(process,arguments)};async function bd(){Mi({logger:t=>Nt(t)});let e=new Cd;e.name("next-maker").description("Teispace Next.js Project Generator").version(ji.version),$a(e),e.parse()}bd().catch(e=>{let t=e&&typeof e=="object"&&"message"in e?e.message:String(e);Nt(`Unexpected error: ${t}`)});
|
|
931
|
+
`,Rs=()=>`node_modules
|
|
932
|
+
**/node_modules
|
|
933
|
+
.git
|
|
934
|
+
.turbo
|
|
935
|
+
**/.next
|
|
936
|
+
**/coverage
|
|
937
|
+
**/playwright-report
|
|
938
|
+
**/test-results
|
|
939
|
+
**/.env
|
|
940
|
+
**/.env.*
|
|
941
|
+
`,js=e=>{if(e.length===0)return{};let t=o=>({...o.dependencies??{},...o.devDependencies??{}}),r=t(e[0]),n={};for(let[o,s]of Object.entries(r))e.every(i=>t(i)[o]===s)&&(n[o]=s);return Object.fromEntries(Object.entries(n).sort(([o],[s])=>o.localeCompare(s)))},Cs=(e,t)=>{let r=structuredClone(e);for(let n of["dependencies","devDependencies"]){let o=r[n];if(o)for(let s of Object.keys(o))t[s]===o[s]&&(o[s]="catalog:")}return r},Ts=e=>Object.keys(e).length?`
|
|
942
|
+
catalog:
|
|
943
|
+
${Object.entries(e).map(([t,r])=>` '${t}': '${r}'`).join(`
|
|
944
|
+
`)}
|
|
945
|
+
`:"";var cp=(e,t=[])=>[...t,e],Os={hooks:!1,commitizen:!1,ci:!1,docker:!1,githubTemplates:!1,communityFiles:[]},As=e=>{e.command("workspace <name>").alias("monorepo").description("Create a pnpm + Turborepo workspace with one starter app per --apps entry").option("--apps <names>","Comma-separated app names","web,admin").option("-y, --yes","Skip prompts and use the starter defaults for every app").option("--preset <name>",`Preset for the apps (${Ie().join(", ")})`).option("--set <key=value>","Starter option applied to every app (repeatable)",cp).option("--starter-path <dir>","Compose from a local starter checkout").option("--docker","Per-app Dockerfiles (turbo prune) and a root docker-compose.yml").option("--no-catalog","Keep dependency ranges in each app instead of the pnpm catalog").option("--no-install","Skip dependency installation").option("--no-git","Skip git init").option("--no-ci","Skip the root GitHub Actions workflow").option("--no-hooks","Skip root git hooks (Husky, lint-staged, commitlint)").action(async(t,r)=>{try{await lp(t,r)}catch(n){x(`${n instanceof Error?n.message:n}`),process.exit(1)}})},je=async(e,t,r,n)=>{let o=$t(e);n.current=o;try{let s=await r();return o.succeed(t),s}finally{n.current===o&&(n.current=null)}},pp=e=>{let t=e.split(",").map(r=>r.trim()).filter(Boolean);if(t.length===0)throw new Error("Pass at least one app name with --apps.");for(let r of t)et(r);if(new Set(t).size!==t.length)throw new Error("App names must be unique.");return t},lp=async(e,t)=>{vt(),et(e);let r=pp(t.apps??"web,admin"),n=v.resolve(process.cwd(),e);if(y(n))throw new Error(`Directory ${e} already exists.`);let o={...t.preset?Ne(t.preset):{},...ye(t.set)};for(let[p,m]of Object.entries(Os))o[p]!==void 0&&JSON.stringify(o[p])!==JSON.stringify(m)&&l(fe.yellow(` ! ${p} is managed at the workspace root; ignoring --set ${p}`)),o[p]=m;o.packageManager="pnpm";let s={current:null},i=async()=>{y(n)&&(s.current?.stop(),s.current=null,l(fe.yellow(`
|
|
946
|
+
Cleaning up ${e}...`)),await Ze(n))},a=xt(async()=>{l(fe.red(`
|
|
947
|
+
Process interrupted.`)),await i()});try{await qt(v.join(n,"apps"),{recursive:!0}),await qt(v.join(n,"packages"),{recursive:!0});let p=B({starterPath:t.starterPath}),m=v.join(n,"apps",r[0]),c=await je(`Fetching starter (${p.location})...`,"Starter fetched.",()=>xe({projectPath:m,source:p,supplied:o,packageManager:"pnpm"}),s);if(!t.yes){let b=await Rt(c.manifest,c.answers);c=tt(c.manifest,{...b,...Os,packageManager:"pnpm"},"pnpm"),l("")}for(let b of c.forced)l(fe.yellow(` ! ${b.reason}; ${b.option} turned off`));let d=JSON.parse(await Jt(v.join(m,"package.json"),"utf-8")),u=await Jt(v.join(m,"pnpm-workspace.yaml"),"utf-8"),f={};for(let b of[".nvmrc",".npmrc",".editorconfig"])y(v.join(m,b))&&(f[b]=await Jt(v.join(m,b),"utf-8"));let h=b=>le(b,{projectName:b,description:`${b} app of ${e}`,readme:!0,copyEnv:!0});await je(`Composing apps/${r[0]}...`,`apps/${r[0]} composed.`,()=>be(m,h(r[0]),c,p),s);for(let b of r.slice(1)){let S=v.join(n,"apps",b);await je(`Composing apps/${b}...`,`apps/${b} composed.`,async()=>{let R=await xe({projectPath:S,source:p,supplied:c.answers,packageManager:"pnpm"});await be(S,h(b),R,p)},s)}let w=[];for(let b of r){let S=v.join(n,"apps",b);for(let D of["pnpm-workspace.yaml","pnpm-lock.yaml",".npmrc",".nvmrc"])await ap(v.join(S,D),{force:!0});let R=JSON.parse(await Jt(v.join(S,"package.json"),"utf-8"));delete R.packageManager,delete R.engines,w.push(R)}let P=t.catalog===!1?{}:js(w);for(let[b,S]of r.entries()){let R=Cs(w[b],P);await I(v.join(n,"apps",S,"package.json"),`${JSON.stringify(R,null,2)}
|
|
948
|
+
`),t.docker&&await I(v.join(n,"apps",S,"Dockerfile"),Ss(S))}await je("Writing workspace root...","Workspace root written.",async()=>{let b={name:e,description:`${e} workspace`,author:d.author??"",apps:r,packageManager:"pnpm",packageManagerPin:d.packageManager??"pnpm@11.25.0",nodeEngine:d.engines?.node??">=24.0.0",turboVersion:"^2.10.0",biomeVersion:d.devDependencies?.["@biomejs/biome"]??"^2.5.0",hooks:t.hooks!==!1,huskyVersion:d.devDependencies?.husky,lintStagedVersion:d.devDependencies?.["lint-staged"],commitlintCliVersion:d.devDependencies?.["@commitlint/cli"],commitlintConfigVersion:d.devDependencies?.["@commitlint/config-conventional"]};await I(v.join(n,"package.json"),gs(b)),await I(v.join(n,"pnpm-workspace.yaml"),hs(u)+Ts(P)),await I(v.join(n,"turbo.json"),ys()),await I(v.join(n,"biome.json"),ws(b.biomeVersion)),await I(v.join(n,".gitignore"),xs()),await I(v.join(n,"README.md"),bs(b,c.manifest.starter.version)),await I(v.join(n,"packages",".gitkeep"),"");for(let[S,R]of Object.entries(f))await I(v.join(n,S),R);if(t.docker&&(await I(v.join(n,"docker-compose.yml"),Es(r)),await I(v.join(n,".dockerignore"),Rs())),t.ci!==!1&&(await qt(v.join(n,".github","workflows"),{recursive:!0}),await I(v.join(n,".github","workflows","ci.yml"),vs())),t.hooks!==!1){await I(v.join(n,".lintstagedrc.mjs"),$s()),await I(v.join(n,"commitlint.config.mjs"),Ps()),await qt(v.join(n,".husky"),{recursive:!0});for(let[S,R]of Object.entries(ks())){let D=v.join(n,".husky",S);await I(D,R),await sp(D,493)}}await I(v.join(n,".next-maker.json"),`${JSON.stringify({workspace:!0,apps:r,starter:c.manifest.starter,answers:c.answers,docker:!!t.docker,catalog:t.catalog!==!1},null,2)}
|
|
949
|
+
`)},s),t.install!==!1&&(await je("Installing dependencies with pnpm...","Dependencies installed.",()=>pe(n,"pnpm"),s),await je("Formatting...","Formatted.",()=>Et(n,"pnpm","lint:fix"),s));for(let b of r){let S=v.join(n,"apps",b,".env.example");y(S)&&await ip(S,v.join(n,"apps",b,".env"))}t.git!==!1&&await je("Initializing git...","Git initialized.",()=>St(n),s),a(),l(""),l(fe.green(`\u2728 Workspace ${e} is ready with ${r.map(b=>`apps/${b}`).join(", ")}.`)),l(""),l("Next:"),l(fe.cyan(` cd ${e}`)),t.install===!1&&l(fe.cyan(" pnpm install")),l(fe.cyan(` pnpm --filter ${r[0]} dev`)),l("")}catch(p){throw a(),s.current?.fail("Failed to create workspace."),s.current=null,await i(),p}};var Is=e=>{Tn(e),As(e),ms(e),Qo(e),ls(e),zo(e),us(e),ns(e),es(e),Ko(e),Po(e),Yo(e),Ho(e),ts(e),Eo(e),Vo(e),ko(e),rs(e),fs(e)};var dp=process.emitWarning;process.emitWarning=function(e,t,r,n){if(!(typeof e=="string"&&e.includes("--localstorage-file")&&e.includes("was provided without a valid path")))return dp.apply(process,arguments)};async function up(){an({logger:t=>bt(t)});let e=new mp;e.name("next-maker").description("Teispace Next.js Project Generator").version(Te.version),Is(e),e.parse()}up().catch(e=>{let t=e&&typeof e=="object"&&"message"in e?e.message:String(e);bt(`Unexpected error: ${t}`)});
|