@forinda/kickjs-cli 6.7.0 → 6.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{agent-docs-tlau7tZv.mjs → agent-docs-fKQUJYgz.mjs} +3 -3
- package/dist/{agent-docs-tlau7tZv.mjs.map → agent-docs-fKQUJYgz.mjs.map} +1 -1
- package/dist/{build-CDi72mKz.mjs → build-BDx9kJD_.mjs} +3 -3
- package/dist/{build-CDi72mKz.mjs.map → build-BDx9kJD_.mjs.map} +1 -1
- package/dist/{builtins-BiTg6p4D.mjs → builtins-5XvbxXOT.mjs} +2 -2
- package/dist/cli.mjs +153 -103
- package/dist/{config-D6C74vFp.mjs → config-13M-pdRz.mjs} +3 -3
- package/dist/{config-D6C74vFp.mjs.map → config-13M-pdRz.mjs.map} +1 -1
- package/dist/{doctor-BHnei8KS.mjs → doctor-ebixckGm.mjs} +28 -28
- package/dist/{doctor-BHnei8KS.mjs.map → doctor-ebixckGm.mjs.map} +1 -1
- package/dist/{fullstack-Cmedpn8G.mjs → fullstack-1pSNtZTQ.mjs} +4 -4
- package/dist/{fullstack-Cmedpn8G.mjs.map → fullstack-1pSNtZTQ.mjs.map} +1 -1
- package/dist/{fullstack-e-wuEMD0.mjs → fullstack-DkQrZR8Y.mjs} +1 -1
- package/dist/index.d.mts +45 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -3
- package/dist/plugin-CQ0NPO0o.mjs +13 -0
- package/dist/plugin-CQ0NPO0o.mjs.map +1 -0
- package/dist/{plugin-BlWy4Nbd.mjs → plugin-CYc-Ejd5.mjs} +3 -3
- package/dist/{plugin-BlWy4Nbd.mjs.map → plugin-CYc-Ejd5.mjs.map} +1 -1
- package/dist/{project-CnU7KcYI.mjs → project-BX9P1ntp.mjs} +5 -5
- package/dist/{project-CnU7KcYI.mjs.map → project-BX9P1ntp.mjs.map} +1 -1
- package/dist/{project-docs-BV-h5EmP.mjs → project-docs-ZT5I_aDa.mjs} +47 -11
- package/dist/project-docs-ZT5I_aDa.mjs.map +1 -0
- package/dist/{project-root-CdqXle6R.mjs → project-root-DYE4IdOm.mjs} +3 -3
- package/dist/{project-root-CdqXle6R.mjs.map → project-root-DYE4IdOm.mjs.map} +1 -1
- package/dist/{prompts-D7bKHNce.mjs → prompts-DWyN3rhd.mjs} +2 -2
- package/dist/{prompts-D7bKHNce.mjs.map → prompts-DWyN3rhd.mjs.map} +1 -1
- package/dist/{rolldown-runtime-DiP_G7eI.mjs → rolldown-runtime-BhiQ_pHx.mjs} +1 -1
- package/dist/{run-plugins-C5kGYAsD.mjs → run-plugins-EHBKYR0W.mjs} +55 -42
- package/dist/run-plugins-EHBKYR0W.mjs.map +1 -0
- package/dist/typegen-BFMgqlSf.mjs +114 -0
- package/dist/typegen-BFMgqlSf.mjs.map +1 -0
- package/dist/{types-BNOSmSFj.mjs → types-BCWqa1Q6.mjs} +1 -1
- package/package.json +3 -3
- package/dist/index.mjs.map +0 -1
- package/dist/project-docs-BV-h5EmP.mjs.map +0 -1
- package/dist/run-plugins-C5kGYAsD.mjs.map +0 -1
- package/dist/typegen-qeQ5co2C.mjs +0 -114
- package/dist/typegen-qeQ5co2C.mjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @forinda/kickjs-cli v6.
|
|
2
|
+
* @forinda/kickjs-cli v6.8.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Felix Orinda
|
|
5
5
|
*
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import{c as e,l as t,s as n}from"./project-docs-
|
|
11
|
+
import{c as e,l as t,s as n}from"./project-docs-ZT5I_aDa.mjs";import{a as r,c as i,d as a,i as o,l as s,n as c,o as l,r as u,s as d,t as f,u as p}from"./prompts-DWyN3rhd.mjs";import{A as m,C as h,D as g,E as _,M as v,N as y,O as b,S as x,T as S,_ as ee,a as C,b as te,c as ne,d as re,f as ie,g as ae,h as oe,i as se,j as ce,k as w,l as le,m as ue,p as de,r as fe,u as pe,v as me,w as he,x as ge,y as _e}from"./doctor-ebixckGm.mjs";import{a as ve,c as ye,o as be,r as xe,t as Se}from"./project-BX9P1ntp.mjs";import{a as T,i as E,o as Ce,s as we}from"./config-13M-pdRz.mjs";import{t as Te}from"./project-root-DYE4IdOm.mjs";import{n as D}from"./types-BCWqa1Q6.mjs";import{t as Ee}from"./plugin-CQ0NPO0o.mjs";import{t as De}from"./build-BDx9kJD_.mjs";import{n as Oe}from"./agent-docs-fKQUJYgz.mjs";import{n as ke}from"./plugin-CYc-Ejd5.mjs";import{a as Ae,c as je,d as Me,f as Ne,g as Pe,h as Fe,i as Ie,l as Le,m as Re,o as ze,p as Be,r as Ve,s as He,t as O,u as Ue}from"./typegen-BFMgqlSf.mjs";import k,{basename as We,dirname as A,join as j,relative as M,resolve as N,sep as P}from"node:path";import{cpSync as Ge,existsSync as F,mkdirSync as Ke,readFileSync as I,readdirSync as qe,rmSync as Je,writeFileSync as Ye}from"node:fs";import{copyFile as Xe,mkdir as L,readFile as R,readdir as Ze,rm as Qe,stat as $e,writeFile as z}from"node:fs/promises";import{fork as et,spawn as tt,spawnSync as nt}from"node:child_process";import{fileURLToPath as rt,pathToFileURL as B}from"node:url";import{arch as it,platform as at,release as ot}from"node:os";const st=[{value:`swagger`,label:`Swagger`,hint:`OpenAPI docs`},{value:`ws`,label:`WebSocket`,hint:`rooms, heartbeat`},{value:`queue`,label:`Queue`,hint:`BullMQ/RabbitMQ/Kafka`},{value:`devtools`,label:`DevTools`,hint:`debug dashboard`}];function ct(e){e.command(`new [name]`).alias(`init`).description(`Create a new KickJS project (use "." for current directory)`).option(`-d, --directory <dir>`,`Target directory (defaults to project name)`).option(`--pm <manager>`,`Package manager: pnpm | npm | yarn | bun`).option(`--git`,`Initialize git repository`).option(`--no-git`,`Skip git initialization`).option(`--install`,`Install dependencies after scaffolding`).option(`--no-install`,`Skip dependency installation`).option(`-f, --force`,`Remove existing files without prompting`).option(`-t, --template <type>`,`Project template: rest | minimal | fullstack`).option(`--runtime <engine>`,`HTTP runtime: express | fastify | h3`).option(`-r, --repo <type>`,`Repository name (inmemory, or any DB name e.g. postgres)`).option(`-s, --schema <lib>`,`Schema library for env / DTOs: zod | valibot | yup (default: zod)`).option(`--packages <packages>`,`Comma-separated packages to include (e.g. auth,swagger,ws,queue)`).option(`-y, --yes`,`Pick safe defaults for every prompt (template=minimal, repo=inmemory, no extras, git+install on)`).option(`--non-interactive`,`alias for --yes`).action(async(e,t)=>{c(`KickJS — Create a new project`);let n=!!(t.yes||t.nonInteractive);e||=n?`my-api`:await i({message:`Project name`,placeholder:`my-api`,defaultValue:`my-api`});let a;if(e===`.`?(a=N(`.`),e=We(a)):a=N(t.directory||e),F(a)){let i=qe(a);if(i.length>0){if(t.force)u.warn(`Clearing existing files in ${a}`);else if(n){u.warn(`Directory "${e}" is not empty. Pass --force to clear it.`),r(`Aborted.`);return}else{u.warn(`Directory "${e}" is not empty:`);let t=i.slice(0,5);for(let e of t)u.message(` - ${e}`);if(i.length>5&&u.message(` ... and ${i.length-5} more`),!await f({message:p.red(`Remove all existing files and proceed?`),initialValue:!1})){r(`Aborted.`);return}}for(let e of i)Je(N(a,e),{recursive:!0,force:!0})}}let s=t.template;s||=n?`minimal`:await l({message:`Project template`,options:[{value:`rest`,label:`REST API`,hint:`Express + Swagger`},{value:`minimal`,label:`Minimal`,hint:`bare Express`},{value:`fullstack`,label:`Fullstack`,hint:`server + Vite React web, typed client`}]});let d=t.runtime;d||=n?`express`:await l({message:`HTTP runtime`,options:[{value:`express`,label:`Express`,hint:`default, zero-config`},{value:`fastify`,label:`Fastify`,hint:`fastify + @fastify/middie`},{value:`h3`,label:`h3`,hint:`Nitro / Nuxt engine`}]});let m=t.pm;m||=n?await ye(void 0):await l({message:`Package manager`,options:[{value:`pnpm`,label:`pnpm`},{value:`npm`,label:`npm`},{value:`yarn`,label:`yarn`},{value:`bun`,label:`bun`}]});let h=t.repo;h||=n?`inmemory`:await i({message:`Repository name`,placeholder:`inmemory (or a DB name, e.g. postgres)`,defaultValue:`inmemory`}),we(h);let g=t.schema;g||=n?`zod`:await l({message:`Schema library (env + DTO validation)`,options:[{value:`zod`,label:`Zod`,hint:`default — broad ecosystem`},{value:`valibot`,label:`Valibot`,hint:`smaller bundle`},{value:`yup`,label:`Yup`,hint:`classic API`}]}),[`zod`,`valibot`,`yup`].includes(g)||(u.warn(`Unknown --schema "${g}", falling back to zod.`),g=`zod`);let _;if(t.packages!==void 0){let e=t.packages.trim().toLowerCase();_=e===``||e===`none`||e===`false`?[]:t.packages.split(`,`).map(e=>e.trim()).filter(Boolean)}else _=n?[]:await o({message:`Select packages to include`,options:[...st],required:!1});let v;v=t.git===void 0?n?!0:await f({message:`Initialize git repository?`,initialValue:!0}):t.git;let y;if(y=t.install===void 0?n?!0:await f({message:`Install dependencies?`,initialValue:!0}):t.install,s===`fullstack`){let{initFullstackProject:t}=await import(`./fullstack-1pSNtZTQ.mjs`);await t({name:e,directory:a,packageManager:m,initGit:v,installDeps:y,schemaLib:g,runtime:d}),r(`Done! Next steps: ${p.cyan(`cd ${e} && ${m}${m===`pnpm`?` dev`:` run dev:server`}`)}`);return}await Se({name:e,directory:a,packageManager:m,initGit:v,installDeps:y,template:s,defaultRepo:h,packages:_,schemaLib:g,runtime:d}),r(`Done! Next steps: ${p.cyan(`cd ${e} && ${m} dev`)}`)})}async function lt(e){let{name:n,outDir:r}=e,i=v(n),a=y(n),o=[],s=j(r,`${i}.plugin.ts`);return await t(s,`import {
|
|
12
12
|
definePlugin,
|
|
13
13
|
type AppAdapter,
|
|
14
14
|
type AppModuleEntry,
|
|
@@ -152,9 +152,11 @@ export const ${a}Plugin = definePlugin<${a}PluginConfig>({
|
|
|
152
152
|
},
|
|
153
153
|
}),
|
|
154
154
|
})
|
|
155
|
-
`),o.push(s),o}function
|
|
156
|
-
`)}\n}\n`:``,h=u.length>0?`${f}.withParams<${c}Params>()({`:`${f}({`,g=u.
|
|
157
|
-
|
|
155
|
+
`),o.push(s),o}function ut(e){return e?e.split(`,`).map(e=>e.trim()).filter(Boolean).map(e=>{let[t,n]=e.split(`:`).map(e=>e.trim());return{name:t,type:n||`string`}}).filter(e=>e.name.length>0):[]}async function dt(e){let{name:n,moduleName:r,modulesDir:i,pattern:a}=e,o=e.type??`http`,s=v(n),c=y(n),l=e.key??ce(n),u=Array.isArray(e.params)?e.params:ut(e.params),d=oe({type:`contributor`,outDir:e.outDir,moduleName:r,modulesDir:i,defaultDir:`src/contributors`,pattern:a,shouldPluralize:e.pluralize??!0}),f=o===`http`?`defineHttpContextDecorator`:`defineContextDecorator`,p=o===`http`?`RequestContext`:`ExecutionContext`,m=u.length>0?`\nexport type ${c}Params = {\n${u.map(e=>` ${e.name}: ${e.type}`).join(`
|
|
156
|
+
`)}\n}\n`:``,h=u.length>0?`${f}.withParams<${c}Params>()({`:`${f}({`,g=u.length>0?` // Every call site must supply these — no placeholder defaults.
|
|
157
|
+
// Add \`paramDefaults: { … }\` for any field whose default is
|
|
158
|
+
// genuinely correct for an undecorated route, and drop it from here.
|
|
159
|
+
requiredParams: [${u.map(e=>`'${e.name}'`).join(`, `)}],\n`:``,_=u.length>0?`(ctx, _deps, params)`:`(ctx)`,b=u.length>0?` // \`params\` is typed as ${c}Params (call-site params merged onto any paramDefaults).`:` // \`ctx\` is a ${p} — read ctx.req / ctx.headers / ctx.params (http) or ctx.get (bare).`,x=`import { ${f} } from '@forinda/kickjs'
|
|
158
160
|
import type { ${p} } from '@forinda/kickjs'
|
|
159
161
|
|
|
160
162
|
/**
|
|
@@ -164,17 +166,26 @@ import type { ${p} } from '@forinda/kickjs'
|
|
|
164
166
|
* matched handler runs — the typed, ordered alternative to
|
|
165
167
|
* \`@Middleware()\` when the only job is to populate \`ctx\`.
|
|
166
168
|
*
|
|
167
|
-
* Apply per method/class
|
|
168
|
-
* \`bootstrap({ contributors: [${c}] })\`:
|
|
169
|
+
* Apply per method/class:
|
|
169
170
|
*
|
|
170
|
-
* @${c}${u.length>0?`({ ${u[0]?.name}: … })`:``}
|
|
171
|
+
${o===`http`?` * @${c}${u.length>0?`({ ${u[0]?.name}: … })`:``}
|
|
171
172
|
* @Get('/')
|
|
172
173
|
* handler(ctx: ${p}) {
|
|
173
|
-
* return ctx.json(ctx.
|
|
174
|
-
* }
|
|
174
|
+
* return ctx.json(ctx.require('${l}'))
|
|
175
|
+
* }`:` * // Any transport whose handler receives an ExecutionContext
|
|
176
|
+
* // (WebSocket, queue, cron). Attach via that transport's decorator,
|
|
177
|
+
* // or register the contributor at a module / bootstrap site below.
|
|
178
|
+
* handler(ctx: ${p}) {
|
|
179
|
+
* const value = ctx.require('${l}')
|
|
180
|
+
* }`}
|
|
181
|
+
*
|
|
182
|
+
* Or register at a module / adapter / bootstrap site — those take a
|
|
183
|
+
* \`ContributorRegistration\`, not the decorator itself:
|
|
184
|
+
*
|
|
185
|
+
* bootstrap({ contributors: [${c}${u.length>0?`.with({ ${u[0]?.name}: … })`:``}.registration] })
|
|
175
186
|
*/
|
|
176
187
|
|
|
177
|
-
// Register '${l}' so \`ctx.
|
|
188
|
+
// Register '${l}' so \`ctx.require('${l}')\` is typed and \`dependsOn: ['${l}']\`
|
|
178
189
|
// is checked. Replace \`unknown\` with the resolved value's real type.
|
|
179
190
|
// (For a key you only depend on — no value type needed — declare it in
|
|
180
191
|
// \`interface ContextKeys\` instead.)
|
|
@@ -186,13 +197,13 @@ declare module '@forinda/kickjs' {
|
|
|
186
197
|
${m}
|
|
187
198
|
export const ${c} = ${h}
|
|
188
199
|
key: '${l}',
|
|
189
|
-
${
|
|
190
|
-
${
|
|
200
|
+
${g} resolve: ${_} => {
|
|
201
|
+
${b}
|
|
191
202
|
// TODO: compute and return the value written to ctx.set('${l}', …)
|
|
192
203
|
throw new Error("${c} contributor: resolve() not implemented")
|
|
193
204
|
},
|
|
194
205
|
})
|
|
195
|
-
`,
|
|
206
|
+
`,S=j(d,`${s}.contributor.ts`);return await t(S,x),[S]}async function ft(e){let n=j(e.outDir,`kick.config.ts`),r=e.modulesDir??`src/modules`,i=e.defaultRepo??`inmemory`;return F(n)&&!e.force&&!await f({message:`kick.config.ts already exists. Overwrite?`,initialValue:!1})?(console.log(`
|
|
196
207
|
Skipped — existing kick.config.ts preserved.`),[]):(await t(n,`import { defineConfig } from '@forinda/kickjs-cli'
|
|
197
208
|
|
|
198
209
|
export default defineConfig({
|
|
@@ -241,7 +252,7 @@ ${p}
|
|
|
241
252
|
`||e[l]===`\r`);)l++;let u=e.slice(l),d=/build\s*:\s*\([^)]*\)\s*=>\s*\(\s*\{/g.exec(s);if(!d)return{migrated:null,reason:`build: () => ({...}) not found in defineModule`};let f=d.index+d[0].length-1,p=V(s,f);if(p===-1)return{migrated:null,reason:`unbalanced build() braces`};let m=s.slice(f+1,p),h=H(m,/register\s*\(([^)]*)\)\s*\{/),g=H(m,/contributors\s*\(\s*\)\s*\{/),_=H(m,/routes\s*\(\s*\)\s*\{/);if(!_)return{migrated:null,reason:`routes() method missing inside build()`};let v=mt(c,{container:h!==null,appModule:!0,moduleRoutes:!0,contributorRegistrations:g!==null}),y=``;return h!==null&&(y+=` register(container: Container): void {${U(h,6,4)} }\n\n`),g!==null&&(y+=` contributors(): ContributorRegistrations {${U(g,6,4)} }\n\n`),y+=` routes(): ModuleRoutes {${U(_,6,4)} }`,{migrated:`${v}${`export class ${r} implements AppModule {
|
|
242
253
|
${y}
|
|
243
254
|
}
|
|
244
|
-
`}${u}`}}function _t(e,t){return t===`class`?gt(e):ht(e)}function vt(e,t){let n=e,r=!1;if(t===`define`){/\bAppModuleClass\b/.test(n)&&(n=n.replaceAll(/\bAppModuleClass\b/g,`AppModuleEntry`),r=!0);let e=/(=\s*\[)([\s\S]*?)(])/,t=e.exec(n);if(t){let i=t[1],a=t[3],o=t[2],s=o.replaceAll(/(\b\w+Module)(?![(.])/g,`$1()`);s!==o&&(n=n.replace(e,`${i}${s}${a}`),r=!0)}}else{/\bAppModuleEntry\b/.test(n)&&(n=n.replaceAll(/\bAppModuleEntry\b/g,`AppModuleClass`),r=!0);let e=/(=\s*\[)([\s\S]*?)(])/,t=e.exec(n);if(t){let i=t[1],a=t[3],o=t[2],s=o.replaceAll(/(\b\w+Module)\s*\(\s*\)/g,`$1`);s!==o&&(n=n.replace(e,`${i}${s}${a}`),r=!0)}}return r?{migrated:n}:{migrated:null,reason:`no changes needed`}}async function yt(e){let t=[];return await n(N(e),0),t;async function n(e,r){let i;try{i=await
|
|
255
|
+
`}${u}`}}function _t(e,t){return t===`class`?gt(e):ht(e)}function vt(e,t){let n=e,r=!1;if(t===`define`){/\bAppModuleClass\b/.test(n)&&(n=n.replaceAll(/\bAppModuleClass\b/g,`AppModuleEntry`),r=!0);let e=/(=\s*\[)([\s\S]*?)(])/,t=e.exec(n);if(t){let i=t[1],a=t[3],o=t[2],s=o.replaceAll(/(\b\w+Module)(?![(.])/g,`$1()`);s!==o&&(n=n.replace(e,`${i}${s}${a}`),r=!0)}}else{/\bAppModuleEntry\b/.test(n)&&(n=n.replaceAll(/\bAppModuleEntry\b/g,`AppModuleClass`),r=!0);let e=/(=\s*\[)([\s\S]*?)(])/,t=e.exec(n);if(t){let i=t[1],a=t[3],o=t[2],s=o.replaceAll(/(\b\w+Module)\s*\(\s*\)/g,`$1`);s!==o&&(n=n.replace(e,`${i}${s}${a}`),r=!0)}}return r?{migrated:n}:{migrated:null,reason:`no changes needed`}}async function yt(e){let t=[];return await n(N(e),0),t;async function n(e,r){let i;try{i=await Ze(e)}catch{return}for(let a of i){if(a===`node_modules`||a===`dist`||a===`.kickjs`)continue;let i=j(e,a),o;try{o=await $e(i)}catch{continue}o.isDirectory()?await n(i,r+1):(a.endsWith(`.module.ts`)||a===`index.ts`&&r===1)&&t.push(i)}}}async function bt(e,t){let n=0;return await r(e,t),n;async function r(e,t){let i;try{i=await Ze(e)}catch{return}await L(t,{recursive:!0});for(let a of i){if(a===`node_modules`||a===`dist`||a===`.kickjs`)continue;let i=j(e,a),o=j(t,a),s;try{s=await $e(i)}catch{continue}s.isDirectory()?await r(i,o):(await Xe(i,o),n++)}}}function xt(e){return j(e,`.kickjs`,`codemod-backups`,`${new Date().toISOString().replaceAll(/[:.]/g,`-`)}-modules`)}async function St(e,t){let{dryRun:n=!1,cwd:r=process.cwd(),target:i}=t,a=t.backup??!n,o=await yt(e),s=await R(j(e,`index.ts`),`utf-8`).then(()=>!0,()=>!1),c=null;a&&(o.length>0||s)&&(c=xt(r),await bt(e,c));let l=[];for(let e of o){let t=_t(await R(e,`utf-8`),i);if(t.migrated==null){l.push({path:e,status:`skipped`,reason:t.reason});continue}n||await z(e,t.migrated,`utf-8`),l.push({path:e,status:`migrated`})}let u=j(e,`index.ts`),d=null;try{d=await R(u,`utf-8`)}catch{return{target:i,files:l,indexStatus:`not-found`,indexPath:u,backupDir:c}}let f=vt(d,i);return f.migrated==null?{target:i,files:l,indexStatus:`skipped`,indexPath:u,indexReason:f.reason,backupDir:c}:(n||await z(u,f.migrated,`utf-8`),{target:i,files:l,indexStatus:`migrated`,indexPath:u,backupDir:c})}async function Ct(e,t){let n=await yt(e),r=[],i=t===`define`?/export\s+class\s+\w+Module\s+implements\s+AppModule\s*\{/:/export\s+const\s+\w+Module\s*=\s*defineModule\s*\(/;for(let e of n){let t=await R(e,`utf-8`);i.test(t)&&r.push(e)}return r}async function wt(e){let{name:n,outDir:r}=e,i=y(n),a=v(n),o=ce(n),s=e.queue??`${a}-queue`,c=[];return await(async(e,n)=>{let i=j(r,e);await t(i,n),c.push(i)})(`${a}.job.ts`,`import { Inject } from '@forinda/kickjs'
|
|
245
256
|
import { Job, Process, QUEUE_MANAGER, type QueueService } from '@forinda/kickjs-queue'
|
|
246
257
|
|
|
247
258
|
/**
|
|
@@ -274,7 +285,7 @@ export class ${i}Job {
|
|
|
274
285
|
// Handle high-priority variant of this job
|
|
275
286
|
}
|
|
276
287
|
}
|
|
277
|
-
`),c}const Tt={string:{ts:`string`,zod:`z.string()`},text:{ts:`string`,zod:`z.string()`},number:{ts:`number`,zod:`z.number()`},int:{ts:`number`,zod:`z.number().int()`},float:{ts:`number`,zod:`z.number()`},boolean:{ts:`boolean`,zod:`z.boolean()`},date:{ts:`string`,zod:`z.string().datetime()`},email:{ts:`string`,zod:`z.string().email()`},url:{ts:`string`,zod:`z.string().url()`},uuid:{ts:`string`,zod:`z.string().uuid()`},json:{ts:`any`,zod:`z.any()`}};function Et(e){return e.map(e=>{let t=e.indexOf(`:`);if(t===-1)throw Error(`Invalid field: "${e}". Use format: name:type (e.g. title:string)`);let n=e.slice(0,t),r=e.slice(t+1);if(!n||!r)throw Error(`Invalid field: "${e}". Use format: name:type (e.g. title:string)`);let i=!1;r.endsWith(`:optional`)&&(r=r.slice(0,-9),i=!0),n.endsWith(`?`)&&(n=n.slice(0,-1),i=!0),r.endsWith(`?`)&&(r=r.slice(0,-1),i=!0);let a=r;if(a.startsWith(`enum:`)){let e=a.slice(5).split(`,`);return{name:n,type:`enum`,tsType:e.map(e=>`'${e}'`).join(` | `),zodType:`z.enum([${e.map(e=>`'${e}'`).join(`, `)}])`,optional:i}}let o=Tt[a];if(!o){let e=[...Object.keys(Tt),`enum:a,b,c`].join(`, `);throw Error(`Unknown field type: "${a}". Valid types: ${e}`)}return{name:n,type:a,tsType:o.ts,zodType:o.zod,optional:i}})}async function Dt(e){let{name:n,fields:r,modulesDir:i,repo:a=`inmemory`,tokenScope:o=`app`,style:s=`define`}=e,c=e.pluralize!==!1,l=v(n),u=y(n),d=c?w(l):l,f=c?m(u):u,p=j(i,d),b=[],
|
|
288
|
+
`),c}const Tt={string:{ts:`string`,zod:`z.string()`},text:{ts:`string`,zod:`z.string()`},number:{ts:`number`,zod:`z.number()`},int:{ts:`number`,zod:`z.number().int()`},float:{ts:`number`,zod:`z.number()`},boolean:{ts:`boolean`,zod:`z.boolean()`},date:{ts:`string`,zod:`z.string().datetime()`},email:{ts:`string`,zod:`z.string().email()`},url:{ts:`string`,zod:`z.string().url()`},uuid:{ts:`string`,zod:`z.string().uuid()`},json:{ts:`any`,zod:`z.any()`}};function Et(e){return e.map(e=>{let t=e.indexOf(`:`);if(t===-1)throw Error(`Invalid field: "${e}". Use format: name:type (e.g. title:string)`);let n=e.slice(0,t),r=e.slice(t+1);if(!n||!r)throw Error(`Invalid field: "${e}". Use format: name:type (e.g. title:string)`);let i=!1;r.endsWith(`:optional`)&&(r=r.slice(0,-9),i=!0),n.endsWith(`?`)&&(n=n.slice(0,-1),i=!0),r.endsWith(`?`)&&(r=r.slice(0,-1),i=!0);let a=r;if(a.startsWith(`enum:`)){let e=a.slice(5).split(`,`);return{name:n,type:`enum`,tsType:e.map(e=>`'${e}'`).join(` | `),zodType:`z.enum([${e.map(e=>`'${e}'`).join(`, `)}])`,optional:i}}let o=Tt[a];if(!o){let e=[...Object.keys(Tt),`enum:a,b,c`].join(`, `);throw Error(`Unknown field type: "${a}". Valid types: ${e}`)}return{name:n,type:a,tsType:o.ts,zodType:o.zod,optional:i}})}async function Dt(e){let{name:n,fields:r,modulesDir:i,repo:a=`inmemory`,tokenScope:o=`app`,style:s=`define`}=e,c=e.pluralize!==!1,l=v(n),u=y(n),d=c?w(l):l,f=c?m(u):u,p=j(i,d),b=[],C=async(e,n)=>{let r=j(p,e);await t(r,n),b.push(r)};await C(`${l}.module.ts`,g({pascal:u,kebab:l,plural:d,repo:a,style:s})),await C(`${l}.constants.ts`,ge({pascal:u,kebab:l})),await C(`${l}.controller.ts`,_({pascal:u,kebab:l,plural:d,pluralPascal:f})),await C(`${l}.service.ts`,x({pascal:u,kebab:l})),await C(`dtos/create-${l}.dto.ts`,Ot(u,r)),await C(`dtos/update-${l}.dto.ts`,kt(u,r)),await C(`dtos/${l}-response.dto.ts`,At(u,r)),await C(`${l}.repository.ts`,S({pascal:u,kebab:l,dtoPrefix:`./dtos`,tokenScope:o}));let te=a===`inmemory`,ne=te?`in-memory-${l}`:`${v(a)}-${l}`,re=te?he({pascal:u,kebab:l,repoPrefix:`.`,dtoPrefix:`./dtos`}):h({pascal:u,kebab:l,repoType:a,repoPrefix:`.`,dtoPrefix:`./dtos`});return await C(`${ne}.repository.ts`,re),await ee(i,u,d,l,s),b}function Ot(e,t){return`import { z } from 'zod'
|
|
278
289
|
|
|
279
290
|
export const create${e}Schema = z.object({
|
|
280
291
|
${t.map(e=>{let t=e.zodType;return` ${e.name}: ${t}${e.optional?`.optional()`:``},`}).join(`
|
|
@@ -323,11 +334,11 @@ describe('${s}', () => {
|
|
|
323
334
|
`),c.push(u),c}const Mt=[`agents`,`claude`,`skills`,`gemini`,`copilot`,`both`,`all`];function W(e){return e.parent?.opts()?.dryRun??!1}function G(e,t=!1){let n=process.cwd();console.log(`\n ${t?`Would generate`:`Generated`} ${e.length} file${e.length===1?``:`s`}:`);for(let t of e)console.log(` ${t.replace(n+`/`,``)}`);t&&console.log(`
|
|
324
335
|
(dry run — no files were written)`),console.log()}async function Nt(e){if(!e)try{let e=await E(process.cwd());await O({cwd:process.cwd(),allowDuplicates:!0,silent:!0,schemaValidator:e?.typegen?.schemaValidator??`zod`,envFile:e?.typegen?.envFile,srcDir:e?.typegen?.srcDir,outDir:e?.typegen?.outDir})}catch{}}const Pt=[{name:`module <name>`,description:`REST module (controller, service, DTOs, repo)`},{name:`scaffold <name> <fields...>`,description:`CRUD module from field definitions`},{name:`controller <name>`,description:`@Controller() class [-m module]`},{name:`service <name>`,description:`@Service() singleton [-m module]`},{name:`middleware <name>`,description:`Express middleware function [-m module]`},{name:`guard <name>`,description:`Route guard (auth, roles, etc.) [-m module]`},{name:`contributor <name>`,description:`Context contributor [--type http|bare] [--params a:string] [-m]`},{name:`dto <name>`,description:`Zod DTO schema [-m module]`},{name:`adapter <name>`,description:`AppAdapter with lifecycle hooks (app-level only)`},{name:`test <name>`,description:`Vitest test scaffold [-m module]`},{name:`job <name>`,description:`Queue @Job processor`},{name:`config`,description:`Generate kick.config.ts`},{name:`agents`,description:`Regenerate AGENTS.md + CLAUDE.md + kickjs-skills.md from upstream templates`}],Ft=new Set(Pt.map(e=>e.name.split(` `)[0]));async function It(){console.log(`
|
|
325
336
|
Built-in generators:
|
|
326
|
-
`);let e=Math.max(...Pt.map(e=>e.name.length));for(let t of Pt)console.log(` kick g ${t.name.padEnd(e+2)} ${t.description}`);let t=await E(process.cwd()),n=
|
|
337
|
+
`);let e=Math.max(...Pt.map(e=>e.name.length));for(let t of Pt)console.log(` kick g ${t.name.padEnd(e+2)} ${t.description}`);let t=await E(process.cwd()),n=ke(t?.plugins??[],t?.commands??[]),r=await se(process.cwd(),n.generators);if(r.generators.length>0){console.log(`
|
|
327
338
|
Plugin generators:
|
|
328
339
|
`);let e=Math.max(...r.generators.map(e=>`${e.spec.name} <name>`.length));for(let{source:t,spec:n}of r.generators){let r=`${n.name} <name>`;console.log(` kick g ${r.padEnd(e+2)} ${n.description} [${t}]`)}}if(r.failed.length>0){console.log(`
|
|
329
340
|
Failed to load:
|
|
330
|
-
`);for(let{source:e,reason:t}of r.failed)console.log(` ${e} — ${t}`)}console.log()}async function Lt(e,t,n){let r=await E(process.cwd()),i=T(r),a=t.modulesDir??i.dir??`src/modules`,o=t.repo??
|
|
341
|
+
`);for(let{source:e,reason:t}of r.failed)console.log(` ${e} — ${t}`)}console.log()}async function Lt(e,t,n){let r=await E(process.cwd()),i=T(r),a=t.modulesDir??i.dir??`src/modules`,o=t.repo??te(i.repo);t.repo&&we(t.repo);let s=t.pattern??r?.pattern??`rest`,c=t.pluralize===!1?!1:i.pluralize??!0,l=Ce(r,process.cwd()),u=i.style??`define`;if(!n&&u===`define`){let e=await Ct(N(a),`define`);if(e.length>0){console.error(`\n ${p.red(`Error:`)} ${e.length} module file(s) still use the legacy \`class … implements AppModule\` shape.\n ${p.dim(`Project setting:`)} modules.style: 'define' (default)\n\n ${p.bold(`Files needing migration:`)}`);for(let t of e.slice(0,5))console.error(` - ${t}`);e.length>5&&console.error(` … and ${e.length-5} more`),console.error(`\n ${p.bold(`Pick one:`)}\n 1. Migrate everything to defineModule:\n ${p.dim(`$`)} kick codemod modules --experimental --apply\n 2. Keep the class form — pin it in kick.config.ts:\n ${p.dim(`// kick.config.ts`)}\n ${p.dim(`export default defineConfig({ modules: { style: 'class' } })`)}\n`),process.exit(1)}}let d=[];for(let r of e){let e=await _e({name:r,modulesDir:N(a),noEntity:t.entity===!1,noTests:t.tests===!1,repo:o,minimal:t.minimal,force:t.force,pattern:s,dryRun:n,pluralize:c,prismaClientPath:i.prismaClientPath,tokenScope:l,style:i.style});d.push(...e)}G(d,n),await Nt(n)}function Rt(t,n){let r=t.command(`generate [names...]`).alias(`g`).description("Generate code scaffolds — bare form `kick g <name>` is shorthand for `kick g module <name>`").option(`--list`,`List all available generators`).option(`--dry-run`,`Preview files that would be generated without writing them`).option(`--no-entity`,`Skip entity and value object generation (module shortcut)`).option(`--no-tests`,`Skip test file generation (module shortcut)`).option(`--repo <type>`,`Repository name: inmemory (default) or any DB name (e.g. postgres)`).option(`--pattern <pattern>`,`Override project pattern: rest | minimal`).option(`--minimal`,`Shorthand for --pattern minimal`).option(`--modules-dir <dir>`,`Modules directory`).option(`--no-pluralize`,`Use singular names (skip auto-pluralization)`).option(`-f, --force`,`Overwrite existing files without prompting`).action(async(t,i,a)=>{if(i.list){await It();return}if(!t||t.length===0){r.help();return}let o=W(a);e(o);let[s,c,...l]=t;if(s){let e=await E(process.cwd()),t=ke(e?.plugins??[],e?.commands??[]),r=await C({generatorName:s,itemName:c??``,args:l,flags:i,cwd:process.cwd(),projectRoot:n?.projectRoot},t.generators);if(r){G(r.files,o);return}if(s!==`module`&&Ft.has(s)){console.error(`\n '${s}' is a generator, not a module name.`),console.error(` Did you mean: kick g ${s} ${c??`<name>`}`),console.error(` If that errors, your @forinda/kickjs-cli is older than the '${s}' generator — upgrade it.\n`),process.exitCode=1;return}}await Lt(t,i,o)});r.command(`module <names...>`).description(`Generate one or more modules (e.g. kick g module user task project)`).option(`--no-entity`,`Skip entity and value object generation`).option(`--no-tests`,`Skip test file generation`).option(`--repo <type>`,`Repository name: inmemory (default) or any DB name (e.g. postgres)`).option(`--pattern <pattern>`,`Override project pattern: rest | minimal`).option(`--minimal`,`Shorthand for --pattern minimal`).option(`--modules-dir <dir>`,`Modules directory`).option(`--no-pluralize`,`Use singular names (skip auto-pluralization)`).option(`-f, --force`,`Overwrite existing files without prompting`).action(async(t,n,r)=>{let i=W(r);e(i),await Lt(t,{...r.optsWithGlobals(),...n},i)}),r.command(`adapter <name>`).description(`Generate an AppAdapter with lifecycle hooks and middleware support`).option(`-o, --out <dir>`,`Output directory`,`src/adapters`).action(async(t,n,r)=>{let i=W(r);e(i),G(await ae({name:t,outDir:N(n.out)}),i)}),r.command(`plugin <name>`).description(`Generate a KickPlugin with DI, modules, adapters, middleware, and lifecycle hooks`).option(`-o, --out <dir>`,`Output directory`,`src/plugins`).action(async(t,n,r)=>{let i=W(r);e(i),G(await lt({name:t,outDir:N(n.out)}),i)}),r.command(`middleware <name>`).description(`Generate an Express middleware function
|
|
331
342
|
Use -m to scope it to a module: kick g middleware auth -m users`).option(`-o, --out <dir>`,`Output directory (overrides --module)`).option(`-m, --module <module>`,`Place inside a module folder`).action(async(t,n,r)=>{let i=W(r);e(i);let a=await E(process.cwd()),o=T(a),s=o.dir??`src/modules`;G(await ue({name:t,outDir:n.out,moduleName:n.module,modulesDir:s,pattern:a?.pattern,pluralize:o.pluralize??!0}),i)}),r.command(`guard <name>`).description(`Generate a route guard (auth, roles, etc.)
|
|
332
343
|
Use -m to scope it to a module: kick g guard admin -m users`).option(`-o, --out <dir>`,`Output directory (overrides --module)`).option(`-m, --module <module>`,`Place inside a module folder`).action(async(t,n,r)=>{let i=W(r);e(i);let a=await E(process.cwd()),o=T(a),s=o.dir??`src/modules`;G(await de({name:t,outDir:n.out,moduleName:n.module,modulesDir:s,pattern:a?.pattern,pluralize:o.pluralize??!0}),i)}),r.command(`contributor <name>`).description(`Generate a Context Contributor (typed alternative to @Middleware for ctx.set)
|
|
333
344
|
--type http (default, RequestContext) | bare (ExecutionContext)
|
|
@@ -345,10 +356,10 @@ describe('${s}', () => {
|
|
|
345
356
|
Usage: kick g scaffold <name> <field:type> [field:type...]
|
|
346
357
|
Example: kick g scaffold Post title:string body:text:optional published:boolean:optional
|
|
347
358
|
Optional: append :optional (shell-safe, no quoting needed)
|
|
348
|
-
`),process.exit(1));let o=await E(process.cwd()),s=T(o),c=r.modulesDir??s.dir??`src/modules`,l=Et(n),u=Ce(o,process.cwd()),d=await Dt({name:t,fields:l,modulesDir:N(c),noEntity:r.entity===!1,noTests:r.tests===!1,pluralize:r.pluralize===!1?!1:s.pluralize??!0,tokenScope:u,style:s.style});console.log(`\n Scaffolded ${t} with ${l.length} field(s):`);for(let e of l)console.log(` ${e.name}: ${e.type}${e.optional?` (optional)`:``}`);G(d,a),await Nt(a)}),r.command(`config`).description(`Generate a kick.config.ts at the project root`).option(`--modules-dir <dir>`,`Modules directory path`,`src/modules`).option(`--repo <type>`,`Repository name: inmemory (default) or any DB name`,`inmemory`).option(`-f, --force`,`Overwrite existing kick.config.ts without prompting`).action(async(t,n)=>{let r=W(n);e(r),G(await ft({outDir:N(`.`),modulesDir:t.modulesDir,defaultRepo:t.repo,force:t.force}),r)}),r.command(`agents`).alias(`agent-docs`).alias(`ai-docs`).description(`Regenerate AGENTS.md + CLAUDE.md + kickjs-skills.md (sync after framework upgrades)`).option(`--only <which>`,`Limit scope: agents | claude | skills | both (agents+claude) | all (default: all)`,`all`).option(`--name <name>`,`Project name (defaults to package.json name)`).option(`--pm <pm>`,`Package manager (defaults to package.json packageManager)`).option(`--template <template>`,`Template: rest | minimal`).option(`-f, --force`,`Overwrite existing files without prompting`).action(async(t,n)=>{let r=W(n);e(r);let i=t.only??`all`;if(!Mt.includes(i)){console.error(` Invalid --only value: ${i}. Expected: ${Mt.join(` | `)}`),process.exitCode=1;return}G(await
|
|
349
|
-
`,
|
|
359
|
+
`),process.exit(1));let o=await E(process.cwd()),s=T(o),c=r.modulesDir??s.dir??`src/modules`,l=Et(n),u=Ce(o,process.cwd()),d=await Dt({name:t,fields:l,modulesDir:N(c),noEntity:r.entity===!1,noTests:r.tests===!1,pluralize:r.pluralize===!1?!1:s.pluralize??!0,tokenScope:u,style:s.style});console.log(`\n Scaffolded ${t} with ${l.length} field(s):`);for(let e of l)console.log(` ${e.name}: ${e.type}${e.optional?` (optional)`:``}`);G(d,a),await Nt(a)}),r.command(`config`).description(`Generate a kick.config.ts at the project root`).option(`--modules-dir <dir>`,`Modules directory path`,`src/modules`).option(`--repo <type>`,`Repository name: inmemory (default) or any DB name`,`inmemory`).option(`-f, --force`,`Overwrite existing kick.config.ts without prompting`).action(async(t,n)=>{let r=W(n);e(r),G(await ft({outDir:N(`.`),modulesDir:t.modulesDir,defaultRepo:t.repo,force:t.force}),r)}),r.command(`agents`).alias(`agent-docs`).alias(`ai-docs`).description(`Regenerate AGENTS.md + CLAUDE.md + kickjs-skills.md (sync after framework upgrades)`).option(`--only <which>`,`Limit scope: agents | claude | skills | both (agents+claude) | all (default: all)`,`all`).option(`--name <name>`,`Project name (defaults to package.json name)`).option(`--pm <pm>`,`Package manager (defaults to package.json packageManager)`).option(`--template <template>`,`Template: rest | minimal`).option(`-f, --force`,`Overwrite existing files without prompting`).action(async(t,n)=>{let r=W(n);e(r);let i=t.only??`all`;if(!Mt.includes(i)){console.error(` Invalid --only value: ${i}. Expected: ${Mt.join(` | `)}`),process.exitCode=1;return}G(await Oe({outDir:N(`.`),only:i,name:t.name,pm:t.pm,template:t.template,force:t.force}),r)});for(let e of n?.generators??[])zt(r,e,n?.projectRoot)}function zt(t,n,r){let{source:i,spec:a}=n,o=a.args?.[0],s=o?.name??`itemName`,c=o?.required?`<${s}>`:`[${s}]`,l=`${a.name} ${c} [extraArgs...]`,u=t.command(l).description(`${a.description} [${i}]`);for(let e of a.flags??[]){let t=e.takesValue?`--${e.name} <value>`:`--${e.name}`,n=e.alias?`-${e.alias}, ${t}`:t;u.option(n,e.description??``)}u.action(async(t,i,o,s)=>{let c=W(s);e(c);let l=await C({generatorName:a.name,itemName:t??``,args:i??[],flags:o,cwd:process.cwd(),projectRoot:r},[n]);l&&G(l.files,c)})}function Bt(e,t,n){let r=nt(process.execPath,[e],{cwd:n,stdio:`inherit`,env:{...process.env,...t}});r.status!==0&&process.exit(r.status??1)}async function Vt(e){let t=k.resolve(e.cwd,`.kickjs/types`);e.check||await L(t,{recursive:!0});let n=new Map,r=e.scan??Fe,i=k.resolve(e.cwd,`.kickjs`,`cache`),a=e.scan?void 0:e.changedFiles,o={cwd:e.cwd,config:e.config,async importTs(e){return await import(B(e).href)},async writeFile(t,n){let r=k.resolve(e.cwd,t);await L(k.dirname(r),{recursive:!0}),await z(r,n,`utf8`)},getScanResult:e=>{let t=Ht(e),o=n.get(t);if(!o){let s={cacheDir:i,...e};o=a?Pe(s,a):r(s),n.set(t,o)}return o},log:console},s=[],c=[];for(let n of e.plugins){let r=n.outExtension??`.d.ts`,i=k.join(t,`${n.id.replace(/\//g,`__`)}${r}`),a;try{a=await n.generate(o)}catch(t){let r=t instanceof Error?t.message:String(t);if(e.check)throw Error(`kick typegen --check: ${n.id} failed to generate (${r})`,{cause:t});o.log.error(` ${n.id}: typegen failed (${r}) — keeping previous output`),s.push({id:n.id,status:`error`,outFile:i});continue}if(a===null){s.push({id:n.id,status:`skipped`});continue}let l=`/* AUTO-GENERATED by kick typegen — do not edit. Plugin: ${n.id} */\n\n`+a+`
|
|
360
|
+
`,u=``;if(F(i)&&(u=await R(i,`utf8`)),u===l){s.push({id:n.id,status:`unchanged`,outFile:i});continue}if(e.check){c.push({id:n.id,outFile:i}),s.push({id:n.id,status:`drifted`,outFile:i});continue}await z(i,l,`utf8`),s.push({id:n.id,status:`written`,outFile:i})}if(c.length>0)throw new Ee(c);return s}function Ht(e){let t=(e.extensions??[]).slice().toSorted().join(`,`),n=(e.exclude??[]).slice().toSorted().join(`,`);return[`root=${e.root}`,`cwd=${e.cwd}`,`extensions=${t}`,`exclude=${n}`,`envFile=${e.envFile??``}`].join(`|`)}function Ut(e,t){let n=new Set(t),r=[],i=[],a=new Set;for(let t of e)n.has(t.id)?(i.push(t),a.add(t.id)):r.push(t);return{enabled:r,skipped:i,unknown:[...n].filter(e=>!a.has(e))}}function Wt(){let e=(process.env.LOG_LEVEL??process.env.KICKJS_LOG_LEVEL??``).toLowerCase();return e===`debug`||e===`trace`}async function Gt(e){let{enabled:t,skipped:n,unknown:r}=Ut(ke([...Ar,...e.config?.plugins??[]],e.config?.commands??[]).typegens,e.config?.typegen?.disable??[]);if(!e.silent&&n.length>0)for(let e of n)console.log(` ${e.id}: disabled (typegen.disable)`);if(!e.silent&&r.length>0&&console.warn(` kick typegen: disable list references unknown id(s): ${r.map(e=>`'${e}'`).join(`, `)}. Run \`kick typegen --list\` to see registered ids.`),t.length===0)return[];try{let n=await Vt({cwd:e.cwd,config:e.config??{},plugins:t,check:e.check,changedFiles:e.changedFiles});if(!e.silent&&Wt())for(let e of n)console.log(` ${e.id}: ${e.status}`);return n}catch(t){if(t instanceof Ee||e.check)throw t;if(!e.silent){let e=t instanceof Error?t.message:String(t);console.warn(` kick typegen plugins: skipped (${e})`)}return[]}}function Kt(e){let t=j(e,`node_modules`,`.bin`),n=process.platform===`win32`;for(let e of[`tsgo`,`tsc`]){let r=n?[`${e}.CMD`,`${e}.cmd`,`${e}.exe`]:[e];for(let i of r){let r=j(t,i);if(F(r))return{cmd:r,args:[`--noEmit`],shell:n,kind:e}}}return null}function qt(e){let t=e.spawnFn??tt,n=null,r=0,i=!1;return{schedule(){if(i)return;let a=++r;n&&=(n.kill(),null);let o=Date.now(),s=t(e.bin.cmd,e.bin.args,{cwd:e.cwd,shell:e.bin.shell,stdio:[`ignore`,`pipe`,`pipe`]});n=s;let c=``;s.stdout?.on(`data`,e=>{c+=e.toString()}),s.stderr?.on(`data`,e=>{c+=e.toString()}),s.on(`error`,()=>{a===r&&(n=null)}),s.on(`close`,t=>{i||a!==r||(n=null,e.onResult({ok:t===0,output:c,durationMs:Date.now()-o,kind:e.bin.kind}))})},dispose(){i=!0,n&&=(n.kill(),null)}}}function Jt(e,t=12){let n=e.trim().split(/\r?\n/);return n.length<=t?n.join(`
|
|
350
361
|
`):`${n.slice(0,t).join(`
|
|
351
|
-
`)}\n… ${n.length-t} more line(s)`}function Yt(e){if(typeof e==`boolean`)return e;let t=process.env.KICKJS_WATCH_POLLING;return t===`1`||t===`true`}async function Xt(e,t,n={}){t&&(process.env.PORT=t);let r=Yt(n.polling),i=process.cwd(),a=await E(i),o=a?.typegen?.schemaValidator??`zod`,s=a?.typegen?.envFile;try{await O({cwd:i,allowDuplicates:!0,schemaValidator:o,envFile:s,srcDir:a?.typegen?.srcDir,outDir:a?.typegen?.outDir,assetMap:a?.assetMap,runPlugins:!1})}catch(e){console.warn(` kick typegen: skipped (${e?.message??e})`)}let c=N(i,a?.typegen?.outDir??`.kickjs/types`);try{await
|
|
362
|
+
`)}\n… ${n.length-t} more line(s)`}function Yt(e){if(typeof e==`boolean`)return e;let t=process.env.KICKJS_WATCH_POLLING;return t===`1`||t===`true`}async function Xt(e,t,n={}){t&&(process.env.PORT=t);let r=Yt(n.polling),i=process.cwd(),a=await E(i),o=a?.typegen?.schemaValidator??`zod`,s=a?.typegen?.envFile;try{await O({cwd:i,allowDuplicates:!0,schemaValidator:o,envFile:s,srcDir:a?.typegen?.srcDir,outDir:a?.typegen?.outDir,assetMap:a?.assetMap,runPlugins:!1})}catch(e){console.warn(` kick typegen: skipped (${e?.message??e})`)}let c=N(i,a?.typegen?.outDir??`.kickjs/types`);try{await Ie(c,await Gt({cwd:i,config:a}),!1)}catch(e){console.warn(` kick typegen: plugin pass skipped (${e?.message??e})`)}let{createRequire:l}=await import(`node:module`),{createServer:u}=await import(B(l(N(`package.json`)).resolve(`vite`)).href);globalThis[ne]=`kick-dev`;let d=await u({configFile:N(`vite.config.ts`),server:{port:t?parseInt(t,10):void 0,...r?{watch:{usePolling:!0,interval:100}}:{}}}),f=n.typecheck??a?.dev?.typecheck??!1,p=null,m=!0;if(f){let e=Kt(i);e?p=qt({cwd:i,bin:e,onResult:e=>{d.hot.send({type:`custom`,event:`kickjs:typecheck`,data:{ok:e.ok,output:e.output,durationMs:e.durationMs}}),e.ok?m||(m=!0,console.log(` kick typecheck: clean again (${e.kind}, ${e.durationMs}ms)`)):(m=!1,console.warn(`\n kick typecheck (${e.kind}, ${e.durationMs}ms):`),console.warn(Jt(e.output).replace(/^/gm,` `)))}}):console.warn(` kick dev: --typecheck requested but neither tsgo (@typescript/native-preview) nor typescript is installed in this project — skipping type checks.`)}let h=le({cwd:i,config:a,emitWarning:e=>{console.warn(e),d.hot.send({type:`custom`,event:`kickjs:typegen-error`,data:{message:e,timestamp:Date.now()}})},onPassComplete:()=>p?.schedule()});d.watcher.on(`add`,e=>h.handleWatchEvent(`add`,e)),d.watcher.on(`unlink`,e=>h.handleWatchEvent(`unlink`,e)),d.watcher.on(`change`,e=>h.handleWatchEvent(`change`,e)),d.watcher.on(`unlinkDir`,e=>h.handleWatchEvent(`unlinkDir`,e)),h.assetSrcRoots.length>0&&d.watcher.add([...h.assetSrcRoots]),await d.listen(),d.printUrls(),console.log(`
|
|
352
363
|
KickJS dev server running (Vite + @forinda/kickjs-vite)
|
|
353
364
|
`),p?.schedule();let g=!1,_=async()=>{if(!g){g=!0,h.dispose(),p?.dispose();try{await globalThis.__kickjs_app_shutdown?.()}catch(e){console.error(` app shutdown hook failed: ${e?.message??e}`)}await d.close(),process.exit(0)}};process.on(`SIGINT`,_),process.on(`SIGTERM`,_),process.on(`SIGBREAK`,_)}function Zt(e){e.command(`dev`).description(`Start development server with Vite HMR (zero-downtime reload)`).option(`-e, --entry <file>`,`Entry file`,`src/index.ts`).option(`-p, --port <port>`,`Port number`).option(`--polling`,`Force chokidar to poll for file changes (Docker / WSL / NFS / older kernels)`).option(`--typecheck`,`Run the project TypeScript checker (tsgo/tsc --noEmit) after each change and report diagnostics`).action(async e=>{try{await Xt(e.entry,e.port,{polling:e.polling,typecheck:e.typecheck})}catch(e){e.code===`ERR_MODULE_NOT_FOUND`&&e.message?.includes(`vite`)?console.error(`
|
|
354
365
|
Error: vite is not installed.
|
|
@@ -357,14 +368,14 @@ describe('${s}', () => {
|
|
|
357
368
|
Dev server failed:`,e.message??e),process.exit(1)}}),e.command(`build`).description(`Build for production via Vite`).action(async()=>{console.log(`
|
|
358
369
|
Building for production...
|
|
359
370
|
`);let{createRequire:e}=await import(`node:module`),{build:t}=await import(B(e(N(`package.json`)).resolve(`vite`)).href);await t({configFile:N(`vite.config.ts`)});let n=await E(process.cwd()),r=n?.copyDirs??[];if(r.length>0){console.log(`
|
|
360
|
-
Copying directories to dist...`);for(let e of r){let t=typeof e==`string`?e:e.src,n=typeof e==`string`?j(`dist`,e):e.dest??j(`dist`,t),r=N(t),i=N(n);if(!F(r)){console.log(` ⚠ Skipped ${t} (not found)`);continue}
|
|
361
|
-
Building asset map...`);try{await
|
|
371
|
+
Copying directories to dist...`);for(let e of r){let t=typeof e==`string`?e:e.src,n=typeof e==`string`?j(`dist`,e):e.dest??j(`dist`,t),r=N(t),i=N(n);if(!F(r)){console.log(` ⚠ Skipped ${t} (not found)`);continue}Ke(i,{recursive:!0}),Ge(r,i,{recursive:!0}),console.log(` ✓ ${t} → ${n}`)}}if(n?.assetMap&&Object.keys(n.assetMap).length>0){console.log(`
|
|
372
|
+
Building asset map...`);try{await De(n,{cwd:process.cwd()})}catch(e){console.error(` ✗ asset build failed: ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}console.log(`
|
|
362
373
|
Build complete.
|
|
363
374
|
`)}),e.command(`build:assets`).description(`Rebuild the .kickjs-assets.json manifest under the configured outDir (no JS rebuild)`).action(async()=>{let e=await E(process.cwd());if(!e?.assetMap||Object.keys(e.assetMap).length===0){console.log(` No assetMap entries — nothing to build.`);return}console.log(`
|
|
364
|
-
Building asset map...`);try{await
|
|
375
|
+
Building asset map...`);try{await De(e,{cwd:process.cwd()}),console.log(`
|
|
365
376
|
Asset build complete.
|
|
366
377
|
`)}catch(e){console.error(` ✗ ${e instanceof Error?e.message:String(e)}`),process.exit(1)}}),e.command(`start`).description(`Start production server`).option(`-e, --entry <file>`,`Entry file`,`dist/index.js`).option(`-p, --port <port>`,`Port number`).action(e=>{let t={NODE_ENV:`production`};e.port&&(t.PORT=String(e.port)),Bt(e.entry,t)}),e.command(`dev:debug`).description(`Start dev server with Node.js inspector attached`).option(`-e, --entry <file>`,`Entry file`,`src/index.ts`).option(`-p, --port <port>`,`Port number`).option(`--inspect-port <port>`,`Inspector port`,`9229`).action(async e=>{let t=e.inspectPort??`9229`;process.env.NODE_OPTIONS=`--inspect=0.0.0.0:${t}`,console.log(` Debugger: ws://0.0.0.0:${t}`);try{await Xt(e.entry,e.port)}catch(e){console.error(`
|
|
367
|
-
Dev server (debug) failed:`,e.message??e),process.exit(1)}})}function Qt(){try{let e=A(
|
|
378
|
+
Dev server (debug) failed:`,e.message??e),process.exit(1)}})}function Qt(){try{let e=A(rt(import.meta.url));return JSON.parse(I(j(e,`..`,`package.json`),`utf-8`)).version??`unknown`}catch{return`unknown`}}const $t=new Set(Object.values(xe).filter(e=>e.deprecated).map(e=>e.pkg));function en(e){let t=j(e,`package.json`);if(!F(t))return[];let n;try{n=JSON.parse(I(t,`utf-8`))}catch{return[]}let r={...n.dependencies,...n.devDependencies};return Object.keys(r).filter(e=>e===`@forinda/kickjs`||e.startsWith(`@forinda/kickjs-`)).toSorted().map(t=>{let n=null,i=j(e,`node_modules`,...t.split(`/`),`package.json`);if(F(i))try{n=JSON.parse(I(i,`utf-8`)).version??null}catch{}return{name:t,installed:n,declared:r[t]??null,deprecated:$t.has(t)}})}function tn(e){let t=e;for(;;){if(F(j(t,`package.json`)))return t;let e=A(t);if(e===t)return null;t=e}}function nn(e){e.command(`info`).description(`Print system and framework info`).action(()=>{let e=[``,` KickJS CLI v${Qt()}`,``,` System:`,` OS: ${at()} ${ot()} (${it()})`,` Node: ${process.version}`],t=tn(process.cwd()),n=t?en(t):[];if(!t)e.push(``,` Packages: (not inside a project — no package.json found)`);else if(n.length===0)e.push(``,` Packages: (no @forinda/kickjs* dependencies in ${t})`);else{e.push(``,` Packages:`);let t=Math.max(...n.map(e=>e.name.length));for(let r of n){let n=r.installed??`${r.declared??`?`} (declared — not installed)`,i=r.deprecated?" [DEPRECATED — see `kick add --list --all`]":``;e.push(` ${r.name.padEnd(t+2)} ${n}${i}`)}}e.push(``),console.log(e.join(`
|
|
368
379
|
`))})}const{bold:K,dim:q,green:rn,red:J,yellow:an,blue:on}=p;function sn(e){let t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60),i=e%60,a=[];return t&&a.push(`${t}d`),n&&a.push(`${n}h`),r&&a.push(`${r}m`),a.push(`${i}s`),a.join(` `)}async function cn(e){let t=await fetch(e,{signal:AbortSignal.timeout(5e3)});if(!t.ok)throw Error(`${t.status} ${t.statusText}`);return t.json()}async function Y(e,t){try{return await cn(`${e}${t}`)}catch{return null}}async function ln(e){let[t,n,r,i,a]=await Promise.all([Y(e,`/health`),Y(e,`/metrics`),Y(e,`/routes`),Y(e,`/container`),Y(e,`/ws`)]);return{health:t,metrics:n,routes:r,container:i,ws:a}}function un(e,t){let{health:n,metrics:r,routes:i,container:a,ws:o}=t,c=q(`─`.repeat(60));if(console.log(),console.log(K(` KickJS Inspector`)+q(` → ${e}`)),console.log(c),n){let e=n.status===`healthy`?rn(`● healthy`):J(`● `+n.status);console.log(` ${K(`Health:`)} ${e}`)}else console.log(` ${K(`Health:`)} ${J(`● unreachable`)}`);if(r){let e=((r.errorRate??0)*100).toFixed(1),t=r.errorRate>.1?J:r.errorRate>0?an:rn;console.log(` ${K(`Uptime:`)} ${sn(r.uptimeSeconds)}`),console.log(` ${K(`Requests:`)} ${r.requests}`),console.log(` ${K(`Errors:`)} ${r.serverErrors} server, ${r.clientErrors??0} client ${q(`(`)}${t(e+`%`)}${q(`)`)}`)}if(a&&console.log(` ${K(`DI:`)} ${a.count} bindings`),o&&o.enabled&&console.log(` ${K(`WS:`)} ${o.connections??0} connections, ${o.namespaces??0} namespaces`),i?.routes?.length){console.log(),console.log(K(` Routes`)),console.log(c),console.log(` ${q(`METHOD`)} ${q(`PATH`.padEnd(36))} ${q(`CONTROLLER`)}`);for(let e of i.routes){let t=e.path.length>36?e.path.slice(0,33)+`...`:e.path.padEnd(36);console.log(` ${s(e.method)} ${t} ${on(e.controller)}.${q(e.handler)}`)}}console.log(c),console.log()}function dn(e){e.command(`inspect [url]`).description(`Connect to a running KickJS app and display debug info`).option(`-p, --port <port>`,`Override port`).option(`-w, --watch`,`Poll every 5 seconds`).option(`-j, --json`,`Output raw JSON`).action(async(e,t)=>{let n=e??`http://localhost:3000`;if(t.port)try{let e=new URL(n);e.port=t.port,n=e.origin}catch{n=`http://localhost:${t.port}`}let r=`${n.replace(/\/$/,``)}/_debug`,i=async()=>{try{let e=await ln(r);t.json?console.log(JSON.stringify(e,null,2)):un(n,e)}catch(e){t.json?console.log(JSON.stringify({error:String(e)})):(console.error(J(` ✖ Could not connect to ${n}`)),console.error(q(` ${e instanceof Error?e.message:String(e)}`))),t.watch||(process.exitCode=1)}};if(t.watch){let e=async()=>{process.stdout.write(`\x1B[2J\x1B[H`),await i()};await e(),setInterval(e,5e3)}else await i()})}function fn(e,t){let n=e.toLowerCase();return t.every(e=>n.includes(e.toLowerCase()))}function X(e,t){let n=e.toLowerCase();return t.some(e=>n.includes(e.toLowerCase()))}const pn=[{match(e,t){let n=fn(e,[`config`,`get`])&&X(e,[`undefined`,`null`]),r=e.includes(`@Value`)&&X(e,[`undefined`,`is not defined`]);return!n&&!r?null:{confidence:n&&r?90:75,diagnosis:{id:`env-schema-not-registered`,title:`ConfigService.get() returns undefined for user-defined keys`,explanation:`Your src/index.ts is missing \`import "./config"\`. That side-effect import
|
|
369
380
|
registers the env schema with kickjs at module-load time. Without it,
|
|
370
381
|
ConfigService falls back to the base schema (PORT/NODE_ENV/LOG_LEVEL only)
|
|
@@ -475,10 +486,10 @@ Pass a message as a positional arg, --message flag, or pipe via stdin:
|
|
|
475
486
|
|
|
476
487
|
`)}function Z(e,t){return e.split(`
|
|
477
488
|
`).map(e=>`${t}${e}`).join(`
|
|
478
|
-
`)}function Q(e,t){return e.length<=t?e:e.slice(0,t-1)+`…`}function kn(e){return e>=90?`high confidence`:e>=70?`good match`:e>=50?`medium confidence`:`low confidence — verify manually`}function An(e){let t=e.command(`mcp`).description(`Model Context Protocol commands (start | init)`);t.command(`start`,{isDefault:!0}).description(`Run the built application as an MCP server over stdio`).option(`-e, --entry <file>`,`Entry file`,`dist/index.js`).option(`--node-arg <arg...>`,`Extra arguments to pass to node`).action(jn),t.command(`init`).description(`Generate .mcp.json for Claude Code / Cursor / Zed`).option(`-n, --name <name>`,`Server name (defaults to package.json name)`).option(`-o, --out <file>`,`Output file`,`.mcp.json`).option(`-f, --force`,`Overwrite an existing entry without prompting`).option(`--global`,`Write to ~/.mcp.json instead of the project root`).action(Mn)}function jn(e){let t=N(e.entry);F(t)||(process.stderr.write(`Error: entry file not found: ${t}\n\nBuild the app first with \`kick build\`, or pass a custom entry:\n kick mcp -e dist/server.js\n`),process.exit(1));let n=[...e.nodeArg??[],t],r=
|
|
489
|
+
`)}function Q(e,t){return e.length<=t?e:e.slice(0,t-1)+`…`}function kn(e){return e>=90?`high confidence`:e>=70?`good match`:e>=50?`medium confidence`:`low confidence — verify manually`}function An(e){let t=e.command(`mcp`).description(`Model Context Protocol commands (start | init)`);t.command(`start`,{isDefault:!0}).description(`Run the built application as an MCP server over stdio`).option(`-e, --entry <file>`,`Entry file`,`dist/index.js`).option(`--node-arg <arg...>`,`Extra arguments to pass to node`).action(jn),t.command(`init`).description(`Generate .mcp.json for Claude Code / Cursor / Zed`).option(`-n, --name <name>`,`Server name (defaults to package.json name)`).option(`-o, --out <file>`,`Output file`,`.mcp.json`).option(`-f, --force`,`Overwrite an existing entry without prompting`).option(`--global`,`Write to ~/.mcp.json instead of the project root`).action(Mn)}function jn(e){let t=N(e.entry);F(t)||(process.stderr.write(`Error: entry file not found: ${t}\n\nBuild the app first with \`kick build\`, or pass a custom entry:\n kick mcp -e dist/server.js\n`),process.exit(1));let n=[...e.nodeArg??[],t],r=tt(process.execPath,n,{stdio:`inherit`,env:{...process.env,KICK_MCP_STDIO:`1`,NODE_ENV:process.env.NODE_ENV??`production`}});r.on(`error`,e=>{process.stderr.write(`Failed to start MCP server: ${e.message}\n`),process.exit(1)}),r.on(`exit`,(e,t)=>{if(t){process.kill(process.pid,t);return}process.exit(e??0)});let i=e=>{r.killed||r.kill(e)};process.on(`SIGINT`,()=>i(`SIGINT`)),process.on(`SIGTERM`,()=>i(`SIGTERM`))}function Mn(e){let t=process.cwd(),n=Nn(t)??We(t),r=e.name??n,i=e.global?N(process.env.HOME??`.`,`.mcp.json`):N(t,e.out),a={command:`kick`,args:[`mcp`],cwd:t},o={mcpServers:{}};if(F(i))try{let e=I(i,`utf8`),t=JSON.parse(e);t&&typeof t==`object`&&t.mcpServers&&(o={mcpServers:{...t.mcpServers}})}catch(e){let t=e instanceof Error?e.message:String(e);process.stderr.write(`Error: existing ${i} is not valid JSON (${t}).\nFix the file or pass --force to overwrite the entry.\n`),process.exit(1)}o.mcpServers[r]&&!e.force&&(process.stderr.write(`Error: an entry for "${r}" already exists in ${i}.\nPass --force to overwrite it, or use --name to pick a different key.\n`),process.exit(1)),o.mcpServers[r]=a,Ye(i,JSON.stringify(o,null,2)+`
|
|
479
490
|
`,`utf8`),process.stdout.write(`\n ✓ Wrote MCP server entry "${r}" to ${i}\n\n To activate it:\n 1. Build your app: kick build\n 2. Restart your MCP client (Claude Code, Cursor, Zed)\n 3. The server should appear in the client's tool picker\n\n`)}function Nn(e){let t=N(e,`package.json`);if(!F(t))return null;try{let e=I(t,`utf8`),n=JSON.parse(e);return typeof n.name==`string`?n.name:null}catch{return null}}function Pn(e){e.command(`tinker`).description(`Interactive REPL with DI container and services loaded`).option(`-e, --entry <file>`,`Entry file to load`,`src/index.ts`).action(async e=>{let t=process.cwd(),n=N(t,e.entry);F(n)||(console.error(`\n Error: ${e.entry} not found.\n`),process.exit(1));let r=In(t,`tsx`);r||(console.error(`
|
|
480
491
|
Error: tsx not found. Install it: pnpm add -D tsx
|
|
481
|
-
`),process.exit(1));let i=Fn(n,e.entry),a=j(t,`.kick-tinker.mjs`),{writeFileSync:o,unlinkSync:s}=await import(`node:fs`);o(a,i,`utf-8`);try{let e
|
|
492
|
+
`),process.exit(1));let i=Fn(n,e.entry),a=j(t,`.kick-tinker.mjs`),{writeFileSync:o,unlinkSync:s}=await import(`node:fs`);o(a,i,`utf-8`);try{let e=et(a,[],{cwd:t,execPath:r,stdio:`inherit`});await new Promise(t=>{e.on(`exit`,()=>t())})}finally{try{s(a)}catch{}}})}function Fn(e,t){return`
|
|
482
493
|
import 'reflect-metadata'
|
|
483
494
|
|
|
484
495
|
// Prevent bootstrap() from starting the HTTP server
|
|
@@ -536,13 +547,15 @@ server.on('exit', () => {
|
|
|
536
547
|
`;)s++;else{for(s+=2;s+1<a.length&&!(a[s]===`*`&&a[s+1]===`/`);)s++;s+=2}continue}let t=a[s]??``;if(t===`'`||t===`"`||t==="`"){let e=t;for(s++;s<a.length&&a[s]!==e;)a[s]===`\\`&&s++,s++}else if(t===`(`)o++;else if(t===`)`&&(o--,o===0))break;s++}if(o!==0)break;let c=a.slice(t,s);if(n.test(c)){let t=e;for(;t>0&&(a[t-1]===` `||a[t-1]===` `||a[t-1]===`
|
|
537
548
|
`);)t--;a=a.slice(0,t)+a.slice(s+1),r=!0,i=t;continue}i=s+1}return{content:a,changed:r}}function Rn(e,t){let n=me(e);if(!n)return e;let r=n.rhsStart,i=n.rhsEnd+1,a=e.slice(r,i);return a=Ln(a,t).content,a=a.replace(RegExp(`\\s*,?\\s*${b(t)}Module\\b(?:\\s*\\(\\s*\\))?\\s*,?`,`g`),e=>{let t=e.trimStart().startsWith(`,`),n=e.trimEnd().endsWith(`,`);return t&&n?`,`:``}),a=a.replace(/,(\s*])/,`$1`),e.slice(0,r)+a+e.slice(i)}async function zn(e){let{name:t,modulesDir:r,force:i}=e,a=e.pluralize!==!1,o=v(t),s=y(t),c=a?w(o):o,l=j(r,c);if(!await n(l)){console.log(`\n Module not found: ${l}\n`);return}if(!i&&!await f({message:p.red(`Delete module '${c}' at ${l}? This cannot be undone.`),initialValue:!1})){console.log(`
|
|
538
549
|
Cancelled.
|
|
539
|
-
`);return}await
|
|
550
|
+
`);return}await Qe(l,{recursive:!0,force:!0}),console.log(` Deleted: ${l}`);let u=j(r,`index.ts`);if(await n(u)){let e=await R(u,`utf-8`),t=e,n=RegExp(`^import\\s*\\{\\s*${b(s)}Module\\s*\\}\\s*from\\s*['"][^'"]*${b(c)}(?:/[^'"]*)?['"].*\\n?`,`gm`);e=e.replace(n,``),e=Rn(e,s),e=e.replace(/\n{3,}/g,`
|
|
540
551
|
|
|
541
|
-
`),e!==t&&(await z(u,e,`utf-8`),console.log(` Unregistered: ${s}Module from ${u}`))}console.log(`\n Module '${c}' removed.\n`)}function Bn(e){e.command(`remove`).alias(`rm`).description(`Remove generated code`).command(`module <names...>`).description(`Remove one or more modules (e.g. kick rm module user task)`).option(`--modules-dir <dir>`,`Modules directory`).option(`--no-pluralize`,`Use singular module name`).option(`-f, --force`,`Skip confirmation prompt`).action(async(e,t)=>{let n=T(await E(process.cwd())),r=t.modulesDir??n.dir??`src/modules`,i=t.pluralize===!1?!1:n.pluralize??!0;for(let n of e)await zn({name:n,modulesDir:N(r),force:t.force,pluralize:i})})}function Vn(e){if(e!==void 0){if(e===`false`||e===`off`||e===`none`)return!1;if(e===`zod`)return`zod`;if(e===`kickjs-schema`||e===`schema`)return`kickjs-schema`;console.warn(` kick typegen: unknown --schema-validator '${e}' (supported: 'zod', 'kickjs-schema', 'false'). Falling back to project config.`)}}function Hn(e){if(e!==void 0)return e===`false`||e===`off`||e===`none`?!1:e}function Un(e){e.command(`typegen`).description(`Generate type-safe DI registry and module types into .kickjs/types/`).option(`-w, --watch`,`Watch source files and regenerate on change`).option(`-s, --src <dir>`,`Source directory to scan`,`src`).option(`-o, --out <dir>`,`Output directory`,`.kickjs/types`).option(`--silent`,`Suppress output`).option(`--allow-duplicates`,`Auto-namespace duplicate class names instead of failing (use with caution)`).option(`--schema-validator <name>`,`Schema validator for body/query/params typing (currently 'zod' or 'false')`).option(`--env-file <path>`,`Path to env schema file for KickEnv typing (default 'src/env.ts'; pass 'false' to disable)`).option(`--check`,`CI gate:
|
|
552
|
+
`),e!==t&&(await z(u,e,`utf-8`),console.log(` Unregistered: ${s}Module from ${u}`))}console.log(`\n Module '${c}' removed.\n`)}function Bn(e){e.command(`remove`).alias(`rm`).description(`Remove generated code`).command(`module <names...>`).description(`Remove one or more modules (e.g. kick rm module user task)`).option(`--modules-dir <dir>`,`Modules directory`).option(`--no-pluralize`,`Use singular module name`).option(`-f, --force`,`Skip confirmation prompt`).action(async(e,t)=>{let n=T(await E(process.cwd())),r=t.modulesDir??n.dir??`src/modules`,i=t.pluralize===!1?!1:n.pluralize??!0;for(let n of e)await zn({name:n,modulesDir:N(r),force:t.force,pluralize:i})})}function Vn(e){if(e!==void 0){if(e===`false`||e===`off`||e===`none`)return!1;if(e===`zod`)return`zod`;if(e===`kickjs-schema`||e===`schema`)return`kickjs-schema`;console.warn(` kick typegen: unknown --schema-validator '${e}' (supported: 'zod', 'kickjs-schema', 'false'). Falling back to project config.`)}}function Hn(e){if(e!==void 0)return e===`false`||e===`off`||e===`none`?!1:e}function Un(e){e.command(`typegen`).description(`Generate type-safe DI registry and module types into .kickjs/types/`).option(`-w, --watch`,`Watch source files and regenerate on change`).option(`-s, --src <dir>`,`Source directory to scan`,`src`).option(`-o, --out <dir>`,`Output directory`,`.kickjs/types`).option(`--silent`,`Suppress output`).option(`--allow-duplicates`,`Auto-namespace duplicate class names instead of failing (use with caution)`).option(`--schema-validator <name>`,`Schema validator for body/query/params typing (currently 'zod' or 'false')`).option(`--env-file <path>`,`Path to env schema file for KickEnv typing (default 'src/env.ts'; pass 'false' to disable)`).option(`--check`,`CI gate: exit non-zero if any generated file in .kickjs/types/ is out of date (routes, env, db, assets, adopter plugins) instead of writing it`).option(`--fix`,`Patch module import.meta.glob() calls to cover decorated classes that aren't loaded by any glob (orphans)`).option(`--list`,"List every registered typegen plugin id (use to populate `typegen.disable`)").option(`--no-cache`,`Disable the persistent scan cache; re-read + re-extract every file from cold`).action(async e=>{let t=Te(process.cwd()),n=await E(t);if(e.list){let{mergeCliPlugins:e}=await import(`./plugin-CYc-Ejd5.mjs`).then(e=>e.t),{builtinCliPlugins:t}=await import(`./builtins-5XvbxXOT.mjs`),r=e([...t,...n?.plugins??[]],n?.commands??[]),i=new Set(n?.typegen?.disable??[]);if(r.typegens.length===0){console.log(` No typegen plugins registered.`);return}let a=Math.max(...r.typegens.map(e=>e.id.length));console.log(`
|
|
542
553
|
Registered typegen plugins:
|
|
543
|
-
`);for(let e of r.typegens){let t=i.has(e.id)?` (disabled)`:``;console.log(` ${e.id.padEnd(a+2)}inputs: ${e.inputs.join(`, `)||`(none)`}${t}`)}console.log();return}let r=Vn(e.schemaValidator)??n?.typegen?.schemaValidator??`zod`,i=Hn(e.envFile)??n?.typegen?.envFile,a={cwd:t,srcDir:e.src??n?.typegen?.srcDir,outDir:e.out??n?.typegen?.outDir,silent:e.silent,fix:e.fix,allowDuplicates:e.allowDuplicates,noCache:e.cache===!1,schemaValidator:r,envFile:i,assetMap:n?.assetMap,runPlugins:!1};try{if(e.watch){let t=await
|
|
554
|
+
`);for(let e of r.typegens){let t=i.has(e.id)?` (disabled)`:``;console.log(` ${e.id.padEnd(a+2)}inputs: ${e.inputs.join(`, `)||`(none)`}${t}`)}console.log();return}let r=Vn(e.schemaValidator)??n?.typegen?.schemaValidator??`zod`,i=Hn(e.envFile)??n?.typegen?.envFile,a={cwd:t,srcDir:e.src??n?.typegen?.srcDir,outDir:e.out??n?.typegen?.outDir,silent:e.silent,fix:e.fix,allowDuplicates:e.allowDuplicates,noCache:e.cache===!1,schemaValidator:r,envFile:i,assetMap:n?.assetMap,runPlugins:!1};try{if(e.watch){let t=await Ve(a);e.silent||console.log(` kick typegen: watching for changes (Ctrl-C to exit)`);let n=()=>{t(),process.exit(0)};process.on(`SIGINT`,n),process.on(`SIGTERM`,n),await new Promise(()=>{})}else{await O(a);let r=await Gt({cwd:t,config:n??null,silent:e.silent,check:e.check});e.check&&r.some(e=>e.status===`written`)&&process.exit(1),e.check||await Ie(N(t,e.out??n?.typegen?.outDir??`.kickjs/types`),r,e.silent??!1)}}catch(e){e instanceof He?console.error(`
|
|
544
555
|
`+e.message+`
|
|
545
|
-
`):e instanceof
|
|
556
|
+
`):e instanceof Ee?console.error(`
|
|
557
|
+
`+e.message+`
|
|
558
|
+
`):e instanceof Error?console.error(`\n kick typegen failed: ${e.message}`):console.error(`\n kick typegen failed: ${JSON.stringify(e)}`),process.exit(1)}})}function Wn(e){let t=[];if(!F(e))return t;let n=qe(e,{withFileTypes:!0});for(let r of n){let n=j(e,r.name);if(r.isDirectory()){if([`node_modules`,`dist`,`.kickjs`,`.git`].includes(r.name))continue;t.push(...Wn(n))}else r.isFile()&&/\.tsx?$/.test(r.name)&&!r.name.endsWith(`.d.ts`)&&t.push(n)}return t}function Gn(e){try{return I(e,`utf-8`)}catch{return``}}const Kn=new Set([`secret`,`changeme`,`password`,`test`,`default`,``]);function qn(e,t){let n=Gn(j(e,`.env`));if(n){let e=n.match(/^JWT_SECRET\s*=\s*['"]?([^'"\n]*)['"]?/m);if(e){let t=e[1].trim();if(Kn.has(t.toLowerCase())||t.length<32)return{severity:`CRITICAL`,message:`JWT_SECRET appears to be a default value or too short (< 32 chars) — change it`}}}for(let e of t)for(let t of[/JWT_SECRET['"]?\s*[:=]\s*['"]?(secret|changeme|password|test|default)['"]?/i,/secret\s*[:=]\s*['"]?(secret|changeme|password|test|default)['"]?/i])if(t.test(e))return{severity:`CRITICAL`,message:`JWT_SECRET appears to be a default value in source code — use an environment variable`};return null}function Jn(e){for(let t of e)if(/cors\s*\(/.test(t)&&/origin\s*:\s*['"]\*['"]/.test(t))return{severity:`CRITICAL`,message:`CORS origin is '*' — restrict to your domains`};return null}function Yn(e){for(let t of e)if(/rateLimit/i.test(t)||/@RateLimit/i.test(t))return null;return{severity:`WARNING`,message:`No rate limiting detected — add rateLimit() middleware or @RateLimit decorator`}}function Xn(){return process.env.NODE_ENV===`production`?null:{severity:`WARNING`,message:`NODE_ENV is '${process.env.NODE_ENV??`undefined`}', not 'production'`}}function Zn(e){let t=!1,n=!1;for(let r of e)/tokenStore/i.test(r)&&(t=!0),/MemoryTokenStore/i.test(r)&&(n=!0);return n?{severity:`WARNING`,message:`MemoryTokenStore detected — use a persistent store (Redis, DB) for production deployments`}:t?null:{severity:`WARNING`,message:`No token revocation store detected — consider adding one for auth token management`}}function Qn(e){for(let t of e)if(/helmet\s*\(/.test(t))return/security\s*\.\s*helmet\s*.*false/.test(t)?{severity:`WARNING`,message:`Helmet security headers are disabled — enable them for production`}:{severity:`INFO`,message:`Helmet security headers active`};return{severity:`WARNING`,message:`Helmet not detected — add helmet() middleware for security headers`}}function $n(e){for(let t of e)if(/AuthAdapter/i.test(t))return{severity:`INFO`,message:`AuthAdapter configured`};return{severity:`INFO`,message:`No AuthAdapter detected — add one if your app requires authentication`}}function er(e){let t=Wn(j(e,`src`)).map(e=>Gn(e)),n=[],r=qn(e,t);r&&n.push(r);let i=Jn(t);i&&n.push(i);let a=Yn(t);a&&n.push(a);let o=Xn();o&&n.push(o);let s=Zn(t);return s&&n.push(s),n.push(Qn(t)),n.push($n(t)),n}function tr(e){e.command(`check`).description(`Audit project for common issues`).option(`--deploy`,`Run production readiness checks`).action(e=>{if(!e.deploy){console.log(`
|
|
546
559
|
Usage: kick check --deploy
|
|
547
560
|
|
|
548
561
|
Available checks:
|
|
@@ -556,7 +569,7 @@ server.on('exit', () => {
|
|
|
556
569
|
The regex-based rewrite handles the shapes our templates produce.
|
|
557
570
|
Hand-rolled modules with non-standard structures may be skipped.
|
|
558
571
|
Always commit before running with --apply.
|
|
559
|
-
`),process.exit(1));let i=T(await E(process.cwd())),a=N(t.modulesDir??i.dir??`src/modules`),o;t.target===`define`||t.target===`class`?o=t.target:t.target===void 0?o=i.style??`define`:(console.error(`\n ${p.red(`Error:`)} --target must be 'define' or 'class' (got '${t.target}').\n`),process.exit(1));let s=p.dim(`→ ${o}`),c=r?p.dim(`(dry-run)`):p.bold(`(applying)`);console.log(`\n ${p.bold(`kick codemod modules`)} ${s} ${c}`),console.log(` modulesDir: ${p.dim(a)}\n`);let l=t.backup!==!1&&!r,u=await St(a,{dryRun:r,target:o,backup:l});if(u.backupDir){let e=u.backupDir;console.log(` ${p.green(`✓`)} backup: ${p.dim(e)}\n ${p.dim(`(restore: rm -rf <modulesDir> && mv "<backup>" <modulesDir>)`)}\n`)}else!r&&t.backup===!1&&console.log(` ${p.dim(`(--no-backup — skipping snapshot)`)}\n`);let d=0,f=0;for(let e of u.files)if(e.status===`migrated`)d++,console.log(` ${p.green(`✓`)} ${e.path}`);else{f++;let t=p.dim(`(${e.reason??`skipped`})`);console.log(` ${p.dim(`-`)} ${e.path} ${t}`)}if(console.log(),u.indexStatus===`migrated`)console.log(` ${p.green(`✓`)} ${u.indexPath}`);else if(u.indexStatus===`skipped`){let e=p.dim(`(${u.indexReason??`skipped`})`);console.log(` ${p.dim(`-`)} ${u.indexPath} ${e}`)}else console.log(` ${p.dim(`-`)} ${u.indexPath} ${p.dim(`(not found)`)}`);let m=r?p.dim(` (dry-run — pass --apply to write)`):``;console.log(`\n ${p.bold(String(d))} migrated, ${p.bold(String(f))} skipped${m}\n`)})}const ir=()=>({id:`kick/assets`,inputs:[`kick.config.ts`,`kick.config.js`,`kick.config.mjs`],async generate(e){if(!F(k.resolve(e.cwd,`kick.config.ts`)))return null;let t=await E(e.cwd);if(!t?.assetMap)return null;let n=
|
|
572
|
+
`),process.exit(1));let i=T(await E(process.cwd())),a=N(t.modulesDir??i.dir??`src/modules`),o;t.target===`define`||t.target===`class`?o=t.target:t.target===void 0?o=i.style??`define`:(console.error(`\n ${p.red(`Error:`)} --target must be 'define' or 'class' (got '${t.target}').\n`),process.exit(1));let s=p.dim(`→ ${o}`),c=r?p.dim(`(dry-run)`):p.bold(`(applying)`);console.log(`\n ${p.bold(`kick codemod modules`)} ${s} ${c}`),console.log(` modulesDir: ${p.dim(a)}\n`);let l=t.backup!==!1&&!r,u=await St(a,{dryRun:r,target:o,backup:l});if(u.backupDir){let e=u.backupDir;console.log(` ${p.green(`✓`)} backup: ${p.dim(e)}\n ${p.dim(`(restore: rm -rf <modulesDir> && mv "<backup>" <modulesDir>)`)}\n`)}else!r&&t.backup===!1&&console.log(` ${p.dim(`(--no-backup — skipping snapshot)`)}\n`);let d=0,f=0;for(let e of u.files)if(e.status===`migrated`)d++,console.log(` ${p.green(`✓`)} ${e.path}`);else{f++;let t=p.dim(`(${e.reason??`skipped`})`);console.log(` ${p.dim(`-`)} ${e.path} ${t}`)}if(console.log(),u.indexStatus===`migrated`)console.log(` ${p.green(`✓`)} ${u.indexPath}`);else if(u.indexStatus===`skipped`){let e=p.dim(`(${u.indexReason??`skipped`})`);console.log(` ${p.dim(`-`)} ${u.indexPath} ${e}`)}else console.log(` ${p.dim(`-`)} ${u.indexPath} ${p.dim(`(not found)`)}`);let m=r?p.dim(` (dry-run — pass --apply to write)`):``;console.log(`\n ${p.bold(String(d))} migrated, ${p.bold(String(f))} skipped${m}\n`)})}const ir=()=>({id:`kick/assets`,inputs:[`kick.config.ts`,`kick.config.js`,`kick.config.mjs`],async generate(e){if(!F(k.resolve(e.cwd,`kick.config.ts`)))return null;let t=await E(e.cwd);if(!t?.assetMap)return null;let n=Ae(t.assetMap,e.cwd);return n.count===0?null:ze(n)}}),ar="/* eslint-disable */\n// AUTO-GENERATED by `kick typegen`. DO NOT EDIT.\n// Re-run with `kick typegen` or rely on `kick dev` to refresh.\n";function or(e,t,n,r={}){if(e.length===0)return`${ar}
|
|
560
573
|
// (no routes discovered yet — annotate a controller method with
|
|
561
574
|
// @Get/@Post/@Put/@Delete/@Patch and re-run \`kick typegen\`)
|
|
562
575
|
declare global {
|
|
@@ -573,18 +586,18 @@ declare global {
|
|
|
573
586
|
|
|
574
587
|
/** Empty until the first route exists — see kick typegen. */
|
|
575
588
|
export const kickRpc = {} as const
|
|
576
|
-
`;let i=new Map;for(let t of e){let e=i.get(t.controller)??[];e.push(t),i.set(t.controller,e)}let a=new Map,o=new Map,s=e=>{let t=`${e.filePath}::${e.controller}`,n=o.get(t);return n||(n=`_C${o.size}`,o.set(t,n)),n},c=(e,i,o)=>{let s=
|
|
589
|
+
`;let i=new Map;for(let t of e){let e=i.get(t.controller)??[];e.push(t),i.set(t.controller,e)}let a=new Map,o=new Map,s=e=>{let t=`${e.filePath}::${e.controller}`,n=o.get(t);return n||(n=`_C${o.size}`,o.set(t,n)),n},c=(e,i,o)=>{let s=ur(e,i.filePath,t,n,a);if(!s){if(e&&n!==!1){let t=o===`params`?`URL-pattern params`:o===`query`&&i.queryFilterable!==null?`the @ApiQueryParams-derived query shape`:`'unknown'`;r.onWarn?.(`route ${i.controller}.${i.method} (${i.httpMethod} ${i.path}): ${o} schema '${e.identifier}' could not be statically resolved — falling back to ${t}. Export the schema from the controller file or import it with a static specifier.`)}return null}return n===`kickjs-schema`?`import('@forinda/kickjs-schema').InferSchemaOutput<typeof ${s}>`:`import('zod').infer<typeof ${s}>`},l=[];for(let[e,t]of i){let n=[` interface ${e} {`];for(let e of t){let t=e.pathParams.length>0?`{ ${e.pathParams.map(e=>`${e}: string`).join(`; `)} }`:`{}`,r=c(e.bodySchema,e,`body`),i=c(e.querySchema,e,`query`),a=c(e.paramsSchema,e,`params`)??t,o=r??`unknown`,l=i??cr(e),u=c(e.responseSchema??null,e,`response`),d=s(e),f=u??`import('@forinda/kickjs').InferHandlerResponse<${d}['${e.method}']>`,p=lr(e);n.push(` /**`,` * ${e.httpMethod} ${e.path}`,...p.map(e=>` * ${e}`),` */`,` ${e.method}: {`,` params: ${a}`,` body: ${o}`,` query: ${l}`,` response: ${f}`,` contextKeys: ${sr(e)}`,` }`)}n.push(` }`),l.push(n.join(`
|
|
577
590
|
`))}let u=[],d=new Set,f=new Set;i.has(`Api`)&&r.onWarn?.(`controller class 'Api' collides with the reserved KickRoutes.Api client map — its interface declaration-merges into the flat route map. Rename the controller.`);for(let[e,t]of i)for(let n of t){let t=`${n.httpMethod} ${n.mountedPath??n.path}`;if(d.has(t)){r.onWarn?.(`duplicate route '${t}' (${e}.${n.method}) — two handlers claim the same verb+path at runtime. KickRoutes.Api keeps the first (scan order, which may not match runtime dispatch); resolve the conflict in the modules.`);continue}d.add(t),f.add(`${e}.${n.method}`),u.push(` '${t}': ${e}['${n.method}']`)}let p=[` interface Api {`,...u,` }`].join(`
|
|
578
|
-
`);l.push(p);let m=[],h=new Set;for(let[e,t]of i){let n=
|
|
591
|
+
`);l.push(p);let m=[],h=new Set;for(let[e,t]of i){let n=pr(e);if(h.has(n)){r.onWarn?.(`RPC manifest: controller key '${n}' (from ${e}) collides with another controller — keeping the first; rename one class for distinct RPC namespaces.`);continue}h.add(n);let i=[];for(let n of t){if(!f.has(`${e}.${n.method}`))continue;let t=`${n.httpMethod} ${n.mountedPath??n.path}`;i.push(` ${n.method}: '${t}',`)}i.length>0&&m.push(` ${n}: {\n${i.join(`
|
|
579
592
|
`)}\n },`)}let g=[`/**`,` * Runtime route manifest for the tRPC-style sugar:`," * `createRpc(api, kickRpc)` from @forinda/kickjs-client.",` */`,`export const kickRpc = {`,...m,`} as const`].join(`
|
|
580
|
-
`),_=[],v=new Map;for(let t of e)v.set(`${t.filePath}::${t.controller}`,t);for(let[e,n]of o){let r=v.get(e),i=
|
|
593
|
+
`),_=[],v=new Map;for(let t of e)v.set(`${t.filePath}::${t.controller}`,t);for(let[e,n]of o){let r=v.get(e),i=fr(``,r.filePath,t),a=r.controllerIsDefaultExport?`default as ${n}`:`${r.controller} as ${n}`;_.push(`import type { ${a} } from '${i}'`)}let y=_.length>0?_.join(`
|
|
581
594
|
`)+`
|
|
582
|
-
`:``,b=
|
|
595
|
+
`:``,b=dr(a)+y,x=l.join(`
|
|
583
596
|
`);return`${ar}${b}
|
|
584
597
|
declare global {
|
|
585
598
|
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
586
599
|
namespace KickRoutes {
|
|
587
|
-
${
|
|
600
|
+
${x}
|
|
588
601
|
}
|
|
589
602
|
|
|
590
603
|
/** Short alias for \`KickRoutes.Api\` — \`createClient<KickApi>(...)\`. */
|
|
@@ -592,9 +605,9 @@ ${ee}
|
|
|
592
605
|
}
|
|
593
606
|
|
|
594
607
|
${g}
|
|
595
|
-
`}function sr(e){if(e.queryFilterable===null)return`unknown`;let t=e.querySortable??[];return`{ filter?: string | string[]; sort?: ${t.length>0?t.flatMap(e=>[`'${e}'`,`'-${e}'`]).join(` | `):`string`}; q?: string; page?: string; limit?: string }`}function
|
|
608
|
+
`}function sr(e){let t=e.contextKeys;return t==null?`string`:t.length===0?`never`:t.map(e=>JSON.stringify(e)).join(` | `)}function cr(e){if(e.queryFilterable===null)return`unknown`;let t=e.querySortable??[];return`{ filter?: string | string[]; sort?: ${t.length>0?t.flatMap(e=>[`'${e}'`,`'-${e}'`]).join(` | `):`string`}; q?: string; page?: string; limit?: string }`}function lr(e){let t=[];return e.queryFilterable&&e.queryFilterable.length>0&&t.push(`Filterable: ${e.queryFilterable.join(`, `)}`),e.querySortable&&e.querySortable.length>0&&t.push(`Sortable: ${e.querySortable.join(`, `)}`),e.querySearchable&&e.querySearchable.length>0&&t.push(`Searchable: ${e.querySearchable.join(`, `)}`),t}function ur(e,t,n,r,i){if(!e||r===!1||e.source===null)return null;let a=fr(e.source,t,n);if(a===`unknown`)return null;let o=`${a}::${e.identifier}`,s=i.get(o)?.specifier;return s?s=i.get(o).specifier:(s=`_S${i.size}`,i.set(o,{identifier:e.identifier,specifier:s})),s}function dr(e){if(e.size===0)return``;let t=[];for(let[n,r]of e){let[e]=n.split(`::`);t.push(`import type { ${r.identifier} as ${r.specifier} } from '${e}'`)}return t.join(`
|
|
596
609
|
`)+`
|
|
597
|
-
`}function
|
|
610
|
+
`}function fr(e,t,n){if(e===null)return`unknown`;let r=A(n);if(e===``){let e=M(r,t).split(P).join(`/`);return e=e.replace(/\.(ts|tsx|mts|cts)$/i,``),e.startsWith(`.`)||(e=`./`+e),e}if(!e.startsWith(`.`)&&!e.startsWith(`/`))return e;let i=M(r,N(A(t),e)).split(P).join(`/`);return i=i.replace(/\.(ts|tsx|mts|cts)$/i,``),i.startsWith(`.`)||(i=`./`+i),i}function pr(e){let t=e.endsWith(`Controller`)?e.slice(0,-10):e,n=t.length>0?t:e;return n.charAt(0).toLowerCase()+n.slice(1)}const mr=()=>({id:`kick/routes`,outExtension:`.ts`,inputs:[`src/**/*.controller.ts`,`src/**/*.module.ts`],async generate(e){let t=await e.getScanResult({root:hr(e),cwd:e.cwd,envFile:gr(e)}),n=e.config?.typegen?.schemaValidator??`zod`,r=k.resolve(e.cwd,`.kickjs/types/kick__routes.ts`);return or(t.routes,r,n,{onWarn:t=>e.log.warn(t)})}});function hr(e){return k.resolve(e.cwd,e.config?.typegen?.srcDir??`src`)}function gr(e){let t=e.config?.typegen?.envFile;if(t!==!1)return t}function _r(e,t,n=`zod`){if(!e)return null;let r=M(A(t),e.filePath).split(P).join(`/`);return r=r.replace(/\.(ts|tsx|mts|cts)$/i,``),r.startsWith(`.`)||(r=`./`+r),`/* eslint-disable */
|
|
598
611
|
// AUTO-GENERATED by \`kick typegen\`. DO NOT EDIT.
|
|
599
612
|
// Re-run with \`kick typegen\` or rely on \`kick dev\` to refresh.
|
|
600
613
|
|
|
@@ -632,6 +645,6 @@ declare global {
|
|
|
632
645
|
}
|
|
633
646
|
|
|
634
647
|
export {}
|
|
635
|
-
`}const
|
|
636
|
-
`)}}]})];export{Ut as applyDisableFilter,Gt as runAllPluginTypegens,
|
|
637
|
-
//# sourceMappingURL=run-plugins-
|
|
648
|
+
`}const vr=()=>({id:`kick/env`,outExtension:`.ts`,inputs:[`src/env.ts`,`src/**/env.ts`,`src/**/*.env.ts`],async generate(e){let t=br(e);if(t===!1)return null;let n=await e.getScanResult({root:yr(e),cwd:e.cwd,envFile:t});if(!n.env)return null;let r=e.config?.typegen?.schemaValidator??`zod`,i=k.resolve(e.cwd,`.kickjs/types/kick__env.ts`);return _r(n.env,i,r)}});function yr(e){return k.resolve(e.cwd,e.config?.typegen?.srcDir??`src`)}function br(e){return e.config?.typegen?.envFile}function xr(e){return k.resolve(e.cwd,e.config?.typegen?.srcDir??`src`)}function Sr(e){let t=e.config?.typegen?.envFile;if(t!==!1)return t}function $(e){return{root:xr(e),cwd:e.cwd,envFile:Sr(e)}}const Cr=()=>({id:`kick/registry`,inputs:[`src/**/*.ts`],async generate(e){let t=await e.getScanResult($(e)),n=k.resolve(e.cwd,`.kickjs/types/kick__registry.d.ts`),r=new Set(t.collisions.map(e=>e.className));return Be(t.classes,n,r)}}),wr=()=>({id:`kick/services`,inputs:[`src/**/*.ts`],async generate(e){let t=await e.getScanResult($(e)),n=new Set(t.collisions.map(e=>e.className));return Re(`ServiceToken`,Le(t.classes,t.tokens,t.injects,n),"(no tokens discovered — declare with createToken<T>() or `kick g service <name>`)")}}),Tr=()=>({id:`kick/modules`,inputs:[`src/**/*.ts`],async generate(e){return Re(`ModuleToken`,je((await e.getScanResult($(e))).classes),"(no @Module classes discovered — `kick g module <name>` to add one)")}}),Er=()=>({id:`kick/plugins`,inputs:[`src/**/*.ts`],async generate(e){return Ne((await e.getScanResult($(e))).pluginsAndAdapters)}}),Dr=()=>({id:`kick/augmentations`,inputs:[`src/**/*.ts`],async generate(e){return Ue((await e.getScanResult($(e))).augmentations)}}),Or=()=>({id:`kick/context`,inputs:[`src/**/*.ts`],async generate(e){let t=await e.getScanResult($(e));return t.contextKeys.length===0?null:Me(t.contextKeys)}}),kr={fastify:{subpath:`@forinda/kickjs/fastify`,typeName:`FastifyRuntimeTypes`},h3:{subpath:`@forinda/kickjs/h3`,typeName:`H3RuntimeTypes`}},Ar=[D({name:`kick/init`,register:ct}),D({name:`kick/generate`,register:Rt}),D({name:`kick/run`,register:Zt}),D({name:`kick/info`,register:nn}),D({name:`kick/inspect`,register:dn}),D({name:`kick/add`,register:ve}),D({name:`kick/list`,register:be}),D({name:`kick/explain`,register:xn}),D({name:`kick/mcp`,register:An}),D({name:`kick/tinker`,register:Pn}),D({name:`kick/remove`,register:Bn}),D({name:`kick/typegen`,register:Un}),D({name:`kick/check`,register:tr}),D({name:`kick/doctor`,register:fe}),D({name:`kick/codemod`,register:rr}),D({name:`kick/registry`,typegens:[Cr()]}),D({name:`kick/services`,typegens:[wr()]}),D({name:`kick/modules`,typegens:[Tr()]}),D({name:`kick/plugins`,typegens:[Er()]}),D({name:`kick/augmentations`,typegens:[Dr()]}),D({name:`kick/context`,typegens:[Or()]}),D({name:`kick/assets`,typegens:[ir()]}),D({name:`kick/routes`,typegens:[mr()]}),D({name:`kick/env`,typegens:[vr()]}),D({name:`kick/runtime`,typegens:[{id:`kick/runtime`,outExtension:`.ts`,inputs:[`kick.config.ts`,`kick.config.js`,`kick.config.mjs`,`kick.config.json`],async generate(e){let t=e.config?.runtime;if(t!==`fastify`&&t!==`h3`)return null;let{subpath:n,typeName:r}=kr[t];return[`// Runtime escape-hatch types for the '${t}' engine (kick.config runtime).`,`declare module '@forinda/kickjs' {`,` interface KickRuntimeRegister {`,` runtime: import('${n}').${r}`,` }`,`}`,``,`export {}`,``].join(`
|
|
649
|
+
`)}}]})];export{Ut as applyDisableFilter,Gt as runAllPluginTypegens,Ar as t};
|
|
650
|
+
//# sourceMappingURL=run-plugins-EHBKYR0W.mjs.map
|