@coze-arch/cli 0.0.1-beta.6 → 0.0.3
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/.coze +7 -2
- package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +46 -0
- package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +229 -0
- package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +47 -0
- package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +34 -0
- package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +46 -0
- package/lib/__templates__/expo/README.md +68 -7
- package/lib/__templates__/expo/_gitignore +2 -1
- package/lib/__templates__/expo/_npmrc +4 -5
- package/lib/__templates__/expo/client/app/+not-found.tsx +15 -64
- package/lib/__templates__/expo/client/app/_layout.tsx +15 -12
- package/lib/__templates__/expo/client/app/index.tsx +1 -0
- package/lib/__templates__/expo/client/app.config.ts +76 -0
- package/lib/__templates__/expo/client/components/Screen.tsx +3 -19
- package/lib/__templates__/expo/client/components/ThemedText.tsx +33 -0
- package/lib/__templates__/expo/client/components/ThemedView.tsx +37 -0
- package/lib/__templates__/expo/client/constants/theme.ts +117 -58
- package/lib/__templates__/expo/client/contexts/AuthContext.tsx +14 -107
- package/lib/__templates__/expo/client/declarations.d.ts +5 -0
- package/lib/__templates__/expo/{eslint.config.mjs → client/eslint.config.mjs} +40 -10
- package/lib/__templates__/expo/client/hooks/useColorScheme.tsx +48 -0
- package/lib/__templates__/expo/client/hooks/useSafeRouter.ts +152 -0
- package/lib/__templates__/expo/client/hooks/useTheme.ts +26 -6
- package/lib/__templates__/expo/client/metro.config.js +124 -0
- package/lib/__templates__/expo/client/package.json +95 -0
- package/lib/__templates__/expo/client/screens/demo/index.tsx +25 -0
- package/lib/__templates__/expo/client/screens/demo/styles.ts +28 -0
- package/lib/__templates__/expo/client/scripts/install-missing-deps.js +11 -10
- package/lib/__templates__/expo/client/tsconfig.json +24 -0
- package/lib/__templates__/expo/client/utils/index.ts +23 -2
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/names.js +1889 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/rule.js +174 -0
- package/lib/__templates__/expo/eslint-plugins/fontawesome6/v5-only-names.js +388 -0
- 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/eslint-plugins/react-native/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/react-native/rule.js +64 -0
- package/lib/__templates__/expo/eslint-plugins/reanimated/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/reanimated/rule.js +88 -0
- package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/index.js +9 -0
- package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/rule.js +120 -0
- package/lib/__templates__/expo/eslint-plugins/restrict-linear-gradient/tech.md +58 -0
- package/lib/__templates__/expo/package.json +16 -101
- package/lib/__templates__/expo/patches/expo@54.0.33.patch +45 -0
- package/lib/__templates__/expo/pnpm-lock.yaml +1622 -3274
- package/lib/__templates__/expo/pnpm-workspace.yaml +3 -0
- package/lib/__templates__/expo/server/build.js +21 -0
- package/lib/__templates__/expo/server/package.json +34 -0
- package/lib/__templates__/expo/server/src/index.ts +20 -0
- package/lib/__templates__/expo/server/tsconfig.json +24 -0
- package/lib/__templates__/expo/template.config.js +58 -1
- package/lib/__templates__/expo/tsconfig.json +1 -24
- 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/.coze +4 -3
- package/lib/__templates__/nextjs/README.md +5 -0
- package/lib/__templates__/nextjs/_gitignore +1 -0
- package/lib/__templates__/nextjs/_npmrc +2 -1
- package/lib/__templates__/nextjs/eslint.config.mjs +5 -0
- package/lib/__templates__/nextjs/next.config.ts +11 -0
- package/lib/__templates__/nextjs/package.json +15 -1
- package/lib/__templates__/nextjs/pnpm-lock.yaml +7694 -4394
- package/lib/__templates__/nextjs/scripts/build.sh +4 -1
- package/lib/__templates__/nextjs/scripts/dev.sh +15 -28
- package/lib/__templates__/nextjs/scripts/prepare.sh +9 -0
- package/lib/__templates__/nextjs/scripts/start.sh +7 -1
- package/lib/__templates__/nextjs/src/app/globals.css +109 -89
- package/lib/__templates__/nextjs/src/app/layout.tsx +20 -33
- package/lib/__templates__/nextjs/src/app/page.tsx +18 -49
- package/lib/__templates__/nextjs/src/components/ui/resizable.tsx +29 -22
- package/lib/__templates__/nextjs/src/components/ui/sidebar.tsx +228 -230
- package/lib/__templates__/nextjs/src/server.ts +35 -0
- package/lib/__templates__/nextjs/template.config.js +68 -3
- 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 +25 -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 +126 -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 +39 -0
- package/lib/__templates__/nuxt-vue/scripts/prepare.sh +14 -0
- package/lib/__templates__/nuxt-vue/scripts/start.sh +21 -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/.coze +14 -0
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +19 -0
- package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +14 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +2 -0
- package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +151 -0
- package/lib/__templates__/taro/.cozeproj/scripts/init_env.sh +5 -0
- package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +24 -0
- package/lib/__templates__/taro/README.md +763 -0
- package/lib/__templates__/taro/_gitignore +41 -0
- package/lib/__templates__/taro/_npmrc +18 -0
- package/lib/__templates__/taro/babel.config.js +12 -0
- package/lib/__templates__/taro/config/dev.ts +9 -0
- package/lib/__templates__/taro/config/index.ts +238 -0
- package/lib/__templates__/taro/config/prod.ts +34 -0
- package/lib/__templates__/taro/eslint.config.mjs +135 -0
- package/lib/__templates__/taro/key/private.appid.key +0 -0
- package/lib/__templates__/taro/package.json +112 -0
- package/lib/__templates__/taro/patches/@tarojs__plugin-mini-ci@4.1.9.patch +30 -0
- package/lib/__templates__/taro/pnpm-lock.yaml +23412 -0
- package/lib/__templates__/taro/pnpm-workspace.yaml +2 -0
- package/lib/__templates__/taro/project.config.json +15 -0
- package/lib/__templates__/taro/server/nest-cli.json +10 -0
- package/lib/__templates__/taro/server/package.json +40 -0
- package/lib/__templates__/taro/server/src/app.controller.ts +23 -0
- package/lib/__templates__/taro/server/src/app.module.ts +10 -0
- package/lib/__templates__/taro/server/src/app.service.ts +8 -0
- package/lib/__templates__/taro/server/src/interceptors/http-status.interceptor.ts +23 -0
- package/lib/__templates__/taro/server/src/main.ts +49 -0
- package/lib/__templates__/taro/server/tsconfig.json +24 -0
- package/lib/__templates__/taro/src/app.config.ts +11 -0
- package/lib/__templates__/taro/src/app.css +156 -0
- package/lib/__templates__/taro/src/app.tsx +9 -0
- package/lib/__templates__/taro/src/components/ui/accordion.tsx +159 -0
- package/lib/__templates__/taro/src/components/ui/alert-dialog.tsx +260 -0
- package/lib/__templates__/taro/src/components/ui/alert.tsx +60 -0
- package/lib/__templates__/taro/src/components/ui/aspect-ratio.tsx +36 -0
- package/lib/__templates__/taro/src/components/ui/avatar.tsx +84 -0
- package/lib/__templates__/taro/src/components/ui/badge.tsx +37 -0
- package/lib/__templates__/taro/src/components/ui/breadcrumb.tsx +117 -0
- package/lib/__templates__/taro/src/components/ui/button-group.tsx +83 -0
- package/lib/__templates__/taro/src/components/ui/button.tsx +67 -0
- package/lib/__templates__/taro/src/components/ui/calendar.tsx +394 -0
- package/lib/__templates__/taro/src/components/ui/card.tsx +108 -0
- package/lib/__templates__/taro/src/components/ui/carousel.tsx +228 -0
- package/lib/__templates__/taro/src/components/ui/checkbox.tsx +58 -0
- package/lib/__templates__/taro/src/components/ui/code-block.tsx +169 -0
- package/lib/__templates__/taro/src/components/ui/collapsible.tsx +71 -0
- package/lib/__templates__/taro/src/components/ui/command.tsx +385 -0
- package/lib/__templates__/taro/src/components/ui/context-menu.tsx +614 -0
- package/lib/__templates__/taro/src/components/ui/dialog.tsx +256 -0
- package/lib/__templates__/taro/src/components/ui/drawer.tsx +192 -0
- package/lib/__templates__/taro/src/components/ui/dropdown-menu.tsx +561 -0
- package/lib/__templates__/taro/src/components/ui/field.tsx +228 -0
- package/lib/__templates__/taro/src/components/ui/hover-card.tsx +282 -0
- package/lib/__templates__/taro/src/components/ui/input-group.tsx +197 -0
- package/lib/__templates__/taro/src/components/ui/input-otp.tsx +136 -0
- package/lib/__templates__/taro/src/components/ui/input.tsx +56 -0
- package/lib/__templates__/taro/src/components/ui/label.tsx +24 -0
- package/lib/__templates__/taro/src/components/ui/menubar.tsx +595 -0
- package/lib/__templates__/taro/src/components/ui/navigation-menu.tsx +264 -0
- package/lib/__templates__/taro/src/components/ui/pagination.tsx +118 -0
- package/lib/__templates__/taro/src/components/ui/popover.tsx +291 -0
- package/lib/__templates__/taro/src/components/ui/portal.tsx +19 -0
- package/lib/__templates__/taro/src/components/ui/progress.tsx +28 -0
- package/lib/__templates__/taro/src/components/ui/radio-group.tsx +64 -0
- package/lib/__templates__/taro/src/components/ui/resizable.tsx +346 -0
- package/lib/__templates__/taro/src/components/ui/scroll-area.tsx +34 -0
- package/lib/__templates__/taro/src/components/ui/select.tsx +438 -0
- package/lib/__templates__/taro/src/components/ui/separator.tsx +30 -0
- package/lib/__templates__/taro/src/components/ui/sheet.tsx +262 -0
- package/lib/__templates__/taro/src/components/ui/skeleton.tsx +17 -0
- package/lib/__templates__/taro/src/components/ui/slider.tsx +203 -0
- package/lib/__templates__/taro/src/components/ui/sonner.tsx +1 -0
- package/lib/__templates__/taro/src/components/ui/switch.tsx +55 -0
- package/lib/__templates__/taro/src/components/ui/table.tsx +142 -0
- package/lib/__templates__/taro/src/components/ui/tabs.tsx +114 -0
- package/lib/__templates__/taro/src/components/ui/textarea.tsx +54 -0
- package/lib/__templates__/taro/src/components/ui/toast.tsx +517 -0
- package/lib/__templates__/taro/src/components/ui/toggle-group.tsx +120 -0
- package/lib/__templates__/taro/src/components/ui/toggle.tsx +77 -0
- package/lib/__templates__/taro/src/components/ui/tooltip.tsx +455 -0
- package/lib/__templates__/taro/src/index.html +39 -0
- package/lib/__templates__/taro/src/lib/hooks/use-keyboard-offset.ts +37 -0
- package/lib/__templates__/taro/src/lib/measure.ts +115 -0
- package/lib/__templates__/taro/src/lib/platform.ts +12 -0
- package/lib/__templates__/taro/src/lib/utils.ts +6 -0
- package/lib/__templates__/taro/src/network.ts +39 -0
- package/lib/__templates__/taro/src/pages/index/index.config.ts +3 -0
- package/lib/__templates__/taro/src/pages/index/index.css +1 -0
- package/lib/__templates__/taro/src/pages/index/index.tsx +33 -0
- 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 +238 -0
- package/lib/__templates__/taro/src/presets/h5-styles.ts +220 -0
- package/lib/__templates__/taro/src/presets/index.tsx +18 -0
- package/lib/__templates__/taro/stylelint.config.mjs +4 -0
- package/lib/__templates__/taro/template.config.js +68 -0
- package/lib/__templates__/taro/tsconfig.json +29 -0
- package/lib/__templates__/taro/types/global.d.ts +32 -0
- package/lib/__templates__/templates.json +173 -36
- package/lib/__templates__/vite/.coze +4 -3
- package/lib/__templates__/vite/README.md +383 -26
- package/lib/__templates__/vite/_gitignore +2 -0
- package/lib/__templates__/vite/_npmrc +2 -1
- package/lib/__templates__/vite/eslint.config.mjs +14 -0
- package/lib/__templates__/vite/package.json +23 -3
- package/lib/__templates__/vite/pnpm-lock.yaml +2509 -293
- package/lib/__templates__/vite/scripts/build.sh +4 -1
- package/lib/__templates__/vite/scripts/dev.sh +16 -28
- package/lib/__templates__/vite/scripts/prepare.sh +9 -0
- package/lib/__templates__/vite/scripts/start.sh +9 -3
- package/lib/__templates__/vite/server/routes/index.ts +31 -0
- package/lib/__templates__/vite/server/server.ts +65 -0
- package/lib/__templates__/vite/server/vite.ts +67 -0
- package/lib/__templates__/vite/src/main.ts +17 -48
- package/lib/__templates__/vite/template.config.js +77 -7
- package/lib/__templates__/vite/tsconfig.json +4 -3
- package/lib/__templates__/vite/vite.config.ts +8 -3
- package/lib/cli.js +1545 -526
- package/package.json +20 -7
- package/lib/__templates__/expo/.cozeproj/scripts/deploy_build.sh +0 -109
- package/lib/__templates__/expo/.cozeproj/scripts/deploy_run.sh +0 -257
- package/lib/__templates__/expo/app.json +0 -63
- package/lib/__templates__/expo/babel.config.js +0 -9
- package/lib/__templates__/expo/client/app/(tabs)/_layout.tsx +0 -43
- package/lib/__templates__/expo/client/app/(tabs)/home.tsx +0 -1
- package/lib/__templates__/expo/client/app/(tabs)/index.tsx +0 -7
- package/lib/__templates__/expo/client/hooks/useColorScheme.ts +0 -1
- package/lib/__templates__/expo/client/index.js +0 -12
- package/lib/__templates__/expo/client/screens/home/index.tsx +0 -54
- package/lib/__templates__/expo/client/screens/home/styles.ts +0 -332
- package/lib/__templates__/expo/metro.config.js +0 -53
- package/lib/__templates__/expo/src/index.ts +0 -12
- package/lib/__templates__/nextjs/.vscode/settings.json +0 -121
- package/lib/__templates__/nextjs/server.mjs +0 -50
- package/lib/__templates__/vite/.vscode/settings.json +0 -7
- /package/lib/__templates__/expo/{eslint-formatter-simple.mjs → client/eslint-formatter-simple.mjs} +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,51 +1,39 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
set -Eeuo pipefail
|
|
3
3
|
|
|
4
|
+
<% if (process.env.NODE_ENV === 'test') { %>
|
|
5
|
+
# 测试环境:支持环境变量覆盖端口
|
|
6
|
+
PORT="${PORT:-<%= port %>}"
|
|
7
|
+
COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
|
|
8
|
+
DEPLOY_RUN_PORT="${DEPLOY_RUN_PORT:-${PORT}}"
|
|
9
|
+
<% } else { %>
|
|
4
10
|
PORT=<%= port %>
|
|
5
11
|
COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
|
|
12
|
+
DEPLOY_RUN_PORT=<%= port %>
|
|
13
|
+
<% } %>
|
|
6
14
|
|
|
7
15
|
cd "${COZE_WORKSPACE_PATH}"
|
|
8
16
|
|
|
9
17
|
kill_port_if_listening() {
|
|
10
18
|
local pids
|
|
11
|
-
|
|
12
|
-
# Check if lsof is available (macOS/BSD) or ss (Linux)
|
|
13
|
-
if command -v lsof >/dev/null 2>&1; then
|
|
14
|
-
# macOS/BSD using lsof
|
|
15
|
-
pids=$(lsof -ti:${PORT} 2>/dev/null || true)
|
|
16
|
-
elif command -v ss >/dev/null 2>&1; then
|
|
17
|
-
# Linux using ss
|
|
18
|
-
pids=$(ss -H -lntp 2>/dev/null | awk -v port="${PORT}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | paste -sd' ' - || true)
|
|
19
|
-
else
|
|
20
|
-
echo "Warning: neither lsof nor ss found, cannot check port ${PORT}"
|
|
21
|
-
return
|
|
22
|
-
fi
|
|
23
|
-
|
|
19
|
+
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)
|
|
24
20
|
if [[ -z "${pids}" ]]; then
|
|
25
|
-
echo "Port ${
|
|
21
|
+
echo "Port ${DEPLOY_RUN_PORT} is free."
|
|
26
22
|
return
|
|
27
23
|
fi
|
|
28
|
-
|
|
29
|
-
echo "Port ${PORT} in use by PIDs: ${pids} (SIGKILL)"
|
|
24
|
+
echo "Port ${DEPLOY_RUN_PORT} in use by PIDs: ${pids} (SIGKILL)"
|
|
30
25
|
echo "${pids}" | xargs -I {} kill -9 {}
|
|
31
26
|
sleep 1
|
|
32
|
-
|
|
33
|
-
# Verify port is cleared
|
|
34
|
-
if command -v lsof >/dev/null 2>&1; then
|
|
35
|
-
pids=$(lsof -ti:${PORT} 2>/dev/null || true)
|
|
36
|
-
elif command -v ss >/dev/null 2>&1; then
|
|
37
|
-
pids=$(ss -H -lntp 2>/dev/null | awk -v port="${PORT}" '$4 ~ ":"port"$"' | grep -o 'pid=[0-9]*' | cut -d= -f2 | paste -sd' ' - || true)
|
|
38
|
-
fi
|
|
39
|
-
|
|
27
|
+
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)
|
|
40
28
|
if [[ -n "${pids}" ]]; then
|
|
41
|
-
echo "Warning: port ${
|
|
29
|
+
echo "Warning: port ${DEPLOY_RUN_PORT} still busy after SIGKILL, PIDs: ${pids}"
|
|
42
30
|
else
|
|
43
|
-
echo "Port ${
|
|
31
|
+
echo "Port ${DEPLOY_RUN_PORT} cleared."
|
|
44
32
|
fi
|
|
45
33
|
}
|
|
46
34
|
|
|
47
35
|
echo "Clearing port ${PORT} before start."
|
|
48
36
|
kill_port_if_listening
|
|
49
|
-
echo "Starting
|
|
37
|
+
echo "Starting express + Vite dev server on port ${PORT}..."
|
|
50
38
|
|
|
51
|
-
npx
|
|
39
|
+
PORT=$PORT npx tsx watch server/server.ts
|
|
@@ -2,14 +2,20 @@
|
|
|
2
2
|
set -Eeuo pipefail
|
|
3
3
|
|
|
4
4
|
COZE_WORKSPACE_PATH="${COZE_WORKSPACE_PATH:-$(pwd)}"
|
|
5
|
+
<% if (process.env.NODE_ENV === 'test') { %>
|
|
6
|
+
# 测试环境:支持环境变量覆盖端口
|
|
7
|
+
PORT="${PORT:-<%= port %>}"
|
|
8
|
+
DEPLOY_RUN_PORT="${DEPLOY_RUN_PORT:-${PORT}}"
|
|
9
|
+
<% } else { %>
|
|
5
10
|
PORT=<%= port %>
|
|
6
11
|
DEPLOY_RUN_PORT="${DEPLOY_RUN_PORT:-$PORT}"
|
|
12
|
+
<% } %>
|
|
7
13
|
|
|
8
14
|
start_service() {
|
|
9
15
|
cd "${COZE_WORKSPACE_PATH}"
|
|
10
|
-
echo "Starting
|
|
11
|
-
|
|
16
|
+
echo "Starting express production server on port ${DEPLOY_RUN_PORT}..."
|
|
17
|
+
PORT=$DEPLOY_RUN_PORT node dist-server/server.js
|
|
12
18
|
}
|
|
13
19
|
|
|
14
|
-
echo "Starting
|
|
20
|
+
echo "Starting express production server on port ${DEPLOY_RUN_PORT}..."
|
|
15
21
|
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,65 @@
|
|
|
1
|
+
// ABOUTME: Express server with Vite integration
|
|
2
|
+
// ABOUTME: Handles API routes and serves frontend in dev/prod modes
|
|
3
|
+
|
|
4
|
+
import { createServer, type Server } from 'http';
|
|
5
|
+
import express from 'express';
|
|
6
|
+
import router from './routes/index';
|
|
7
|
+
import { setupVite } from './vite';
|
|
8
|
+
|
|
9
|
+
const isDev = process.env.COZE_PROJECT_ENV !== 'PROD';
|
|
10
|
+
const port = parseInt(process.env.PORT || '<%= port %>', 10);
|
|
11
|
+
const hostname = process.env.HOSTNAME || 'localhost';
|
|
12
|
+
const app = express();
|
|
13
|
+
// 使用 http.createServer 包装 Express app,以便支持 WebSocket 等协议升级
|
|
14
|
+
const server = createServer(app);
|
|
15
|
+
|
|
16
|
+
async function startServer(): Promise<Server> {
|
|
17
|
+
// 请求日志(仅开发环境)
|
|
18
|
+
if (isDev) {
|
|
19
|
+
app.use((req, res, next) => {
|
|
20
|
+
const start = Date.now();
|
|
21
|
+
res.on('finish', () => {
|
|
22
|
+
const ms = Date.now() - start;
|
|
23
|
+
console.log(`${req.method} ${req.url} - ${ms}ms`);
|
|
24
|
+
});
|
|
25
|
+
next();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// 添加请求体解析
|
|
30
|
+
app.use(express.json());
|
|
31
|
+
app.use(express.urlencoded({ extended: true }));
|
|
32
|
+
|
|
33
|
+
// 注册 API 路由
|
|
34
|
+
app.use(router);
|
|
35
|
+
|
|
36
|
+
// 集成 Vite(开发模式)或静态文件服务(生产模式)
|
|
37
|
+
await setupVite(app);
|
|
38
|
+
|
|
39
|
+
// 全局错误处理
|
|
40
|
+
app.use((err: Error, req: express.Request, res: express.Response) => {
|
|
41
|
+
console.error('Server error:', err);
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
const status = 'status' in err ? (err as any).status || 500 : 500;
|
|
44
|
+
res.status(status).json({
|
|
45
|
+
error: err.message || 'Internal server error',
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
server.once('error', err => {
|
|
50
|
+
console.error('Server error:', err);
|
|
51
|
+
process.exit(1);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
server.listen(port, () => {
|
|
55
|
+
console.log(`\n✨ Server running at http://${hostname}:${port}`);
|
|
56
|
+
console.log(`📝 Environment: ${isDev ? 'development' : 'production'}\n`);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
return server;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
startServer().catch(err => {
|
|
63
|
+
console.error('Failed to start server:', err);
|
|
64
|
+
process.exit(1);
|
|
65
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// ABOUTME: Vite integration for Express server
|
|
2
|
+
// ABOUTME: Handles dev middleware and production static file serving
|
|
3
|
+
|
|
4
|
+
import type { Application, Request, Response } from 'express';
|
|
5
|
+
import express from 'express';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
import fs from 'fs';
|
|
8
|
+
import { createServer as createViteServer } from 'vite';
|
|
9
|
+
import viteConfig from '../vite.config';
|
|
10
|
+
|
|
11
|
+
const isDev = process.env.COZE_PROJECT_ENV !== 'PROD';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 集成 Vite 开发服务器(中间件模式)
|
|
15
|
+
*/
|
|
16
|
+
export async function setupViteMiddleware(app: Application) {
|
|
17
|
+
const vite = await createViteServer({
|
|
18
|
+
...viteConfig,
|
|
19
|
+
server: {
|
|
20
|
+
...viteConfig.server,
|
|
21
|
+
middlewareMode: true,
|
|
22
|
+
},
|
|
23
|
+
appType: 'spa',
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// 使用 Vite middleware
|
|
27
|
+
app.use(vite.middlewares);
|
|
28
|
+
|
|
29
|
+
console.log('🚀 Vite dev server initialized');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 设置生产环境静态文件服务
|
|
34
|
+
*/
|
|
35
|
+
export function setupStaticServer(app: Application) {
|
|
36
|
+
const distPath = path.resolve(process.cwd(), 'dist');
|
|
37
|
+
|
|
38
|
+
if (!fs.existsSync(distPath)) {
|
|
39
|
+
console.error('❌ dist folder not found. Please run "pnpm build" first.');
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// 1. 服务静态文件(如果存在对应文件则直接返回)
|
|
44
|
+
app.use(express.static(distPath));
|
|
45
|
+
|
|
46
|
+
// 2. SPA fallback - 所有未处理的请求返回 index.html
|
|
47
|
+
// 到达这里的请求说明:
|
|
48
|
+
// - 不是 API 请求(已被前面注册的路由处理)
|
|
49
|
+
// - 不是静态文件(express.static 未找到对应文件)
|
|
50
|
+
// - 需要返回 index.html 让前端路由处理
|
|
51
|
+
app.use((_req: Request, res: Response) => {
|
|
52
|
+
res.sendFile(path.join(distPath, 'index.html'));
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
console.log('📦 Serving static files from dist/');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 根据环境设置 Vite
|
|
60
|
+
*/
|
|
61
|
+
export async function setupVite(app: Application) {
|
|
62
|
+
if (isDev) {
|
|
63
|
+
await setupViteMiddleware(app);
|
|
64
|
+
} else {
|
|
65
|
+
setupStaticServer(app);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -7,57 +7,26 @@ export function initApp(): void {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
app.innerHTML = `
|
|
10
|
-
<div class="flex
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
<!-- 头部:Logo 和 产品名称 -->
|
|
14
|
-
<div class="flex items-center gap-3">
|
|
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">
|
|
11
|
+
<main class="flex w-full h-full max-w-3xl flex-col items-center justify-center px-16 py-32 sm:items-center">
|
|
12
|
+
<div class="flex flex-col items-center justify-between gap-4">
|
|
15
13
|
<img
|
|
16
|
-
|
|
17
|
-
src="https://lf3-static.bytednsdoc.com/obj/eden-cn/hkpzboz/coze_logo.png"
|
|
14
|
+
src="https://lf-coze-web-cdn.coze.cn/obj/eden-cn/lm-lgvj/ljhwZthlaukjlkulzlp/coze-coding/icon/coze-coding.gif"
|
|
18
15
|
alt="扣子编程 Logo"
|
|
19
|
-
width=
|
|
20
|
-
height=
|
|
21
|
-
style="width:
|
|
16
|
+
width={156}
|
|
17
|
+
height={130}
|
|
18
|
+
style="width: 156px; height: 130px; object-fit: contain;"
|
|
22
19
|
/>
|
|
23
|
-
<
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
</
|
|
33
|
-
<p class="max-w-2xl text-lg leading-8 text-zinc-600 dark:text-zinc-400">
|
|
34
|
-
当前是空白入口文件,项目正在开发中,请稍候...
|
|
35
|
-
<br />
|
|
36
|
-
开发完成后界面将自动更新。如未自动更新成功,可以手动点击右上角刷新或重启按钮查看效果。
|
|
37
|
-
</p>
|
|
38
|
-
</div>
|
|
39
|
-
|
|
40
|
-
<!-- 底部按钮区 -->
|
|
41
|
-
<div class="flex w-full flex-col gap-4 text-base font-medium sm:w-auto sm:flex-row">
|
|
42
|
-
<!-- 按钮 1:前往首页 -->
|
|
43
|
-
<a
|
|
44
|
-
class="flex h-12 w-full min-w-[160px] items-center justify-center gap-2 rounded-full bg-black px-8 text-white transition-colors hover:bg-zinc-800 dark:bg-white dark:text-black dark:hover:bg-zinc-200 md:w-auto"
|
|
45
|
-
href="https://code.coze.cn/"
|
|
46
|
-
target="_blank"
|
|
47
|
-
rel="noopener noreferrer"
|
|
48
|
-
>
|
|
49
|
-
前往首页
|
|
50
|
-
</a>
|
|
51
|
-
|
|
52
|
-
<!-- 按钮 2:查看文档 -->
|
|
53
|
-
<a
|
|
54
|
-
class="flex h-12 w-full min-w-[160px] items-center justify-center rounded-full border border-solid border-black/[.08] px-8 transition-colors hover:border-transparent hover:bg-black/[.04] dark:border-white/[.145] dark:hover:bg-[#1a1a1a] md:w-auto"
|
|
55
|
-
href="https://docs.coze.cn/"
|
|
56
|
-
target="_blank"
|
|
57
|
-
rel="noopener noreferrer"
|
|
58
|
-
>
|
|
59
|
-
查看文档
|
|
60
|
-
</a>
|
|
20
|
+
<div>
|
|
21
|
+
<div class="flex flex-col items-center gap-2 text-center sm:items-center sm:text-center">
|
|
22
|
+
<h1 class="max-w-xl text-base font-semibold leading-tight tracking-tight text-foreground dark:text-foreground">
|
|
23
|
+
应用开发中
|
|
24
|
+
</h1>
|
|
25
|
+
<p class="max-w-2xl text-sm-14 leading-8 text-muted-foreground dark:text-muted-foreground">
|
|
26
|
+
请稍后,页面即将呈现
|
|
27
|
+
</p>
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
61
30
|
</div>
|
|
62
31
|
</main>
|
|
63
32
|
</div>
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
import { resolve, join, basename } from 'path';
|
|
4
|
+
import { appendFileSync, openSync, closeSync, mkdirSync } from 'fs';
|
|
5
|
+
|
|
2
6
|
|
|
3
7
|
|
|
4
8
|
|
|
@@ -24,17 +28,29 @@ export const paramsSchema = {
|
|
|
24
28
|
maximum: 65535,
|
|
25
29
|
description: 'Development server port',
|
|
26
30
|
},
|
|
31
|
+
hmrPort: {
|
|
32
|
+
type: 'number',
|
|
33
|
+
default: 6000,
|
|
34
|
+
minimum: 1024,
|
|
35
|
+
maximum: 65535,
|
|
36
|
+
description: 'Development HMR server port',
|
|
37
|
+
},
|
|
27
38
|
},
|
|
28
39
|
required: [],
|
|
29
40
|
additionalProperties: false,
|
|
30
41
|
};
|
|
31
42
|
|
|
43
|
+
const description = `Vite(简单项目):\`coze init \${COZE_WORKSPACE_PATH} --template vite\`
|
|
44
|
+
- 适用:轻量级 SPA、纯前端交互、仪表盘等轻量级项目。`;
|
|
45
|
+
|
|
32
46
|
const config = {
|
|
47
|
+
description: description,
|
|
33
48
|
paramsSchema,
|
|
34
49
|
|
|
35
50
|
defaultParams: {
|
|
36
51
|
port: 5000,
|
|
37
|
-
|
|
52
|
+
hmrPort: 6000,
|
|
53
|
+
appName: 'projects',
|
|
38
54
|
},
|
|
39
55
|
|
|
40
56
|
onBeforeRender: async context => {
|
|
@@ -44,13 +60,67 @@ const config = {
|
|
|
44
60
|
return context;
|
|
45
61
|
},
|
|
46
62
|
|
|
47
|
-
onAfterRender: async (
|
|
63
|
+
onAfterRender: async (_context, outputPath) => {
|
|
48
64
|
console.log(`\nProject created at: ${outputPath}`);
|
|
49
|
-
console.log(
|
|
50
|
-
console.log(
|
|
51
|
-
console.log(
|
|
52
|
-
console.log(
|
|
53
|
-
console.log(` - Port: ${
|
|
65
|
+
console.log('\nConfiguration:');
|
|
66
|
+
console.log(' - Framework: vite');
|
|
67
|
+
console.log(' - TypeScript: enabled');
|
|
68
|
+
console.log(' - App Router: enabled');
|
|
69
|
+
console.log(` - Port: ${_context.port}`);
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
onComplete: async (_context, outputPath) => {
|
|
73
|
+
// Skip pnpm update in test environment to avoid monorepo workspace issues
|
|
74
|
+
if (process.env.NODE_ENV === 'test') {
|
|
75
|
+
console.log('⊘ Skipping dependency update in test environment');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const cmd = 'pnpm';
|
|
80
|
+
const args = ['update', 'coze-coding-dev-sdk@^0.7.0'];
|
|
81
|
+
console.log(
|
|
82
|
+
`\nTriggering: ${cmd} ${args.join(' ')} (running in background)`,
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const projectRoot = resolve(outputPath);
|
|
87
|
+
|
|
88
|
+
// Determine log directory
|
|
89
|
+
const logDir = process.env.COZE_LOG_DIR || resolve(__dirname, '../.log');
|
|
90
|
+
mkdirSync(logDir, { recursive: true });
|
|
91
|
+
|
|
92
|
+
// Use project name in log file to avoid conflicts
|
|
93
|
+
const projectName = basename(projectRoot);
|
|
94
|
+
const logFile = join(logDir, `${projectName}-init.log`);
|
|
95
|
+
|
|
96
|
+
// Write log header
|
|
97
|
+
const timestamp = new Date().toISOString();
|
|
98
|
+
appendFileSync(
|
|
99
|
+
logFile,
|
|
100
|
+
`\n=== [${timestamp}] ${cmd} ${args.join(' ')} ===\n`,
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
// Open log file for appending
|
|
104
|
+
const logFd = openSync(logFile, 'a');
|
|
105
|
+
|
|
106
|
+
// Spawn in detached mode
|
|
107
|
+
const child = spawn(cmd, args, {
|
|
108
|
+
cwd: projectRoot,
|
|
109
|
+
detached: true,
|
|
110
|
+
stdio: ['ignore', logFd, logFd],
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
child.unref();
|
|
114
|
+
closeSync(logFd);
|
|
115
|
+
|
|
116
|
+
console.log(
|
|
117
|
+
'✓ coze-coding-dev-sdk update triggered (running in background)',
|
|
118
|
+
);
|
|
119
|
+
console.log(` Log file: ${logFile}`);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error('✗ Failed to trigger coze-coding-dev-sdk update:', error);
|
|
122
|
+
console.log(' You can manually run: pnpm update coze-coding-dev-sdk');
|
|
123
|
+
}
|
|
54
124
|
},
|
|
55
125
|
};
|
|
56
126
|
|
|
@@ -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
|
}
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { defineConfig } from 'vite';
|
|
2
2
|
|
|
3
3
|
export default defineConfig({
|
|
4
|
-
port: '<%= port %>',
|
|
5
|
-
host: '0.0.0.0',
|
|
6
4
|
server: {
|
|
5
|
+
port: <%= port %>,
|
|
6
|
+
host: '0.0.0.0',
|
|
7
|
+
allowedHosts: true,
|
|
7
8
|
hmr: {
|
|
8
9
|
overlay: true,
|
|
9
10
|
path: '/hot/vite-hmr',
|
|
10
|
-
port:
|
|
11
|
+
port: <%= hmrPort %>,
|
|
11
12
|
clientPort: 443,
|
|
12
13
|
timeout: 30000,
|
|
13
14
|
},
|
|
15
|
+
watch: {
|
|
16
|
+
usePolling: true,
|
|
17
|
+
interval: 100,
|
|
18
|
+
}
|
|
14
19
|
},
|
|
15
20
|
});
|