@forinda/kickjs-cli 8.4.0 → 8.6.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/{project-docs-Ck3uzaEG.mjs → agent-docs-BFOgLbXq.mjs} +81 -71
- package/dist/agent-docs-BFOgLbXq.mjs.map +1 -0
- package/dist/{project-docs-8d5GNDIw.mjs → agent-docs-BU1rORKA.mjs} +75 -67
- package/dist/{build-Bw_SFnBG.mjs → build-CdIpRyfy.mjs} +3 -3
- package/dist/{build-Bw_SFnBG.mjs.map → build-CdIpRyfy.mjs.map} +1 -1
- package/dist/{build-BrNa6gYZ.mjs → build-DlfIkjcw.mjs} +2 -2
- package/dist/{builtins-DHjV84lv.mjs → builtins-CfAXBoIM.mjs} +2 -2
- package/dist/{builtins-CNZ4QP-z.mjs → builtins-CmuUgcIq.mjs} +36 -31
- package/dist/cli.mjs +2 -2
- package/dist/config-SvlcF3Ls.mjs +12 -0
- package/dist/config-ndsVdO8u.mjs +13 -0
- package/dist/config-ndsVdO8u.mjs.map +1 -0
- package/dist/{doctor-DzqvC6jF.mjs → doctor-D3RMXkxE.mjs} +6 -6
- package/dist/{doctor-DzqvC6jF.mjs.map → doctor-D3RMXkxE.mjs.map} +1 -1
- package/dist/fs-DdNMcW_P.mjs +12 -0
- package/dist/fs-DdNMcW_P.mjs.map +1 -0
- package/dist/fs-v57MCgpH.mjs +11 -0
- package/dist/fullstack-DOufUeMv.mjs +95 -0
- package/dist/fullstack-LJwhodT-.mjs +96 -0
- package/dist/fullstack-LJwhodT-.mjs.map +1 -0
- package/dist/index.d.mts +15 -24
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +2 -2
- package/dist/{plugin-C11bSFtE.mjs → plugin-Dighdqh-.mjs} +2 -2
- package/dist/{plugin-BdN4scZR.mjs → plugin-Dn67elEZ.mjs} +2 -2
- package/dist/project-AXCA1hD9.mjs +45 -0
- package/dist/project-Cb_NLUWI.mjs +46 -0
- package/dist/project-Cb_NLUWI.mjs.map +1 -0
- package/dist/{project-root-DORRVmte.mjs → project-root-C7TrLJlZ.mjs} +3 -3
- package/dist/{project-root-DORRVmte.mjs.map → project-root-C7TrLJlZ.mjs.map} +1 -1
- package/dist/{project-root-D_rrQbpy.mjs → project-root-Dgvy5kYG.mjs} +2 -2
- package/dist/{prompts-DHHDYxLL.mjs → prompts-CSATvwXw.mjs} +2 -2
- package/dist/{prompts-DHHDYxLL.mjs.map → prompts-CSATvwXw.mjs.map} +1 -1
- package/dist/{rolldown-runtime-LCdccCoI.mjs → rolldown-runtime-BhxEEqxa.mjs} +1 -1
- package/dist/{run-plugins-DSYGn4AC.mjs → run-plugins-Cf_6BgGZ.mjs} +34 -29
- package/dist/run-plugins-Cf_6BgGZ.mjs.map +1 -0
- package/dist/{typegen-Bv9EzadE.mjs → typegen-97E_RYNp.mjs} +4 -4
- package/dist/typegen-CYhFNfIu.mjs +132 -0
- package/dist/{typegen-COTKpuqW.mjs.map → typegen-CYhFNfIu.mjs.map} +1 -1
- package/dist/{types-CW4qiwB1.mjs → types-lHwt_SNI.mjs} +1 -1
- package/package.json +10 -9
- package/templates/base/feature.json +18 -0
- package/templates/base/files/README.md +61 -0
- package/templates/base/files/_dot_editorconfig +13 -0
- package/templates/base/files/_dot_env +2 -0
- package/templates/base/files/_dot_env.example +2 -0
- package/templates/base/files/_dot_env.test +9 -0
- package/templates/base/files/_dot_env.test.example +11 -0
- package/templates/base/files/_dot_gitattributes +18 -0
- package/templates/base/files/_dot_gitignore +14 -0
- package/templates/base/files/_dot_oxfmtrc.json +9 -0
- package/templates/base/files/kick.config.ts +58 -0
- package/templates/base/files/src/modules/hello/hello.controller.ts +26 -0
- package/templates/base/files/src/modules/hello/hello.module.ts +21 -0
- package/templates/base/files/src/modules/hello/hello.service.ts +12 -0
- package/templates/base/files/src/modules/index.ts +7 -0
- package/templates/base/files/tsconfig.json +21 -0
- package/templates/base/files/vite.config.ts +31 -0
- package/templates/base/files/vitest.config.ts +18 -0
- package/templates/feature-devtools/feature.json +13 -0
- package/templates/feature-queue/feature.json +16 -0
- package/templates/feature-queue/files/_dot_env.append +2 -0
- package/templates/feature-queue/files/_dot_env.example.append +2 -0
- package/templates/feature-swagger/feature.json +16 -0
- package/templates/feature-ws/feature.json +13 -0
- package/templates/fullstack-root/files/_dot_gitignore +8 -0
- package/templates/fullstack-root/files/netlify.toml +13 -0
- package/templates/fullstack-root/files/vercel.json +5 -0
- package/templates/host-config/files/netlify.toml +6 -0
- package/templates/host-config/files/vercel.json +5 -0
- package/templates/runtime-express/feature.json +22 -0
- package/templates/runtime-fastify/feature.json +13 -0
- package/templates/runtime-h3/feature.json +13 -0
- package/templates/schema-valibot/feature.json +3 -0
- package/templates/schema-valibot/files/src/config/index.ts +41 -0
- package/templates/schema-yup/feature.json +3 -0
- package/templates/schema-yup/files/src/config/index.ts +43 -0
- package/templates/schema-zod/feature.json +3 -0
- package/templates/schema-zod/files/src/config/index.ts +41 -0
- package/templates/server-fullstack/feature.json +13 -0
- package/templates/template-minimal/feature.json +10 -0
- package/templates/template-minimal/files/src/index.ts +17 -0
- package/templates/template-rest/feature.json +10 -0
- package/templates/template-rest/files/src/index.ts +28 -0
- package/templates/web-kick/files/web/index.html +12 -0
- package/templates/web-kick/files/web/src/App.tsx +45 -0
- package/templates/web-kick/files/web/src/api.ts +14 -0
- package/templates/web-kick/files/web/src/main.tsx +9 -0
- package/templates/web-kick/files/web/tsconfig.json +15 -0
- package/templates/web-kick/files/web/vite.config.ts +13 -0
- package/dist/agent-docs-BIYv2Od-.mjs +0 -11
- package/dist/agent-docs-DWRW_0cn.mjs +0 -12
- package/dist/agent-docs-DWRW_0cn.mjs.map +0 -1
- package/dist/config-B6LRxtE1.mjs +0 -13
- package/dist/config-B6LRxtE1.mjs.map +0 -1
- package/dist/config-DIH8bQUO.mjs +0 -12
- package/dist/fullstack-BwdcyVD3.mjs +0 -195
- package/dist/fullstack-BwdcyVD3.mjs.map +0 -1
- package/dist/fullstack-CkAO5DhE.mjs +0 -194
- package/dist/project--WiWkarb.mjs +0 -450
- package/dist/project-JoccwqS2.mjs +0 -451
- package/dist/project-JoccwqS2.mjs.map +0 -1
- package/dist/project-docs-8d5GNDIw.mjs.map +0 -1
- package/dist/run-plugins-DSYGn4AC.mjs.map +0 -1
- package/dist/typegen-COTKpuqW.mjs +0 -132
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @forinda/kickjs-cli v8.4.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) Felix Orinda
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
import{l as e}from"./project-docs-8d5GNDIw.mjs";import{d as t,f as n,i as r,n as i,o as a,p as o,t as s}from"./project-JoccwqS2.mjs";import{join as c}from"node:path";import{execFileSync as l}from"node:child_process";const u=`https://kickjs.app/guide/fullstack-frontend.html`,d=[{value:`react-ts`,label:`React`},{value:`react-compiler-ts`,label:`React + Compiler`},{value:`vue-ts`,label:`Vue`},{value:`svelte-ts`,label:`Svelte`},{value:`solid-ts`,label:`Solid`},{value:`preact-ts`,label:`Preact`},{value:`lit-ts`,label:`Lit`},{value:`qwik-ts`,label:`Qwik`},{value:`vanilla-ts`,label:`Vanilla`}],f=`react-ts`;function p(e,t,n=f){let r=[`--template`,n,`--no-interactive`,`--no-immediate`];return e===`yarn`||e===`bun`?[e,`create`,`vite`,t,...r]:e===`npm`?[e,`create`,`vite@latest`,t,`--`,...r]:[e,`create`,`vite@latest`,t,...r]}async function m(d){let{name:m,directory:g,schemaLib:_=`zod`,runtime:v=`express`,frontend:y=`kick`,viteTemplate:b=f}=d,x=[`pnpm`,`npm`,`yarn`,`bun`].includes(d.packageManager),S=x?d.packageManager:`pnpm`,E=g,D=e=>console.log(` ${e}`);d.packageManager!==void 0&&!x&&D(`Warning: unknown package manager '${String(d.packageManager)}' — falling back to pnpm.`),console.log(`\n Creating fullstack KickJS workspace: ${m}\n`),console.log(` Resolving package versions...`);let O=await i();if(await s({name:`${m}-server`,directory:c(E,`server`),packageManager:S,template:`minimal`,schemaLib:_,runtime:v,withClientMap:!0,strictPort:!0,approveInstallScripts:!1,platformConfig:!1,initGit:!1,installDeps:!1,spaClientDir:`../web/dist`,versions:O}),y===`vite`){console.log(`\n Handing web/ to create-vite (${b})...\n`);let[e,...t]=p(S,`web`,b);o(e,t,{cwd:E})}else await h(E,m,O);await e(c(E,`package.json`),C(m,S,O[`@forinda/kickjs-cli`])),S===`pnpm`&&await e(c(E,`pnpm-workspace.yaml`),`packages:
|
|
12
|
-
- server
|
|
13
|
-
- web
|
|
14
|
-
`),a(S,E,r),await e(c(E,`.gitignore`),w()),await e(c(E,`netlify.toml`),t({command:`${S} run build:netlify`,publish:`web/dist`,spa:!0})),await e(c(E,`vercel.json`),n(`${S} run build:vercel`)),await e(c(E,`README.md`),T(m,S,y));let{generateAgentDocs:k}=await import(`./agent-docs-DWRW_0cn.mjs`).then(e=>e.t);if(await k({outDir:E,name:m,pm:S,template:`fullstack`,only:`all`,force:!0}),d.installDeps){console.log(`\n Installing workspace dependencies with ${S}...\n`);try{o(S,[`install`],{cwd:E})}catch{console.log(`\n Warning: ${S} install failed. Run it manually.`)}}try{let{runTypegen:e}=await import(`./typegen-COTKpuqW.mjs`).then(e=>e.n);await e({cwd:c(E,`server`),allowDuplicates:!0,silent:!0})}catch{}if(d.initGit)try{l(`git`,[`init`],{cwd:E,stdio:`pipe`}),l(`git`,[`branch`,`-M`,`main`],{cwd:E,stdio:`pipe`}),l(`git`,[`add`,`-A`],{cwd:E,stdio:`pipe`}),l(`git`,[`commit`,`-m`,`chore: initial commit from kick new (fullstack)`],{cwd:E,stdio:`pipe`}),D(`Git repository initialized`)}catch{D(`Warning: git init failed (git may not be installed)`)}console.log(`
|
|
15
|
-
Fullstack workspace scaffolded!`),console.log(),D(`Next steps:`),D(` cd ${m}`),d.installDeps||D(` ${S} install`),S===`pnpm`?D(` pnpm dev # runs server (kick dev) + web (vite) together`):(D(` ${S} run dev:server # terminal 1`),D(` ${S} run dev:web # terminal 2`)),D(``),y===`vite`?(D(`web/ is create-vite output, unwired. To type it against the API:`),D(` ${u}`)):(D(`The web app calls the API through @forinda/kickjs-client —`),D(`edit server/src/modules/hello and watch web/src/App.tsx's types follow.`)),D(``)}async function h(t,n,r){await e(c(t,`web/package.json`),g(n,r)),await e(c(t,`web/vite.config.ts`),_()),await e(c(t,`web/tsconfig.json`),v()),await e(c(t,`web/index.html`),y(n)),await e(c(t,`web/src/main.tsx`),b()),await e(c(t,`web/src/App.tsx`),x()),await e(c(t,`web/src/api.ts`),S())}function g(e,t){let n=e=>t[e]??`latest`;return`${JSON.stringify({name:`${e}-web`,private:!0,version:`0.0.0`,type:`module`,scripts:{dev:`vite`,build:`tsc --noEmit && vite build`,preview:`vite preview`,typecheck:`tsc --noEmit`},dependencies:{"@forinda/kickjs-client":n(`@forinda/kickjs-client`),react:n(`react`),"react-dom":n(`react-dom`)},devDependencies:{"@types/react":n(`@types/react`),"@types/react-dom":n(`@types/react-dom`),"@vitejs/plugin-react":n(`@vitejs/plugin-react`),typescript:n(`typescript`),vite:n(`vite`)}},null,2)}\n`}function _(){return`import { defineConfig } from 'vite'
|
|
16
|
-
import react from '@vitejs/plugin-react'
|
|
17
|
-
|
|
18
|
-
export default defineConfig({
|
|
19
|
-
plugins: [react()],
|
|
20
|
-
server: {
|
|
21
|
-
// The KickJS server (kick dev) listens on 3000; the client's baseUrl is
|
|
22
|
-
// the relative '/api/v1', so the browser hits Vite and Vite forwards.
|
|
23
|
-
proxy: {
|
|
24
|
-
'/api': 'http://localhost:3000',
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
})
|
|
28
|
-
`}function v(){return`${JSON.stringify({compilerOptions:{target:`ES2022`,lib:[`ES2022`,`DOM`,`DOM.Iterable`],module:`ESNext`,moduleResolution:`bundler`,jsx:`react-jsx`,strict:!0,skipLibCheck:!0,noEmit:!0,isolatedModules:!0,types:[`../server/.kickjs/types/kick__client`]},include:[`src`]},null,2)}\n`}function y(e){return`<!doctype html>
|
|
29
|
-
<html lang="en">
|
|
30
|
-
<head>
|
|
31
|
-
<meta charset="UTF-8" />
|
|
32
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
33
|
-
<title>${e}</title>
|
|
34
|
-
</head>
|
|
35
|
-
<body>
|
|
36
|
-
<div id="root"></div>
|
|
37
|
-
<script type="module" src="/src/main.tsx"><\/script>
|
|
38
|
-
</body>
|
|
39
|
-
</html>
|
|
40
|
-
`}function b(){return`import { StrictMode } from 'react'
|
|
41
|
-
import { createRoot } from 'react-dom/client'
|
|
42
|
-
import { App } from './App'
|
|
43
|
-
|
|
44
|
-
createRoot(document.getElementById('root')!).render(
|
|
45
|
-
<StrictMode>
|
|
46
|
-
<App />
|
|
47
|
-
</StrictMode>,
|
|
48
|
-
)
|
|
49
|
-
`}function x(){return`import { useEffect, useState } from 'react'
|
|
50
|
-
import { api } from './api'
|
|
51
|
-
|
|
52
|
-
// The response types below are INFERRED from the server's handlers —
|
|
53
|
-
// change server/src/modules/hello/hello.service.ts and these types follow on
|
|
54
|
-
// the next \`kick typegen\`. Not under \`kick dev\`: resolving the client map
|
|
55
|
-
// builds a whole TypeScript program, so it is a build step, not a per-save one.
|
|
56
|
-
type Greeting = Awaited<ReturnType<typeof fetchGreeting>>
|
|
57
|
-
|
|
58
|
-
function fetchGreeting() {
|
|
59
|
-
return api.get('/hello')
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function App() {
|
|
63
|
-
const [greeting, setGreeting] = useState<Greeting | null>(null)
|
|
64
|
-
const [health, setHealth] = useState<string>('checking…')
|
|
65
|
-
|
|
66
|
-
useEffect(() => {
|
|
67
|
-
fetchGreeting().then(setGreeting).catch(console.error)
|
|
68
|
-
api
|
|
69
|
-
.get('/hello/health')
|
|
70
|
-
.then((h) => setHealth(h.status))
|
|
71
|
-
.catch(() => setHealth('down'))
|
|
72
|
-
}, [])
|
|
73
|
-
|
|
74
|
-
return (
|
|
75
|
-
<main style={{ fontFamily: 'system-ui', maxWidth: 640, margin: '4rem auto', padding: '0 1rem' }}>
|
|
76
|
-
<h1>KickJS fullstack</h1>
|
|
77
|
-
<p>
|
|
78
|
-
<strong>{greeting?.message ?? 'loading…'}</strong>
|
|
79
|
-
</p>
|
|
80
|
-
<p>
|
|
81
|
-
Server said hello at <code>{greeting?.timestamp ?? '…'}</code> — health:{' '}
|
|
82
|
-
<code>{health}</code>
|
|
83
|
-
</p>
|
|
84
|
-
<p style={{ color: '#666' }}>
|
|
85
|
-
This call is typed end to end: <code>api.get('/hello')</code> returns the exact shape
|
|
86
|
-
<code> HelloService.greet()</code> produces. Rename a field on the server and this file
|
|
87
|
-
stops compiling.
|
|
88
|
-
</p>
|
|
89
|
-
</main>
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
`}function S(){return`import { createClient } from '@forinda/kickjs-client'
|
|
93
|
-
|
|
94
|
-
// KickClientApi is ambient — the resolved route map from
|
|
95
|
-
// server/.kickjs/types/kick__client.d.ts, wired in tsconfig's \`types\`. Every
|
|
96
|
-
// response type is a literal shape, so nothing from the server's source graph
|
|
97
|
-
// enters this program.
|
|
98
|
-
//
|
|
99
|
-
// Keys are module-mount-relative paths; the bootstrap-level '/api/v1' prefix
|
|
100
|
-
// lives here in baseUrl, and the Vite dev proxy forwards it to the KickJS
|
|
101
|
-
// server.
|
|
102
|
-
//
|
|
103
|
-
// Prefer an explicit import? The same file exports the type:
|
|
104
|
-
// import type { Api } from '../../server/.kickjs/types/kick__client'
|
|
105
|
-
export const api = createClient<KickClientApi.Api>({ baseUrl: '/api/v1' })
|
|
106
|
-
`}function C(e,t,n){let r=t===`pnpm`?{dev:`pnpm --parallel -r run dev`,start:`pnpm --filter ./server run start`,"dev:server":`pnpm --filter ./server dev`,"dev:web":`pnpm --filter ./web dev`,build:`pnpm --filter ./server exec kick typegen && pnpm -r run build`,"build:netlify":`pnpm build && pnpm --filter ./server exec kick build:netlify`,"build:vercel":`pnpm build && pnpm --filter ./server exec kick build:vercel`,typecheck:`kick typecheck --cwd server && kick typecheck --cwd web`}:{start:`cd server && ${t} run start`,"dev:server":`cd server && ${t} run dev`,"dev:web":`cd web && ${t} run dev`,build:`cd server && ${t} exec kick typegen && cd .. && ${t} run build:server && ${t} run build:web`,"build:netlify":`${t} run build && cd server && ${t} exec kick build:netlify`,"build:vercel":`${t} run build && cd server && ${t} exec kick build:vercel`,"build:server":`cd server && ${t} run build`,"build:web":`cd web && ${t} run build`,typecheck:`kick typecheck --cwd server && kick typecheck --cwd web`};return`${JSON.stringify({name:e,private:!0,version:`0.0.0`,type:`module`,scripts:r,devDependencies:{"@forinda/kickjs-cli":n},workspaces:[`server`,`web`]},null,2)}\n`}function w(){return`node_modules/
|
|
107
|
-
dist/
|
|
108
|
-
.env
|
|
109
|
-
*.log
|
|
110
|
-
.DS_Store
|
|
111
|
-
# Platform build output — written by \`kick build:netlify\` / \`kick build:vercel\`.
|
|
112
|
-
.netlify/
|
|
113
|
-
.vercel/
|
|
114
|
-
`}function T(e,t,n=`kick`){let r=`# ${e}
|
|
115
|
-
|
|
116
|
-
Fullstack KickJS workspace — typed end to end.
|
|
117
|
-
|
|
118
|
-
| Package | What |
|
|
119
|
-
| --------- | ----------------------------------------------------------------- |
|
|
120
|
-
| \`server/\` | KickJS API (decorators, DI, \`kick dev\` with typegen watch) |
|
|
121
|
-
| \`web/\` | Vite + React, typed against the API via \`@forinda/kickjs-client\` |
|
|
122
|
-
|
|
123
|
-
## Develop
|
|
124
|
-
|
|
125
|
-
\`\`\`bash
|
|
126
|
-
${t} install
|
|
127
|
-
${t===`pnpm`?`pnpm dev # server (kick dev) + web (vite), in parallel`:`${t} run dev:server # terminal 1\n${t} run dev:web # terminal 2`}
|
|
128
|
-
\`\`\`
|
|
129
|
-
|
|
130
|
-
Server: http://localhost:3000 · Web: http://localhost:5173 (Vite proxies \`/api\`).
|
|
131
|
-
|
|
132
|
-
## The type loop
|
|
133
|
-
|
|
134
|
-
1. Server handlers **return** their payloads (\`return this.service.greet(...)\`).
|
|
135
|
-
2. \`kick typegen\` emits \`server/.kickjs/types/kick__client.d.ts\` — the flat
|
|
136
|
-
route map with every response type resolved to a literal shape.
|
|
137
|
-
3. \`web/tsconfig.json\` lists that file in \`types\`, so \`KickClientApi\` is
|
|
138
|
-
ambient — no import, no bridge file.
|
|
139
|
-
4. \`web/src/api.ts\`'s \`createClient<KickClientApi.Api>\` types every call site.
|
|
140
|
-
|
|
141
|
-
Because the map holds resolved types rather than references to controllers,
|
|
142
|
-
\`web\` never compiles server source: no \`experimentalDecorators\`, no path
|
|
143
|
-
aliases into \`server/src\`.
|
|
144
|
-
|
|
145
|
-
Rename a field in \`server/src/modules/hello/hello.service.ts\` → \`web/src/App.tsx\`
|
|
146
|
-
stops compiling. That's the point.
|
|
147
|
-
|
|
148
|
-
### Keeping the map fresh
|
|
149
|
-
|
|
150
|
-
\`server/.kickjs/types/kick__client.d.ts\` is generated, and \`web\` reads it as
|
|
151
|
-
an ambient type package. Two things follow.
|
|
152
|
-
|
|
153
|
-
**It is not refreshed by \`kick dev\`.** Resolving it builds a whole TypeScript
|
|
154
|
-
program over the server, which is a build-step cost rather than a per-save one,
|
|
155
|
-
so a renamed response field surfaces on the next \`kick typegen\` rather than on
|
|
156
|
-
save. Everything else in \`.kickjs/types\` still updates on save. Add
|
|
157
|
-
\`kick typegen --check\` to CI and a stale map fails the build.
|
|
158
|
-
|
|
159
|
-
**It needs a compiler API.** TypeScript 7 ships none, so \`server\` depends on
|
|
160
|
-
\`@typescript/typescript6\`. Remove it and typegen skips this one file, saying
|
|
161
|
-
so; \`web\` then reports \`TS2688\` because the file it lists in \`types\` is gone.
|
|
162
|
-
|
|
163
|
-
### The other way to wire it
|
|
164
|
-
|
|
165
|
-
A \`types\` entry says "this is a global type package", which is what the map is,
|
|
166
|
-
and it fails loudly when the file is missing. If you would rather it be quiet
|
|
167
|
-
when absent — say, a repo where the map is not always generated — use
|
|
168
|
-
\`include\` instead:
|
|
169
|
-
|
|
170
|
-
\`\`\`json
|
|
171
|
-
{ "include": ["src", "../server/.kickjs/types/kick__client.d.ts"] }
|
|
172
|
-
\`\`\`
|
|
173
|
-
|
|
174
|
-
That tolerates the file not existing, at the cost of \`KickClientApi\` silently
|
|
175
|
-
not resolving. Note \`types\` replaces TypeScript's automatic \`@types\`
|
|
176
|
-
inclusion, so if you add entries there, list the ones you rely on too
|
|
177
|
-
(\`"types": ["node", "../server/.kickjs/types/kick__client"]\`).
|
|
178
|
-
|
|
179
|
-
Or skip the global entirely — the same file exports the type:
|
|
180
|
-
|
|
181
|
-
\`\`\`ts
|
|
182
|
-
import type { Api } from '../../server/.kickjs/types/kick__client'
|
|
183
|
-
|
|
184
|
-
export const api = createClient<Api>({ baseUrl: '/api/v1' })
|
|
185
|
-
\`\`\`
|
|
186
|
-
|
|
187
|
-
Docs: https://kickjs.app/guide/typed-client.html
|
|
188
|
-
`;if(n!==`vite`)return r;let i=r.indexOf(`## The type loop`);return`${r.slice(0,i).replace("Vite + React, typed against the API via `@forinda/kickjs-client`",`create-vite scaffold — unwired (see below) `).replace(" (Vite proxies `/api`)",``)}## Wiring web/ to the API
|
|
189
|
-
|
|
190
|
-
\`web/\` is whatever create-vite scaffolded; nothing connects it to the API yet.
|
|
191
|
-
Four steps — typed client, \`/api\` dev proxy, route-map types, \`src/api.ts\`:
|
|
192
|
-
|
|
193
|
-
${u}
|
|
194
|
-
`}export{f as DEFAULT_VITE_TEMPLATE,d as VITE_TEMPLATES,m as initFullstackProject};
|
|
195
|
-
//# sourceMappingURL=fullstack-BwdcyVD3.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"fullstack-BwdcyVD3.mjs","names":[],"sources":["../src/generators/fullstack.ts"],"sourcesContent":["// `kick new --template fullstack` — a pnpm-workspace monorepo:\n//\n// my-app/\n// server/ KickJS API (the standard scaffold, minus its own git/install)\n// web/ Vite + React frontend typed end-to-end via\n// @forinda/kickjs-client + the server's generated KickRoutes.Api\n//\n// The type loop: server controllers use return-value handlers → `kick\n// typegen` (run here once, re-run by `kick dev`) emits\n// server/.kickjs/types/kick__client.d.ts → web tsconfig `types` (ambient)\n// side-effect-imports that file (type-only, erased at runtime) → the web\n// client calls `api.get('/hello')` with the handler's actual response type.\n\nimport { join } from 'node:path'\nimport { execFileSync } from 'node:child_process'\n\nimport { writeFileSafe } from '../utils/fs'\nimport { runCommand } from '../utils/shell'\nimport { initProject, resolveSiblingVersions } from './project'\nimport { TEMPLATE_BUILDS, approveInstallScripts } from '../commands/add'\nimport { generateNetlifyToml, generateVercelJson } from './templates/project-config'\n\n/** Wiring a frontend we did not scaffold: typed client, proxy, route types. */\nexport const FRONTEND_WIRING_URL = 'https://kickjs.app/guide/fullstack-frontend.html'\n\n/**\n * create-vite's TypeScript templates, in the order it lists them. Only the\n * `-ts` half: the wiring is typed — the route map is a `.d.ts` and the client\n * is `createClient<KickClientApi.Api>` — so a JavaScript template would leave\n * the reader following a guide that cannot apply.\n */\nexport const VITE_TEMPLATES = [\n { value: 'react-ts', label: 'React' },\n { value: 'react-compiler-ts', label: 'React + Compiler' },\n { value: 'vue-ts', label: 'Vue' },\n { value: 'svelte-ts', label: 'Svelte' },\n { value: 'solid-ts', label: 'Solid' },\n { value: 'preact-ts', label: 'Preact' },\n { value: 'lit-ts', label: 'Lit' },\n { value: 'qwik-ts', label: 'Qwik' },\n { value: 'vanilla-ts', label: 'Vanilla' },\n] as const\n\nexport const DEFAULT_VITE_TEMPLATE = 'react-ts'\n\n/**\n * How each package manager runs create-vite, with the framework decided here\n * rather than by its prompts:\n *\n * - `--template` picks a TypeScript template, so the wiring guide applies;\n * - `--no-interactive` means it never waits for input (CI, `--yes`);\n * - `--no-immediate` stops it installing and launching a dev server — the\n * workspace install happens once, at the root, after this returns.\n */\nexport function createViteCommand(\n pm: 'pnpm' | 'npm' | 'yarn' | 'bun',\n dir: string,\n template: string = DEFAULT_VITE_TEMPLATE,\n): string[] {\n const flags = ['--template', template, '--no-interactive', '--no-immediate']\n // yarn and bun resolve `create vite` to create-vite themselves; npm and pnpm\n // take the versioned package name, and npm needs `--` before the flags or it\n // eats them itself.\n if (pm === 'yarn' || pm === 'bun') return [pm, 'create', 'vite', dir, ...flags]\n if (pm === 'npm') return [pm, 'create', 'vite@latest', dir, '--', ...flags]\n return [pm, 'create', 'vite@latest', dir, ...flags]\n}\n\nexport interface InitFullstackOptions {\n name: string\n directory: string\n packageManager?: 'pnpm' | 'npm' | 'yarn' | 'bun'\n /**\n * Who scaffolds `web/`. `'kick'` writes the wired React app (typed client,\n * dev proxy, route-map types). `'vite'` hands the directory to\n * `create-vite` and wires nothing — you pick the framework, and the guide\n * at {@link FRONTEND_WIRING_URL} covers connecting it.\n */\n frontend?: 'kick' | 'vite'\n /** create-vite template for `frontend: 'vite'`. Default `react-ts`. */\n viteTemplate?: string\n initGit?: boolean\n installDeps?: boolean\n schemaLib?: 'zod' | 'valibot' | 'yup'\n runtime?: 'express' | 'fastify' | 'h3'\n}\n\nexport async function initFullstackProject(options: InitFullstackOptions): Promise<void> {\n const {\n name,\n directory,\n schemaLib = 'zod',\n runtime = 'express',\n frontend = 'kick',\n viteTemplate = DEFAULT_VITE_TEMPLATE,\n } = options\n // `--pm` arrives as a free CLI string — allowlist before it reaches a\n // process invocation (execFileSync takes an argv array, no shell, but a\n // bogus binary name is still a confusing failure).\n const pmValid = (['pnpm', 'npm', 'yarn', 'bun'] as const).includes(\n options.packageManager as never,\n )\n const packageManager = pmValid\n ? (options.packageManager as 'pnpm' | 'npm' | 'yarn' | 'bun')\n : 'pnpm'\n const dir = directory\n const log = (msg: string) => console.log(` ${msg}`)\n if (options.packageManager !== undefined && !pmValid) {\n log(\n `Warning: unknown package manager '${String(options.packageManager)}' — falling back to pnpm.`,\n )\n }\n\n console.log(`\\n Creating fullstack KickJS workspace: ${name}\\n`)\n\n // One map for both packages: the workspace shares a toolchain, so server/\n // and web/ must not end up on different vite or TypeScript majors.\n console.log(' Resolving package versions...')\n const versions = await resolveSiblingVersions()\n\n // ── server/ — the standard scaffold, deferred install/git ──────────\n await initProject({\n name: `${name}-server`,\n directory: join(dir, 'server'),\n packageManager,\n template: 'minimal',\n schemaLib,\n runtime,\n // web/ reads the resolved route map from the ambient KickClientApi\n // namespace, which needs the TS 7 compiler API to produce.\n withClientMap: true,\n // web/vite.config.ts proxies /api to the server's port; if kick dev moved\n // to another port the proxy would silently reach the wrong process.\n strictPort: true,\n // server/ is a workspace member; the root records the approvals.\n approveInstallScripts: false,\n // netlify.toml / vercel.json live at the workspace root, written below.\n platformConfig: false,\n // Root owns install + git so the lockfile/commit cover the workspace.\n initGit: false,\n installDeps: false,\n // Production single-origin serving. `web/` builds to `web/dist`, and\n // nothing served it before — `pnpm build` produced a frontend the API had\n // no way to hand out, so every deploy needed a hand-wired static host or\n // a second process. The adapter is inert until `../web/dist` exists, so\n // `dev` (Vite serves the client and proxies /api here) is untouched.\n spaClientDir: '../web/dist',\n versions,\n })\n\n // ── web/ — either our wired React app, or whatever create-vite makes ──\n if (frontend === 'vite') {\n // create-vite scaffolds it with the chosen TypeScript template. Nothing\n // is patched afterwards: a scaffold we didn't write is not ours to\n // rewrite, and the wiring is four steps in the guide.\n console.log(`\\n Handing web/ to create-vite (${viteTemplate})...\\n`)\n const [file, ...args] = createViteCommand(packageManager, 'web', viteTemplate)\n runCommand(file!, args, { cwd: dir })\n } else {\n await writeWebTemplate(dir, name, versions)\n }\n\n // ── workspace root ──────────────────────────────────────────────────\n await writeFileSafe(\n join(dir, 'package.json'),\n rootPackageJson(name, packageManager, versions['@forinda/kickjs-cli']),\n )\n // Only pnpm reads this file. npm / yarn / bun declare workspaces via the\n // `workspaces` field in the root package.json instead — see rootPackageJson.\n if (packageManager === 'pnpm') {\n await writeFileSafe(join(dir, 'pnpm-workspace.yaml'), 'packages:\\n - server\\n - web\\n')\n }\n // Before install, at the root every package manager reads them from.\n approveInstallScripts(packageManager, dir, TEMPLATE_BUILDS)\n await writeFileSafe(join(dir, '.gitignore'), rootGitignore())\n // Platform deploy config, at the root both platforms build from.\n await writeFileSafe(\n join(dir, 'netlify.toml'),\n generateNetlifyToml({\n command: `${packageManager} run build:netlify`,\n publish: 'web/dist',\n spa: true,\n }),\n )\n await writeFileSafe(\n join(dir, 'vercel.json'),\n generateVercelJson(`${packageManager} run build:vercel`),\n )\n await writeFileSafe(join(dir, 'README.md'), rootReadme(name, packageManager, frontend))\n\n // Workspace-root agent docs (CLAUDE.md + .agents/) flavored for the\n // fullstack layout — the server/ subdir keeps its own generated set.\n const { generateAgentDocs } = await import('./agent-docs')\n await generateAgentDocs({\n outDir: dir,\n name,\n pm: packageManager,\n template: 'fullstack',\n only: 'all',\n force: true,\n })\n\n // ── install (root — covers both workspace packages) ────────────────\n if (options.installDeps) {\n console.log(`\\n Installing workspace dependencies with ${packageManager}...\\n`)\n try {\n // `runCommand`, not bare execFileSync — on Windows every package\n // manager is a `.cmd` shim that execFileSync cannot spawn.\n runCommand(packageManager, ['install'], { cwd: dir })\n } catch {\n console.log(`\\n Warning: ${packageManager} install failed. Run it manually.`)\n }\n }\n\n // ── typegen (server) so web's KickRoutes.Api resolves immediately ──\n try {\n const { runTypegen } = await import('../typegen')\n await runTypegen({ cwd: join(dir, 'server'), allowDuplicates: true, silent: true })\n } catch {\n // Non-fatal — `kick dev` in server/ retries on boot.\n }\n\n // ── git (root) ──────────────────────────────────────────────────────\n if (options.initGit) {\n try {\n execFileSync('git', ['init'], { cwd: dir, stdio: 'pipe' })\n execFileSync('git', ['branch', '-M', 'main'], { cwd: dir, stdio: 'pipe' })\n execFileSync('git', ['add', '-A'], { cwd: dir, stdio: 'pipe' })\n execFileSync('git', ['commit', '-m', 'chore: initial commit from kick new (fullstack)'], {\n cwd: dir,\n stdio: 'pipe',\n })\n log('Git repository initialized')\n } catch {\n log('Warning: git init failed (git may not be installed)')\n }\n }\n\n console.log('\\n Fullstack workspace scaffolded!')\n console.log()\n log('Next steps:')\n log(` cd ${name}`)\n if (!options.installDeps) log(` ${packageManager} install`)\n if (packageManager === 'pnpm') {\n log(' pnpm dev # runs server (kick dev) + web (vite) together')\n } else {\n log(` ${packageManager} run dev:server # terminal 1`)\n log(` ${packageManager} run dev:web # terminal 2`)\n }\n log('')\n if (frontend === 'vite') {\n // Nothing in web/ knows about the API yet — say so, and say where the\n // four wiring steps live rather than half-wiring someone else's scaffold.\n log('web/ is create-vite output, unwired. To type it against the API:')\n log(` ${FRONTEND_WIRING_URL}`)\n } else {\n log('The web app calls the API through @forinda/kickjs-client —')\n log(\"edit server/src/modules/hello and watch web/src/App.tsx's types follow.\")\n }\n log('')\n}\n\n// ── web templates ─────────────────────────────────────────────────────\n\n/** The wired React app: typed client, dev proxy, route-map types. */\nasync function writeWebTemplate(\n dir: string,\n name: string,\n versions: Record<string, string>,\n): Promise<void> {\n await writeFileSafe(join(dir, 'web/package.json'), webPackageJson(name, versions))\n await writeFileSafe(join(dir, 'web/vite.config.ts'), webViteConfig())\n await writeFileSafe(join(dir, 'web/tsconfig.json'), webTsConfig())\n await writeFileSafe(join(dir, 'web/index.html'), webIndexHtml(name))\n await writeFileSafe(join(dir, 'web/src/main.tsx'), webMain())\n await writeFileSafe(join(dir, 'web/src/App.tsx'), webApp())\n await writeFileSafe(join(dir, 'web/src/api.ts'), webApi())\n}\n\nfunction webPackageJson(name: string, versions: Record<string, string>): string {\n // Every range here is resolved at scaffold time — see THIRD_PARTY_PACKAGES.\n const dep = (pkg: string) => versions[pkg] ?? 'latest'\n return `${JSON.stringify(\n {\n name: `${name}-web`,\n private: true,\n version: '0.0.0',\n type: 'module',\n scripts: {\n dev: 'vite',\n build: 'tsc --noEmit && vite build',\n preview: 'vite preview',\n typecheck: 'tsc --noEmit',\n },\n dependencies: {\n '@forinda/kickjs-client': dep('@forinda/kickjs-client'),\n react: dep('react'),\n 'react-dom': dep('react-dom'),\n },\n devDependencies: {\n '@types/react': dep('@types/react'),\n '@types/react-dom': dep('@types/react-dom'),\n '@vitejs/plugin-react': dep('@vitejs/plugin-react'),\n // Same majors as the server package: one workspace, one toolchain.\n typescript: dep('typescript'),\n vite: dep('vite'),\n },\n },\n null,\n 2,\n )}\\n`\n}\n\nfunction webViteConfig(): string {\n return `import { defineConfig } from 'vite'\nimport react from '@vitejs/plugin-react'\n\nexport default defineConfig({\n plugins: [react()],\n server: {\n // The KickJS server (kick dev) listens on 3000; the client's baseUrl is\n // the relative '/api/v1', so the browser hits Vite and Vite forwards.\n proxy: {\n '/api': 'http://localhost:3000',\n },\n },\n})\n`\n}\n\nexport function webTsConfig(): string {\n return `${JSON.stringify(\n {\n compilerOptions: {\n target: 'ES2022',\n lib: ['ES2022', 'DOM', 'DOM.Iterable'],\n module: 'ESNext',\n moduleResolution: 'bundler',\n jsx: 'react-jsx',\n strict: true,\n skipLibCheck: true,\n noEmit: true,\n isolatedModules: true,\n // The resolved client route map, as an ambient global type package —\n // the same mechanism as \"node\" or \"vitest/globals\". It makes\n // `KickClientApi.Api` available with no import and no bridge file.\n //\n // Note this is a `types` ENTRY, not an `include`: the map is a global\n // type package, not source of this app. It also means the file must\n // exist — `kick new` runs typegen for you, and `kick typegen` in\n // server/ refreshes it. (An `include` entry tolerates the file being\n // absent; a `types` entry reports TS2688, which is the louder and\n // more useful failure for something the app depends on.)\n //\n // No `experimentalDecorators` here: unlike the ambient\n // `KickRoutes.Api` bridge, this map carries no reference to the\n // server's decorated controller sources.\n types: ['../server/.kickjs/types/kick__client'],\n },\n include: ['src'],\n },\n null,\n 2,\n )}\\n`\n}\n\nfunction webIndexHtml(name: string): string {\n return `<!doctype html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <title>${name}</title>\n </head>\n <body>\n <div id=\"root\"></div>\n <script type=\"module\" src=\"/src/main.tsx\"></script>\n </body>\n</html>\n`\n}\n\nfunction webMain(): string {\n return `import { StrictMode } from 'react'\nimport { createRoot } from 'react-dom/client'\nimport { App } from './App'\n\ncreateRoot(document.getElementById('root')!).render(\n <StrictMode>\n <App />\n </StrictMode>,\n)\n`\n}\n\nfunction webApp(): string {\n return `import { useEffect, useState } from 'react'\nimport { api } from './api'\n\n// The response types below are INFERRED from the server's handlers —\n// change server/src/modules/hello/hello.service.ts and these types follow on\n// the next \\`kick typegen\\`. Not under \\`kick dev\\`: resolving the client map\n// builds a whole TypeScript program, so it is a build step, not a per-save one.\ntype Greeting = Awaited<ReturnType<typeof fetchGreeting>>\n\nfunction fetchGreeting() {\n return api.get('/hello')\n}\n\nexport function App() {\n const [greeting, setGreeting] = useState<Greeting | null>(null)\n const [health, setHealth] = useState<string>('checking…')\n\n useEffect(() => {\n fetchGreeting().then(setGreeting).catch(console.error)\n api\n .get('/hello/health')\n .then((h) => setHealth(h.status))\n .catch(() => setHealth('down'))\n }, [])\n\n return (\n <main style={{ fontFamily: 'system-ui', maxWidth: 640, margin: '4rem auto', padding: '0 1rem' }}>\n <h1>KickJS fullstack</h1>\n <p>\n <strong>{greeting?.message ?? 'loading…'}</strong>\n </p>\n <p>\n Server said hello at <code>{greeting?.timestamp ?? '…'}</code> — health:{' '}\n <code>{health}</code>\n </p>\n <p style={{ color: '#666' }}>\n This call is typed end to end: <code>api.get('/hello')</code> returns the exact shape\n <code> HelloService.greet()</code> produces. Rename a field on the server and this file\n stops compiling.\n </p>\n </main>\n )\n}\n`\n}\n\nexport function webApi(): string {\n return `import { createClient } from '@forinda/kickjs-client'\n\n// KickClientApi is ambient — the resolved route map from\n// server/.kickjs/types/kick__client.d.ts, wired in tsconfig's \\`types\\`. Every\n// response type is a literal shape, so nothing from the server's source graph\n// enters this program.\n//\n// Keys are module-mount-relative paths; the bootstrap-level '/api/v1' prefix\n// lives here in baseUrl, and the Vite dev proxy forwards it to the KickJS\n// server.\n//\n// Prefer an explicit import? The same file exports the type:\n// import type { Api } from '../../server/.kickjs/types/kick__client'\nexport const api = createClient<KickClientApi.Api>({ baseUrl: '/api/v1' })\n`\n}\n\n// ── root templates ────────────────────────────────────────────────────\n\nfunction rootPackageJson(name: string, pm: string, cliVersion: string): string {\n const scripts: Record<string, string> =\n pm === 'pnpm'\n ? {\n dev: 'pnpm --parallel -r run dev',\n // One origin: the server serves `web/dist` through SpaAdapter.\n start: 'pnpm --filter ./server run start',\n 'dev:server': 'pnpm --filter ./server dev',\n 'dev:web': 'pnpm --filter ./web dev',\n // Typegen first: web's `tsc` reads server/.kickjs/types, which is\n // git-ignored, so a fresh clone (CI, Netlify, Vercel) has none and\n // `pnpm -r run build` races the two packages anyway.\n build: 'pnpm --filter ./server exec kick typegen && pnpm -r run build',\n 'build:netlify': 'pnpm build && pnpm --filter ./server exec kick build:netlify',\n 'build:vercel': 'pnpm build && pnpm --filter ./server exec kick build:vercel',\n // No `npx`: the binary is `kick` but the package is\n // `@forinda/kickjs-cli`, so npx cannot map one to the other and\n // falls back to the REGISTRY — where `kick` is an unrelated\n // AngularJS scaffolder. It runs, prints its own help, and exits 0,\n // so this script would pass without type-checking anything.\n //\n // Every package manager puts `node_modules/.bin` on PATH for\n // scripts, so the bare name resolves locally, and a missing install\n // fails loudly instead of fetching a stranger.\n typecheck: 'kick typecheck --cwd server && kick typecheck --cwd web',\n }\n : {\n // cd-based scripts — the one form npm, yarn (classic AND berry),\n // and bun all run identically; workspace-filter flags differ per\n // manager (--workspace vs `yarn workspace <name>` vs --filter).\n start: `cd server && ${pm} run start`,\n 'dev:server': `cd server && ${pm} run dev`,\n 'dev:web': `cd web && ${pm} run dev`,\n // Typegen first — see the pnpm branch above.\n build: `cd server && ${pm} exec kick typegen && cd .. && ${pm} run build:server && ${pm} run build:web`,\n 'build:netlify': `${pm} run build && cd server && ${pm} exec kick build:netlify`,\n 'build:vercel': `${pm} run build && cd server && ${pm} exec kick build:vercel`,\n 'build:server': `cd server && ${pm} run build`,\n 'build:web': `cd web && ${pm} run build`,\n // No `npx`: the binary is `kick` but the package is\n // `@forinda/kickjs-cli`, so npx cannot map one to the other and\n // falls back to the REGISTRY — where `kick` is an unrelated\n // AngularJS scaffolder. It runs, prints its own help, and exits 0,\n // so this script would pass without type-checking anything.\n //\n // Every package manager puts `node_modules/.bin` on PATH for\n // scripts, so the bare name resolves locally, and a missing install\n // fails loudly instead of fetching a stranger.\n typecheck: 'kick typecheck --cwd server && kick typecheck --cwd web',\n }\n return `${JSON.stringify(\n {\n name,\n private: true,\n version: '0.0.0',\n type: 'module',\n scripts,\n // The CLI is a ROOT dependency so the bare `kick` in the scripts above\n // resolves: package managers put `node_modules/.bin` on PATH for\n // scripts, and the CLI otherwise lives only in `server/node_modules`.\n devDependencies: { '@forinda/kickjs-cli': cliVersion },\n workspaces: ['server', 'web'],\n },\n null,\n 2,\n )}\\n`\n}\n\nfunction rootGitignore(): string {\n return `node_modules/\ndist/\n.env\n*.log\n.DS_Store\n# Platform build output — written by \\`kick build:netlify\\` / \\`kick build:vercel\\`.\n.netlify/\n.vercel/\n`\n}\n\nexport function rootReadme(name: string, pm: string, frontend: 'kick' | 'vite' = 'kick'): string {\n const readme = `# ${name}\n\nFullstack KickJS workspace — typed end to end.\n\n| Package | What |\n| --------- | ----------------------------------------------------------------- |\n| \\`server/\\` | KickJS API (decorators, DI, \\`kick dev\\` with typegen watch) |\n| \\`web/\\` | Vite + React, typed against the API via \\`@forinda/kickjs-client\\` |\n\n## Develop\n\n\\`\\`\\`bash\n${pm} install\n${pm === 'pnpm' ? 'pnpm dev # server (kick dev) + web (vite), in parallel' : `${pm} run dev:server # terminal 1\\n${pm} run dev:web # terminal 2`}\n\\`\\`\\`\n\nServer: http://localhost:3000 · Web: http://localhost:5173 (Vite proxies \\`/api\\`).\n\n## The type loop\n\n1. Server handlers **return** their payloads (\\`return this.service.greet(...)\\`).\n2. \\`kick typegen\\` emits \\`server/.kickjs/types/kick__client.d.ts\\` — the flat\n route map with every response type resolved to a literal shape.\n3. \\`web/tsconfig.json\\` lists that file in \\`types\\`, so \\`KickClientApi\\` is\n ambient — no import, no bridge file.\n4. \\`web/src/api.ts\\`'s \\`createClient<KickClientApi.Api>\\` types every call site.\n\nBecause the map holds resolved types rather than references to controllers,\n\\`web\\` never compiles server source: no \\`experimentalDecorators\\`, no path\naliases into \\`server/src\\`.\n\nRename a field in \\`server/src/modules/hello/hello.service.ts\\` → \\`web/src/App.tsx\\`\nstops compiling. That's the point.\n\n### Keeping the map fresh\n\n\\`server/.kickjs/types/kick__client.d.ts\\` is generated, and \\`web\\` reads it as\nan ambient type package. Two things follow.\n\n**It is not refreshed by \\`kick dev\\`.** Resolving it builds a whole TypeScript\nprogram over the server, which is a build-step cost rather than a per-save one,\nso a renamed response field surfaces on the next \\`kick typegen\\` rather than on\nsave. Everything else in \\`.kickjs/types\\` still updates on save. Add\n\\`kick typegen --check\\` to CI and a stale map fails the build.\n\n**It needs a compiler API.** TypeScript 7 ships none, so \\`server\\` depends on\n\\`@typescript/typescript6\\`. Remove it and typegen skips this one file, saying\nso; \\`web\\` then reports \\`TS2688\\` because the file it lists in \\`types\\` is gone.\n\n### The other way to wire it\n\nA \\`types\\` entry says \"this is a global type package\", which is what the map is,\nand it fails loudly when the file is missing. If you would rather it be quiet\nwhen absent — say, a repo where the map is not always generated — use\n\\`include\\` instead:\n\n\\`\\`\\`json\n{ \"include\": [\"src\", \"../server/.kickjs/types/kick__client.d.ts\"] }\n\\`\\`\\`\n\nThat tolerates the file not existing, at the cost of \\`KickClientApi\\` silently\nnot resolving. Note \\`types\\` replaces TypeScript's automatic \\`@types\\`\ninclusion, so if you add entries there, list the ones you rely on too\n(\\`\"types\": [\"node\", \"../server/.kickjs/types/kick__client\"]\\`).\n\nOr skip the global entirely — the same file exports the type:\n\n\\`\\`\\`ts\nimport type { Api } from '../../server/.kickjs/types/kick__client'\n\nexport const api = createClient<Api>({ baseUrl: '/api/v1' })\n\\`\\`\\`\n\nDocs: https://kickjs.app/guide/typed-client.html\n`\n\n if (frontend !== 'vite') return readme\n\n // create-vite's output is not ours to describe: it has no typed client, no\n // proxy and no route-map types until the reader wires them. Everything from\n // \"The type loop\" on is about files that do not exist in that scaffold.\n const typeLoop = readme.indexOf('## The type loop')\n return `${readme\n .slice(0, typeLoop)\n .replace(\n 'Vite + React, typed against the API via `@forinda/kickjs-client`',\n 'create-vite scaffold — unwired (see below) ',\n )\n .replace(' (Vite proxies `/api`)', '')}## Wiring web/ to the API\n\n\\`web/\\` is whatever create-vite scaffolded; nothing connects it to the API yet.\nFour steps — typed client, \\`/api\\` dev proxy, route-map types, \\`src/api.ts\\`:\n\n${FRONTEND_WIRING_URL}\n`\n}\n"],"mappings":";;;;;;;;;;wNAuBA,MAAa,EAAsB,mDAQtB,EAAiB,CAC5B,CAAE,MAAO,WAAY,MAAO,OAAQ,EACpC,CAAE,MAAO,oBAAqB,MAAO,kBAAmB,EACxD,CAAE,MAAO,SAAU,MAAO,KAAM,EAChC,CAAE,MAAO,YAAa,MAAO,QAAS,EACtC,CAAE,MAAO,WAAY,MAAO,OAAQ,EACpC,CAAE,MAAO,YAAa,MAAO,QAAS,EACtC,CAAE,MAAO,SAAU,MAAO,KAAM,EAChC,CAAE,MAAO,UAAW,MAAO,MAAO,EAClC,CAAE,MAAO,aAAc,MAAO,SAAU,CAC1C,EAEa,EAAwB,WAWrC,SAAgB,EACd,EACA,EACA,EAAmB,EACT,CACV,IAAM,EAAQ,CAAC,aAAc,EAAU,mBAAoB,gBAAgB,EAM3E,OAFI,IAAO,QAAU,IAAO,MAAc,CAAC,EAAI,SAAU,OAAQ,EAAK,GAAG,CAAK,EAC1E,IAAO,MAAc,CAAC,EAAI,SAAU,cAAe,EAAK,KAAM,GAAG,CAAK,EACnE,CAAC,EAAI,SAAU,cAAe,EAAK,GAAG,CAAK,CACpD,CAqBA,eAAsB,EAAqB,EAA8C,CACvF,GAAM,CACJ,OACA,YACA,YAAY,MACZ,UAAU,UACV,WAAW,OACX,eAAe,G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C/F,IAAM,EAAS,KAAK,EAAK;;;;;;;;;;;;EAYzB,EAAG;EACH,IAAO,OAAS,oEAAsE,GAAG,EAAG,kCAAkC,EAAG,gCAAgC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+DjK,GAAI,IAAa,OAAQ,OAAO,EAKhC,IAAM,EAAW,EAAO,QAAQ,kBAAkB,EAClD,MAAO,GAAG,EACP,MAAM,EAAG,CAAQ,CAAC,CAClB,QACC,mEACA,mEACF,CAAC,CACA,QAAQ,yBAA0B,EAAE,EAAE;;;;;EAKzC,EAAoB;CAEtB"}
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @forinda/kickjs-cli v8.4.0
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) Felix Orinda
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
import{d as e,f as t,i as n,n as r,o as i,p as a,t as o}from"./project--WiWkarb.mjs";import{l as s}from"./project-docs-Ck3uzaEG.mjs";import{join as c}from"node:path";import{execFileSync as l}from"node:child_process";const u=`https://kickjs.app/guide/fullstack-frontend.html`,d=[{value:`react-ts`,label:`React`},{value:`react-compiler-ts`,label:`React + Compiler`},{value:`vue-ts`,label:`Vue`},{value:`svelte-ts`,label:`Svelte`},{value:`solid-ts`,label:`Solid`},{value:`preact-ts`,label:`Preact`},{value:`lit-ts`,label:`Lit`},{value:`qwik-ts`,label:`Qwik`},{value:`vanilla-ts`,label:`Vanilla`}],f=`react-ts`;function p(e,t,n=f){let r=[`--template`,n,`--no-interactive`,`--no-immediate`];return e===`yarn`||e===`bun`?[e,`create`,`vite`,t,...r]:e===`npm`?[e,`create`,`vite@latest`,t,`--`,...r]:[e,`create`,`vite@latest`,t,...r]}async function m(d){let{name:m,directory:g,schemaLib:_=`zod`,runtime:v=`express`,frontend:y=`kick`,viteTemplate:b=f}=d,x=[`pnpm`,`npm`,`yarn`,`bun`].includes(d.packageManager),S=x?d.packageManager:`pnpm`,E=g,D=e=>console.log(` ${e}`);d.packageManager!==void 0&&!x&&D(`Warning: unknown package manager '${String(d.packageManager)}' — falling back to pnpm.`),console.log(`\n Creating fullstack KickJS workspace: ${m}\n`),console.log(` Resolving package versions...`);let O=await r();if(await o({name:`${m}-server`,directory:c(E,`server`),packageManager:S,template:`minimal`,schemaLib:_,runtime:v,withClientMap:!0,strictPort:!0,approveInstallScripts:!1,platformConfig:!1,initGit:!1,installDeps:!1,spaClientDir:`../web/dist`,versions:O}),y===`vite`){console.log(`\n Handing web/ to create-vite (${b})...\n`);let[e,...t]=p(S,`web`,b);a(e,t,{cwd:E})}else await h(E,m,O);await s(c(E,`package.json`),C(m,S,O[`@forinda/kickjs-cli`])),S===`pnpm`&&await s(c(E,`pnpm-workspace.yaml`),`packages:
|
|
12
|
-
- server
|
|
13
|
-
- web
|
|
14
|
-
`),i(S,E,n),await s(c(E,`.gitignore`),w()),await s(c(E,`netlify.toml`),e({command:`${S} run build:netlify`,publish:`web/dist`,spa:!0})),await s(c(E,`vercel.json`),t(`${S} run build:vercel`)),await s(c(E,`README.md`),T(m,S,y));let{generateAgentDocs:k}=await import(`./agent-docs-BIYv2Od-.mjs`).then(e=>e.t);if(await k({outDir:E,name:m,pm:S,template:`fullstack`,only:`all`,force:!0}),d.installDeps){console.log(`\n Installing workspace dependencies with ${S}...\n`);try{a(S,[`install`],{cwd:E})}catch{console.log(`\n Warning: ${S} install failed. Run it manually.`)}}try{let{runTypegen:e}=await import(`./typegen-Bv9EzadE.mjs`).then(e=>e.n);await e({cwd:c(E,`server`),allowDuplicates:!0,silent:!0})}catch{}if(d.initGit)try{l(`git`,[`init`],{cwd:E,stdio:`pipe`}),l(`git`,[`branch`,`-M`,`main`],{cwd:E,stdio:`pipe`}),l(`git`,[`add`,`-A`],{cwd:E,stdio:`pipe`}),l(`git`,[`commit`,`-m`,`chore: initial commit from kick new (fullstack)`],{cwd:E,stdio:`pipe`}),D(`Git repository initialized`)}catch{D(`Warning: git init failed (git may not be installed)`)}console.log(`
|
|
15
|
-
Fullstack workspace scaffolded!`),console.log(),D(`Next steps:`),D(` cd ${m}`),d.installDeps||D(` ${S} install`),S===`pnpm`?D(` pnpm dev # runs server (kick dev) + web (vite) together`):(D(` ${S} run dev:server # terminal 1`),D(` ${S} run dev:web # terminal 2`)),D(``),y===`vite`?(D(`web/ is create-vite output, unwired. To type it against the API:`),D(` ${u}`)):(D(`The web app calls the API through @forinda/kickjs-client —`),D(`edit server/src/modules/hello and watch web/src/App.tsx's types follow.`)),D(``)}async function h(e,t,n){await s(c(e,`web/package.json`),g(t,n)),await s(c(e,`web/vite.config.ts`),_()),await s(c(e,`web/tsconfig.json`),v()),await s(c(e,`web/index.html`),y(t)),await s(c(e,`web/src/main.tsx`),b()),await s(c(e,`web/src/App.tsx`),x()),await s(c(e,`web/src/api.ts`),S())}function g(e,t){let n=e=>t[e]??`latest`;return`${JSON.stringify({name:`${e}-web`,private:!0,version:`0.0.0`,type:`module`,scripts:{dev:`vite`,build:`tsc --noEmit && vite build`,preview:`vite preview`,typecheck:`tsc --noEmit`},dependencies:{"@forinda/kickjs-client":n(`@forinda/kickjs-client`),react:n(`react`),"react-dom":n(`react-dom`)},devDependencies:{"@types/react":n(`@types/react`),"@types/react-dom":n(`@types/react-dom`),"@vitejs/plugin-react":n(`@vitejs/plugin-react`),typescript:n(`typescript`),vite:n(`vite`)}},null,2)}\n`}function _(){return`import { defineConfig } from 'vite'
|
|
16
|
-
import react from '@vitejs/plugin-react'
|
|
17
|
-
|
|
18
|
-
export default defineConfig({
|
|
19
|
-
plugins: [react()],
|
|
20
|
-
server: {
|
|
21
|
-
// The KickJS server (kick dev) listens on 3000; the client's baseUrl is
|
|
22
|
-
// the relative '/api/v1', so the browser hits Vite and Vite forwards.
|
|
23
|
-
proxy: {
|
|
24
|
-
'/api': 'http://localhost:3000',
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
})
|
|
28
|
-
`}function v(){return`${JSON.stringify({compilerOptions:{target:`ES2022`,lib:[`ES2022`,`DOM`,`DOM.Iterable`],module:`ESNext`,moduleResolution:`bundler`,jsx:`react-jsx`,strict:!0,skipLibCheck:!0,noEmit:!0,isolatedModules:!0,types:[`../server/.kickjs/types/kick__client`]},include:[`src`]},null,2)}\n`}function y(e){return`<!doctype html>
|
|
29
|
-
<html lang="en">
|
|
30
|
-
<head>
|
|
31
|
-
<meta charset="UTF-8" />
|
|
32
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
33
|
-
<title>${e}</title>
|
|
34
|
-
</head>
|
|
35
|
-
<body>
|
|
36
|
-
<div id="root"></div>
|
|
37
|
-
<script type="module" src="/src/main.tsx"><\/script>
|
|
38
|
-
</body>
|
|
39
|
-
</html>
|
|
40
|
-
`}function b(){return`import { StrictMode } from 'react'
|
|
41
|
-
import { createRoot } from 'react-dom/client'
|
|
42
|
-
import { App } from './App'
|
|
43
|
-
|
|
44
|
-
createRoot(document.getElementById('root')!).render(
|
|
45
|
-
<StrictMode>
|
|
46
|
-
<App />
|
|
47
|
-
</StrictMode>,
|
|
48
|
-
)
|
|
49
|
-
`}function x(){return`import { useEffect, useState } from 'react'
|
|
50
|
-
import { api } from './api'
|
|
51
|
-
|
|
52
|
-
// The response types below are INFERRED from the server's handlers —
|
|
53
|
-
// change server/src/modules/hello/hello.service.ts and these types follow on
|
|
54
|
-
// the next \`kick typegen\`. Not under \`kick dev\`: resolving the client map
|
|
55
|
-
// builds a whole TypeScript program, so it is a build step, not a per-save one.
|
|
56
|
-
type Greeting = Awaited<ReturnType<typeof fetchGreeting>>
|
|
57
|
-
|
|
58
|
-
function fetchGreeting() {
|
|
59
|
-
return api.get('/hello')
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function App() {
|
|
63
|
-
const [greeting, setGreeting] = useState<Greeting | null>(null)
|
|
64
|
-
const [health, setHealth] = useState<string>('checking…')
|
|
65
|
-
|
|
66
|
-
useEffect(() => {
|
|
67
|
-
fetchGreeting().then(setGreeting).catch(console.error)
|
|
68
|
-
api
|
|
69
|
-
.get('/hello/health')
|
|
70
|
-
.then((h) => setHealth(h.status))
|
|
71
|
-
.catch(() => setHealth('down'))
|
|
72
|
-
}, [])
|
|
73
|
-
|
|
74
|
-
return (
|
|
75
|
-
<main style={{ fontFamily: 'system-ui', maxWidth: 640, margin: '4rem auto', padding: '0 1rem' }}>
|
|
76
|
-
<h1>KickJS fullstack</h1>
|
|
77
|
-
<p>
|
|
78
|
-
<strong>{greeting?.message ?? 'loading…'}</strong>
|
|
79
|
-
</p>
|
|
80
|
-
<p>
|
|
81
|
-
Server said hello at <code>{greeting?.timestamp ?? '…'}</code> — health:{' '}
|
|
82
|
-
<code>{health}</code>
|
|
83
|
-
</p>
|
|
84
|
-
<p style={{ color: '#666' }}>
|
|
85
|
-
This call is typed end to end: <code>api.get('/hello')</code> returns the exact shape
|
|
86
|
-
<code> HelloService.greet()</code> produces. Rename a field on the server and this file
|
|
87
|
-
stops compiling.
|
|
88
|
-
</p>
|
|
89
|
-
</main>
|
|
90
|
-
)
|
|
91
|
-
}
|
|
92
|
-
`}function S(){return`import { createClient } from '@forinda/kickjs-client'
|
|
93
|
-
|
|
94
|
-
// KickClientApi is ambient — the resolved route map from
|
|
95
|
-
// server/.kickjs/types/kick__client.d.ts, wired in tsconfig's \`types\`. Every
|
|
96
|
-
// response type is a literal shape, so nothing from the server's source graph
|
|
97
|
-
// enters this program.
|
|
98
|
-
//
|
|
99
|
-
// Keys are module-mount-relative paths; the bootstrap-level '/api/v1' prefix
|
|
100
|
-
// lives here in baseUrl, and the Vite dev proxy forwards it to the KickJS
|
|
101
|
-
// server.
|
|
102
|
-
//
|
|
103
|
-
// Prefer an explicit import? The same file exports the type:
|
|
104
|
-
// import type { Api } from '../../server/.kickjs/types/kick__client'
|
|
105
|
-
export const api = createClient<KickClientApi.Api>({ baseUrl: '/api/v1' })
|
|
106
|
-
`}function C(e,t,n){let r=t===`pnpm`?{dev:`pnpm --parallel -r run dev`,start:`pnpm --filter ./server run start`,"dev:server":`pnpm --filter ./server dev`,"dev:web":`pnpm --filter ./web dev`,build:`pnpm --filter ./server exec kick typegen && pnpm -r run build`,"build:netlify":`pnpm build && pnpm --filter ./server exec kick build:netlify`,"build:vercel":`pnpm build && pnpm --filter ./server exec kick build:vercel`,typecheck:`kick typecheck --cwd server && kick typecheck --cwd web`}:{start:`cd server && ${t} run start`,"dev:server":`cd server && ${t} run dev`,"dev:web":`cd web && ${t} run dev`,build:`cd server && ${t} exec kick typegen && cd .. && ${t} run build:server && ${t} run build:web`,"build:netlify":`${t} run build && cd server && ${t} exec kick build:netlify`,"build:vercel":`${t} run build && cd server && ${t} exec kick build:vercel`,"build:server":`cd server && ${t} run build`,"build:web":`cd web && ${t} run build`,typecheck:`kick typecheck --cwd server && kick typecheck --cwd web`};return`${JSON.stringify({name:e,private:!0,version:`0.0.0`,type:`module`,scripts:r,devDependencies:{"@forinda/kickjs-cli":n},workspaces:[`server`,`web`]},null,2)}\n`}function w(){return`node_modules/
|
|
107
|
-
dist/
|
|
108
|
-
.env
|
|
109
|
-
*.log
|
|
110
|
-
.DS_Store
|
|
111
|
-
# Platform build output — written by \`kick build:netlify\` / \`kick build:vercel\`.
|
|
112
|
-
.netlify/
|
|
113
|
-
.vercel/
|
|
114
|
-
`}function T(e,t,n=`kick`){let r=`# ${e}
|
|
115
|
-
|
|
116
|
-
Fullstack KickJS workspace — typed end to end.
|
|
117
|
-
|
|
118
|
-
| Package | What |
|
|
119
|
-
| --------- | ----------------------------------------------------------------- |
|
|
120
|
-
| \`server/\` | KickJS API (decorators, DI, \`kick dev\` with typegen watch) |
|
|
121
|
-
| \`web/\` | Vite + React, typed against the API via \`@forinda/kickjs-client\` |
|
|
122
|
-
|
|
123
|
-
## Develop
|
|
124
|
-
|
|
125
|
-
\`\`\`bash
|
|
126
|
-
${t} install
|
|
127
|
-
${t===`pnpm`?`pnpm dev # server (kick dev) + web (vite), in parallel`:`${t} run dev:server # terminal 1\n${t} run dev:web # terminal 2`}
|
|
128
|
-
\`\`\`
|
|
129
|
-
|
|
130
|
-
Server: http://localhost:3000 · Web: http://localhost:5173 (Vite proxies \`/api\`).
|
|
131
|
-
|
|
132
|
-
## The type loop
|
|
133
|
-
|
|
134
|
-
1. Server handlers **return** their payloads (\`return this.service.greet(...)\`).
|
|
135
|
-
2. \`kick typegen\` emits \`server/.kickjs/types/kick__client.d.ts\` — the flat
|
|
136
|
-
route map with every response type resolved to a literal shape.
|
|
137
|
-
3. \`web/tsconfig.json\` lists that file in \`types\`, so \`KickClientApi\` is
|
|
138
|
-
ambient — no import, no bridge file.
|
|
139
|
-
4. \`web/src/api.ts\`'s \`createClient<KickClientApi.Api>\` types every call site.
|
|
140
|
-
|
|
141
|
-
Because the map holds resolved types rather than references to controllers,
|
|
142
|
-
\`web\` never compiles server source: no \`experimentalDecorators\`, no path
|
|
143
|
-
aliases into \`server/src\`.
|
|
144
|
-
|
|
145
|
-
Rename a field in \`server/src/modules/hello/hello.service.ts\` → \`web/src/App.tsx\`
|
|
146
|
-
stops compiling. That's the point.
|
|
147
|
-
|
|
148
|
-
### Keeping the map fresh
|
|
149
|
-
|
|
150
|
-
\`server/.kickjs/types/kick__client.d.ts\` is generated, and \`web\` reads it as
|
|
151
|
-
an ambient type package. Two things follow.
|
|
152
|
-
|
|
153
|
-
**It is not refreshed by \`kick dev\`.** Resolving it builds a whole TypeScript
|
|
154
|
-
program over the server, which is a build-step cost rather than a per-save one,
|
|
155
|
-
so a renamed response field surfaces on the next \`kick typegen\` rather than on
|
|
156
|
-
save. Everything else in \`.kickjs/types\` still updates on save. Add
|
|
157
|
-
\`kick typegen --check\` to CI and a stale map fails the build.
|
|
158
|
-
|
|
159
|
-
**It needs a compiler API.** TypeScript 7 ships none, so \`server\` depends on
|
|
160
|
-
\`@typescript/typescript6\`. Remove it and typegen skips this one file, saying
|
|
161
|
-
so; \`web\` then reports \`TS2688\` because the file it lists in \`types\` is gone.
|
|
162
|
-
|
|
163
|
-
### The other way to wire it
|
|
164
|
-
|
|
165
|
-
A \`types\` entry says "this is a global type package", which is what the map is,
|
|
166
|
-
and it fails loudly when the file is missing. If you would rather it be quiet
|
|
167
|
-
when absent — say, a repo where the map is not always generated — use
|
|
168
|
-
\`include\` instead:
|
|
169
|
-
|
|
170
|
-
\`\`\`json
|
|
171
|
-
{ "include": ["src", "../server/.kickjs/types/kick__client.d.ts"] }
|
|
172
|
-
\`\`\`
|
|
173
|
-
|
|
174
|
-
That tolerates the file not existing, at the cost of \`KickClientApi\` silently
|
|
175
|
-
not resolving. Note \`types\` replaces TypeScript's automatic \`@types\`
|
|
176
|
-
inclusion, so if you add entries there, list the ones you rely on too
|
|
177
|
-
(\`"types": ["node", "../server/.kickjs/types/kick__client"]\`).
|
|
178
|
-
|
|
179
|
-
Or skip the global entirely — the same file exports the type:
|
|
180
|
-
|
|
181
|
-
\`\`\`ts
|
|
182
|
-
import type { Api } from '../../server/.kickjs/types/kick__client'
|
|
183
|
-
|
|
184
|
-
export const api = createClient<Api>({ baseUrl: '/api/v1' })
|
|
185
|
-
\`\`\`
|
|
186
|
-
|
|
187
|
-
Docs: https://kickjs.app/guide/typed-client.html
|
|
188
|
-
`;if(n!==`vite`)return r;let i=r.indexOf(`## The type loop`);return`${r.slice(0,i).replace("Vite + React, typed against the API via `@forinda/kickjs-client`",`create-vite scaffold — unwired (see below) `).replace(" (Vite proxies `/api`)",``)}## Wiring web/ to the API
|
|
189
|
-
|
|
190
|
-
\`web/\` is whatever create-vite scaffolded; nothing connects it to the API yet.
|
|
191
|
-
Four steps — typed client, \`/api\` dev proxy, route-map types, \`src/api.ts\`:
|
|
192
|
-
|
|
193
|
-
${u}
|
|
194
|
-
`}export{f as DEFAULT_VITE_TEMPLATE,d as VITE_TEMPLATES,m as initFullstackProject};
|