@jasonshimmy/vite-plugin-cer-app 0.1.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/.github/copilot-instructions.md +130 -0
- package/.github/workflows/publish.yml +206 -0
- package/.nvmrc +1 -0
- package/CHANGELOG.md +10 -0
- package/IMPLEMENTATION_PLAN.md +391 -0
- package/README.md +231 -0
- package/VITE_PLUGIN_FRAMEWORK_PLAN.md +594 -0
- package/commits.txt +3 -0
- package/dist/__tests__/plugin/path-utils.test.d.ts +2 -0
- package/dist/__tests__/plugin/path-utils.test.d.ts.map +1 -0
- package/dist/__tests__/plugin/path-utils.test.js +305 -0
- package/dist/__tests__/plugin/path-utils.test.js.map +1 -0
- package/dist/__tests__/plugin/scanner.test.d.ts +2 -0
- package/dist/__tests__/plugin/scanner.test.d.ts.map +1 -0
- package/dist/__tests__/plugin/scanner.test.js +143 -0
- package/dist/__tests__/plugin/scanner.test.js.map +1 -0
- package/dist/__tests__/plugin/transforms/auto-import.test.d.ts +2 -0
- package/dist/__tests__/plugin/transforms/auto-import.test.d.ts.map +1 -0
- package/dist/__tests__/plugin/transforms/auto-import.test.js +151 -0
- package/dist/__tests__/plugin/transforms/auto-import.test.js.map +1 -0
- package/dist/__tests__/plugin/transforms/head-inject.test.d.ts +2 -0
- package/dist/__tests__/plugin/transforms/head-inject.test.d.ts.map +1 -0
- package/dist/__tests__/plugin/transforms/head-inject.test.js +151 -0
- package/dist/__tests__/plugin/transforms/head-inject.test.js.map +1 -0
- package/dist/__tests__/plugin/virtual/components.test.d.ts +2 -0
- package/dist/__tests__/plugin/virtual/components.test.d.ts.map +1 -0
- package/dist/__tests__/plugin/virtual/components.test.js +47 -0
- package/dist/__tests__/plugin/virtual/components.test.js.map +1 -0
- package/dist/__tests__/plugin/virtual/composables.test.d.ts +2 -0
- package/dist/__tests__/plugin/virtual/composables.test.d.ts.map +1 -0
- package/dist/__tests__/plugin/virtual/composables.test.js +48 -0
- package/dist/__tests__/plugin/virtual/composables.test.js.map +1 -0
- package/dist/__tests__/plugin/virtual/layouts.test.d.ts +2 -0
- package/dist/__tests__/plugin/virtual/layouts.test.d.ts.map +1 -0
- package/dist/__tests__/plugin/virtual/layouts.test.js +59 -0
- package/dist/__tests__/plugin/virtual/layouts.test.js.map +1 -0
- package/dist/__tests__/plugin/virtual/middleware.test.d.ts +2 -0
- package/dist/__tests__/plugin/virtual/middleware.test.d.ts.map +1 -0
- package/dist/__tests__/plugin/virtual/middleware.test.js +58 -0
- package/dist/__tests__/plugin/virtual/middleware.test.js.map +1 -0
- package/dist/__tests__/plugin/virtual/plugins.test.d.ts +2 -0
- package/dist/__tests__/plugin/virtual/plugins.test.d.ts.map +1 -0
- package/dist/__tests__/plugin/virtual/plugins.test.js +73 -0
- package/dist/__tests__/plugin/virtual/plugins.test.js.map +1 -0
- package/dist/__tests__/plugin/virtual/routes.test.d.ts +2 -0
- package/dist/__tests__/plugin/virtual/routes.test.d.ts.map +1 -0
- package/dist/__tests__/plugin/virtual/routes.test.js +167 -0
- package/dist/__tests__/plugin/virtual/routes.test.js.map +1 -0
- package/dist/__tests__/plugin/virtual/server-api.test.d.ts +2 -0
- package/dist/__tests__/plugin/virtual/server-api.test.d.ts.map +1 -0
- package/dist/__tests__/plugin/virtual/server-api.test.js +72 -0
- package/dist/__tests__/plugin/virtual/server-api.test.js.map +1 -0
- package/dist/__tests__/runtime/use-head.test.d.ts +2 -0
- package/dist/__tests__/runtime/use-head.test.d.ts.map +1 -0
- package/dist/__tests__/runtime/use-head.test.js +202 -0
- package/dist/__tests__/runtime/use-head.test.js.map +1 -0
- package/dist/__tests__/runtime/use-page-data.test.d.ts +2 -0
- package/dist/__tests__/runtime/use-page-data.test.d.ts.map +1 -0
- package/dist/__tests__/runtime/use-page-data.test.js +41 -0
- package/dist/__tests__/runtime/use-page-data.test.js.map +1 -0
- package/dist/cli/commands/build.d.ts +3 -0
- package/dist/cli/commands/build.d.ts.map +1 -0
- package/dist/cli/commands/build.js +103 -0
- package/dist/cli/commands/build.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +3 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/dev.js +92 -0
- package/dist/cli/commands/dev.js.map +1 -0
- package/dist/cli/commands/generate.d.ts +7 -0
- package/dist/cli/commands/generate.d.ts.map +1 -0
- package/dist/cli/commands/generate.js +72 -0
- package/dist/cli/commands/generate.js.map +1 -0
- package/dist/cli/commands/preview.d.ts +3 -0
- package/dist/cli/commands/preview.d.ts.map +1 -0
- package/dist/cli/commands/preview.js +191 -0
- package/dist/cli/commands/preview.js.map +1 -0
- package/dist/cli/create/index.d.ts +3 -0
- package/dist/cli/create/index.d.ts.map +1 -0
- package/dist/cli/create/index.js +184 -0
- package/dist/cli/create/index.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +17 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin/build-ssg.d.ts +12 -0
- package/dist/plugin/build-ssg.d.ts.map +1 -0
- package/dist/plugin/build-ssg.js +212 -0
- package/dist/plugin/build-ssg.js.map +1 -0
- package/dist/plugin/build-ssr.d.ts +10 -0
- package/dist/plugin/build-ssr.d.ts.map +1 -0
- package/dist/plugin/build-ssr.js +139 -0
- package/dist/plugin/build-ssr.js.map +1 -0
- package/dist/plugin/dev-server.d.ts +46 -0
- package/dist/plugin/dev-server.d.ts.map +1 -0
- package/dist/plugin/dev-server.js +194 -0
- package/dist/plugin/dev-server.js.map +1 -0
- package/dist/plugin/dts-generator.d.ts +27 -0
- package/dist/plugin/dts-generator.d.ts.map +1 -0
- package/dist/plugin/dts-generator.js +180 -0
- package/dist/plugin/dts-generator.js.map +1 -0
- package/dist/plugin/index.d.ts +13 -0
- package/dist/plugin/index.d.ts.map +1 -0
- package/dist/plugin/index.js +298 -0
- package/dist/plugin/index.js.map +1 -0
- package/dist/plugin/path-utils.d.ts +57 -0
- package/dist/plugin/path-utils.d.ts.map +1 -0
- package/dist/plugin/path-utils.js +160 -0
- package/dist/plugin/path-utils.js.map +1 -0
- package/dist/plugin/scanner.d.ts +17 -0
- package/dist/plugin/scanner.d.ts.map +1 -0
- package/dist/plugin/scanner.js +54 -0
- package/dist/plugin/scanner.js.map +1 -0
- package/dist/plugin/transforms/auto-import.d.ts +14 -0
- package/dist/plugin/transforms/auto-import.d.ts.map +1 -0
- package/dist/plugin/transforms/auto-import.js +154 -0
- package/dist/plugin/transforms/auto-import.js.map +1 -0
- package/dist/plugin/transforms/head-inject.d.ts +29 -0
- package/dist/plugin/transforms/head-inject.d.ts.map +1 -0
- package/dist/plugin/transforms/head-inject.js +127 -0
- package/dist/plugin/transforms/head-inject.js.map +1 -0
- package/dist/plugin/virtual/components.d.ts +6 -0
- package/dist/plugin/virtual/components.d.ts.map +1 -0
- package/dist/plugin/virtual/components.js +22 -0
- package/dist/plugin/virtual/components.js.map +1 -0
- package/dist/plugin/virtual/composables.d.ts +6 -0
- package/dist/plugin/virtual/composables.d.ts.map +1 -0
- package/dist/plugin/virtual/composables.js +22 -0
- package/dist/plugin/virtual/composables.js.map +1 -0
- package/dist/plugin/virtual/error.d.ts +13 -0
- package/dist/plugin/virtual/error.d.ts.map +1 -0
- package/dist/plugin/virtual/error.js +32 -0
- package/dist/plugin/virtual/error.js.map +1 -0
- package/dist/plugin/virtual/layouts.d.ts +6 -0
- package/dist/plugin/virtual/layouts.d.ts.map +1 -0
- package/dist/plugin/virtual/layouts.js +33 -0
- package/dist/plugin/virtual/layouts.js.map +1 -0
- package/dist/plugin/virtual/loading.d.ts +11 -0
- package/dist/plugin/virtual/loading.d.ts.map +1 -0
- package/dist/plugin/virtual/loading.js +30 -0
- package/dist/plugin/virtual/loading.js.map +1 -0
- package/dist/plugin/virtual/middleware.d.ts +6 -0
- package/dist/plugin/virtual/middleware.d.ts.map +1 -0
- package/dist/plugin/virtual/middleware.js +36 -0
- package/dist/plugin/virtual/middleware.js.map +1 -0
- package/dist/plugin/virtual/plugins.d.ts +6 -0
- package/dist/plugin/virtual/plugins.d.ts.map +1 -0
- package/dist/plugin/virtual/plugins.js +30 -0
- package/dist/plugin/virtual/plugins.js.map +1 -0
- package/dist/plugin/virtual/routes.d.ts +16 -0
- package/dist/plugin/virtual/routes.d.ts.map +1 -0
- package/dist/plugin/virtual/routes.js +131 -0
- package/dist/plugin/virtual/routes.js.map +1 -0
- package/dist/plugin/virtual/server-api.d.ts +6 -0
- package/dist/plugin/virtual/server-api.d.ts.map +1 -0
- package/dist/plugin/virtual/server-api.js +41 -0
- package/dist/plugin/virtual/server-api.js.map +1 -0
- package/dist/plugin/virtual/server-middleware.d.ts +6 -0
- package/dist/plugin/virtual/server-middleware.d.ts.map +1 -0
- package/dist/plugin/virtual/server-middleware.js +36 -0
- package/dist/plugin/virtual/server-middleware.js.map +1 -0
- package/dist/runtime/app-template.d.ts +10 -0
- package/dist/runtime/app-template.d.ts.map +1 -0
- package/dist/runtime/app-template.js +143 -0
- package/dist/runtime/app-template.js.map +1 -0
- package/dist/runtime/composables/index.d.ts +4 -0
- package/dist/runtime/composables/index.d.ts.map +1 -0
- package/dist/runtime/composables/index.js +3 -0
- package/dist/runtime/composables/index.js.map +1 -0
- package/dist/runtime/composables/use-head.d.ts +30 -0
- package/dist/runtime/composables/use-head.d.ts.map +1 -0
- package/dist/runtime/composables/use-head.js +182 -0
- package/dist/runtime/composables/use-head.js.map +1 -0
- package/dist/runtime/composables/use-page-data.d.ts +32 -0
- package/dist/runtime/composables/use-page-data.d.ts.map +1 -0
- package/dist/runtime/composables/use-page-data.js +41 -0
- package/dist/runtime/composables/use-page-data.js.map +1 -0
- package/dist/runtime/entry-client-template.d.ts +8 -0
- package/dist/runtime/entry-client-template.d.ts.map +1 -0
- package/dist/runtime/entry-client-template.js +18 -0
- package/dist/runtime/entry-client-template.js.map +1 -0
- package/dist/runtime/entry-server-template.d.ts +9 -0
- package/dist/runtime/entry-server-template.d.ts.map +1 -0
- package/dist/runtime/entry-server-template.js +72 -0
- package/dist/runtime/entry-server-template.js.map +1 -0
- package/dist/types/api.d.ts +16 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +2 -0
- package/dist/types/api.js.map +1 -0
- package/dist/types/config.d.ts +32 -0
- package/dist/types/config.d.ts.map +1 -0
- package/dist/types/config.js +4 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/middleware.d.ts +6 -0
- package/dist/types/middleware.d.ts.map +1 -0
- package/dist/types/middleware.js +2 -0
- package/dist/types/middleware.js.map +1 -0
- package/dist/types/page.d.ts +21 -0
- package/dist/types/page.d.ts.map +1 -0
- package/dist/types/page.js +2 -0
- package/dist/types/page.js.map +1 -0
- package/dist/types/plugin.d.ts +12 -0
- package/dist/types/plugin.d.ts.map +1 -0
- package/dist/types/plugin.js +2 -0
- package/dist/types/plugin.js.map +1 -0
- package/docs/cli.md +233 -0
- package/docs/components.md +114 -0
- package/docs/composables.md +99 -0
- package/docs/configuration.md +270 -0
- package/docs/data-loading.md +165 -0
- package/docs/getting-started.md +235 -0
- package/docs/head-management.md +206 -0
- package/docs/layouts.md +112 -0
- package/docs/middleware.md +140 -0
- package/docs/plugins.md +138 -0
- package/docs/rendering-modes.md +251 -0
- package/docs/routing.md +180 -0
- package/docs/server-api.md +172 -0
- package/docs/testing.md +462 -0
- package/package.json +75 -0
- package/src/__tests__/plugin/path-utils.test.ts +399 -0
- package/src/__tests__/plugin/scanner.test.ts +172 -0
- package/src/__tests__/plugin/transforms/auto-import.test.ts +229 -0
- package/src/__tests__/plugin/transforms/head-inject.test.ts +178 -0
- package/src/__tests__/plugin/virtual/components.test.ts +56 -0
- package/src/__tests__/plugin/virtual/composables.test.ts +57 -0
- package/src/__tests__/plugin/virtual/layouts.test.ts +70 -0
- package/src/__tests__/plugin/virtual/middleware.test.ts +68 -0
- package/src/__tests__/plugin/virtual/plugins.test.ts +84 -0
- package/src/__tests__/plugin/virtual/routes.test.ts +202 -0
- package/src/__tests__/plugin/virtual/server-api.test.ts +85 -0
- package/src/__tests__/runtime/use-head.test.ts +243 -0
- package/src/__tests__/runtime/use-page-data.test.ts +45 -0
- package/src/cli/commands/build.ts +114 -0
- package/src/cli/commands/dev.ts +101 -0
- package/src/cli/commands/generate.ts +81 -0
- package/src/cli/commands/preview.ts +218 -0
- package/src/cli/create/index.ts +250 -0
- package/src/cli/create/templates/spa/app/app.ts.tpl +74 -0
- package/src/cli/create/templates/spa/app/layouts/default.ts.tpl +15 -0
- package/src/cli/create/templates/spa/app/pages/index.ts.tpl +8 -0
- package/src/cli/create/templates/spa/cer.config.ts.tpl +6 -0
- package/src/cli/create/templates/spa/index.html.tpl +12 -0
- package/src/cli/create/templates/spa/package.json.tpl +18 -0
- package/src/cli/create/templates/ssg/app/app.ts.tpl +74 -0
- package/src/cli/create/templates/ssg/app/layouts/default.ts.tpl +15 -0
- package/src/cli/create/templates/ssg/app/pages/index.ts.tpl +17 -0
- package/src/cli/create/templates/ssg/cer.config.ts.tpl +13 -0
- package/src/cli/create/templates/ssg/index.html.tpl +12 -0
- package/src/cli/create/templates/ssg/package.json.tpl +19 -0
- package/src/cli/create/templates/ssr/app/app.ts.tpl +74 -0
- package/src/cli/create/templates/ssr/app/layouts/default.ts.tpl +15 -0
- package/src/cli/create/templates/ssr/app/pages/index.ts.tpl +8 -0
- package/src/cli/create/templates/ssr/cer.config.ts.tpl +10 -0
- package/src/cli/create/templates/ssr/index.html.tpl +12 -0
- package/src/cli/create/templates/ssr/package.json.tpl +18 -0
- package/src/cli/index.ts +20 -0
- package/src/index.ts +13 -0
- package/src/plugin/build-ssg.ts +259 -0
- package/src/plugin/build-ssr.ts +147 -0
- package/src/plugin/dev-server.ts +266 -0
- package/src/plugin/dts-generator.ts +214 -0
- package/src/plugin/index.ts +330 -0
- package/src/plugin/path-utils.ts +186 -0
- package/src/plugin/scanner.ts +65 -0
- package/src/plugin/transforms/auto-import.ts +190 -0
- package/src/plugin/transforms/head-inject.ts +161 -0
- package/src/plugin/virtual/components.ts +28 -0
- package/src/plugin/virtual/composables.ts +28 -0
- package/src/plugin/virtual/error.ts +34 -0
- package/src/plugin/virtual/layouts.ts +41 -0
- package/src/plugin/virtual/loading.ts +33 -0
- package/src/plugin/virtual/middleware.ts +45 -0
- package/src/plugin/virtual/plugins.ts +36 -0
- package/src/plugin/virtual/routes.ts +147 -0
- package/src/plugin/virtual/server-api.ts +52 -0
- package/src/plugin/virtual/server-middleware.ts +44 -0
- package/src/runtime/app-template.ts +142 -0
- package/src/runtime/composables/index.ts +3 -0
- package/src/runtime/composables/use-head.ts +204 -0
- package/src/runtime/composables/use-page-data.ts +39 -0
- package/src/runtime/entry-client-template.ts +17 -0
- package/src/runtime/entry-server-template.ts +71 -0
- package/src/types/api.ts +19 -0
- package/src/types/config.ts +39 -0
- package/src/types/index.ts +6 -0
- package/src/types/middleware.ts +16 -0
- package/src/types/page.ts +29 -0
- package/src/types/plugin.ts +13 -0
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +19 -0
- package/vitest.config.ts +29 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { build } from 'vite';
|
|
2
|
+
import { join, resolve } from 'pathe';
|
|
3
|
+
import { existsSync } from 'node:fs';
|
|
4
|
+
/**
|
|
5
|
+
* The server entry template that wires all virtual modules together and
|
|
6
|
+
* exports a request handler for Node.js (Express-compatible).
|
|
7
|
+
*/
|
|
8
|
+
function generateServerEntryCode(config) {
|
|
9
|
+
return `// AUTO-GENERATED server entry by vite-plugin-cer-app
|
|
10
|
+
import 'virtual:cer-components'
|
|
11
|
+
import routes from 'virtual:cer-routes'
|
|
12
|
+
import layouts from 'virtual:cer-layouts'
|
|
13
|
+
import plugins from 'virtual:cer-plugins'
|
|
14
|
+
import apiRoutes from 'virtual:cer-server-api'
|
|
15
|
+
import { html, registerBuiltinComponents } from '@jasonshimmy/custom-elements-runtime'
|
|
16
|
+
import { initRouter } from '@jasonshimmy/custom-elements-runtime/router'
|
|
17
|
+
import { createStreamingSSRHandler } from '@jasonshimmy/custom-elements-runtime/ssr-middleware'
|
|
18
|
+
|
|
19
|
+
registerBuiltinComponents()
|
|
20
|
+
|
|
21
|
+
// Per-request VNode factory: initialize a fresh router at the request URL,
|
|
22
|
+
// resolve the active layout from the matched route's meta, wrap the router-view
|
|
23
|
+
// in that layout element, and call the route's data loader so the result is
|
|
24
|
+
// serialized as window.__CER_DATA__ for client-side hydration.
|
|
25
|
+
//
|
|
26
|
+
// createStreamingSSRHandler threads the router through each component's SSR
|
|
27
|
+
// context so concurrent renders never share state.
|
|
28
|
+
const vnodeFactory = async (req) => {
|
|
29
|
+
const router = initRouter({ routes, initialUrl: req.url ?? '/' })
|
|
30
|
+
const current = router.getCurrent()
|
|
31
|
+
const { route, params } = router.matchRoute(current.path)
|
|
32
|
+
const layoutName = route?.meta?.layout ?? 'default'
|
|
33
|
+
const layoutTag = layouts[layoutName]
|
|
34
|
+
const inner = html\`<router-view></router-view>\`
|
|
35
|
+
const vnode = layoutTag
|
|
36
|
+
? { tag: layoutTag, props: {}, children: [inner] }
|
|
37
|
+
: inner
|
|
38
|
+
|
|
39
|
+
// Call the route's data loader (if present) and serialize for client hydration.
|
|
40
|
+
let head
|
|
41
|
+
if (route?.load) {
|
|
42
|
+
try {
|
|
43
|
+
const mod = await route.load()
|
|
44
|
+
if (typeof mod.loader === 'function') {
|
|
45
|
+
const query = current.query ?? {}
|
|
46
|
+
const data = await mod.loader({ params, query, req })
|
|
47
|
+
if (data !== undefined && data !== null) {
|
|
48
|
+
head = \`<script>window.__CER_DATA__ = \${JSON.stringify(data)}</script>\`
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} catch {
|
|
52
|
+
// Loader errors are non-fatal during SSR; the client will refetch.
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return { vnode, router, head }
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const handler = createStreamingSSRHandler(vnodeFactory, {
|
|
60
|
+
render: {
|
|
61
|
+
dsd: ${config.ssr.dsd},
|
|
62
|
+
},
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
export { apiRoutes, plugins, layouts }
|
|
66
|
+
export default handler
|
|
67
|
+
`;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Runs the dual (client + server) SSR build using Vite's programmatic API.
|
|
71
|
+
*
|
|
72
|
+
* 1. Client bundle: normal Vite build (outputs to dist/client)
|
|
73
|
+
* 2. Server bundle: SSR build (outputs to dist/server), uses a generated entry
|
|
74
|
+
*/
|
|
75
|
+
export async function buildSSR(config, viteUserConfig = {}) {
|
|
76
|
+
const clientOutDir = join(config.root, 'dist/client');
|
|
77
|
+
const serverOutDir = join(config.root, 'dist/server');
|
|
78
|
+
// Determine client entry — prefer entry-client.ts, fall back to app.ts
|
|
79
|
+
const clientEntry = existsSync(resolve(config.srcDir, 'entry-client.ts'))
|
|
80
|
+
? resolve(config.srcDir, 'entry-client.ts')
|
|
81
|
+
: resolve(config.srcDir, 'app.ts');
|
|
82
|
+
// Build the client bundle
|
|
83
|
+
console.log('[cer-app] Building client bundle...');
|
|
84
|
+
await build({
|
|
85
|
+
...viteUserConfig,
|
|
86
|
+
root: config.root,
|
|
87
|
+
build: {
|
|
88
|
+
...viteUserConfig.build,
|
|
89
|
+
outDir: clientOutDir,
|
|
90
|
+
ssrManifest: true,
|
|
91
|
+
rollupOptions: {
|
|
92
|
+
input: clientEntry,
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
// Generate server entry source inline via a virtual plugin
|
|
97
|
+
const serverEntryCode = generateServerEntryCode(config);
|
|
98
|
+
const VIRTUAL_SERVER_ENTRY = 'virtual:cer-server-entry';
|
|
99
|
+
const RESOLVED_SERVER_ENTRY = '\0virtual:cer-server-entry';
|
|
100
|
+
// Build the server (SSR) bundle
|
|
101
|
+
console.log('[cer-app] Building server bundle...');
|
|
102
|
+
await build({
|
|
103
|
+
...viteUserConfig,
|
|
104
|
+
root: config.root,
|
|
105
|
+
plugins: [
|
|
106
|
+
...(viteUserConfig.plugins ?? []),
|
|
107
|
+
{
|
|
108
|
+
name: 'vite-plugin-cer-server-entry',
|
|
109
|
+
enforce: 'pre',
|
|
110
|
+
resolveId(id) {
|
|
111
|
+
if (id === VIRTUAL_SERVER_ENTRY)
|
|
112
|
+
return RESOLVED_SERVER_ENTRY;
|
|
113
|
+
},
|
|
114
|
+
load(id) {
|
|
115
|
+
if (id === RESOLVED_SERVER_ENTRY)
|
|
116
|
+
return serverEntryCode;
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
build: {
|
|
121
|
+
...viteUserConfig.build,
|
|
122
|
+
outDir: serverOutDir,
|
|
123
|
+
ssr: true,
|
|
124
|
+
rollupOptions: {
|
|
125
|
+
input: VIRTUAL_SERVER_ENTRY,
|
|
126
|
+
output: {
|
|
127
|
+
entryFileNames: 'server.js',
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
ssr: {
|
|
132
|
+
noExternal: ['@jasonshimmy/custom-elements-runtime'],
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
console.log('[cer-app] SSR build complete.');
|
|
136
|
+
console.log(` Client: ${clientOutDir}`);
|
|
137
|
+
console.log(` Server: ${serverOutDir}`);
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=build-ssr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-ssr.js","sourceRoot":"","sources":["../../src/plugin/build-ssr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAmB,MAAM,MAAM,CAAA;AAC7C,OAAO,EAAE,IAAI,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AE1D,gCAAgC;IAChC,OAAO,CAAC,GAAG,CAAC,qCAAqC,CAAC,CAAA;IAClD,MAAM,KAAK,CAAC;QACV,GAAG,cAAc;QACjB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,OAAO,EAAE;YACP,GAAG,CAAC,cAAc,CAAC,OAAO,IAAI,EAAE,CAAC;YACjC;gBACE,IAAI,EAAE,8BAA8B;gBACpC,OAAO,EAAE,KAAc;gBACvB,SAAS,CAAC,EAAU;oBAClB,IAAI,EAAE,KAAK,oBAAoB;wBAAE,OAAO,qBAAqB,CAAA;gBAC/D,CAAC;gBACD,IAAI,CAAC,EAAU;oBACb,IAAI,EAAE,KAAK,qBAAqB;wBAAE,OAAO,eAAe,CAAA;gBAC1D,CAAC;aACF;SACF;QACD,KAAK,EAAE;YACL,GAAG,cAAc,CAAC,KAAK;YACvB,MAAM,EAAE,YAAY;YACpB,GAAG,EAAE,IAAI;YACT,aAAa,EAAE;gBACb,KAAK,EAAE,oBAAoB;gBAC3B,MAAM,EAAE;oBACN,cAAc,EAAE,WAAW;iBAC5B;aACF;SACF;QACD,GAAG,EAAE;YACH,UAAU,EAAE,CAAC,sCAAsC,CAAC;SACrD;KACF,CAAC,CAAA;IAEF,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAA;IAC5C,OAAO,CAAC,GAAG,CAAC,aAAa,YAAY,EAAE,CAAC,CAAA;IACxC,OAAO,CAAC,GAAG,CAAC,aAAa,YAAY,EAAE,CAAC,CAAA;AAC1C,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { ViteDevServer } from 'vite';
|
|
2
|
+
export interface ResolvedCerConfig {
|
|
3
|
+
mode: 'spa' | 'ssr' | 'ssg';
|
|
4
|
+
srcDir: string;
|
|
5
|
+
root: string;
|
|
6
|
+
pagesDir: string;
|
|
7
|
+
layoutsDir: string;
|
|
8
|
+
componentsDir: string;
|
|
9
|
+
composablesDir: string;
|
|
10
|
+
pluginsDir: string;
|
|
11
|
+
middlewareDir: string;
|
|
12
|
+
serverApiDir: string;
|
|
13
|
+
serverMiddlewareDir: string;
|
|
14
|
+
port: number;
|
|
15
|
+
ssr: {
|
|
16
|
+
dsd: boolean;
|
|
17
|
+
streaming: boolean;
|
|
18
|
+
};
|
|
19
|
+
ssg: {
|
|
20
|
+
routes: 'auto' | string[];
|
|
21
|
+
concurrency: number;
|
|
22
|
+
fallback: boolean;
|
|
23
|
+
};
|
|
24
|
+
router: {
|
|
25
|
+
base?: string;
|
|
26
|
+
scrollToFragment?: boolean | object;
|
|
27
|
+
};
|
|
28
|
+
jitCss: {
|
|
29
|
+
content: string[];
|
|
30
|
+
extendedColors: boolean;
|
|
31
|
+
};
|
|
32
|
+
autoImports: {
|
|
33
|
+
components: boolean;
|
|
34
|
+
composables: boolean;
|
|
35
|
+
directives: boolean;
|
|
36
|
+
runtime: boolean;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Configures the Vite dev server with:
|
|
41
|
+
* 1. API route handlers from server/api/
|
|
42
|
+
* 2. Server middleware from server/middleware/
|
|
43
|
+
* 3. SSR HTML rendering (when mode is 'ssr')
|
|
44
|
+
*/
|
|
45
|
+
export declare function configureCerDevServer(server: ViteDevServer, config: ResolvedCerConfig): void;
|
|
46
|
+
//# sourceMappingURL=dev-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dev-server.d.ts","sourceRoot":"","sources":["../../src/plugin/dev-server.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAIzC,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK,CAAA;IAC3B,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,MAAM,CAAA;IACpB,mBAAmB,EAAE,MAAM,CAAA;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,GAAG,EAAE;QAAE,GAAG,EAAE,OAAO,CAAC;QAAC,SAAS,EAAE,OAAO,CAAA;KAAE,CAAA;IACzC,GAAG,EAAE;QAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAE,CAAA;IAC1E,MAAM,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,gBAAgB,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;KAAE,CAAA;IAC9D,MAAM,EAAE;QAAE,OAAO,EAAE,MAAM,EAAE,CAAC;QAAC,cAAc,EAAE,OAAO,CAAA;KAAE,CAAA;IACtD,WAAW,EAAE;QAAE,UAAU,EAAE,OAAO,CAAC;QAAC,WAAW,EAAE,OAAO,CAAC;QAAC,UAAU,EAAE,OAAO,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,CAAA;CAClG;AAwFD;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,iBAAiB,GACxB,IAAI,CAkJN"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { resolve } from 'pathe';
|
|
2
|
+
/**
|
|
3
|
+
* Reads the raw body from an IncomingMessage as a Buffer.
|
|
4
|
+
*/
|
|
5
|
+
function readBody(req) {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
const chunks = [];
|
|
8
|
+
req.on('data', (chunk) => chunks.push(chunk));
|
|
9
|
+
req.on('end', () => resolve(Buffer.concat(chunks)));
|
|
10
|
+
req.on('error', reject);
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Parses the request body for JSON content types.
|
|
15
|
+
* Attaches the parsed body (or raw buffer) to `(req as any).body`.
|
|
16
|
+
*/
|
|
17
|
+
async function parseBody(req) {
|
|
18
|
+
const contentType = req.headers['content-type'] ?? '';
|
|
19
|
+
const method = req.method?.toUpperCase() ?? 'GET';
|
|
20
|
+
if (!['POST', 'PUT', 'PATCH'].includes(method)) {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
const buf = await readBody(req);
|
|
24
|
+
if (contentType.includes('application/json')) {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(buf.toString('utf-8'));
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return buf;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Extracts route params from a path pattern.
|
|
36
|
+
* e.g. pattern="/api/users/:id", path="/api/users/42" -> { id: "42" }
|
|
37
|
+
*/
|
|
38
|
+
function matchApiPath(pattern, urlPath) {
|
|
39
|
+
const patternParts = pattern.split('/');
|
|
40
|
+
const urlParts = urlPath.split('?')[0].split('/');
|
|
41
|
+
if (patternParts.length !== urlParts.length)
|
|
42
|
+
return null;
|
|
43
|
+
const params = {};
|
|
44
|
+
for (let i = 0; i < patternParts.length; i++) {
|
|
45
|
+
const p = patternParts[i];
|
|
46
|
+
const u = urlParts[i];
|
|
47
|
+
if (p.startsWith(':')) {
|
|
48
|
+
params[p.slice(1)] = decodeURIComponent(u);
|
|
49
|
+
}
|
|
50
|
+
else if (p !== u) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return params;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Parses URL query string into a plain object.
|
|
58
|
+
*/
|
|
59
|
+
function parseQuery(url) {
|
|
60
|
+
const qIndex = url.indexOf('?');
|
|
61
|
+
if (qIndex === -1)
|
|
62
|
+
return {};
|
|
63
|
+
const qs = url.slice(qIndex + 1);
|
|
64
|
+
const result = {};
|
|
65
|
+
for (const part of qs.split('&')) {
|
|
66
|
+
if (!part)
|
|
67
|
+
continue;
|
|
68
|
+
const eqIdx = part.indexOf('=');
|
|
69
|
+
if (eqIdx === -1) {
|
|
70
|
+
result[decodeURIComponent(part)] = '';
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
result[decodeURIComponent(part.slice(0, eqIdx))] = decodeURIComponent(part.slice(eqIdx + 1));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Configures the Vite dev server with:
|
|
80
|
+
* 1. API route handlers from server/api/
|
|
81
|
+
* 2. Server middleware from server/middleware/
|
|
82
|
+
* 3. SSR HTML rendering (when mode is 'ssr')
|
|
83
|
+
*/
|
|
84
|
+
export function configureCerDevServer(server, config) {
|
|
85
|
+
server.middlewares.use(async (req, res, next) => {
|
|
86
|
+
const url = req.url ?? '/';
|
|
87
|
+
const method = req.method?.toUpperCase() ?? 'GET';
|
|
88
|
+
// 1. Server middleware from server/middleware/ runs first (CORS, auth, logging, etc.)
|
|
89
|
+
try {
|
|
90
|
+
const smMod = await server.ssrLoadModule('virtual:cer-server-middleware');
|
|
91
|
+
const serverMiddleware = (smMod.serverMiddleware ?? smMod.default ?? []);
|
|
92
|
+
for (const { handler } of serverMiddleware) {
|
|
93
|
+
if (typeof handler === 'function') {
|
|
94
|
+
let calledNext = false;
|
|
95
|
+
await handler(req, res, () => {
|
|
96
|
+
calledNext = true;
|
|
97
|
+
});
|
|
98
|
+
if (!calledNext)
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// middleware module not ready — continue
|
|
105
|
+
}
|
|
106
|
+
// 2. API route handlers from server/api/
|
|
107
|
+
try {
|
|
108
|
+
const mod = await server.ssrLoadModule('virtual:cer-server-api');
|
|
109
|
+
const apiRoutes = mod.apiRoutes ?? mod.default?.apiRoutes ?? [];
|
|
110
|
+
for (const route of apiRoutes) {
|
|
111
|
+
const params = matchApiPath(route.path, url.split('?')[0]);
|
|
112
|
+
if (params === null)
|
|
113
|
+
continue;
|
|
114
|
+
const query = parseQuery(url);
|
|
115
|
+
const body = await parseBody(req);
|
|
116
|
+
// Augment request
|
|
117
|
+
const augmentedReq = req;
|
|
118
|
+
augmentedReq.params = params;
|
|
119
|
+
augmentedReq.query = query;
|
|
120
|
+
augmentedReq.body = body;
|
|
121
|
+
// Augment response with json() and status() helpers
|
|
122
|
+
const augmentedRes = res;
|
|
123
|
+
augmentedRes.json = function (data) {
|
|
124
|
+
const json = JSON.stringify(data);
|
|
125
|
+
this.setHeader('Content-Type', 'application/json');
|
|
126
|
+
this.end(json);
|
|
127
|
+
};
|
|
128
|
+
augmentedRes.status = function (code) {
|
|
129
|
+
this.statusCode = code;
|
|
130
|
+
return this;
|
|
131
|
+
};
|
|
132
|
+
// Try to find a handler for the HTTP method. Exports may be GET/POST (uppercase)
|
|
133
|
+
// or get/post (lowercase); try both plus a 'default' fallback.
|
|
134
|
+
const handlerKey = method.toLowerCase();
|
|
135
|
+
const handler = route.handlers[handlerKey] ??
|
|
136
|
+
route.handlers[method.toUpperCase()] ??
|
|
137
|
+
route.handlers['default'];
|
|
138
|
+
if (typeof handler === 'function') {
|
|
139
|
+
try {
|
|
140
|
+
await handler(augmentedReq, augmentedRes);
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
server.ssrFixStacktrace(err);
|
|
144
|
+
console.error(`[cer-app] API handler error at ${route.path}:`, err);
|
|
145
|
+
res.statusCode = 500;
|
|
146
|
+
res.setHeader('Content-Type', 'application/json');
|
|
147
|
+
res.end(JSON.stringify({ error: 'Internal Server Error' }));
|
|
148
|
+
}
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// virtual:cer-server-api not yet ready or empty — continue
|
|
155
|
+
}
|
|
156
|
+
// 3. SSR mode: intercept HTML requests
|
|
157
|
+
if (config.mode === 'ssr') {
|
|
158
|
+
const acceptsHtml = (req.headers['accept'] ?? '').includes('text/html') ||
|
|
159
|
+
url === '/' ||
|
|
160
|
+
(!url.includes('.') && !url.startsWith('/api/'));
|
|
161
|
+
if (acceptsHtml) {
|
|
162
|
+
try {
|
|
163
|
+
// Load the SSR entry module
|
|
164
|
+
const ssrEntry = await server.ssrLoadModule(resolve(config.srcDir, 'entry-server.ts'));
|
|
165
|
+
const handler = ssrEntry.handler ?? ssrEntry.default?.handler;
|
|
166
|
+
if (typeof handler === 'function') {
|
|
167
|
+
await handler(req, res);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
// Fallback: render using template + ssrEntry render function
|
|
171
|
+
const renderFn = ssrEntry.render ?? ssrEntry.default?.render;
|
|
172
|
+
if (typeof renderFn === 'function') {
|
|
173
|
+
const template = await server.transformIndexHtml(url, `<!DOCTYPE html><html><head></head><body><div id="app"></div></body></html>`);
|
|
174
|
+
const result = await renderFn({ url, req });
|
|
175
|
+
const rendered = template.replace('<div id="app"></div>', `<div id="app">${result.html ?? ''}</div>`);
|
|
176
|
+
res.setHeader('Content-Type', 'text/html; charset=utf-8');
|
|
177
|
+
res.end(rendered);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
catch (err) {
|
|
182
|
+
server.ssrFixStacktrace(err);
|
|
183
|
+
console.error('[cer-app] SSR render error:', err);
|
|
184
|
+
res.statusCode = 500;
|
|
185
|
+
res.setHeader('Content-Type', 'text/plain');
|
|
186
|
+
res.end('SSR Error: ' + String(err));
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
next();
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=dev-server.js.map
|
|
@@ -0,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;oBACrC,OAAO,CAAC,KAAK,CAAC,6BAA6B,EAAE,GAAG,CAAC,CAAA;oBACjD,GAAG,CAAC,UAAU,GAAG,GAAG,CAAA;oBACpB,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,YAAY,CAAC,CAAA;oBAC3C,GAAG,CAAC,GAAG,CAAC,aAAa,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAA;oBACpC,OAAM;gBACR,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,EAAE,CAAA;IACR,CAAC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writes `cer-tsconfig.json` to the project root containing path aliases for
|
|
3
|
+
* the `~/` prefix. Users extend it from their `tsconfig.json`:
|
|
4
|
+
* { "extends": "./cer-tsconfig.json" }
|
|
5
|
+
*/
|
|
6
|
+
export declare function writeTsconfigPaths(root: string, srcDir: string): void;
|
|
7
|
+
/**
|
|
8
|
+
* Scans a composables directory and returns a map of export name → file path.
|
|
9
|
+
* Uses a simple regex to find exported identifiers.
|
|
10
|
+
*/
|
|
11
|
+
export declare function scanComposableExports(composablesDir: string): Promise<Map<string, string>>;
|
|
12
|
+
/**
|
|
13
|
+
* Generates the content of `cer-auto-imports.d.ts`.
|
|
14
|
+
* @param root - project root (where the .d.ts file will be written)
|
|
15
|
+
*/
|
|
16
|
+
export declare function generateAutoImportDts(root: string, composablesDir: string, composableExports?: Map<string, string>): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Generates the content of `cer-env.d.ts` — a script (non-module) file
|
|
19
|
+
* containing ambient `declare module` declarations for all virtual modules.
|
|
20
|
+
* Must NOT contain `export {}` or any top-level imports/exports.
|
|
21
|
+
*/
|
|
22
|
+
export declare function generateVirtualModuleDts(root: string, composablesDir: string, composableExports?: Map<string, string>): Promise<string>;
|
|
23
|
+
/**
|
|
24
|
+
* Writes both `cer-auto-imports.d.ts` and `cer-env.d.ts` to the project root.
|
|
25
|
+
*/
|
|
26
|
+
export declare function writeAutoImportDts(root: string, composablesDir: string, composableExports?: Map<string, string>): Promise<void>;
|
|
27
|
+
//# sourceMappingURL=dts-generator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dts-generator.d.ts","sourceRoot":"","sources":["../../src/plugin/dts-generator.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAcrE;AAqCD;;;GAGG;AACH,wBAAsB,qBAAqB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAiBhG;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,MAAM,EACtB,iBAAiB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACtC,OAAO,CAAC,MAAM,CAAC,CA8CjB;AAED;;;;GAIG;AACH,wBAAsB,wBAAwB,CAC5C,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,MAAM,EACtB,iBAAiB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACtC,OAAO,CAAC,MAAM,CAAC,CAiDjB;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,MAAM,EACtB,iBAAiB,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACtC,OAAO,CAAC,IAAI,CAAC,CAMf"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { writeFileSync } from 'node:fs';
|
|
2
|
+
import { readFileSync, existsSync } from 'node:fs';
|
|
3
|
+
import { join, relative } from 'pathe';
|
|
4
|
+
import { scanDirectory } from './scanner.js';
|
|
5
|
+
/**
|
|
6
|
+
* Writes `cer-tsconfig.json` to the project root containing path aliases for
|
|
7
|
+
* the `~/` prefix. Users extend it from their `tsconfig.json`:
|
|
8
|
+
* { "extends": "./cer-tsconfig.json" }
|
|
9
|
+
*/
|
|
10
|
+
export function writeTsconfigPaths(root, srcDir) {
|
|
11
|
+
const rel = './' + relative(root, srcDir).replace(/\\/g, '/');
|
|
12
|
+
const paths = {
|
|
13
|
+
'~/*': [`${rel}/*`],
|
|
14
|
+
'~/pages/*': [`${rel}/pages/*`],
|
|
15
|
+
'~/layouts/*': [`${rel}/layouts/*`],
|
|
16
|
+
'~/components/*': [`${rel}/components/*`],
|
|
17
|
+
'~/composables/*': [`${rel}/composables/*`],
|
|
18
|
+
'~/plugins/*': [`${rel}/plugins/*`],
|
|
19
|
+
'~/middleware/*': [`${rel}/middleware/*`],
|
|
20
|
+
'~/assets/*': [`${rel}/assets/*`],
|
|
21
|
+
};
|
|
22
|
+
const content = JSON.stringify({ compilerOptions: { paths } }, null, 2) + '\n';
|
|
23
|
+
writeFileSync(join(root, 'cer-tsconfig.json'), content, 'utf-8');
|
|
24
|
+
}
|
|
25
|
+
const RUNTIME_GLOBALS = [
|
|
26
|
+
'component',
|
|
27
|
+
'html',
|
|
28
|
+
'css',
|
|
29
|
+
'ref',
|
|
30
|
+
'computed',
|
|
31
|
+
'watch',
|
|
32
|
+
'watchEffect',
|
|
33
|
+
'useProps',
|
|
34
|
+
'useEmit',
|
|
35
|
+
'useOnConnected',
|
|
36
|
+
'useOnDisconnected',
|
|
37
|
+
'useOnAttributeChanged',
|
|
38
|
+
'useOnError',
|
|
39
|
+
'useStyle',
|
|
40
|
+
'useDesignTokens',
|
|
41
|
+
'useGlobalStyle',
|
|
42
|
+
'useExpose',
|
|
43
|
+
'useSlots',
|
|
44
|
+
'provide',
|
|
45
|
+
'inject',
|
|
46
|
+
'createComposable',
|
|
47
|
+
'nextTick',
|
|
48
|
+
'defineModel',
|
|
49
|
+
'getCurrentComponentContext',
|
|
50
|
+
'isReactiveState',
|
|
51
|
+
'unsafeHTML',
|
|
52
|
+
'decodeEntities',
|
|
53
|
+
'useTeleport',
|
|
54
|
+
];
|
|
55
|
+
const DIRECTIVE_GLOBALS = ['when', 'each', 'match', 'anchorBlock'];
|
|
56
|
+
const FRAMEWORK_GLOBALS = ['useHead', 'usePageData'];
|
|
57
|
+
/**
|
|
58
|
+
* Scans a composables directory and returns a map of export name → file path.
|
|
59
|
+
* Uses a simple regex to find exported identifiers.
|
|
60
|
+
*/
|
|
61
|
+
export async function scanComposableExports(composablesDir) {
|
|
62
|
+
const result = new Map();
|
|
63
|
+
if (!existsSync(composablesDir))
|
|
64
|
+
return result;
|
|
65
|
+
const files = await scanDirectory('**/*.ts', composablesDir);
|
|
66
|
+
const exportPattern = /export\s+(?:async\s+)?(?:function|const|let|var|class)\s+(\w+)/g;
|
|
67
|
+
for (const file of files) {
|
|
68
|
+
const code = readFileSync(file, 'utf-8');
|
|
69
|
+
exportPattern.lastIndex = 0;
|
|
70
|
+
let match;
|
|
71
|
+
while ((match = exportPattern.exec(code)) !== null) {
|
|
72
|
+
result.set(match[1], file);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Generates the content of `cer-auto-imports.d.ts`.
|
|
79
|
+
* @param root - project root (where the .d.ts file will be written)
|
|
80
|
+
*/
|
|
81
|
+
export async function generateAutoImportDts(root, composablesDir, composableExports) {
|
|
82
|
+
const exports = composableExports ?? await scanComposableExports(composablesDir);
|
|
83
|
+
const lines = [
|
|
84
|
+
'// AUTO-GENERATED by vite-plugin-cer-app',
|
|
85
|
+
'// Do not edit — regenerated automatically on dev server start and build.',
|
|
86
|
+
'',
|
|
87
|
+
'export {}',
|
|
88
|
+
'',
|
|
89
|
+
'declare global {',
|
|
90
|
+
];
|
|
91
|
+
for (const name of RUNTIME_GLOBALS) {
|
|
92
|
+
lines.push(` const ${name}: typeof import('@jasonshimmy/custom-elements-runtime')['${name}']`);
|
|
93
|
+
}
|
|
94
|
+
lines.push('');
|
|
95
|
+
for (const name of DIRECTIVE_GLOBALS) {
|
|
96
|
+
lines.push(` const ${name}: typeof import('@jasonshimmy/custom-elements-runtime/directives')['${name}']`);
|
|
97
|
+
}
|
|
98
|
+
lines.push('');
|
|
99
|
+
for (const name of FRAMEWORK_GLOBALS) {
|
|
100
|
+
lines.push(` const ${name}: typeof import('vite-plugin-cer-app/composables')['${name}']`);
|
|
101
|
+
}
|
|
102
|
+
if (exports.size > 0) {
|
|
103
|
+
lines.push('');
|
|
104
|
+
for (const [name, filePath] of exports) {
|
|
105
|
+
// Use a path relative to the project root so the .d.ts is portable
|
|
106
|
+
const rel = './' + relative(root, filePath).replace(/\.ts$/, '');
|
|
107
|
+
lines.push(` const ${name}: typeof import('${rel}')['${name}']`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
lines.push('');
|
|
111
|
+
lines.push(' // SSR loader data injected as window.__CER_DATA__ by the server.');
|
|
112
|
+
lines.push(' // Consumed once by usePageData() during client hydration.');
|
|
113
|
+
lines.push(' // eslint-disable-next-line @typescript-eslint/no-explicit-any');
|
|
114
|
+
lines.push(' var __CER_DATA__: any');
|
|
115
|
+
lines.push('}');
|
|
116
|
+
lines.push('');
|
|
117
|
+
return lines.join('\n');
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Generates the content of `cer-env.d.ts` — a script (non-module) file
|
|
121
|
+
* containing ambient `declare module` declarations for all virtual modules.
|
|
122
|
+
* Must NOT contain `export {}` or any top-level imports/exports.
|
|
123
|
+
*/
|
|
124
|
+
export async function generateVirtualModuleDts(root, composablesDir, composableExports) {
|
|
125
|
+
const exports = composableExports ?? await scanComposableExports(composablesDir);
|
|
126
|
+
const lines = [
|
|
127
|
+
'// AUTO-GENERATED by vite-plugin-cer-app',
|
|
128
|
+
'// Do not edit — regenerated automatically on dev server start and build.',
|
|
129
|
+
'',
|
|
130
|
+
`declare module 'virtual:cer-routes' {`,
|
|
131
|
+
` import type { Route } from '@jasonshimmy/custom-elements-runtime/router'`,
|
|
132
|
+
` const routes: Route[]`,
|
|
133
|
+
` export default routes`,
|
|
134
|
+
`}`,
|
|
135
|
+
'',
|
|
136
|
+
`declare module 'virtual:cer-layouts' {}`,
|
|
137
|
+
`declare module 'virtual:cer-components' {}`,
|
|
138
|
+
'',
|
|
139
|
+
`declare module 'virtual:cer-plugins' {`,
|
|
140
|
+
` import type { AppPlugin } from 'vite-plugin-cer-app/types'`,
|
|
141
|
+
` const plugins: AppPlugin[]`,
|
|
142
|
+
` export default plugins`,
|
|
143
|
+
`}`,
|
|
144
|
+
'',
|
|
145
|
+
`declare module 'virtual:cer-composables' {`,
|
|
146
|
+
];
|
|
147
|
+
for (const [name, filePath] of exports) {
|
|
148
|
+
const rel = './' + relative(root, filePath).replace(/\.ts$/, '');
|
|
149
|
+
lines.push(` export { ${name} } from '${rel}'`);
|
|
150
|
+
}
|
|
151
|
+
lines.push(`}`);
|
|
152
|
+
lines.push('');
|
|
153
|
+
lines.push(`declare module 'virtual:cer-middleware' {`);
|
|
154
|
+
lines.push(` const middleware: Record<string, Function>`);
|
|
155
|
+
lines.push(` export { middleware }`);
|
|
156
|
+
lines.push(`}`);
|
|
157
|
+
lines.push('');
|
|
158
|
+
lines.push(`declare module 'virtual:cer-loading' {`);
|
|
159
|
+
lines.push(` export const hasLoading: boolean`);
|
|
160
|
+
lines.push(` export const loadingTag: string | null`);
|
|
161
|
+
lines.push(`}`);
|
|
162
|
+
lines.push('');
|
|
163
|
+
lines.push(`declare module 'virtual:cer-error' {`);
|
|
164
|
+
lines.push(` export const hasError: boolean`);
|
|
165
|
+
lines.push(` export const errorTag: string | null`);
|
|
166
|
+
lines.push(`}`);
|
|
167
|
+
lines.push('');
|
|
168
|
+
return lines.join('\n');
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Writes both `cer-auto-imports.d.ts` and `cer-env.d.ts` to the project root.
|
|
172
|
+
*/
|
|
173
|
+
export async function writeAutoImportDts(root, composablesDir, composableExports) {
|
|
174
|
+
const scanned = composableExports ?? await scanComposableExports(composablesDir);
|
|
175
|
+
const autoImportsContent = await generateAutoImportDts(root, composablesDir, scanned);
|
|
176
|
+
const envContent = await generateVirtualModuleDts(root, composablesDir, scanned);
|
|
177
|
+
writeFileSync(join(root, 'cer-auto-imports.d.ts'), autoImportsContent, 'utf-8');
|
|
178
|
+
writeFileSync(join(root, 'cer-env.d.ts'), envContent, 'utf-8');
|
|
179
|
+
}
|
|
180
|
+
//# sourceMappingURL=dts-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dts-generator.js","sourceRoot":"","sources":["../../src/plugin/dts-generator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AACvC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAE5C;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,MAAc;IAC7D,MAAM,GAAG,GAAG,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAA;IAC7D,MAAM,KAAK,GAA6B;QACtC,KAAK,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC;QACnB,WAAW,EAAE,CAAC,GAAG,GAAG,UAAU,CAAC;QAC/B,aAAa,EAAE,CAAC,GAAG,GAAG,YAAY,CAAC;QACnC,gBAAgB,EAAE,CAAC,GAAG,GAAG,eAAe,CAAC;QACzC,iBAAiB,EAAE,CAAC,GAAG,GAAG,gBAAgB,CAAC;QAC3C,aAAa,EAAE,CAAC,GAAG,GAAG,YAAY,CAAC;QACnC,gBAAgB,EAAE,CAAC,GAAG,GAAG,eAAe,CAAC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AAI,MAAM,qBAAqB,CAAC,cAAc,CAAC,CAAA;IAChF,MAAM,kBAAkB,GAAG,MAAM,qBAAqB,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,CAAC,CAAA;IACrF,MAAM,UAAU,GAAG,MAAM,wBAAwB,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,CAAC,CAAA;IAChF,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,uBAAuB,CAAC,EAAE,kBAAkB,EAAE,OAAO,CAAC,CAAA;IAC/E,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,EAAE,UAAU,EAAE,OAAO,CAAC,CAAA;AAChE,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Plugin } from 'vite';
|
|
2
|
+
import type { CerAppConfig } from '../types/config.js';
|
|
3
|
+
import type { ResolvedCerConfig } from './dev-server.js';
|
|
4
|
+
/**
|
|
5
|
+
* Fills in default values for all config fields and resolves absolute paths.
|
|
6
|
+
*/
|
|
7
|
+
export declare function resolveConfig(userConfig: CerAppConfig, root?: string): ResolvedCerConfig;
|
|
8
|
+
/**
|
|
9
|
+
* The main cerApp() Vite plugin factory.
|
|
10
|
+
* Returns an array of plugins: the cer-app orchestrator + the runtime JIT CSS plugin(s).
|
|
11
|
+
*/
|
|
12
|
+
export declare function cerApp(userConfig?: CerAppConfig): Plugin[];
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/plugin/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAA6B,MAAM,MAAM,CAAA;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AAqCxD;;GAEG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,YAAY,EAAE,IAAI,GAAE,MAAsB,GAAG,iBAAiB,CA6CvG;AAqFD;;;GAGG;AACH,wBAAgB,MAAM,CAAC,UAAU,GAAE,YAAiB,GAAG,MAAM,EAAE,CAwJ9D"}
|