@coze-arch/cli 0.0.1-alpha.f74941 → 0.0.1-alpha.ff64d9

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 (167) hide show
  1. package/lib/__templates__/expo/.coze +7 -2
  2. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +46 -0
  3. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +220 -0
  4. package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +47 -0
  5. package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +34 -0
  6. package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +45 -0
  7. package/lib/__templates__/expo/README.md +66 -7
  8. package/lib/__templates__/expo/_gitignore +1 -1
  9. package/lib/__templates__/expo/_npmrc +3 -5
  10. package/lib/__templates__/expo/client/app/_layout.tsx +14 -14
  11. package/lib/__templates__/expo/client/app/demo.tsx +1 -0
  12. package/lib/__templates__/expo/client/app/index.tsx +1 -0
  13. package/lib/__templates__/expo/client/app.config.ts +75 -0
  14. package/lib/__templates__/expo/client/components/ThemedText.tsx +33 -0
  15. package/lib/__templates__/expo/client/components/ThemedView.tsx +38 -0
  16. package/lib/__templates__/expo/client/constants/theme.ts +786 -50
  17. package/lib/__templates__/expo/client/contexts/AuthContext.tsx +14 -107
  18. package/lib/__templates__/expo/client/declarations.d.ts +5 -0
  19. package/lib/__templates__/expo/client/hooks/useColorScheme.ts +34 -1
  20. package/lib/__templates__/expo/client/hooks/useTheme.ts +1 -1
  21. package/lib/__templates__/expo/client/metro.config.js +121 -0
  22. package/lib/__templates__/expo/client/package.json +93 -0
  23. package/lib/__templates__/expo/client/screens/demo/index.tsx +25 -0
  24. package/lib/__templates__/expo/client/screens/demo/styles.ts +28 -0
  25. package/lib/__templates__/expo/client/scripts/install-missing-deps.js +36 -12
  26. package/lib/__templates__/expo/client/tsconfig.json +24 -0
  27. package/lib/__templates__/expo/client/utils/index.ts +1 -2
  28. package/lib/__templates__/expo/package.json +13 -92
  29. package/lib/__templates__/expo/pnpm-lock.yaml +675 -678
  30. package/lib/__templates__/expo/pnpm-workspace.yaml +3 -0
  31. package/lib/__templates__/expo/server/package.json +32 -0
  32. package/lib/__templates__/expo/{src → server/src}/index.ts +8 -2
  33. package/lib/__templates__/expo/server/tsconfig.json +24 -0
  34. package/lib/__templates__/expo/template.config.js +2 -1
  35. package/lib/__templates__/expo/tsconfig.json +1 -24
  36. package/lib/__templates__/nextjs/.coze +4 -3
  37. package/lib/__templates__/nextjs/README.md +341 -19
  38. package/lib/__templates__/nextjs/_npmrc +2 -1
  39. package/lib/__templates__/nextjs/components.json +21 -0
  40. package/lib/__templates__/nextjs/next.config.ts +12 -0
  41. package/lib/__templates__/nextjs/package.json +56 -2
  42. package/lib/__templates__/nextjs/pnpm-lock.yaml +7951 -1519
  43. package/lib/__templates__/nextjs/scripts/dev.sh +9 -27
  44. package/lib/__templates__/{react-rsbuild/scripts/build.sh → nextjs/scripts/prepare.sh} +0 -5
  45. package/lib/__templates__/nextjs/src/app/globals.css +124 -13
  46. package/lib/__templates__/nextjs/src/app/layout.tsx +19 -30
  47. package/lib/__templates__/nextjs/src/app/page.tsx +35 -23
  48. package/lib/__templates__/nextjs/src/components/ui/accordion.tsx +66 -0
  49. package/lib/__templates__/nextjs/src/components/ui/alert-dialog.tsx +157 -0
  50. package/lib/__templates__/nextjs/src/components/ui/alert.tsx +66 -0
  51. package/lib/__templates__/nextjs/src/components/ui/aspect-ratio.tsx +11 -0
  52. package/lib/__templates__/nextjs/src/components/ui/avatar.tsx +53 -0
  53. package/lib/__templates__/nextjs/src/components/ui/badge.tsx +46 -0
  54. package/lib/__templates__/nextjs/src/components/ui/breadcrumb.tsx +109 -0
  55. package/lib/__templates__/nextjs/src/components/ui/button-group.tsx +83 -0
  56. package/lib/__templates__/nextjs/src/components/ui/button.tsx +62 -0
  57. package/lib/__templates__/nextjs/src/components/ui/calendar.tsx +220 -0
  58. package/lib/__templates__/nextjs/src/components/ui/card.tsx +92 -0
  59. package/lib/__templates__/nextjs/src/components/ui/carousel.tsx +241 -0
  60. package/lib/__templates__/nextjs/src/components/ui/chart.tsx +357 -0
  61. package/lib/__templates__/nextjs/src/components/ui/checkbox.tsx +32 -0
  62. package/lib/__templates__/nextjs/src/components/ui/collapsible.tsx +33 -0
  63. package/lib/__templates__/nextjs/src/components/ui/command.tsx +184 -0
  64. package/lib/__templates__/nextjs/src/components/ui/context-menu.tsx +252 -0
  65. package/lib/__templates__/nextjs/src/components/ui/dialog.tsx +143 -0
  66. package/lib/__templates__/nextjs/src/components/ui/drawer.tsx +135 -0
  67. package/lib/__templates__/nextjs/src/components/ui/dropdown-menu.tsx +257 -0
  68. package/lib/__templates__/nextjs/src/components/ui/empty.tsx +104 -0
  69. package/lib/__templates__/nextjs/src/components/ui/field.tsx +248 -0
  70. package/lib/__templates__/nextjs/src/components/ui/form.tsx +167 -0
  71. package/lib/__templates__/nextjs/src/components/ui/hover-card.tsx +44 -0
  72. package/lib/__templates__/nextjs/src/components/ui/input-group.tsx +170 -0
  73. package/lib/__templates__/nextjs/src/components/ui/input-otp.tsx +77 -0
  74. package/lib/__templates__/nextjs/src/components/ui/input.tsx +21 -0
  75. package/lib/__templates__/nextjs/src/components/ui/item.tsx +193 -0
  76. package/lib/__templates__/nextjs/src/components/ui/kbd.tsx +28 -0
  77. package/lib/__templates__/nextjs/src/components/ui/label.tsx +24 -0
  78. package/lib/__templates__/nextjs/src/components/ui/menubar.tsx +276 -0
  79. package/lib/__templates__/nextjs/src/components/ui/navigation-menu.tsx +168 -0
  80. package/lib/__templates__/nextjs/src/components/ui/pagination.tsx +127 -0
  81. package/lib/__templates__/nextjs/src/components/ui/popover.tsx +48 -0
  82. package/lib/__templates__/nextjs/src/components/ui/progress.tsx +31 -0
  83. package/lib/__templates__/nextjs/src/components/ui/radio-group.tsx +45 -0
  84. package/lib/__templates__/nextjs/src/components/ui/resizable.tsx +63 -0
  85. package/lib/__templates__/nextjs/src/components/ui/scroll-area.tsx +58 -0
  86. package/lib/__templates__/nextjs/src/components/ui/select.tsx +190 -0
  87. package/lib/__templates__/nextjs/src/components/ui/separator.tsx +28 -0
  88. package/lib/__templates__/nextjs/src/components/ui/sheet.tsx +139 -0
  89. package/lib/__templates__/nextjs/src/components/ui/sidebar.tsx +724 -0
  90. package/lib/__templates__/nextjs/src/components/ui/skeleton.tsx +13 -0
  91. package/lib/__templates__/nextjs/src/components/ui/slider.tsx +63 -0
  92. package/lib/__templates__/nextjs/src/components/ui/sonner.tsx +40 -0
  93. package/lib/__templates__/nextjs/src/components/ui/spinner.tsx +16 -0
  94. package/lib/__templates__/nextjs/src/components/ui/switch.tsx +31 -0
  95. package/lib/__templates__/nextjs/src/components/ui/table.tsx +116 -0
  96. package/lib/__templates__/nextjs/src/components/ui/tabs.tsx +66 -0
  97. package/lib/__templates__/nextjs/src/components/ui/textarea.tsx +18 -0
  98. package/lib/__templates__/nextjs/src/components/ui/toggle-group.tsx +83 -0
  99. package/lib/__templates__/nextjs/src/components/ui/toggle.tsx +47 -0
  100. package/lib/__templates__/nextjs/src/components/ui/tooltip.tsx +61 -0
  101. package/lib/__templates__/nextjs/src/hooks/use-mobile.ts +19 -0
  102. package/lib/__templates__/nextjs/src/lib/utils.ts +6 -0
  103. package/lib/__templates__/nextjs/template.config.js +32 -2
  104. package/lib/__templates__/templates.json +61 -74
  105. package/lib/__templates__/vite/.coze +4 -3
  106. package/lib/__templates__/vite/README.md +204 -26
  107. package/lib/__templates__/vite/_npmrc +2 -1
  108. package/lib/__templates__/vite/eslint.config.mjs +9 -0
  109. package/lib/__templates__/vite/package.json +6 -2
  110. package/lib/__templates__/vite/pnpm-lock.yaml +3486 -19
  111. package/lib/__templates__/vite/scripts/dev.sh +7 -26
  112. package/lib/__templates__/{rsbuild/scripts/build.sh → vite/scripts/prepare.sh} +0 -5
  113. package/lib/__templates__/vite/src/main.ts +1 -2
  114. package/lib/__templates__/vite/template.config.js +39 -6
  115. package/lib/__templates__/vite/vite.config.ts +3 -3
  116. package/lib/cli.js +634 -313
  117. package/package.json +11 -4
  118. package/lib/__templates__/expo/.cozeproj/scripts/deploy_build.sh +0 -109
  119. package/lib/__templates__/expo/.cozeproj/scripts/deploy_run.sh +0 -257
  120. package/lib/__templates__/expo/app.json +0 -63
  121. package/lib/__templates__/expo/babel.config.js +0 -9
  122. package/lib/__templates__/expo/client/app/(tabs)/_layout.tsx +0 -43
  123. package/lib/__templates__/expo/client/app/(tabs)/home.tsx +0 -1
  124. package/lib/__templates__/expo/client/app/(tabs)/index.tsx +0 -7
  125. package/lib/__templates__/expo/client/app/+not-found.tsx +0 -79
  126. package/lib/__templates__/expo/client/index.js +0 -11
  127. package/lib/__templates__/expo/client/screens/home/index.tsx +0 -54
  128. package/lib/__templates__/expo/client/screens/home/styles.ts +0 -332
  129. package/lib/__templates__/expo/metro.config.js +0 -53
  130. package/lib/__templates__/nextjs/.vscode/settings.json +0 -121
  131. package/lib/__templates__/react-rsbuild/.coze +0 -11
  132. package/lib/__templates__/react-rsbuild/.vscode/settings.json +0 -121
  133. package/lib/__templates__/react-rsbuild/README.md +0 -61
  134. package/lib/__templates__/react-rsbuild/_gitignore +0 -97
  135. package/lib/__templates__/react-rsbuild/_npmrc +0 -22
  136. package/lib/__templates__/react-rsbuild/package.json +0 -31
  137. package/lib/__templates__/react-rsbuild/pnpm-lock.yaml +0 -997
  138. package/lib/__templates__/react-rsbuild/rsbuild.config.ts +0 -13
  139. package/lib/__templates__/react-rsbuild/scripts/dev.sh +0 -51
  140. package/lib/__templates__/react-rsbuild/scripts/start.sh +0 -15
  141. package/lib/__templates__/react-rsbuild/src/App.tsx +0 -60
  142. package/lib/__templates__/react-rsbuild/src/index.css +0 -21
  143. package/lib/__templates__/react-rsbuild/src/index.html +0 -12
  144. package/lib/__templates__/react-rsbuild/src/index.tsx +0 -16
  145. package/lib/__templates__/react-rsbuild/tailwind.config.js +0 -9
  146. package/lib/__templates__/react-rsbuild/template.config.js +0 -54
  147. package/lib/__templates__/react-rsbuild/tsconfig.json +0 -17
  148. package/lib/__templates__/rsbuild/.coze +0 -11
  149. package/lib/__templates__/rsbuild/.vscode/settings.json +0 -7
  150. package/lib/__templates__/rsbuild/README.md +0 -61
  151. package/lib/__templates__/rsbuild/_gitignore +0 -97
  152. package/lib/__templates__/rsbuild/_npmrc +0 -22
  153. package/lib/__templates__/rsbuild/package.json +0 -24
  154. package/lib/__templates__/rsbuild/pnpm-lock.yaml +0 -888
  155. package/lib/__templates__/rsbuild/rsbuild.config.ts +0 -12
  156. package/lib/__templates__/rsbuild/scripts/dev.sh +0 -51
  157. package/lib/__templates__/rsbuild/scripts/start.sh +0 -15
  158. package/lib/__templates__/rsbuild/src/index.css +0 -21
  159. package/lib/__templates__/rsbuild/src/index.html +0 -12
  160. package/lib/__templates__/rsbuild/src/index.ts +0 -5
  161. package/lib/__templates__/rsbuild/src/main.ts +0 -65
  162. package/lib/__templates__/rsbuild/tailwind.config.js +0 -9
  163. package/lib/__templates__/rsbuild/template.config.js +0 -56
  164. package/lib/__templates__/rsbuild/tsconfig.json +0 -16
  165. package/lib/__templates__/vite/.vscode/settings.json +0 -7
  166. /package/lib/__templates__/expo/{eslint-formatter-simple.mjs → client/eslint-formatter-simple.mjs} +0 -0
  167. /package/lib/__templates__/expo/{eslint.config.mjs → client/eslint.config.mjs} +0 -0
@@ -3,5 +3,10 @@ entrypoint = "server.js"
3
3
  requires = ["nodejs-24"]
4
4
 
5
5
  [dev]
6
- build = ["bash", ".cozeproj/scripts/deploy_build.sh"]
7
- run = ["bash", ".cozeproj/scripts/deploy_run.sh"]
6
+ build = ["bash", ".cozeproj/scripts/dev_build.sh"]
7
+ run = ["bash", ".cozeproj/scripts/dev_run.sh"]
8
+
9
+ [deploy]
10
+ build = ["bash", ".cozeproj/scripts/prod_build.sh"]
11
+ run = ["bash", ".cozeproj/scripts/prod_run.sh"]
12
+ build_app_dir = "./client"
@@ -0,0 +1,46 @@
1
+ #!/bin/bash
2
+ if [ -z "${BASH_VERSION:-}" ]; then exec /usr/bin/env bash "$0" "$@"; fi
3
+ set -euo pipefail
4
+ ROOT_DIR="$(pwd)"
5
+ PREVIEW_DIR="${COZE_PREVIEW_DIR:-/source/preview}"
6
+
7
+ # ==================== 配置项 ====================
8
+ SERVER_DIR="app"
9
+ EXPO_DIR="expo"
10
+ CHECK_HASH_SCRIPT="$ROOT_DIR/check_hash.py"
11
+
12
+ check_command() {
13
+ if ! command -v "$1" &> /dev/null; then
14
+ echo "error:命令 $1 未找到,请先安装"
15
+ fi
16
+ }
17
+
18
+ echo "==================== 开始构建 ===================="
19
+
20
+ echo "检查根目录 pre_install.py"
21
+ if [ -f "$PREVIEW_DIR/pre_install.py" ]; then
22
+ echo "执行:python $PREVIEW_DIR/pre_install.py"
23
+ python "$PREVIEW_DIR/pre_install.py" || echo "pre_install.py 执行失败"
24
+ fi
25
+
26
+ echo "开始执行构建脚本(build_dev.sh)..."
27
+ echo "正在检查依赖命令是否存在..."
28
+ # 检查核心命令
29
+ check_command "pnpm"
30
+ check_command "npm"
31
+
32
+ echo "==================== 安装项目依赖 ===================="
33
+ if [ ! -f "package.json" ]; then
34
+ echo "项目目录下无 package.json,不是合法的 Node.js 项目"
35
+ fi
36
+ # 步骤 2.1/2.2:安装项目依赖
37
+ pnpm install --registry=https://registry.npmmirror.com || echo "Expo 项目依赖安装失败(pnpm 执行出错)"
38
+
39
+ echo "检查根目录 post_install.py"
40
+ if [ -f "$PREVIEW_DIR/post_install.py" ]; then
41
+ echo "执行:python $PREVIEW_DIR/post_install.py"
42
+ python "$PREVIEW_DIR/post_install.py" || echo "post_install.py 执行失败"
43
+ fi
44
+
45
+ echo "==================== 依赖安装完成!====================\n"
46
+ echo "下一步:执行 ./deploy_run.sh 启动服务"
@@ -0,0 +1,220 @@
1
+ ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
2
+ PREVIEW_DIR="${COZE_PREVIEW_DIR:-/source/preview}"
3
+ LOG_DIR="${COZE_LOG_DIR:-$ROOT_DIR/logs}"
4
+ LOG_FILE="$LOG_DIR/app.log"
5
+ mkdir -p "$LOG_DIR"
6
+
7
+ # ==================== 配置项 ====================
8
+ # Server 服务配置
9
+ SERVER_HOST="0.0.0.0"
10
+ SERVER_PORT="9091"
11
+ # Expo 项目配置
12
+ EXPO_HOST="0.0.0.0"
13
+ EXPO_DIR="expo"
14
+ EXPO_PORT="5000"
15
+ WEB_URL="${COZE_PROJECT_DOMAIN_DEFAULT:-http://127.0.0.1:${SERVER_PORT}}"
16
+ ASSUME_YES="1"
17
+ EXPO_PUBLIC_BACKEND_BASE_URL="${EXPO_PUBLIC_BACKEND_BASE_URL:-$WEB_URL}"
18
+
19
+
20
+ EXPO_PACKAGER_PROXY_URL="${EXPO_PUBLIC_BACKEND_BASE_URL}"
21
+ export EXPO_PUBLIC_BACKEND_BASE_URL EXPO_PACKAGER_PROXY_URL
22
+ # 运行时变量(为避免 set -u 的未绑定错误,预置为空)
23
+ SERVER_PID=""
24
+ EXPO_PID=""
25
+ # ==================== 工具函数 ====================
26
+ check_command() {
27
+ if ! command -v "$1" &> /dev/null; then
28
+ echo "error:命令 $1 未找到,请先安装"
29
+ fi
30
+ }
31
+ while [ $# -gt 0 ]; do
32
+ case "$1" in
33
+ -y|--yes)
34
+ ASSUME_YES="1"
35
+ shift
36
+ ;;
37
+ *)
38
+ shift
39
+ ;;
40
+ esac
41
+ done
42
+ is_port_free() {
43
+ ! lsof -iTCP:"$1" -sTCP:LISTEN >/dev/null 2>&1
44
+ }
45
+ choose_next_free_port() {
46
+ local start=$1
47
+ local p=$start
48
+ while ! is_port_free "$p"; do
49
+ p=$((p+1))
50
+ done
51
+ echo "$p"
52
+ }
53
+ ensure_port() {
54
+ local var_name=$1
55
+ local port_val=$2
56
+ if is_port_free "$port_val"; then
57
+ echo "端口未占用:$port_val"
58
+ eval "$var_name=$port_val"
59
+ else
60
+ echo "端口已占用:$port_val"
61
+ local choice
62
+ if [ "$ASSUME_YES" = "1" ]; then choice="Y"; else read -r -p "是否关闭该端口的进程?[Y/n] " choice || choice="Y"; fi
63
+ if [ -z "$choice" ] || [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then
64
+ if command -v lsof &> /dev/null; then
65
+ local pids
66
+ pids=$(lsof -t -i tcp:"$port_val" -sTCP:LISTEN 2>/dev/null || true)
67
+ if [ -n "$pids" ]; then
68
+ echo "正在关闭进程:$pids"
69
+ kill -9 $pids 2>/dev/null || echo "关闭进程失败:$pids"
70
+ eval "$var_name=$port_val"
71
+ else
72
+ echo "未获取到占用该端口的进程"
73
+ eval "$var_name=$port_val"
74
+ fi
75
+ else
76
+ echo "缺少 lsof,无法自动关闭进程"
77
+ eval "$var_name=$port_val"
78
+ fi
79
+ else
80
+ local new_port
81
+ new_port=$(choose_next_free_port "$port_val")
82
+ info "使用新的端口:$new_port"
83
+ eval "$var_name=$new_port"
84
+ fi
85
+ fi
86
+ }
87
+
88
+ pipe_to_log() {
89
+ local source="${1:-CLIENT}"
90
+ local raw_log="${2:-}"
91
+ local line timestamp ts msg record
92
+ while IFS= read -r line || [ -n "$line" ]; do
93
+ if [ -n "$raw_log" ]; then
94
+ echo "$line" >> "$raw_log"
95
+ fi
96
+ line=$(echo "[$source] $line" | sed 's/\x1b\[[0-9;]*[a-zA-Z]//g; s/\x1b\[[0-9;]*m//g')
97
+ msg="${line}"
98
+ echo "$msg"
99
+ done
100
+ }
101
+
102
+ wait_port_connectable() {
103
+ local host=$1 port=$2 retries=${3:-10}
104
+ for _ in $(seq 1 "$retries"); do
105
+ nc -z -w 1 "$host" "$port" >/dev/null 2>&1 && return 0
106
+ sleep 1
107
+ done
108
+ return 1
109
+ }
110
+
111
+ start_expo() {
112
+ local offline="${1:-0}"
113
+
114
+ pushd ./client
115
+
116
+ if [ "$offline" = "1" ]; then
117
+ ( EXPO_OFFLINE=1 EXPO_NO_DOCTOR=1 EXPO_PUBLIC_BACKEND_BASE_URL="$EXPO_PUBLIC_BACKEND_BASE_URL" EXPO_PACKAGER_PROXY_URL="$EXPO_PACKAGER_PROXY_URL" \
118
+ nohup npx expo start --clear --port "$EXPO_PORT" 2>&1 | pipe_to_log "CLIENT" "../logs/client.log" ) &
119
+ else
120
+ ( EXPO_NO_DOCTOR=1 EXPO_PUBLIC_BACKEND_BASE_URL="$EXPO_PUBLIC_BACKEND_BASE_URL" EXPO_PACKAGER_PROXY_URL="$EXPO_PACKAGER_PROXY_URL" \
121
+ nohup npx expo start --clear --port "$EXPO_PORT" 2>&1 | pipe_to_log "CLIENT" "../logs/client.log" ) &
122
+ fi
123
+ EXPO_PID=$!
124
+ disown $EXPO_PID 2>/dev/null || true
125
+
126
+ popd
127
+ }
128
+
129
+ detect_expo_fetch_failed() {
130
+ local timeout="${1:-8}"
131
+ local waited=0
132
+ local log_file="logs/client.log"
133
+ while [ "$waited" -lt "$timeout" ]; do
134
+ if [ -f "$log_file" ] && grep -q "TypeError: fetch failed" "$log_file" 2>/dev/null; then
135
+ return 0
136
+ fi
137
+ sleep 1
138
+ waited=$((waited+1))
139
+ done
140
+ return 1
141
+ }
142
+
143
+ # ==================== 前置检查 ====================
144
+ # 关掉nginx进程
145
+ ps -ef | grep nginx | grep -v grep | awk '{print $2}' | xargs -r kill -9
146
+
147
+ echo "检查根目录 pre_install.py"
148
+ if [ -f "$PREVIEW_DIR/pre_install.py" ]; then
149
+ echo "执行:python $PREVIEW_DIR/pre_install.py"
150
+ python "$PREVIEW_DIR/pre_install.py" || echo "pre_install.py 执行失败"
151
+ fi
152
+
153
+ echo "==================== 开始启动 ===================="
154
+ echo "开始执行服务启动脚本(start_dev.sh)..."
155
+ echo "正在检查依赖命令和目录是否存在..."
156
+ # 检查核心命令
157
+ check_command "npm"
158
+ check_command "pnpm"
159
+ check_command "lsof"
160
+ check_command "bash"
161
+
162
+ echo "准备日志目录:logs"
163
+ mkdir -p logs
164
+ # 端口占用预检查与处理
165
+ ensure_port SERVER_PORT "$SERVER_PORT"
166
+ ensure_port EXPO_PORT "$EXPO_PORT"
167
+
168
+ echo "==================== 启动 server 服务 ===================="
169
+ echo "正在执行:pnpm run dev"
170
+ ( SERVER_PORT="$SERVER_PORT" nohup pnpm run dev --prefix ./server ) &
171
+ SERVER_PID=$!
172
+ disown $SERVER_PID 2>/dev/null || true
173
+ if [ -z "${SERVER_PID}" ]; then
174
+ echo "无法获取 server 后台进程 PID"
175
+ fi
176
+ echo "server 服务已启动,进程 ID:${SERVER_PID:-unknown}"
177
+
178
+ echo "==================== 启动 Expo 项目 ===================="
179
+ echo "开始启动 Expo 服务,端口 ${EXPO_PORT}"
180
+ start_expo 0
181
+ if detect_expo_fetch_failed 8; then
182
+ echo "Expo 启动检测到网络错误:TypeError: fetch failed,启用离线模式重试"
183
+ if [ -n "${EXPO_PID}" ]; then kill -9 "$EXPO_PID" 2>/dev/null || true; fi
184
+ : > logs/client.log
185
+ start_expo 1
186
+ fi
187
+ # 输出以下环境变量,确保 Expo 项目能正确连接到 Server 服务
188
+ echo "Expo 环境变量配置:"
189
+ echo "EXPO_PUBLIC_BACKEND_BASE_URL=${EXPO_PUBLIC_BACKEND_BASE_URL}"
190
+ echo "EXPO_PACKAGER_PROXY_URL=${EXPO_PACKAGER_PROXY_URL}"
191
+ if [ -z "${EXPO_PID}" ]; then
192
+ echo "无法获取 Expo 后台进程 PID"
193
+ fi
194
+
195
+ echo "所有服务已启动。Server PID: ${SERVER_PID}, Expo PID: ${EXPO_PID}"
196
+
197
+ echo "检查 Server 服务端口:$SERVER_HOST:$SERVER_PORT"
198
+ if wait_port_connectable "$SERVER_HOST" "$SERVER_PORT" 10 2; then
199
+ echo "端口可连接:$SERVER_HOST:$SERVER_PORT"
200
+ else
201
+ echo "端口不可连接:$SERVER_HOST:$SERVER_PORT 10 次)"
202
+ fi
203
+
204
+ echo "检查 Expo 服务端口:$EXPO_HOST:$EXPO_PORT"
205
+ if wait_port_connectable "$EXPO_HOST" "$EXPO_PORT" 10 2; then
206
+ echo "端口可连接:$EXPO_HOST:$EXPO_PORT"
207
+ else
208
+ echo "端口不可连接:$EXPO_HOST:$EXPO_PORT(已尝试 10 次)"
209
+ fi
210
+
211
+ echo "服务端口检查完成"
212
+
213
+ echo "检查根目录 post_run.py"
214
+ if [ -f "$ROOT_DIR/post_run.py" ]; then
215
+ echo "启动检查中"
216
+ python "$ROOT_DIR/post_run.py" --port "$EXPO_PORT" || echo "post_run.py 执行失败"
217
+ echo "启动检查结束"
218
+ fi
219
+
220
+ echo "==================== 服务启动完成 ===================="
@@ -0,0 +1,47 @@
1
+ #!/bin/bash
2
+ if [ -z "${BASH_VERSION:-}" ]; then exec /usr/bin/env bash "$0" "$@"; fi
3
+ set -euo pipefail
4
+ ROOT_DIR="$(pwd)"
5
+
6
+ # ==================== 工具函数 ====================
7
+ info() {
8
+ echo "[INFO] $1"
9
+ }
10
+ warn() {
11
+ echo "[WARN] $1"
12
+ }
13
+ error() {
14
+ echo "[ERROR] $1"
15
+ exit 1
16
+ }
17
+ check_command() {
18
+ if ! command -v "$1" &> /dev/null; then
19
+ error "命令 $1 未找到,请先安装"
20
+ fi
21
+ }
22
+
23
+ info "==================== 开始构建 ===================="
24
+ info "开始执行构建脚本(build_prod.sh)..."
25
+ info "正在检查依赖命令是否存在..."
26
+ # 检查核心命令
27
+ check_command "pnpm"
28
+ check_command "npm"
29
+
30
+ # ==================== 安装 Node 依赖 ====================
31
+ info "==================== 安装 Node 依赖 ===================="
32
+ info "开始安装 Node 依赖"
33
+ if [ -f "$ROOT_DIR/package.json" ]; then
34
+ info "进入目录:$ROOT_DIR"
35
+ info "正在执行:pnpm install"
36
+ (cd "$ROOT_DIR" && pnpm install --registry=https://registry.npmmirror.com) || error "Node 依赖安装失败"
37
+ else
38
+ warn "未找到 $ROOT_DIR/package.json 文件,请检查路径是否正确"
39
+ fi
40
+ info "==================== 依赖安装完成!====================\n"
41
+
42
+ info "==================== dist打包 ===================="
43
+ info "开始执行:pnpm run build --prefix server"
44
+ (cd "$ROOT_DIR" && pnpm run build --prefix ./server) || error "dist打包失败"
45
+ info "==================== dist打包完成!====================\n"
46
+
47
+ info "下一步:执行 ./prod_run.sh 启动服务"
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/env bash
2
+ # 产物部署使用
3
+ set -euo pipefail
4
+
5
+ ROOT_DIR="$(pwd)"
6
+
7
+ HOST="${HOST:-0.0.0.0}"
8
+ PORT="${PORT:-5000}"
9
+
10
+ # ==================== 工具函数 ====================
11
+ info() {
12
+ echo "[INFO] $1"
13
+ }
14
+ warn() {
15
+ echo "[WARN] $1"
16
+ }
17
+ error() {
18
+ echo "[ERROR] $1"
19
+ exit 1
20
+ }
21
+ check_command() {
22
+ if ! command -v "$1" &> /dev/null; then
23
+ error "命令 $1 未找到,请先安装"
24
+ fi
25
+ }
26
+
27
+ # ============== 启动服务 ======================
28
+ # 检查核心命令
29
+ check_command "pnpm"
30
+ check_command "npm"
31
+
32
+ info "开始执行:pnpm run start"
33
+ (cd "$ROOT_DIR" && PORT="$PORT" pnpm run start --prefix ./server) || error "服务启动失败"
34
+ info "服务启动完成!\n"
@@ -0,0 +1,45 @@
1
+ #!/bin/bash
2
+
3
+ ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
4
+ SERVER_DIR="$ROOT_DIR/server"
5
+ LOG_DIR="$ROOT_DIR/logs"
6
+ LOG_FILE="$LOG_DIR/server.log"
7
+ SERVER_PORT="${SERVER_PORT:-9091}"
8
+
9
+ mkdir -p "$LOG_DIR"
10
+
11
+ pipe_to_log() {
12
+ local source="${1:-SERVER}"
13
+ local raw_log="${2:-}"
14
+ local line
15
+ while IFS= read -r line || [ -n "$line" ]; do
16
+ if [ -n "$raw_log" ]; then
17
+ echo "$line" >> "$raw_log"
18
+ fi
19
+ line=$(echo "[$source] $line" | sed 's/\x1b\[[0-9;]*[a-zA-Z]//g; s/\x1b\[[0-9;]*m//g')
20
+ echo "$line"
21
+ done
22
+ }
23
+
24
+ kill_old_server() {
25
+ if command -v lsof &> /dev/null; then
26
+ local pids
27
+ pids=$(lsof -t -i tcp:"$SERVER_PORT" -sTCP:LISTEN 2>/dev/null || true)
28
+ if [ -n "$pids" ]; then
29
+ echo "正在关闭旧的 server 进程:$pids"
30
+ kill -9 $pids 2>/dev/null || echo "关闭进程失败:$pids"
31
+ sleep 1
32
+ fi
33
+ fi
34
+ }
35
+
36
+ echo "==================== Server Dev Run ===================="
37
+ echo "Server 目录:$SERVER_DIR"
38
+ echo "Server 端口:$SERVER_PORT"
39
+ echo "日志文件:$LOG_FILE"
40
+
41
+ kill_old_server
42
+
43
+ echo "启动 server 服务..."
44
+ cd "$SERVER_DIR"
45
+ NODE_ENV=development PORT="$SERVER_PORT" npx tsx ./src/index.ts 2>&1 | pipe_to_log "SERVER" "$LOG_FILE"
@@ -1,13 +1,72 @@
1
- # Expo App Template
1
+ # Expo App + Express.js
2
+
3
+ ## 目录结构规范(严格遵循)
4
+
5
+ 当前仓库是一个 monorepo(基于 pnpm 的 workspace)
6
+
7
+ - Expo 代码在 client 目录,Express.js 代码在 server 目录
8
+ - 本模板默认无 Tab Bar,可按需改造
9
+
10
+ 目录结构说明
11
+
12
+ ├── server/ # 服务端代码根目录 (Express.js)
13
+ | ├── src/
14
+ │ │ └── index.ts # Express 入口文件
15
+ | └── package.json # 服务端 package.json
16
+ ├── client/ # React Native 前端代码
17
+ │ ├── app/ # Expo Router 路由目录(仅路由配置)
18
+ │ │ ├── _layout.tsx # 根布局文件(必需)
19
+ │ │ ├── home.tsx # 首页
20
+ │ │ └── index.tsx # re-export home.tsx
21
+ │ ├── screens/ # 页面实现目录(与 app/ 路由对应)
22
+ │ │ └── home/
23
+ │ │ ├── index.tsx # 页面组件实现
24
+ │ │ └── styles.ts # 页面样式
25
+ │ ├── components/ # 可复用组件
26
+ │ │ └── Screen.tsx # 页面容器组件(必用)
27
+ │ ├── hooks/ # 自定义 Hooks
28
+ │ ├── contexts/ # React Context 代码
29
+ │ ├── assets/ # 静态资源
30
+ | └── package.json # Expo 应用 package.json
31
+ ├── package.json
32
+ ├── .cozeproj # 预置脚手架脚本(禁止修改)
33
+ └── .coze # 配置文件(禁止修改)
34
+
2
35
  ## 安装依赖
36
+
37
+ ### 命令
38
+
3
39
  ```bash
4
- pnpm install
40
+ pnpm i
5
41
  ```
6
- ## 启动 Metro 服务
7
- ```bash
8
- npx expo start
42
+
43
+ ### 新增依赖约束
44
+
45
+ 如果需要新增依赖,需在 client 和 server 各自的目录添加(原因:隔离前后端的依赖),禁止在根目录直接安装依赖
46
+
47
+ ### 新增依赖标准流程
48
+
49
+ - 编辑 `client/package.json` 或 `server/package.json`
50
+ - 在根目录执行 `pnpm i`
51
+
52
+ ## Expo 开发规范
53
+
54
+ ### 路径别名
55
+
56
+ Expo 配置了 `@/` 路径别名指向 `client/` 目录:
57
+
58
+ ```tsx
59
+ // 正确
60
+ import { Screen } from '@/components/Screen';
61
+
62
+ // 避免相对路径
63
+ import { Screen } from '../../../components/Screen';
9
64
  ```
10
- ## 启动 Node 服务器
65
+
66
+ ## 本地开发
67
+
68
+ 运行 coze dev 可以同时启动前端和后端服务,如果端口已占用,该命令会先杀掉占用端口的进程再启动,也可以用来重启前端和后端服务
69
+
11
70
  ```bash
12
- npm run server
71
+ coze dev
13
72
  ```
@@ -8,4 +8,4 @@ expo/expo-env.d.ts
8
8
  expo-env.d.ts
9
9
  .DS_Store
10
10
  logs/
11
- tsconfig.tsbuildinfo
11
+ *.tsbuildinfo
@@ -1,4 +1,4 @@
1
- registry=https://registry.npmjs.org
1
+ registry=https://registry.npmmirror.com
2
2
 
3
3
  strictStorePkgContentCheck=false
4
4
  verifyStoreIntegrity=false
@@ -8,15 +8,13 @@ network-concurrency=16
8
8
  fetch-retries=3
9
9
  fetch-timeout=60000
10
10
 
11
- # 严格使用 peer dependencies
11
+ # peerDependencies
12
12
  strict-peer-dependencies=false
13
-
14
- # 自动生成 lockfile
15
13
  auto-install-peers=true
16
14
 
17
15
  # lockfile 配置
18
16
  lockfile=true
19
17
  prefer-frozen-lockfile=true
20
18
 
21
- # 如果 lockfile 存在但过期,更新而不是失败
19
+ # semver 选择最高版本
22
20
  resolution-mode=highest
@@ -14,20 +14,20 @@ LogBox.ignoreLogs([
14
14
  export default function RootLayout() {
15
15
  return (
16
16
  <AuthProvider>
17
- <GestureHandlerRootView style={{ flex: 1 }}>
18
- <StatusBar style="dark"></StatusBar>
19
- <Stack screenOptions={{
20
- // 设置所有页面的切换动画为从右侧滑入,适用于iOS 和 Android
21
- animation: 'slide_from_right',
22
- gestureEnabled: true,
23
- gestureDirection: 'horizontal',
24
- // 隐藏自带的头部
25
- headerShown: false
26
- }}>
27
- <Stack.Screen name="(tabs)" options={{ title: "" }} />
28
- </Stack>
29
- <Toast />
30
- </GestureHandlerRootView>
17
+ <GestureHandlerRootView style={{ flex: 1 }}>
18
+ <StatusBar style="dark"></StatusBar>
19
+ <Stack screenOptions={{
20
+ // 设置所有页面的切换动画为从右侧滑入,适用于iOS 和 Android
21
+ animation: 'slide_from_right',
22
+ gestureEnabled: true,
23
+ gestureDirection: 'horizontal',
24
+ // 隐藏自带的头部
25
+ headerShown: false
26
+ }}>
27
+ <Stack.Screen name="index" options={{ title: "" }} />
28
+ </Stack>
29
+ <Toast />
30
+ </GestureHandlerRootView>
31
31
  </AuthProvider>
32
32
  );
33
33
  }
@@ -0,0 +1 @@
1
+ export { default } from '@/screens/demo'
@@ -0,0 +1 @@
1
+ export { default } from '@/screens/demo';
@@ -0,0 +1,75 @@
1
+ import { ExpoConfig, ConfigContext } from 'expo/config';
2
+
3
+ const appName = 'My App';
4
+ const slugAppName = 'my-app';
5
+
6
+ export default ({ config }: ConfigContext): ExpoConfig => {
7
+ return {
8
+ ...config,
9
+ "name": appName,
10
+ "slug": slugAppName,
11
+ "version": "1.0.0",
12
+ "orientation": "portrait",
13
+ "icon": "./assets/images/icon.png",
14
+ "scheme": "myapp",
15
+ "userInterfaceStyle": "automatic",
16
+ "newArchEnabled": true,
17
+ "ios": {
18
+ "supportsTablet": true
19
+ },
20
+ "android": {
21
+ "adaptiveIcon": {
22
+ "foregroundImage": "./assets/images/adaptive-icon.png",
23
+ "backgroundColor": "#ffffff"
24
+ },
25
+ "package": "com.anonymous.myapp"
26
+ },
27
+ "web": {
28
+ "bundler": "metro",
29
+ "output": "single",
30
+ "favicon": "./assets/images/favicon.png"
31
+ },
32
+ "plugins": [
33
+ process.env.EXPO_PUBLIC_BACKEND_BASE_URL ? [
34
+ "expo-router",
35
+ {
36
+ "origin": process.env.EXPO_PUBLIC_BACKEND_BASE_URL
37
+ }
38
+ ] : 'expo-router',
39
+ [
40
+ "expo-splash-screen",
41
+ {
42
+ "image": "./assets/images/splash-icon.png",
43
+ "imageWidth": 200,
44
+ "resizeMode": "contain",
45
+ "backgroundColor": "#ffffff"
46
+ }
47
+ ],
48
+ [
49
+ "expo-image-picker",
50
+ {
51
+ "photosPermission": `允许${appName}访问您的相册,以便您上传或保存图片。`,
52
+ "cameraPermission": `允许${appName}使用您的相机,以便您直接拍摄照片上传。`,
53
+ "microphonePermission": `允许${appName}访问您的麦克风,以便您拍摄带有声音的视频。`
54
+ }
55
+ ],
56
+ [
57
+ "expo-location",
58
+ {
59
+ "locationWhenInUsePermission": `${appName}需要访问您的位置以提供周边服务及导航功能。`
60
+ }
61
+ ],
62
+ [
63
+ "expo-camera",
64
+ {
65
+ "cameraPermission": `${appName}需要访问相机以拍摄照片和视频。`,
66
+ "microphonePermission": `${appName}需要访问麦克风以录制视频声音。`,
67
+ "recordAudioAndroid": true
68
+ }
69
+ ]
70
+ ],
71
+ "experiments": {
72
+ "typedRoutes": true
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,33 @@
1
+ import React from 'react';
2
+ import { Text, TextProps, TextStyle } from 'react-native';
3
+ import { useTheme } from '@/hooks/useTheme';
4
+ import { Typography } from '@/constants/theme';
5
+
6
+ type TypographyVariant = keyof typeof Typography;
7
+
8
+ interface ThemedTextProps extends TextProps {
9
+ variant?: TypographyVariant;
10
+ color?: string;
11
+ }
12
+
13
+ export function ThemedText({
14
+ variant = 'body',
15
+ color,
16
+ style,
17
+ children,
18
+ ...props
19
+ }: ThemedTextProps) {
20
+ const { theme } = useTheme();
21
+ const typographyStyle = Typography[variant];
22
+
23
+ const textStyle: TextStyle = {
24
+ ...typographyStyle,
25
+ color: color ?? theme.textPrimary,
26
+ };
27
+
28
+ return (
29
+ <Text style={[textStyle, style]} {...props}>
30
+ {children}
31
+ </Text>
32
+ );
33
+ }