Skip to content

Commit 314bd79

Browse files
committed
refactor(examples): standardize devframe tool examples to app/ + src/node/ + playgrounds/
Apply the built-in plugin layout to the five examples that define a devframe: - files-inspector, streaming-chat (Preact): app/ = SPA, src/node/ = definition + rpc, playgrounds/ boots the built tool; dev serves the app with HMR + a live node bridge, play builds then runs the playground - sse-basic: extract the inline definition into src/node/, move the client into app/, keep the SSE-only bridge; add dev/play - next-runtime-snapshot (Next): app/ = the Next app, src/node/ = definition + rpc, scripts/build-spa.mjs uses a mode-explicit recursive copy; add playgrounds/ + play - json-render (no own SPA, reuses the prebuilt UI): consolidate the definition, dashboard, and shared code under src/node/; retarget the ./ and ./dashboard exports - update json-render/dashboard alias, tsconfig.base paths, and the next-runtime-snapshot knip postcss config The framework HOST examples (hub-*, a11y-messages-playground, demo-dock-client) mount devframes rather than defining one, so they keep their framework-idiomatic layouts.
1 parent 0abf43f commit 314bd79

86 files changed

Lines changed: 632 additions & 226 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

alias.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export const alias = {
7777
'@devframes/json-render-ui/hub': r('json-render-ui/src/hub.ts'),
7878
'@devframes/json-render-ui/spa': r('json-render-ui/src/spa.ts'),
7979
'@devframes/json-render-ui': r('json-render-ui/src/index.ts'),
80-
'json-render/dashboard': fileURLToPath(new URL('./examples/json-render/src/dashboard.ts', import.meta.url)),
80+
'json-render/dashboard': fileURLToPath(new URL('./examples/json-render/src/node/dashboard.ts', import.meta.url)),
8181
'@devframes/plugin-code-server/node': p('code-server/src/node/setup.ts'),
8282
'@devframes/plugin-code-server/constants': p('code-server/src/node/constants.ts'),
8383
'@devframes/plugin-code-server/types': p('code-server/src/node/types.ts'),
File renamed without changes.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// Re-exports the shared devframe class-helper builders (see
22
// `design/design.ts`) so this surface stays in lockstep with every other.
3-
export * from '../../../../design/design'
3+
export * from '../../../design/design'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import type { Server } from 'node:http'
2+
import type { Plugin } from 'vite'
3+
import { fileURLToPath } from 'node:url'
4+
import preact from '@preact/preset-vite'
5+
import { initDevframe } from 'devframe/initiate'
6+
import { resolveBasePath } from 'devframe/internal'
7+
import UnoCSS from 'unocss/vite'
8+
import { defineConfig } from 'vite'
9+
import { alias } from '../../../alias'
10+
import devframe from '../src/node/index.ts'
11+
12+
/**
13+
* Serve-only plugin that bridges the node side (RPC + WebSocket +
14+
* `__connection.json`) onto Vite's dev server under the devframe base path,
15+
* mounted as a post middleware so Vite serves the HMR SPA first and the
16+
* devframe host only answers the routes it owns. Inert during `vite build`.
17+
*/
18+
function filesInspectorDevBridge(): Plugin {
19+
return {
20+
name: 'files-inspector-dev-bridge',
21+
apply: 'serve',
22+
configureServer(server) {
23+
const instance = initDevframe(devframe, {
24+
base: resolveBasePath(devframe, 'hosted'),
25+
distDir: false,
26+
server: server.httpServer as Server,
27+
auth: false,
28+
})
29+
return () => server.middlewares.use(instance.nodeMiddleware)
30+
},
31+
}
32+
}
33+
34+
/**
35+
* `base: './'` for the build keeps the mount path portable: the same output
36+
* works whether devframe serves it at `/` (standalone) or under a base path
37+
* (mounted in a hub). In `vite dev` the panel is served under the devframe
38+
* base path so its `document.baseURI` matches production, and the dev bridge
39+
* bridges the node side there with HMR.
40+
*/
41+
export default defineConfig(({ command }) => ({
42+
base: command === 'serve' ? resolveBasePath(devframe, 'hosted') : './',
43+
root: fileURLToPath(new URL('.', import.meta.url)),
44+
resolve: { alias },
45+
plugins: [UnoCSS(), preact(), filesInspectorDevBridge()],
46+
build: {
47+
outDir: fileURLToPath(new URL('../dist/client', import.meta.url)),
48+
emptyOutDir: true,
49+
},
50+
}))

examples/files-inspector/bin.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22
import process from 'node:process'
33
import { createCac } from 'devframe/adapters/cac'
4-
import devframe from './src/devframe.ts'
4+
import devframe from './src/node/index.ts'
55

66
async function main() {
77
// Serve the agent surface at `/__mcp` and register for `devframe connect`

0 commit comments

Comments
 (0)