@coze-arch/cli 0.0.1-alpha.e665f4 → 0.0.1-alpha.e70f72
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/README.md +1 -0
- package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +1 -1
- package/lib/__templates__/expo/client/components/Screen.tsx +2 -2
- package/lib/__templates__/expo/client/eslint.config.mjs +4 -0
- package/lib/__templates__/expo/client/metro.config.js +3 -0
- package/lib/__templates__/expo/client/package.json +35 -35
- package/lib/__templates__/expo/client/scripts/install-missing-deps.js +10 -10
- package/lib/__templates__/expo/eslint-plugins/forbid-emoji/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/forbid-emoji/rule.js +112 -0
- package/lib/__templates__/expo/eslint-plugins/forbid-emoji/tech.md +94 -0
- package/lib/__templates__/expo/package.json +1 -1
- package/lib/__templates__/expo/pnpm-lock.yaml +394 -221
- package/lib/__templates__/expo/server/package.json +9 -7
- package/lib/__templates__/expo/server/src/index.ts +1 -0
- package/lib/__templates__/expo/template.config.js +1 -1
- package/lib/__templates__/native-static/.coze +11 -0
- package/lib/__templates__/native-static/index.html +33 -0
- package/lib/__templates__/native-static/styles/main.css +136 -0
- package/lib/__templates__/native-static/template.config.js +22 -0
- package/lib/__templates__/nextjs/README.md +5 -0
- package/lib/__templates__/nextjs/eslint.config.mjs +5 -0
- package/lib/__templates__/nextjs/next.config.ts +1 -2
- package/lib/__templates__/nextjs/package.json +5 -6
- package/lib/__templates__/nextjs/pnpm-lock.yaml +1145 -109
- package/lib/__templates__/nextjs/scripts/build.sh +4 -1
- package/lib/__templates__/nextjs/scripts/dev.sh +4 -4
- package/lib/__templates__/nextjs/scripts/start.sh +1 -1
- package/lib/__templates__/nextjs/src/app/layout.tsx +1 -1
- package/lib/__templates__/nextjs/src/app/page.tsx +4 -3
- package/lib/__templates__/nextjs/src/server.ts +35 -0
- package/lib/__templates__/nextjs/tsconfig.json +1 -1
- package/lib/__templates__/nuxt-vue/.coze +12 -0
- package/lib/__templates__/nuxt-vue/README.md +73 -0
- package/lib/__templates__/nuxt-vue/_gitignore +24 -0
- package/lib/__templates__/nuxt-vue/_npmrc +23 -0
- package/lib/__templates__/nuxt-vue/app/app.vue +6 -0
- package/lib/__templates__/nuxt-vue/app/pages/index.vue +23 -0
- package/lib/__templates__/nuxt-vue/assets/css/main.css +24 -0
- package/lib/__templates__/nuxt-vue/nuxt.config.ts +116 -0
- package/lib/__templates__/nuxt-vue/package.json +35 -0
- package/lib/__templates__/nuxt-vue/pnpm-lock.yaml +8759 -0
- package/lib/__templates__/nuxt-vue/postcss.config.mjs +8 -0
- package/lib/__templates__/nuxt-vue/public/favicon.ico +0 -0
- package/lib/__templates__/nuxt-vue/public/robots.txt +2 -0
- package/lib/__templates__/nuxt-vue/scripts/build.sh +14 -0
- package/lib/__templates__/nuxt-vue/scripts/dev.sh +32 -0
- package/lib/__templates__/nuxt-vue/scripts/prepare.sh +14 -0
- package/lib/__templates__/nuxt-vue/scripts/start.sh +15 -0
- package/lib/__templates__/nuxt-vue/server/api/hello.ts +10 -0
- package/lib/__templates__/nuxt-vue/server/middleware/logger.ts +10 -0
- package/lib/__templates__/nuxt-vue/server/routes/health.ts +10 -0
- package/lib/__templates__/nuxt-vue/tailwind.config.js +13 -0
- package/lib/__templates__/nuxt-vue/template.config.js +87 -0
- package/lib/__templates__/nuxt-vue/tsconfig.json +18 -0
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +2 -2
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +4 -3
- package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +0 -15
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +117 -24
- package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +24 -1
- package/lib/__templates__/taro/README.md +81 -17
- package/lib/__templates__/taro/config/index.ts +87 -37
- package/lib/__templates__/taro/config/prod.ts +4 -5
- package/lib/__templates__/taro/eslint.config.mjs +27 -4
- package/lib/__templates__/taro/package.json +16 -4
- package/lib/__templates__/taro/patches/@tarojs__plugin-mini-ci@4.1.9.patch +30 -0
- package/lib/__templates__/taro/pnpm-lock.yaml +785 -115
- package/lib/__templates__/taro/server/package.json +3 -1
- package/lib/__templates__/taro/server/src/main.ts +14 -2
- package/lib/__templates__/taro/src/app.css +18 -18
- package/lib/__templates__/taro/src/app.tsx +9 -0
- package/lib/__templates__/taro/src/index.html +20 -1
- package/lib/__templates__/taro/src/presets/dev-debug.ts +23 -0
- package/lib/__templates__/taro/src/presets/h5-container.tsx +15 -0
- package/lib/__templates__/taro/src/presets/h5-navbar.tsx +201 -0
- package/lib/__templates__/taro/src/presets/h5-styles.ts +142 -0
- package/lib/__templates__/taro/src/presets/index.tsx +18 -0
- package/lib/__templates__/templates.json +43 -0
- package/lib/__templates__/vite/README.md +190 -11
- package/lib/__templates__/vite/_gitignore +1 -0
- package/lib/__templates__/vite/eslint.config.mjs +6 -1
- package/lib/__templates__/vite/package.json +14 -3
- package/lib/__templates__/vite/pnpm-lock.yaml +820 -1593
- package/lib/__templates__/vite/scripts/build.sh +4 -1
- package/lib/__templates__/vite/scripts/dev.sh +5 -4
- package/lib/__templates__/vite/scripts/start.sh +3 -3
- package/lib/__templates__/vite/server/routes/index.ts +31 -0
- package/lib/__templates__/vite/server/server.ts +55 -0
- package/lib/__templates__/vite/server/vite.ts +71 -0
- package/lib/__templates__/vite/src/main.ts +2 -2
- package/lib/__templates__/vite/tsconfig.json +4 -3
- package/lib/__templates__/vite/vite.config.ts +1 -0
- package/lib/cli.js +123 -156
- package/package.json +7 -3
- package/lib/__templates__/taro/src/app.ts +0 -14
- package/lib/__templates__/taro/src/utils/h5-styles.ts +0 -22
- package/lib/__templates__/taro/src/utils/wx-debug.ts +0 -23
- /package/lib/__templates__/expo/patches/{expo@54.0.32.patch → expo@54.0.33.patch} +0 -0
|
@@ -8,7 +8,10 @@ cd "${COZE_WORKSPACE_PATH}"
|
|
|
8
8
|
echo "Installing dependencies..."
|
|
9
9
|
pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
|
|
10
10
|
|
|
11
|
-
echo "Building
|
|
11
|
+
echo "Building frontend with Vite..."
|
|
12
12
|
npx vite build
|
|
13
13
|
|
|
14
|
+
echo "Bundling server with tsup..."
|
|
15
|
+
npx tsup server/server.ts --format cjs --platform node --target node20 --outDir dist-server --no-splitting --no-minify --external vite
|
|
16
|
+
|
|
14
17
|
echo "Build completed successfully!"
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
set -Eeuo pipefail
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
# 优先使用 COZE_E2E_PORT(E2E 测试专用),否则使用默认值
|
|
5
|
+
PORT="${COZE_E2E_PORT:-<%= port %>}"
|
|
5
6
|
COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
|
|
6
|
-
DEPLOY_RUN_PORT
|
|
7
|
+
DEPLOY_RUN_PORT="${COZE_E2E_PORT:-<%= port %>}"
|
|
7
8
|
|
|
8
9
|
cd "${COZE_WORKSPACE_PATH}"
|
|
9
10
|
|
|
@@ -27,6 +28,6 @@ kill_port_if_listening() {
|
|
|
27
28
|
|
|
28
29
|
echo "Clearing port ${PORT} before start."
|
|
29
30
|
kill_port_if_listening
|
|
30
|
-
echo "Starting
|
|
31
|
+
echo "Starting Koa + Vite dev server on port ${PORT}..."
|
|
31
32
|
|
|
32
|
-
npx
|
|
33
|
+
PORT=$PORT npx tsx watch server/server.ts
|
|
@@ -7,9 +7,9 @@ DEPLOY_RUN_PORT="${DEPLOY_RUN_PORT:-$PORT}"
|
|
|
7
7
|
|
|
8
8
|
start_service() {
|
|
9
9
|
cd "${COZE_WORKSPACE_PATH}"
|
|
10
|
-
echo "Starting
|
|
11
|
-
|
|
10
|
+
echo "Starting Koa production server on port ${DEPLOY_RUN_PORT}..."
|
|
11
|
+
PORT=$DEPLOY_RUN_PORT node dist-server/server.js
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
echo "Starting
|
|
14
|
+
echo "Starting Koa production server on port ${DEPLOY_RUN_PORT}..."
|
|
15
15
|
start_service
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { Router } from 'express';
|
|
2
|
+
|
|
3
|
+
const router = Router();
|
|
4
|
+
|
|
5
|
+
// API 路由示例
|
|
6
|
+
router.get('/api/hello', (req, res) => {
|
|
7
|
+
res.json({
|
|
8
|
+
message: 'Hello from Express + Vite!',
|
|
9
|
+
timestamp: new Date().toISOString(),
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
router.post('/api/data', (req, res) => {
|
|
14
|
+
const requestData = req.body;
|
|
15
|
+
res.json({
|
|
16
|
+
success: true,
|
|
17
|
+
data: requestData,
|
|
18
|
+
receivedAt: new Date().toISOString(),
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// 健康检查接口
|
|
23
|
+
router.get('/api/health', (req, res) => {
|
|
24
|
+
res.json({
|
|
25
|
+
status: 'ok',
|
|
26
|
+
env: process.env.COZE_PROJECT_ENV,
|
|
27
|
+
timestamp: new Date().toISOString(),
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export default router;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// ABOUTME: Express server with Vite integration
|
|
2
|
+
// ABOUTME: Handles API routes and serves frontend in dev/prod modes
|
|
3
|
+
|
|
4
|
+
import express from 'express';
|
|
5
|
+
import router from './routes/index';
|
|
6
|
+
import { setupVite } from './vite';
|
|
7
|
+
|
|
8
|
+
const isDev = process.env.COZE_PROJECT_ENV !== 'PROD';
|
|
9
|
+
|
|
10
|
+
async function createServer() {
|
|
11
|
+
const app = express();
|
|
12
|
+
|
|
13
|
+
// 请求日志(仅开发环境)
|
|
14
|
+
if (isDev) {
|
|
15
|
+
app.use((req, res, next) => {
|
|
16
|
+
const start = Date.now();
|
|
17
|
+
res.on('finish', () => {
|
|
18
|
+
const ms = Date.now() - start;
|
|
19
|
+
console.log(`${req.method} ${req.url} - ${ms}ms`);
|
|
20
|
+
});
|
|
21
|
+
next();
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 添加请求体解析
|
|
26
|
+
app.use(express.json());
|
|
27
|
+
app.use(express.urlencoded({ extended: true }));
|
|
28
|
+
|
|
29
|
+
// 注册 API 路由
|
|
30
|
+
app.use(router);
|
|
31
|
+
|
|
32
|
+
// 集成 Vite(开发模式)或静态文件服务(生产模式)
|
|
33
|
+
await setupVite(app);
|
|
34
|
+
|
|
35
|
+
// 全局错误处理
|
|
36
|
+
app.use((err: Error, req: express.Request, res: express.Response) => {
|
|
37
|
+
console.error('Server error:', err);
|
|
38
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
|
+
const status = 'status' in err ? (err as any).status || 500 : 500;
|
|
40
|
+
res.status(status).json({
|
|
41
|
+
error: err.message || 'Internal server error',
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const port = process.env.PORT || <%= port %>;
|
|
46
|
+
app.listen(port, () => {
|
|
47
|
+
console.log(`\n✨ Server running at http://localhost:${port}`);
|
|
48
|
+
console.log(`📝 Environment: ${isDev ? 'development' : 'production'}\n`);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
createServer().catch((err) => {
|
|
53
|
+
console.error('Failed to start server:', err);
|
|
54
|
+
process.exit(1);
|
|
55
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// ABOUTME: Vite integration for Express server
|
|
2
|
+
// ABOUTME: Handles dev middleware and production static file serving
|
|
3
|
+
|
|
4
|
+
import type { Application } from 'express';
|
|
5
|
+
import express from 'express';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import fs from 'fs';
|
|
8
|
+
|
|
9
|
+
const isDev = process.env.COZE_PROJECT_ENV !== 'PROD';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 集成 Vite 开发服务器(中间件模式)
|
|
13
|
+
* 使用动态 import 避免在生产构建时打包 vite
|
|
14
|
+
*/
|
|
15
|
+
export async function setupViteMiddleware(app: Application) {
|
|
16
|
+
// 动态导入 vite,只在开发环境运行时加载
|
|
17
|
+
const { createServer: createViteServer } = await import('vite');
|
|
18
|
+
|
|
19
|
+
const vite = await createViteServer({
|
|
20
|
+
server: {
|
|
21
|
+
middlewareMode: true,
|
|
22
|
+
hmr: {
|
|
23
|
+
port: process.env.HMR_PORT ? parseInt(process.env.HMR_PORT) : undefined,
|
|
24
|
+
overlay: true,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
appType: 'spa',
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// 使用 Vite middleware
|
|
31
|
+
app.use(vite.middlewares);
|
|
32
|
+
|
|
33
|
+
console.log('🚀 Vite dev server initialized');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 设置生产环境静态文件服务
|
|
38
|
+
*/
|
|
39
|
+
export function setupStaticServer(app: Application) {
|
|
40
|
+
const distPath = path.resolve(process.cwd(), 'dist');
|
|
41
|
+
|
|
42
|
+
if (!fs.existsSync(distPath)) {
|
|
43
|
+
console.error('❌ dist folder not found. Please run "pnpm build" first.');
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 服务静态文件
|
|
48
|
+
app.use(express.static(distPath));
|
|
49
|
+
|
|
50
|
+
// SPA fallback - 所有非 API 请求返回 index.html
|
|
51
|
+
app.use((req, res, next) => {
|
|
52
|
+
if (!req.path.startsWith('/api')) {
|
|
53
|
+
res.sendFile(path.join(distPath, 'index.html'));
|
|
54
|
+
} else {
|
|
55
|
+
next();
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
console.log('📦 Serving static files from dist/');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 根据环境设置 Vite
|
|
64
|
+
*/
|
|
65
|
+
export async function setupVite(app: Application) {
|
|
66
|
+
if (isDev) {
|
|
67
|
+
await setupViteMiddleware(app);
|
|
68
|
+
} else {
|
|
69
|
+
setupStaticServer(app);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -7,8 +7,7 @@ export function initApp(): void {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
app.innerHTML = `
|
|
10
|
-
<div class="flex h-full items-center justify-center bg-background text-foreground transition-colors duration-300 dark:bg-background dark:text-foreground overflow-hidden">
|
|
11
|
-
{/* 主容器 */}
|
|
10
|
+
<div class="flex h-full items-center justify-center bg-background text-foreground transition-colors duration-300 dark:bg-background dark:text-foreground overflow-hidden min-h-screen">
|
|
12
11
|
<main class="flex w-full h-full max-w-3xl flex-col items-center justify-center px-16 py-32 sm:items-center">
|
|
13
12
|
<div class="flex flex-col items-center justify-between gap-4">
|
|
14
13
|
<img
|
|
@@ -16,6 +15,7 @@ export function initApp(): void {
|
|
|
16
15
|
alt="扣子编程 Logo"
|
|
17
16
|
width={156}
|
|
18
17
|
height={130}
|
|
18
|
+
style="width: 156px; height: 130px; object-fit: contain;"
|
|
19
19
|
/>
|
|
20
20
|
<div>
|
|
21
21
|
<div class="flex flex-col items-center gap-2 text-center sm:items-center sm:text-center">
|
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
"target": "ES2020",
|
|
4
4
|
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
5
5
|
"module": "ESNext",
|
|
6
|
-
"moduleResolution": "
|
|
6
|
+
"moduleResolution": "node",
|
|
7
7
|
"strict": true,
|
|
8
8
|
"esModuleInterop": true,
|
|
9
9
|
"skipLibCheck": true,
|
|
10
10
|
"forceConsistentCasingInFileNames": true,
|
|
11
11
|
"resolveJsonModule": true,
|
|
12
12
|
"isolatedModules": true,
|
|
13
|
-
"noEmit": true
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
"types": ["node"]
|
|
14
15
|
},
|
|
15
|
-
"include": ["src"]
|
|
16
|
+
"include": ["src", "server"]
|
|
16
17
|
}
|