@lark-apaas/coding-templates 0.1.24 → 0.1.25

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/coding-templates",
3
- "version": "0.1.24",
3
+ "version": "0.1.25",
4
4
  "description": "OpenClaw project templates for mclaw CLI",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -12,6 +12,7 @@
12
12
  ]
13
13
  },
14
14
  "scripts": {
15
+ "postinstall": "pnpm rebuild @lark-apaas/express-datapaas",
15
16
  "dev": "tsx --watch --watch-path server --watch-path shared server/index.ts",
16
17
  "build": "bash scripts/build.sh",
17
18
  "lint": "npm run lint:client && npm run lint:server",
@@ -47,7 +48,8 @@
47
48
  "@radix-ui/react-toggle-group": "^1.1.10",
48
49
  "@radix-ui/react-tooltip": "^1.1.18",
49
50
  "@lark-apaas/client-toolkit-lite": "^0.0.2",
50
- "@lark-apaas/express-core": "^0.0.3",
51
+ "@lark-apaas/express-core": "^0.0.5",
52
+ "@lark-apaas/express-datapaas": "^0.0.3",
51
53
  "@formkit/auto-animate": "^0.9.0",
52
54
  "framer-motion": "^12.38.0",
53
55
  "class-variance-authority": "^0.7.1",
@@ -87,5 +89,11 @@
87
89
  "tsx": "^4",
88
90
  "typescript": "~5.9",
89
91
  "vite": "^8"
92
+ },
93
+ "pnpm": {
94
+ "onlyBuiltDependencies": [
95
+ "@lark-apaas/express-datapaas",
96
+ "esbuild"
97
+ ]
90
98
  }
91
99
  }
@@ -32,7 +32,9 @@ echo '{ "version": 1, "type": "apex", "fallback": "index.html" }' > "$OUTPUT/rou
32
32
  # 服务端产物(tsc 输出保留 server/、shared/ 子目录)
33
33
  cp -r "$ROOT/dist/server/"* "$OUTPUT/"
34
34
 
35
- # package.json node_modules mclaw-dev deployprune 步骤生成
35
+ # 声明 CJS(服务端 tsc 输出为 commonjs,需要覆盖根 package.json"type": "module")
36
+ # deploy 时 prune 步骤会用精简版覆盖此文件
37
+ echo '{ "private": true }' > "$OUTPUT/package.json"
36
38
 
37
39
  # 4. assets/ → dist/output_resource/(JS/CSS/字体,上传到 CDN)
38
40
  if [ -d "$ROOT/dist/client/assets" ]; then
@@ -8,76 +8,42 @@ import { registerRoutes } from "./routes/index";
8
8
 
9
9
  const port = Number(process.env.FORCE_SERVER_PORT) || 3000;
10
10
  const host = process.env.FORCE_SERVER_HOST || "localhost";
11
- const isDev = process.env.NODE_ENV !== "production";
11
+ const basePath = process.env.CLIENT_BASE_PATH || "/";
12
12
 
13
13
  const app = express();
14
14
 
15
- // Platform middleware: body parsing, cookie, user context, DB + RLS, view context
15
+ // Platform middleware
16
16
  const { close } = setup(app, {
17
17
  database: { schema },
18
18
  csrf: { enabled: false },
19
19
  viewContext: { enabled: false },
20
20
  });
21
21
 
22
- // Register API routes
23
- registerRoutes(app);
22
+ // All routes under basePath
23
+ const router = express.Router();
24
+ registerRoutes(router);
24
25
 
25
- // HTML rendering: dev uses Vite middleware mode, prod reads build output
26
- async function setupHtmlRendering() {
27
- if (isDev) {
28
- // @ts-ignore -- vite types require bundler moduleResolution, dev-only import
29
- const { createServer } = await import("vite");
30
- const vite = await createServer({
31
- server: { middlewareMode: true },
32
- appType: "custom",
33
- });
26
+ const templatePath = path.resolve(__dirname, "../index.html");
27
+ const template = hbs.compile(fs.readFileSync(templatePath, "utf-8"));
34
28
 
35
- // Vite handles static assets, module serving, and HMR
36
- app.use(vite.middlewares);
37
-
38
- app.get("/{*path}", createViewContextMiddleware(), async (req: Request, res: Response) => {
39
- const rawHtml = fs.readFileSync(
40
- path.resolve(__dirname, "../client/index.html"),
41
- "utf-8",
42
- );
43
- // Vite transform: inject HMR client, resolve module imports
44
- const transformed = await vite.transformIndexHtml(req.originalUrl, rawHtml);
45
- // HBS render: inject platform data
46
- const template = hbs.compile(transformed);
47
- const html = template({
48
- ...res.locals,
49
- appConfig: safeStringify({
50
- appId: res.locals.appId || process.env.MCLAW_APP_ID || "",
51
- cdnDomain: process.env.MCLAW_CDN_DOMAIN || "",
52
- }),
53
- });
54
- res.type("html").send(html);
55
- });
56
- } else {
57
- const templatePath = path.resolve(__dirname, "../index.html");
58
- const template = hbs.compile(fs.readFileSync(templatePath, "utf-8"));
29
+ router.get("/{*path}", createViewContextMiddleware(), (_req: Request, res: Response) => {
30
+ const html = template({
31
+ ...res.locals,
32
+ appConfig: safeStringify({
33
+ appId: res.locals.appId || process.env.MCLAW_APP_ID || "",
34
+ cdnDomain: process.env.MCLAW_CDN_DOMAIN || "",
35
+ }),
36
+ });
37
+ res.type("html").send(html);
38
+ });
59
39
 
60
- app.get("/{*path}", createViewContextMiddleware(), (_req: Request, res: Response) => {
61
- const html = template({
62
- ...res.locals,
63
- appConfig: safeStringify({
64
- appId: res.locals.appId || process.env.MCLAW_APP_ID || "",
65
- cdnDomain: process.env.MCLAW_CDN_DOMAIN || "",
66
- }),
67
- });
68
- res.type("html").send(html);
69
- });
70
- }
71
- }
40
+ app.use(basePath, router);
72
41
 
73
- setupHtmlRendering().then(() => {
74
- const server = app.listen(port, host, () => {
75
- console.log(`Server running at http://${host}:${port}`);
76
- });
42
+ const server = app.listen(port, host, () => {
43
+ console.log(`Server running at http://${host}:${port}${basePath}`);
44
+ });
77
45
 
78
- // Graceful shutdown
79
- process.on("SIGTERM", async () => {
80
- server.close();
81
- await close();
82
- });
46
+ process.on("SIGTERM", async () => {
47
+ server.close();
48
+ await close();
83
49
  });
@@ -1,7 +1,7 @@
1
- import type { Express } from "express";
1
+ import type { Router } from "express";
2
2
  // import postsRouter from "./posts";
3
3
 
4
- export function registerRoutes(app: Express) {
4
+ export function registerRoutes(app: Router) {
5
5
  // 在此注册 API 路由
6
6
  //
7
7
  // 使用示例: