@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.
Files changed (97) hide show
  1. package/README.md +1 -0
  2. package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +1 -1
  3. package/lib/__templates__/expo/client/components/Screen.tsx +2 -2
  4. package/lib/__templates__/expo/client/eslint.config.mjs +4 -0
  5. package/lib/__templates__/expo/client/metro.config.js +3 -0
  6. package/lib/__templates__/expo/client/package.json +35 -35
  7. package/lib/__templates__/expo/client/scripts/install-missing-deps.js +10 -10
  8. package/lib/__templates__/expo/eslint-plugins/forbid-emoji/index.js +9 -0
  9. package/lib/__templates__/expo/eslint-plugins/forbid-emoji/rule.js +112 -0
  10. package/lib/__templates__/expo/eslint-plugins/forbid-emoji/tech.md +94 -0
  11. package/lib/__templates__/expo/package.json +1 -1
  12. package/lib/__templates__/expo/pnpm-lock.yaml +394 -221
  13. package/lib/__templates__/expo/server/package.json +9 -7
  14. package/lib/__templates__/expo/server/src/index.ts +1 -0
  15. package/lib/__templates__/expo/template.config.js +1 -1
  16. package/lib/__templates__/native-static/.coze +11 -0
  17. package/lib/__templates__/native-static/index.html +33 -0
  18. package/lib/__templates__/native-static/styles/main.css +136 -0
  19. package/lib/__templates__/native-static/template.config.js +22 -0
  20. package/lib/__templates__/nextjs/README.md +5 -0
  21. package/lib/__templates__/nextjs/eslint.config.mjs +5 -0
  22. package/lib/__templates__/nextjs/next.config.ts +1 -2
  23. package/lib/__templates__/nextjs/package.json +5 -6
  24. package/lib/__templates__/nextjs/pnpm-lock.yaml +1145 -109
  25. package/lib/__templates__/nextjs/scripts/build.sh +4 -1
  26. package/lib/__templates__/nextjs/scripts/dev.sh +4 -4
  27. package/lib/__templates__/nextjs/scripts/start.sh +1 -1
  28. package/lib/__templates__/nextjs/src/app/layout.tsx +1 -1
  29. package/lib/__templates__/nextjs/src/app/page.tsx +4 -3
  30. package/lib/__templates__/nextjs/src/server.ts +35 -0
  31. package/lib/__templates__/nextjs/tsconfig.json +1 -1
  32. package/lib/__templates__/nuxt-vue/.coze +12 -0
  33. package/lib/__templates__/nuxt-vue/README.md +73 -0
  34. package/lib/__templates__/nuxt-vue/_gitignore +24 -0
  35. package/lib/__templates__/nuxt-vue/_npmrc +23 -0
  36. package/lib/__templates__/nuxt-vue/app/app.vue +6 -0
  37. package/lib/__templates__/nuxt-vue/app/pages/index.vue +23 -0
  38. package/lib/__templates__/nuxt-vue/assets/css/main.css +24 -0
  39. package/lib/__templates__/nuxt-vue/nuxt.config.ts +116 -0
  40. package/lib/__templates__/nuxt-vue/package.json +35 -0
  41. package/lib/__templates__/nuxt-vue/pnpm-lock.yaml +8759 -0
  42. package/lib/__templates__/nuxt-vue/postcss.config.mjs +8 -0
  43. package/lib/__templates__/nuxt-vue/public/favicon.ico +0 -0
  44. package/lib/__templates__/nuxt-vue/public/robots.txt +2 -0
  45. package/lib/__templates__/nuxt-vue/scripts/build.sh +14 -0
  46. package/lib/__templates__/nuxt-vue/scripts/dev.sh +32 -0
  47. package/lib/__templates__/nuxt-vue/scripts/prepare.sh +14 -0
  48. package/lib/__templates__/nuxt-vue/scripts/start.sh +15 -0
  49. package/lib/__templates__/nuxt-vue/server/api/hello.ts +10 -0
  50. package/lib/__templates__/nuxt-vue/server/middleware/logger.ts +10 -0
  51. package/lib/__templates__/nuxt-vue/server/routes/health.ts +10 -0
  52. package/lib/__templates__/nuxt-vue/tailwind.config.js +13 -0
  53. package/lib/__templates__/nuxt-vue/template.config.js +87 -0
  54. package/lib/__templates__/nuxt-vue/tsconfig.json +18 -0
  55. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +2 -2
  56. package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +4 -3
  57. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +0 -15
  58. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +117 -24
  59. package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +24 -1
  60. package/lib/__templates__/taro/README.md +81 -17
  61. package/lib/__templates__/taro/config/index.ts +87 -37
  62. package/lib/__templates__/taro/config/prod.ts +4 -5
  63. package/lib/__templates__/taro/eslint.config.mjs +27 -4
  64. package/lib/__templates__/taro/package.json +16 -4
  65. package/lib/__templates__/taro/patches/@tarojs__plugin-mini-ci@4.1.9.patch +30 -0
  66. package/lib/__templates__/taro/pnpm-lock.yaml +785 -115
  67. package/lib/__templates__/taro/server/package.json +3 -1
  68. package/lib/__templates__/taro/server/src/main.ts +14 -2
  69. package/lib/__templates__/taro/src/app.css +18 -18
  70. package/lib/__templates__/taro/src/app.tsx +9 -0
  71. package/lib/__templates__/taro/src/index.html +20 -1
  72. package/lib/__templates__/taro/src/presets/dev-debug.ts +23 -0
  73. package/lib/__templates__/taro/src/presets/h5-container.tsx +15 -0
  74. package/lib/__templates__/taro/src/presets/h5-navbar.tsx +201 -0
  75. package/lib/__templates__/taro/src/presets/h5-styles.ts +142 -0
  76. package/lib/__templates__/taro/src/presets/index.tsx +18 -0
  77. package/lib/__templates__/templates.json +43 -0
  78. package/lib/__templates__/vite/README.md +190 -11
  79. package/lib/__templates__/vite/_gitignore +1 -0
  80. package/lib/__templates__/vite/eslint.config.mjs +6 -1
  81. package/lib/__templates__/vite/package.json +14 -3
  82. package/lib/__templates__/vite/pnpm-lock.yaml +820 -1593
  83. package/lib/__templates__/vite/scripts/build.sh +4 -1
  84. package/lib/__templates__/vite/scripts/dev.sh +5 -4
  85. package/lib/__templates__/vite/scripts/start.sh +3 -3
  86. package/lib/__templates__/vite/server/routes/index.ts +31 -0
  87. package/lib/__templates__/vite/server/server.ts +55 -0
  88. package/lib/__templates__/vite/server/vite.ts +71 -0
  89. package/lib/__templates__/vite/src/main.ts +2 -2
  90. package/lib/__templates__/vite/tsconfig.json +4 -3
  91. package/lib/__templates__/vite/vite.config.ts +1 -0
  92. package/lib/cli.js +123 -156
  93. package/package.json +7 -3
  94. package/lib/__templates__/taro/src/app.ts +0 -14
  95. package/lib/__templates__/taro/src/utils/h5-styles.ts +0 -22
  96. package/lib/__templates__/taro/src/utils/wx-debug.ts +0 -23
  97. /package/lib/__templates__/expo/patches/{expo@54.0.32.patch → expo@54.0.33.patch} +0 -0
@@ -0,0 +1,8 @@
1
+ const config = {
2
+ plugins: {
3
+ tailwindcss: {},
4
+ autoprefixer: {},
5
+ },
6
+ };
7
+
8
+ export default config;
@@ -0,0 +1,2 @@
1
+ User-Agent: *
2
+ Disallow:
@@ -0,0 +1,14 @@
1
+ #!/bin/bash
2
+ set -Eeuo pipefail
3
+
4
+ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
5
+
6
+ cd "${COZE_WORKSPACE_PATH}"
7
+
8
+ echo "Installing dependencies..."
9
+ pnpm install --prefer-frozen-lockfile --prefer-offline --loglevel debug --reporter=append-only
10
+
11
+ echo "Building the Nuxt.js project..."
12
+ npx nuxt build
13
+
14
+ echo "Build completed successfully!"
@@ -0,0 +1,32 @@
1
+ #!/bin/bash
2
+ set -Eeuo pipefail
3
+
4
+ # 优先使用 COZE_E2E_PORT(E2E 测试专用),否则使用默认值
5
+ PORT="${COZE_E2E_PORT:-<%= port %>}"
6
+ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
7
+ DEPLOY_RUN_PORT="${COZE_E2E_PORT:-<%= port %>}"
8
+ cd "${COZE_WORKSPACE_PATH}"
9
+
10
+ kill_port_if_listening() {
11
+ local pids
12
+ pids=$(ss -H -lntp 2>/dev/null | awk -v port="${DEPLOY_RUN_PORT}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | paste -sd' ' - || true)
13
+ if [[ -z "${pids}" ]]; then
14
+ echo "Port ${DEPLOY_RUN_PORT} is free."
15
+ return
16
+ fi
17
+ echo "Port ${DEPLOY_RUN_PORT} in use by PIDs: ${pids} (SIGKILL)"
18
+ echo "${pids}" | xargs -I {} kill -9 {}
19
+ sleep 1
20
+ pids=$(ss -H -lntp 2>/dev/null | awk -v port="${DEPLOY_RUN_PORT}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | paste -sd' ' - || true)
21
+ if [[ -n "${pids}" ]]; then
22
+ echo "Warning: port ${DEPLOY_RUN_PORT} still busy after SIGKILL, PIDs: ${pids}"
23
+ else
24
+ echo "Port ${DEPLOY_RUN_PORT} cleared."
25
+ fi
26
+ }
27
+
28
+ echo "Clearing port ${PORT} before start."
29
+ kill_port_if_listening
30
+ echo "Starting Nuxt dev server on port ${PORT}..."
31
+
32
+ PORT=$PORT npx nuxt dev
@@ -0,0 +1,14 @@
1
+ #!/bin/bash
2
+ set -Eeuo pipefail
3
+
4
+ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
5
+
6
+ cd "${COZE_WORKSPACE_PATH}"
7
+
8
+ echo "Installing dependencies..."
9
+ pnpm install --prefer-frozen-lockfile --prefer-offline
10
+
11
+ echo "Preparing Nuxt project..."
12
+ pnpm exec nuxt prepare
13
+
14
+ echo "Preparation completed successfully!"
@@ -0,0 +1,15 @@
1
+ #!/bin/bash
2
+ set -Eeuo pipefail
3
+
4
+ COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
5
+ PORT=<%= port %>
6
+ DEPLOY_RUN_PORT="${DEPLOY_RUN_PORT:-$PORT}"
7
+
8
+ start_service() {
9
+ cd "${COZE_WORKSPACE_PATH}"
10
+ echo "Starting Nuxt.js service on port ${DEPLOY_RUN_PORT} for production..."
11
+ PORT=${DEPLOY_RUN_PORT} node .output/server/index.mjs
12
+ }
13
+
14
+ echo "Starting Nuxt.js service on port ${DEPLOY_RUN_PORT} for production..."
15
+ start_service
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Hello API 示例
3
+ * 访问: http://localhost:<%= port %>/api/hello
4
+ */
5
+ export default defineEventHandler(() => {
6
+ return {
7
+ message: 'Hello from Nuxt API',
8
+ timestamp: new Date().toISOString(),
9
+ };
10
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 请求日志中间件(仅开发环境)
3
+ */
4
+ export default defineEventHandler((event) => {
5
+ const isDev = process.env.COZE_PROJECT_ENV !== 'PROD';
6
+
7
+ if (isDev) {
8
+ console.log(`${event.method} ${event.path}`);
9
+ }
10
+ });
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 健康检查路由
3
+ * 访问: http://localhost:<%= port %>/health
4
+ */
5
+ export default defineEventHandler(() => {
6
+ return {
7
+ status: 'ok',
8
+ timestamp: new Date().toISOString(),
9
+ };
10
+ });
@@ -0,0 +1,13 @@
1
+ /** @type {import('tailwindcss').Config} */
2
+ export default {
3
+ content: [
4
+ './app/**/*.{js,ts,jsx,tsx,vue}',
5
+ './pages/**/*.{js,ts,jsx,tsx,vue}',
6
+ './components/**/*.{js,ts,jsx,tsx,vue}',
7
+ ],
8
+ darkMode: 'media',
9
+ theme: {
10
+ extend: {},
11
+ },
12
+ plugins: [],
13
+ };
@@ -0,0 +1,87 @@
1
+
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+ const description = `Nuxt.js(服务端 + Vue):\`coze init \${COZE_WORKSPACE_PATH} --template nuxt-vue\`
11
+ - 适用:全栈应用、需要服务端接口能力的 Vue 项目
12
+ - 特点:
13
+ - **服务端能力**:内置服务端 API 路由,可直接创建后端接口
14
+ - **Vue 3**:基于最新的 Vue 3 Composition API
15
+ - **Vite**:使用 Vite 作为构建工具,开发体验极佳
16
+ - **TypeScript**:完整的 TypeScript 支持
17
+ - **文件路由**:基于文件系统的自动路由
18
+ - **项目理解加速**:可依赖项目下 \`package.json\` 和 \`nuxt.config.ts\` 理解项目配置`;
19
+
20
+ export const paramsSchema = {
21
+ type: 'object',
22
+ properties: {
23
+ appName: {
24
+ type: 'string',
25
+ minLength: 1,
26
+ pattern: '^[a-z0-9-]+$',
27
+ description:
28
+ 'Application name (lowercase, alphanumeric and hyphens only)',
29
+ },
30
+ port: {
31
+ type: 'number',
32
+ default: 5000,
33
+ minimum: 1024,
34
+ maximum: 65535,
35
+ description: 'Development server port (for Nuxt dev server)',
36
+ },
37
+ hmrPort: {
38
+ type: 'number',
39
+ default: 6000,
40
+ minimum: 1024,
41
+ maximum: 65535,
42
+ description: 'Hot Module Replacement (HMR) port',
43
+ },
44
+ },
45
+ required: [],
46
+ additionalProperties: false,
47
+ };
48
+
49
+ const config = {
50
+ description: description,
51
+ paramsSchema,
52
+
53
+ // 显式定义默认参数,确保在渲染时可用
54
+ defaultParams: {
55
+ port: 5000,
56
+ hmrPort: 6000,
57
+ appName: 'nuxt-vue',
58
+ },
59
+
60
+ onBeforeRender: async context => {
61
+ console.log(`Creating Nuxt.js project: ${context.appName}`);
62
+ return context;
63
+ },
64
+
65
+ onAfterRender: async (_context, outputPath) => {
66
+ console.log(`\nProject created at: ${outputPath}`);
67
+ console.log('\nConfiguration:');
68
+ console.log(' - Framework: Nuxt.js');
69
+ console.log(' - TypeScript: enabled');
70
+ console.log(' - Vue: 3.x');
71
+ console.log(' - Build Tool: Vite');
72
+ console.log(` - Port: ${_context.port}`);
73
+ },
74
+
75
+ onComplete: async (_context, _outputPath) => {
76
+ // Skip additional setup in test environment
77
+ if (process.env.NODE_ENV === 'test') {
78
+ console.log('⊘ Skipping additional setup in test environment');
79
+ return;
80
+ }
81
+
82
+ console.log('\n✓ Nuxt.js project setup completed!');
83
+ console.log(' You can now start the development server');
84
+ },
85
+ };
86
+
87
+ export default config;
@@ -0,0 +1,18 @@
1
+ {
2
+ // https://nuxt.com/docs/guide/concepts/typescript
3
+ "files": [],
4
+ "references": [
5
+ {
6
+ "path": "./.nuxt/tsconfig.app.json"
7
+ },
8
+ {
9
+ "path": "./.nuxt/tsconfig.server.json"
10
+ },
11
+ {
12
+ "path": "./.nuxt/tsconfig.shared.json"
13
+ },
14
+ {
15
+ "path": "./.nuxt/tsconfig.node.json"
16
+ }
17
+ ]
18
+ }
@@ -2,10 +2,10 @@
2
2
  set -Eeuo pipefail
3
3
 
4
4
  cd "${COZE_WORKSPACE_PATH}"
5
- if [ -f "./.cozeproj/init_env.sh" ]; then
5
+ if [ -f "./.cozeproj/scripts/init_env.sh" ]; then
6
6
  echo "⚙️ Initializing environment..."
7
7
  # 使用 bash 执行,确保即使没有 x 权限也能跑
8
- bash ./.cozeproj/init_env.sh
8
+ bash ./.cozeproj/scripts/init_env.sh
9
9
  else
10
10
  echo "⚠️ Warning: init_env.sh not found, skipping environment init."
11
11
  fi
@@ -4,10 +4,11 @@ set -Eeuo pipefail
4
4
  start_service() {
5
5
  cd "${COZE_WORKSPACE_PATH}/server/dist"
6
6
 
7
- echo "Starting Static File Server on port 3000 for deploy..."
7
+ local port="${DEPLOY_RUN_PORT:-3000}"
8
+ echo "Starting Static File Server on port ${port} for deploy..."
8
9
 
9
- node ./main.js
10
+ node ./main.js -p "${port}"
10
11
  }
11
12
 
12
- echo "Starting HTTP service on port 3000 for deploy..."
13
+ echo "Starting HTTP service for deploy..."
13
14
  start_service
@@ -1,17 +1,2 @@
1
1
  #!/bin/bash
2
2
  set -Eeuo pipefail
3
-
4
- cd "${COZE_WORKSPACE_PATH}"
5
- if [ -f "./.cozeproj/init_env.sh" ]; then
6
- echo "⚙️ Initializing environment..."
7
- # 使用 bash 执行,确保即使没有 x 权限也能跑
8
- bash ./.cozeproj/init_env.sh
9
- else
10
- echo "⚠️ Warning: init_env.sh not found, skipping environment init."
11
- fi
12
-
13
- echo "Installing dependencies..."
14
- pnpm install --offline --frozen-lockfile --reporter=silent || \
15
- pnpm install --reporter=silent
16
-
17
- echo "Dependencies installed successfully!"
@@ -1,58 +1,151 @@
1
1
  #!/bin/bash
2
-
3
2
  echo "⚙️ dev_run.sh 开始运行"
4
3
  set -Eeuo pipefail
5
4
 
6
5
  cd "${COZE_WORKSPACE_PATH}"
7
6
 
7
+ # ---------------------------------------------------------
8
+ # PID 文件,用于追踪上一次启动的进程树
9
+ # ---------------------------------------------------------
10
+ PID_FILE="/tmp/coze-dev-run.pid"
11
+
12
+ # ---------------------------------------------------------
13
+ # 工具函数
14
+ # ---------------------------------------------------------
15
+ kill_process_tree() {
16
+ local pid=$1
17
+ local children
18
+ children=$(pgrep -P "${pid}" 2>/dev/null || true)
19
+ for child in ${children}; do
20
+ kill_process_tree "${child}"
21
+ done
22
+ if kill -0 "${pid}" 2>/dev/null; then
23
+ echo "Killing PID ${pid}"
24
+ kill -9 "${pid}" 2>/dev/null || true
25
+ fi
26
+ }
27
+
8
28
  kill_port_if_listening() {
9
29
  local port=$1
10
30
  local pids
11
- pids=$(ss -H -lntp 2>/dev/null | awk -v port="${port}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | paste -sd' ' - || true)
31
+ pids=$(ss -H -lntp 2>/dev/null | awk -v port="${port}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | sort -u | paste -sd' ' - || true)
12
32
  if [[ -z "${pids}" ]]; then
13
- echo "Port ${port} is free."
14
- return
33
+ echo "Port ${port} is free."
34
+ return
15
35
  fi
16
- echo "Port ${port} in use by PIDs: ${pids} (SIGKILL)"
17
- echo "${pids}" | xargs -I {} kill -9 {}
36
+ echo "Port ${port} in use by PIDs: ${pids}"
37
+ for pid in ${pids}; do
38
+ kill_process_tree "${pid}"
39
+ done
18
40
  sleep 1
19
- pids=$(ss -H -lntp 2>/dev/null | awk -v port="${port}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | paste -sd' ' - || true)
41
+ pids=$(ss -H -lntp 2>/dev/null | awk -v port="${port}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | sort -u | paste -sd' ' - || true)
20
42
  if [[ -n "${pids}" ]]; then
21
- echo "Warning: port ${port} still busy after SIGKILL, PIDs: ${pids}"
43
+ echo "Warning: port ${port} still busy after cleanup, PIDs: ${pids}"
22
44
  else
23
- echo "Port ${port} cleared."
45
+ echo "Port ${port} cleared."
24
46
  fi
25
47
  }
26
48
 
49
+ # ---------------------------------------------------------
50
+ # 1. 清理上一次运行残留的整棵进程树
51
+ # ---------------------------------------------------------
52
+ cleanup_previous_run() {
53
+ # 1a. 通过 PID 文件清理上次的进程树
54
+ if [[ -f "${PID_FILE}" ]]; then
55
+ local old_pid
56
+ old_pid=$(cat "${PID_FILE}" 2>/dev/null || true)
57
+ if [[ -n "${old_pid}" ]] && kill -0 "${old_pid}" 2>/dev/null; then
58
+ echo "🧹 Killing previous dev process tree (root PID: ${old_pid})..."
59
+ kill_process_tree "${old_pid}"
60
+ fi
61
+ rm -f "${PID_FILE}"
62
+ fi
63
+
64
+ # 1b. 兜底:按特征匹配清理所有残留的相关进程(排除自身)
65
+ echo "🧹 Cleaning up any orphaned dev processes..."
66
+ local patterns=(
67
+ "pnpm dev"
68
+ "concurrently.*dev:web.*dev:server"
69
+ "nest start --watch"
70
+ "taro build --type h5 --watch"
71
+ "node --enable-source-maps.*/workspace/projects/server/dist/main"
72
+ "esbuild --service.*--ping"
73
+ )
74
+ for pattern in "${patterns[@]}"; do
75
+ local pids
76
+ pids=$(pgrep -f "${pattern}" 2>/dev/null || true)
77
+ for pid in ${pids}; do
78
+ # 不杀自己和自己的父进程链
79
+ if [[ "${pid}" != "$$" ]] && [[ "${pid}" != "${PPID}" ]]; then
80
+ echo " Killing orphan PID ${pid} matching '${pattern}'"
81
+ kill -9 "${pid}" 2>/dev/null || true
82
+ fi
83
+ done
84
+ done
85
+ sleep 1
86
+ }
87
+
88
+ # ---------------------------------------------------------
89
+ # 2. 安装依赖
90
+ # ---------------------------------------------------------
91
+ echo "📦 Installing dependencies..."
92
+ pnpm install
93
+ echo "✅ Dependencies installed successfully!"
94
+
95
+ # ---------------------------------------------------------
96
+ # 3. 清理旧进程 + 端口
97
+ # ---------------------------------------------------------
98
+ SERVER_PORT=3000
99
+
100
+ cleanup_previous_run
101
+
102
+ echo "Clearing port ${DEPLOY_RUN_PORT} (web) before start."
103
+ kill_port_if_listening "${DEPLOY_RUN_PORT}"
104
+ echo "Clearing port ${SERVER_PORT} (server) before start."
105
+ kill_port_if_listening "${SERVER_PORT}"
106
+
107
+ # ---------------------------------------------------------
108
+ # 4. 退出时自动清理子进程(信号 trap)
109
+ # ---------------------------------------------------------
110
+ cleanup_on_exit() {
111
+ echo "🛑 dev_run.sh exiting, cleaning up child processes..."
112
+ # 杀掉当前脚本的所有子进程
113
+ kill -- -$$ 2>/dev/null || true
114
+ rm -f "${PID_FILE}"
115
+ exit 0
116
+ }
117
+ trap cleanup_on_exit EXIT INT TERM HUP
118
+
119
+ # ---------------------------------------------------------
120
+ # 5. 启动服务
121
+ # ---------------------------------------------------------
27
122
  start_service() {
28
123
  cd "${COZE_WORKSPACE_PATH}"
29
124
 
30
- # ---------------------------------------------------------
31
- # 0. 动态注入环境变量
32
- # ---------------------------------------------------------
33
- if [ -n "$COZE_PROJECT_DOMAIN_DEFAULT" ]; then
125
+ # 动态注入环境变量
126
+ if [ -n "${COZE_PROJECT_DOMAIN_DEFAULT:-}" ]; then
34
127
  export PROJECT_DOMAIN="$COZE_PROJECT_DOMAIN_DEFAULT"
35
128
  echo "✅ 环境变量已动态注入: PROJECT_DOMAIN=$PROJECT_DOMAIN"
36
129
  else
37
130
  echo "⚠️ 警告: COZE_PROJECT_DOMAIN_DEFAULT 未设置,使用 .env.local 中的配置"
38
131
  fi
39
132
 
40
- # ---------------------------------------------------------
41
133
  # 启动 Taro H5 和 NestJS Server
42
- # ---------------------------------------------------------
43
134
  echo "Starting Taro H5 Dev Server and NestJS Server..."
44
135
 
45
- # ⚠️ 重要:为了让 Taro 使用平台动态分配的端口
46
136
  export PORT=${DEPLOY_RUN_PORT}
137
+ rm -f /tmp/coze-logs/dev.log
138
+ mkdir -p /tmp/coze-logs
47
139
 
48
- exec pnpm dev
49
- }
140
+ # 后台启动并记录 PID
141
+ pnpm dev 2>&1 | tee /tmp/coze-logs/dev.log &
142
+ local dev_pid=$!
143
+ echo "${dev_pid}" > "${PID_FILE}"
144
+ echo "📝 Dev process started with PID: ${dev_pid} (saved to ${PID_FILE})"
50
145
 
51
- SERVER_PORT=<%= serverPort %>
146
+ # 前台等待,保证 trap 能正常捕获信号
147
+ wait "${dev_pid}" || true
148
+ }
52
149
 
53
- echo "Clearing port ${DEPLOY_RUN_PORT} (web) before start."
54
- kill_port_if_listening "${DEPLOY_RUN_PORT}"
55
- echo "Clearing port ${SERVER_PORT} (server) before start."
56
- kill_port_if_listening "${SERVER_PORT}"
57
150
  echo "Starting HTTP services on port ${DEPLOY_RUN_PORT} (web) and ${SERVER_PORT} (server)..."
58
- start_service
151
+ start_service
@@ -1 +1,24 @@
1
- pnpm build:weapp
1
+ # build_weapp.sh - 通过 PID 文件精确杀掉自己上次的构建进程
2
+ export OUTPUT_ROOT=dist
3
+ PID_FILE="/tmp/coze-build_weapp.pid"
4
+
5
+ # 杀掉上次的构建进程组
6
+ if [ -f "$PID_FILE" ]; then
7
+ OLD_PID=$(cat "$PID_FILE")
8
+ if kill -0 "$OLD_PID" 2>/dev/null; then
9
+ echo "正在终止上次的构建进程组 (PID: $OLD_PID)..."
10
+ # 关键:kill 负数 PID = 杀掉整个进程组
11
+ kill -9 -"$OLD_PID" 2>/dev/null
12
+ sleep 1
13
+ fi
14
+ rm -f "$PID_FILE"
15
+ fi
16
+
17
+ # 用 setsid 创建新的进程组,方便下次整组杀掉
18
+ setsid pnpm build:weapp &
19
+ echo $! > "$PID_FILE"
20
+
21
+ echo "构建已启动 (PID: $(cat $PID_FILE))"
22
+
23
+ wait $!
24
+ rm -f "$PID_FILE"
@@ -10,7 +10,7 @@
10
10
  - **样式**: TailwindCSS 4.1.18
11
11
  - **Tailwind 适配层**: weapp-tailwindcss 4.9.2
12
12
  - **状态管理**: Zustand 5.0.9
13
- - **图标库**: lucide-react 0.511.0
13
+ - **图标库**: lucide-react-taro latest
14
14
  - **工程化**: Vite 4.2.0
15
15
  - **包管理**: pnpm
16
16
  - **运行时**: Node.js >= 18
@@ -28,14 +28,16 @@
28
28
  │ ├── dev.ts # 开发环境配置
29
29
  │ └── prod.ts # 生产环境配置
30
30
  ├── server/ # NestJS 后端服务
31
- │ └── src/
31
+ │ └── src/
32
32
  │ ├── main.ts # 服务入口
33
33
  │ ├── app.module.ts # 根模块
34
34
  │ ├── app.controller.ts # 应用控制器
35
35
  │ └── app.service.ts # 应用服务
36
36
  ├── src/ # 前端源码
37
37
  │ ├── pages/ # 页面组件
38
+ │ ├── presets/ # 框架预置逻辑(无需读取,如无必要不改动)
38
39
  │ ├── utils/ # 工具函数
40
+ │ ├── network.ts # 封装好的网络请求工具
39
41
  │ ├── app.ts # 应用入口
40
42
  │ ├── app.config.ts # 应用配置
41
43
  │ └── app.css # 全局样式
@@ -237,8 +239,8 @@ Network 是对 Taro.request、Taro.uploadFile、Taro.downloadFile 的封装,
237
239
  import { Network } from '@/network'
238
240
 
239
241
  // GET 请求
240
- const data = await Network.request({
241
- url: '/api/hello'
242
+ const data = await Network.request({
243
+ url: '/api/hello'
242
244
  })
243
245
 
244
246
  // POST 请求
@@ -267,8 +269,8 @@ await Network.downloadFile({
267
269
  import Taro from '@tarojs/taro'
268
270
 
269
271
  // ❌ 会导致自动域名拼接无法生效,除非是特殊指定域名
270
- const data = await Network.request({
271
- url: 'http://localhost/api/hello'
272
+ const data = await Network.request({
273
+ url: 'http://localhost/api/hello'
272
274
  })
273
275
 
274
276
  // ❌ 不要直接使用 Taro.request
@@ -344,23 +346,29 @@ const router = useRouter()
344
346
  const { id } = router.params
345
347
  ```
346
348
 
347
- ### 图标使用 (lucide-react)
349
+ ### 图标使用 (lucide-react-taro)
350
+
351
+ **IMPORTANT: 禁止使用 lucide-react,必须使用 lucide-react-taro 替代。**
348
352
 
349
- 项目集成了 [lucide-react](https://lucide.dev/) 图标库,提供丰富的 SVG 图标:
353
+ lucide-react-taro Lucide 图标库的 Taro 适配版本,专为小程序环境优化,API 与 lucide-react 一致:
350
354
 
351
355
  ```tsx
352
356
  import { View } from '@tarojs/components'
353
- import { Home, Settings, User, Search, Heart, Star } from 'lucide-react'
357
+ import { House, Settings, User, Search, Camera, Zap } from 'lucide-react-taro'
354
358
 
355
359
  const IconDemo = () => {
356
360
  return (
357
361
  <View className="flex gap-4">
358
- <Home size={24} color="#333" />
359
- <Settings size={24} className="text-blue-500" />
360
- <User size={20} strokeWidth={1.5} />
361
- <Search size={24} />
362
- <Heart size={24} fill="red" color="red" />
363
- <Star size={24} className="text-yellow-500" />
362
+ {/* 基本用法 */}
363
+ <House />
364
+ {/* 自定义尺寸和颜色 */}
365
+ <Settings size={32} color="#1890ff" />
366
+ {/* 自定义描边宽度 */}
367
+ <User size={24} strokeWidth={1.5} />
368
+ {/* 绝对描边宽度(描边不随 size 缩放) */}
369
+ <Camera size={48} strokeWidth={2} absoluteStrokeWidth />
370
+ {/* 组合使用 */}
371
+ <Zap size={32} color="#ff6b00" strokeWidth={1.5} className="my-icon" />
364
372
  </View>
365
373
  )
366
374
  }
@@ -368,12 +376,68 @@ const IconDemo = () => {
368
376
 
369
377
  常用属性:
370
378
  - `size` - 图标大小(默认 24)
371
- - `color` - 图标颜色
379
+ - `color` - 图标颜色(默认 currentColor,小程序中建议显式设置)
372
380
  - `strokeWidth` - 线条粗细(默认 2)
373
- - `className` - 支持 Tailwind 类名
381
+ - `absoluteStrokeWidth` - 绝对描边宽度,启用后描边不随 size 缩放
382
+ - `className` / `style` - 自定义样式
374
383
 
375
384
  更多图标请访问:https://lucide.dev/icons
376
385
 
386
+ ### TabBar 图标生成 (CLI 工具)
387
+
388
+ **IMPORTANT: 微信小程序的 TabBar 不支持 base64 或 SVG 图片,必须使用本地 PNG 文件。**
389
+
390
+ lucide-react-taro 提供了 CLI 工具来生成 TabBar 所需的 PNG 图标:
391
+
392
+ ```bash
393
+ # 生成带选中状态的图标
394
+ npx taro-lucide-tabbar House Settings User -c "#999999" -a "#1890ff"
395
+
396
+ # 指定输出目录和尺寸
397
+ npx taro-lucide-tabbar House Settings User -c "#999999" -a "#1890ff" -o ./src/assets/tabbar -s 81
398
+ ```
399
+
400
+ CLI 参数:
401
+ - `--color, -c` (默认 #000000): 图标颜色
402
+ - `--active-color, -a`: 选中状态颜色
403
+ - `--size, -s` (默认 81): 图标尺寸
404
+ - `--output, -o` (默认 ./tabbar-icons): 输出目录
405
+ - `--stroke-width` (默认 2): 描边宽度
406
+
407
+ 在 `app.config.ts` 中使用生成的图标:
408
+
409
+ > IMPORTANT:iconPath 和 selectedIconPath 必须以 `./` 开头,否则图标无法渲染
410
+
411
+ ```typescript
412
+ export default defineAppConfig({
413
+ tabBar: {
414
+ color: '#999999',
415
+ selectedColor: '#1890ff',
416
+ backgroundColor: '#ffffff',
417
+ borderStyle: 'black',
418
+ list: [
419
+ {
420
+ pagePath: 'pages/index/index',
421
+ text: '首页',
422
+ iconPath: './assets/tabbar/house.png',
423
+ selectedIconPath: './assets/tabbar/house-active.png',
424
+ },
425
+ {
426
+ pagePath: 'pages/settings/index',
427
+ text: '设置',
428
+ iconPath: './assets/tabbar/settings.png',
429
+ selectedIconPath: './assets/tabbar/settings-active.png',
430
+ },
431
+ {
432
+ pagePath: 'pages/user/index',
433
+ text: '用户',
434
+ iconPath: './assets/tabbar/user.png',
435
+ selectedIconPath: './assets/tabbar/user-active.png',
436
+ },
437
+ ],
438
+ },
439
+ })
440
+
377
441
  ### Tailwind CSS 样式开发
378
442
 
379
443
  IMPORTANT:必须使用 tailwindcss 实现样式,只有在必要情况下才能 fallback 到 css / less