@coze-arch/cli 0.0.1-alpha.01c0ee
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 +143 -0
- package/bin/main +2 -0
- package/lib/__templates__/expo/.coze +12 -0
- 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 +74 -0
- package/lib/__templates__/expo/_gitignore +11 -0
- package/lib/__templates__/expo/_npmrc +20 -0
- package/lib/__templates__/expo/client/app/+not-found.tsx +30 -0
- package/lib/__templates__/expo/client/app/_layout.tsx +36 -0
- 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/assets/fonts/SpaceMono-Regular.ttf +0 -0
- package/lib/__templates__/expo/client/assets/images/adaptive-icon.png +0 -0
- package/lib/__templates__/expo/client/assets/images/default-avatar.png +0 -0
- package/lib/__templates__/expo/client/assets/images/favicon.png +0 -0
- package/lib/__templates__/expo/client/assets/images/icon.png +0 -0
- package/lib/__templates__/expo/client/assets/images/partial-react-logo.png +0 -0
- package/lib/__templates__/expo/client/assets/images/react-logo.png +0 -0
- package/lib/__templates__/expo/client/assets/images/react-logo@2x.png +0 -0
- package/lib/__templates__/expo/client/assets/images/react-logo@3x.png +0 -0
- package/lib/__templates__/expo/client/assets/images/splash-icon.png +0 -0
- package/lib/__templates__/expo/client/components/Screen.tsx +314 -0
- package/lib/__templates__/expo/client/components/SmartDateInput.tsx +238 -0
- 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 +177 -0
- package/lib/__templates__/expo/client/contexts/AuthContext.tsx +49 -0
- package/lib/__templates__/expo/client/declarations.d.ts +5 -0
- package/lib/__templates__/expo/client/eslint-formatter-simple.mjs +49 -0
- package/lib/__templates__/expo/client/eslint.config.mjs +128 -0
- 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 +33 -0
- 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 +105 -0
- package/lib/__templates__/expo/client/tsconfig.json +24 -0
- package/lib/__templates__/expo/client/utils/index.ts +76 -0
- 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 +25 -0
- package/lib/__templates__/expo/patches/expo@54.0.33.patch +45 -0
- package/lib/__templates__/expo/pnpm-lock.yaml +12657 -0
- 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 +106 -0
- package/lib/__templates__/expo/tsconfig.json +1 -0
- 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/.babelrc +15 -0
- package/lib/__templates__/nextjs/.coze +12 -0
- package/lib/__templates__/nextjs/README.md +363 -0
- package/lib/__templates__/nextjs/_gitignore +99 -0
- package/lib/__templates__/nextjs/_npmrc +23 -0
- package/lib/__templates__/nextjs/components.json +21 -0
- package/lib/__templates__/nextjs/eslint.config.mjs +23 -0
- package/lib/__templates__/nextjs/next-env.d.ts +6 -0
- package/lib/__templates__/nextjs/next.config.ts +18 -0
- package/lib/__templates__/nextjs/package.json +93 -0
- package/lib/__templates__/nextjs/pnpm-lock.yaml +12404 -0
- package/lib/__templates__/nextjs/postcss.config.mjs +7 -0
- package/lib/__templates__/nextjs/public/file.svg +1 -0
- package/lib/__templates__/nextjs/public/globe.svg +1 -0
- package/lib/__templates__/nextjs/public/next.svg +1 -0
- package/lib/__templates__/nextjs/public/vercel.svg +1 -0
- package/lib/__templates__/nextjs/public/window.svg +1 -0
- package/lib/__templates__/nextjs/scripts/build.sh +17 -0
- package/lib/__templates__/nextjs/scripts/dev.sh +39 -0
- package/lib/__templates__/nextjs/scripts/prepare.sh +9 -0
- package/lib/__templates__/nextjs/scripts/start.sh +21 -0
- package/lib/__templates__/nextjs/src/app/favicon.ico +0 -0
- package/lib/__templates__/nextjs/src/app/globals.css +137 -0
- package/lib/__templates__/nextjs/src/app/layout.tsx +74 -0
- package/lib/__templates__/nextjs/src/app/page.tsx +35 -0
- package/lib/__templates__/nextjs/src/app/robots.ts +11 -0
- package/lib/__templates__/nextjs/src/components/ui/accordion.tsx +66 -0
- package/lib/__templates__/nextjs/src/components/ui/alert-dialog.tsx +157 -0
- package/lib/__templates__/nextjs/src/components/ui/alert.tsx +66 -0
- package/lib/__templates__/nextjs/src/components/ui/aspect-ratio.tsx +11 -0
- package/lib/__templates__/nextjs/src/components/ui/avatar.tsx +53 -0
- package/lib/__templates__/nextjs/src/components/ui/badge.tsx +46 -0
- package/lib/__templates__/nextjs/src/components/ui/breadcrumb.tsx +109 -0
- package/lib/__templates__/nextjs/src/components/ui/button-group.tsx +83 -0
- package/lib/__templates__/nextjs/src/components/ui/button.tsx +62 -0
- package/lib/__templates__/nextjs/src/components/ui/calendar.tsx +220 -0
- package/lib/__templates__/nextjs/src/components/ui/card.tsx +92 -0
- package/lib/__templates__/nextjs/src/components/ui/carousel.tsx +241 -0
- package/lib/__templates__/nextjs/src/components/ui/chart.tsx +357 -0
- package/lib/__templates__/nextjs/src/components/ui/checkbox.tsx +32 -0
- package/lib/__templates__/nextjs/src/components/ui/collapsible.tsx +33 -0
- package/lib/__templates__/nextjs/src/components/ui/command.tsx +184 -0
- package/lib/__templates__/nextjs/src/components/ui/context-menu.tsx +252 -0
- package/lib/__templates__/nextjs/src/components/ui/dialog.tsx +143 -0
- package/lib/__templates__/nextjs/src/components/ui/drawer.tsx +135 -0
- package/lib/__templates__/nextjs/src/components/ui/dropdown-menu.tsx +257 -0
- package/lib/__templates__/nextjs/src/components/ui/empty.tsx +104 -0
- package/lib/__templates__/nextjs/src/components/ui/field.tsx +248 -0
- package/lib/__templates__/nextjs/src/components/ui/form.tsx +167 -0
- package/lib/__templates__/nextjs/src/components/ui/hover-card.tsx +44 -0
- package/lib/__templates__/nextjs/src/components/ui/input-group.tsx +170 -0
- package/lib/__templates__/nextjs/src/components/ui/input-otp.tsx +77 -0
- package/lib/__templates__/nextjs/src/components/ui/input.tsx +21 -0
- package/lib/__templates__/nextjs/src/components/ui/item.tsx +193 -0
- package/lib/__templates__/nextjs/src/components/ui/kbd.tsx +28 -0
- package/lib/__templates__/nextjs/src/components/ui/label.tsx +24 -0
- package/lib/__templates__/nextjs/src/components/ui/menubar.tsx +276 -0
- package/lib/__templates__/nextjs/src/components/ui/navigation-menu.tsx +168 -0
- package/lib/__templates__/nextjs/src/components/ui/pagination.tsx +127 -0
- package/lib/__templates__/nextjs/src/components/ui/popover.tsx +48 -0
- package/lib/__templates__/nextjs/src/components/ui/progress.tsx +31 -0
- package/lib/__templates__/nextjs/src/components/ui/radio-group.tsx +45 -0
- package/lib/__templates__/nextjs/src/components/ui/resizable.tsx +63 -0
- package/lib/__templates__/nextjs/src/components/ui/scroll-area.tsx +58 -0
- package/lib/__templates__/nextjs/src/components/ui/select.tsx +190 -0
- package/lib/__templates__/nextjs/src/components/ui/separator.tsx +28 -0
- package/lib/__templates__/nextjs/src/components/ui/sheet.tsx +139 -0
- package/lib/__templates__/nextjs/src/components/ui/sidebar.tsx +724 -0
- package/lib/__templates__/nextjs/src/components/ui/skeleton.tsx +13 -0
- package/lib/__templates__/nextjs/src/components/ui/slider.tsx +63 -0
- package/lib/__templates__/nextjs/src/components/ui/sonner.tsx +40 -0
- package/lib/__templates__/nextjs/src/components/ui/spinner.tsx +16 -0
- package/lib/__templates__/nextjs/src/components/ui/switch.tsx +31 -0
- package/lib/__templates__/nextjs/src/components/ui/table.tsx +116 -0
- package/lib/__templates__/nextjs/src/components/ui/tabs.tsx +66 -0
- package/lib/__templates__/nextjs/src/components/ui/textarea.tsx +18 -0
- package/lib/__templates__/nextjs/src/components/ui/toggle-group.tsx +83 -0
- package/lib/__templates__/nextjs/src/components/ui/toggle.tsx +47 -0
- package/lib/__templates__/nextjs/src/components/ui/tooltip.tsx +61 -0
- package/lib/__templates__/nextjs/src/hooks/use-mobile.ts +19 -0
- package/lib/__templates__/nextjs/src/lib/utils.ts +6 -0
- package/lib/__templates__/nextjs/src/server.ts +35 -0
- package/lib/__templates__/nextjs/template.config.js +120 -0
- package/lib/__templates__/nextjs/tsconfig.json +34 -0
- 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 +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 +40 -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 +237 -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 +162 -0
- package/lib/__templates__/vite/.coze +12 -0
- package/lib/__templates__/vite/README.md +418 -0
- package/lib/__templates__/vite/_gitignore +67 -0
- package/lib/__templates__/vite/_npmrc +23 -0
- package/lib/__templates__/vite/eslint.config.mjs +14 -0
- package/lib/__templates__/vite/index.html +13 -0
- package/lib/__templates__/vite/package.json +44 -0
- package/lib/__templates__/vite/pnpm-lock.yaml +3465 -0
- package/lib/__templates__/vite/postcss.config.js +6 -0
- package/lib/__templates__/vite/scripts/build.sh +17 -0
- package/lib/__templates__/vite/scripts/dev.sh +39 -0
- package/lib/__templates__/vite/scripts/prepare.sh +9 -0
- package/lib/__templates__/vite/scripts/start.sh +21 -0
- 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/index.css +21 -0
- package/lib/__templates__/vite/src/index.ts +5 -0
- package/lib/__templates__/vite/src/main.ts +34 -0
- package/lib/__templates__/vite/tailwind.config.js +9 -0
- package/lib/__templates__/vite/template.config.js +127 -0
- package/lib/__templates__/vite/tsconfig.json +17 -0
- package/lib/__templates__/vite/vite.config.ts +20 -0
- package/lib/cli.js +2631 -0
- package/package.json +81 -0
package/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# @coze-coding/cli
|
|
2
|
+
|
|
3
|
+
Coze Coding 的项目模板引擎,提供基于前端技术栈的项目初始化能力。
|
|
4
|
+
|
|
5
|
+
## 特性
|
|
6
|
+
|
|
7
|
+
- 🚀 **快速初始化**: 一键创建预配置的项目模板
|
|
8
|
+
- 🤖 **AI 优先设计**: 专为 AI Agent 消费设计,提供清晰的错误信息和自描述能力
|
|
9
|
+
- 📦 **多模板支持**: 支持 React、Next.js、HTML 等多种技术栈
|
|
10
|
+
- 🔧 **类型安全**: 基于 JSON Schema 的参数校验和 TypeScript 类型生成
|
|
11
|
+
- ⚡ **命令代理**: 统一的 dev/build/start 命令,抹平不同技术栈差异
|
|
12
|
+
|
|
13
|
+
## 安装
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
rush update
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## 使用
|
|
21
|
+
|
|
22
|
+
### 初始化项目
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
coze-coding init --template react --app-name my-app --use-typescript --use-tailwind
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### 查看可用模板
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
coze-coding init --help
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 开发命令
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# 启动开发服务器
|
|
38
|
+
coze-coding dev
|
|
39
|
+
|
|
40
|
+
# 构建生产版本
|
|
41
|
+
coze-coding build
|
|
42
|
+
|
|
43
|
+
# 启动生产服务器
|
|
44
|
+
coze-coding start
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 模板参数
|
|
48
|
+
|
|
49
|
+
每个模板都有自己的参数配置,通过 CLI 参数透传。参数名使用 kebab-case 格式,会自动转换为 camelCase 传入模板配置。
|
|
50
|
+
|
|
51
|
+
例如:
|
|
52
|
+
- `--app-name` → `appName`
|
|
53
|
+
- `--use-typescript` → `useTypeScript`
|
|
54
|
+
- `--port` → `port`
|
|
55
|
+
|
|
56
|
+
## 开发模板
|
|
57
|
+
|
|
58
|
+
### 模板结构
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
template-name/
|
|
62
|
+
├── template.config.ts # 模板配置(开发时)
|
|
63
|
+
├── template.config.js # 模板配置(生产时)
|
|
64
|
+
├── .coze # 项目配置文件
|
|
65
|
+
└── src/ # 源代码(支持 EJS 模板)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### 参数定义
|
|
69
|
+
|
|
70
|
+
使用 JSON Schema 定义模板参数:
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
import type { JSONSchemaType } from 'ajv';
|
|
74
|
+
|
|
75
|
+
export interface TemplateParams {
|
|
76
|
+
appName: string;
|
|
77
|
+
useTypeScript: boolean;
|
|
78
|
+
port: number;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const paramsSchema: JSONSchemaType<TemplateParams> = {
|
|
82
|
+
type: 'object',
|
|
83
|
+
properties: {
|
|
84
|
+
appName: {
|
|
85
|
+
type: 'string',
|
|
86
|
+
minLength: 1,
|
|
87
|
+
pattern: '^[a-z0-9-]+$',
|
|
88
|
+
cliParam: '--app-name',
|
|
89
|
+
description: 'Application name'
|
|
90
|
+
},
|
|
91
|
+
useTypeScript: {
|
|
92
|
+
type: 'boolean',
|
|
93
|
+
default: true,
|
|
94
|
+
cliParam: '--use-typescript',
|
|
95
|
+
description: 'Enable TypeScript'
|
|
96
|
+
},
|
|
97
|
+
port: {
|
|
98
|
+
type: 'number',
|
|
99
|
+
default: 3000,
|
|
100
|
+
minimum: 1024,
|
|
101
|
+
maximum: 65535,
|
|
102
|
+
cliParam: '--port',
|
|
103
|
+
description: 'Development server port'
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
required: ['appName'],
|
|
107
|
+
additionalProperties: false
|
|
108
|
+
};
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 生命周期钩子
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
export const onBeforeRender = (context) => {
|
|
115
|
+
// 渲染前处理
|
|
116
|
+
return context;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export const onAfterRender = (context, outputPath) => {
|
|
120
|
+
// 渲染后处理
|
|
121
|
+
};
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## 编码规范
|
|
125
|
+
|
|
126
|
+
本项目严格遵循函数式编程风格:
|
|
127
|
+
|
|
128
|
+
- ✅ 使用纯函数和不可变数据
|
|
129
|
+
- ✅ 函数组合和高阶函数
|
|
130
|
+
- ✅ 使用工厂函数和闭包
|
|
131
|
+
- ❌ 禁止使用 class
|
|
132
|
+
- ❌ 避免副作用和可变状态
|
|
133
|
+
|
|
134
|
+
详见 [技术设计文档](./docs/technical-design.md#7-编码规范)
|
|
135
|
+
|
|
136
|
+
## 文档
|
|
137
|
+
|
|
138
|
+
- [需求文档](./docs/requirement.md)
|
|
139
|
+
- [技术设计](./docs/technical-design.md)
|
|
140
|
+
|
|
141
|
+
## 许可证
|
|
142
|
+
|
|
143
|
+
内部项目
|
package/bin/main
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
entrypoint = "server.js"
|
|
3
|
+
requires = ["nodejs-24"]
|
|
4
|
+
|
|
5
|
+
[dev]
|
|
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,229 @@
|
|
|
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_CLIENT_FILE="$LOG_DIR/client.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
|
+
EXPO_PUBLIC_COZE_PROJECT_ID="${COZE_PROJECT_ID:-}"
|
|
19
|
+
|
|
20
|
+
EXPO_PACKAGER_PROXY_URL="${EXPO_PUBLIC_BACKEND_BASE_URL}"
|
|
21
|
+
export EXPO_PUBLIC_BACKEND_BASE_URL EXPO_PACKAGER_PROXY_URL EXPO_PUBLIC_COZE_PROJECT_ID
|
|
22
|
+
# 运行时变量(为避免 set -u 的未绑定错误,预置为空)
|
|
23
|
+
SERVER_PID=""
|
|
24
|
+
EXPO_PID=""
|
|
25
|
+
|
|
26
|
+
# ==================== 工具函数 ====================
|
|
27
|
+
check_command() {
|
|
28
|
+
if ! command -v "$1" &> /dev/null; then
|
|
29
|
+
echo "error:命令 $1 未找到,请先安装"
|
|
30
|
+
fi
|
|
31
|
+
}
|
|
32
|
+
while [ $# -gt 0 ]; do
|
|
33
|
+
case "$1" in
|
|
34
|
+
-y|--yes)
|
|
35
|
+
ASSUME_YES="1"
|
|
36
|
+
shift
|
|
37
|
+
;;
|
|
38
|
+
*)
|
|
39
|
+
shift
|
|
40
|
+
;;
|
|
41
|
+
esac
|
|
42
|
+
done
|
|
43
|
+
is_port_free() {
|
|
44
|
+
! lsof -iTCP:"$1" -sTCP:LISTEN >/dev/null 2>&1
|
|
45
|
+
}
|
|
46
|
+
choose_next_free_port() {
|
|
47
|
+
local start=$1
|
|
48
|
+
local p=$start
|
|
49
|
+
while ! is_port_free "$p"; do
|
|
50
|
+
p=$((p+1))
|
|
51
|
+
done
|
|
52
|
+
echo "$p"
|
|
53
|
+
}
|
|
54
|
+
ensure_port() {
|
|
55
|
+
local var_name=$1
|
|
56
|
+
local port_val=$2
|
|
57
|
+
if is_port_free "$port_val"; then
|
|
58
|
+
echo "端口未占用:$port_val"
|
|
59
|
+
eval "$var_name=$port_val"
|
|
60
|
+
else
|
|
61
|
+
echo "端口已占用:$port_val"
|
|
62
|
+
local choice
|
|
63
|
+
if [ "$ASSUME_YES" = "1" ]; then choice="Y"; else read -r -p "是否关闭该端口的进程?[Y/n] " choice || choice="Y"; fi
|
|
64
|
+
if [ -z "$choice" ] || [ "$choice" = "y" ] || [ "$choice" = "Y" ]; then
|
|
65
|
+
if command -v lsof &> /dev/null; then
|
|
66
|
+
local pids
|
|
67
|
+
pids=$(lsof -t -i tcp:"$port_val" -sTCP:LISTEN 2>/dev/null || true)
|
|
68
|
+
if [ -n "$pids" ]; then
|
|
69
|
+
echo "正在关闭进程:$pids"
|
|
70
|
+
kill -9 $pids 2>/dev/null || echo "关闭进程失败:$pids"
|
|
71
|
+
eval "$var_name=$port_val"
|
|
72
|
+
else
|
|
73
|
+
echo "未获取到占用该端口的进程"
|
|
74
|
+
eval "$var_name=$port_val"
|
|
75
|
+
fi
|
|
76
|
+
else
|
|
77
|
+
echo "缺少 lsof,无法自动关闭进程"
|
|
78
|
+
eval "$var_name=$port_val"
|
|
79
|
+
fi
|
|
80
|
+
else
|
|
81
|
+
local new_port
|
|
82
|
+
new_port=$(choose_next_free_port "$port_val")
|
|
83
|
+
info "使用新的端口:$new_port"
|
|
84
|
+
eval "$var_name=$new_port"
|
|
85
|
+
fi
|
|
86
|
+
fi
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
pipe_to_log() {
|
|
90
|
+
local source="${1:-CLIENT}"
|
|
91
|
+
local raw_log="${2:-}"
|
|
92
|
+
local line clean_line timestamp
|
|
93
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
94
|
+
clean_line=$(printf '%s' "$line" | sed 's/\x1b\[[0-9;]*[mA-Za-z]//g')
|
|
95
|
+
if echo "$clean_line" | grep -qE '(^(Web|iOS|Android) node_modules/.*expo-router.*entry\.js.*%|^(Web|iOS|Android) Bundled [0-9]+ms node_modules/.*expo-router.*entry\.js|Logs will appear in the browser)'; then
|
|
96
|
+
continue
|
|
97
|
+
fi
|
|
98
|
+
if [ -n "$raw_log" ]; then
|
|
99
|
+
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
|
100
|
+
echo "[$timestamp] $clean_line" >> "$raw_log"
|
|
101
|
+
fi
|
|
102
|
+
printf '[%s] %s\n' "$source" "$clean_line"
|
|
103
|
+
done
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
wait_port_connectable() {
|
|
107
|
+
local host=$1 port=$2 retries=${3:-10}
|
|
108
|
+
for _ in $(seq 1 "$retries"); do
|
|
109
|
+
nc -z -w 1 "$host" "$port" >/dev/null 2>&1 && return 0
|
|
110
|
+
sleep 1
|
|
111
|
+
done
|
|
112
|
+
return 1
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
start_expo() {
|
|
116
|
+
local offline="${1:-0}"
|
|
117
|
+
|
|
118
|
+
pushd "$ROOT_DIR/client"
|
|
119
|
+
|
|
120
|
+
if [ "$offline" = "1" ]; then
|
|
121
|
+
( EXPO_OFFLINE=1 EXPO_NO_DEPENDENCY_VALIDATION=1 EXPO_PUBLIC_BACKEND_BASE_URL="$EXPO_PUBLIC_BACKEND_BASE_URL" EXPO_PACKAGER_PROXY_URL="$EXPO_PACKAGER_PROXY_URL" EXPO_PUBLIC_COZE_PROJECT_ID="$EXPO_PUBLIC_COZE_PROJECT_ID" \
|
|
122
|
+
nohup npx expo start --clear --port "$EXPO_PORT" 2>&1 | pipe_to_log "CLIENT" "$LOG_CLIENT_FILE" ) &
|
|
123
|
+
else
|
|
124
|
+
( EXPO_NO_DEPENDENCY_VALIDATION=1 EXPO_PUBLIC_BACKEND_BASE_URL="$EXPO_PUBLIC_BACKEND_BASE_URL" EXPO_PACKAGER_PROXY_URL="$EXPO_PACKAGER_PROXY_URL" EXPO_PUBLIC_COZE_PROJECT_ID="$EXPO_PUBLIC_COZE_PROJECT_ID" \
|
|
125
|
+
nohup npx expo start --clear --port "$EXPO_PORT" 2>&1 | pipe_to_log "CLIENT" "$LOG_CLIENT_FILE" ) &
|
|
126
|
+
fi
|
|
127
|
+
EXPO_PID=$!
|
|
128
|
+
disown $EXPO_PID 2>/dev/null || true
|
|
129
|
+
|
|
130
|
+
popd
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
detect_expo_fetch_failed() {
|
|
134
|
+
local timeout="${1:-8}"
|
|
135
|
+
local waited=0
|
|
136
|
+
local log_file="$LOG_CLIENT_FILE"
|
|
137
|
+
while [ "$waited" -lt "$timeout" ]; do
|
|
138
|
+
if [ -f "$log_file" ] && tail -n 100 "$log_file" 2>/dev/null | grep -q "TypeError: fetch failed"; then
|
|
139
|
+
return 0
|
|
140
|
+
fi
|
|
141
|
+
sleep 1
|
|
142
|
+
waited=$((waited+1))
|
|
143
|
+
done
|
|
144
|
+
return 1
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
# ==================== 前置检查 ====================
|
|
148
|
+
# 关掉nginx进程
|
|
149
|
+
ps -ef | grep nginx | grep -v grep | awk '{print $2}' | xargs -r kill -9
|
|
150
|
+
|
|
151
|
+
echo "检查根目录 pre_install.py"
|
|
152
|
+
if [ -f "$PREVIEW_DIR/pre_install.py" ]; then
|
|
153
|
+
echo "执行:python $PREVIEW_DIR/pre_install.py"
|
|
154
|
+
python "$PREVIEW_DIR/pre_install.py" || echo "pre_install.py 执行失败"
|
|
155
|
+
fi
|
|
156
|
+
|
|
157
|
+
echo "检查根目录 post_install.py"
|
|
158
|
+
if [ -f "$PREVIEW_DIR/post_install.py" ]; then
|
|
159
|
+
echo "执行:python $PREVIEW_DIR/post_install.py"
|
|
160
|
+
python "$PREVIEW_DIR/post_install.py" || echo "post_install.py 执行失败"
|
|
161
|
+
fi
|
|
162
|
+
|
|
163
|
+
echo "==================== 开始启动 ===================="
|
|
164
|
+
echo "开始执行服务启动脚本(start_dev.sh)..."
|
|
165
|
+
echo "正在检查依赖命令和目录是否存在..."
|
|
166
|
+
# 检查核心命令
|
|
167
|
+
check_command "npm"
|
|
168
|
+
check_command "pnpm"
|
|
169
|
+
check_command "lsof"
|
|
170
|
+
check_command "bash"
|
|
171
|
+
|
|
172
|
+
# 端口占用预检查与处理
|
|
173
|
+
ensure_port SERVER_PORT "$SERVER_PORT"
|
|
174
|
+
ensure_port EXPO_PORT "$EXPO_PORT"
|
|
175
|
+
|
|
176
|
+
echo "==================== 启动 server 服务 ===================="
|
|
177
|
+
echo "正在执行:pnpm run dev (server)"
|
|
178
|
+
( pushd "$ROOT_DIR/server" > /dev/null && SERVER_PORT="$SERVER_PORT" nohup pnpm run dev; popd > /dev/null ) &
|
|
179
|
+
SERVER_PID=$!
|
|
180
|
+
disown $SERVER_PID 2>/dev/null || true
|
|
181
|
+
if [ -z "${SERVER_PID}" ]; then
|
|
182
|
+
echo "无法获取 server 后台进程 PID"
|
|
183
|
+
fi
|
|
184
|
+
echo "server 服务已启动,进程 ID:${SERVER_PID:-unknown}"
|
|
185
|
+
|
|
186
|
+
echo "==================== 启动 Expo 项目 ===================="
|
|
187
|
+
echo "开始启动 Expo 服务,端口 ${EXPO_PORT}"
|
|
188
|
+
start_expo 0
|
|
189
|
+
if detect_expo_fetch_failed 8; then
|
|
190
|
+
echo "Expo 启动检测到网络错误:TypeError: fetch failed,启用离线模式重试"
|
|
191
|
+
if [ -n "${EXPO_PID}" ]; then kill -9 "$EXPO_PID" 2>/dev/null || true; fi
|
|
192
|
+
: > "$ROOT_DIR/logs/client.log"
|
|
193
|
+
start_expo 1
|
|
194
|
+
fi
|
|
195
|
+
# 输出以下环境变量,确保 Expo 项目能正确连接到 Server 服务
|
|
196
|
+
echo "Expo 环境变量配置:"
|
|
197
|
+
echo "EXPO_PUBLIC_BACKEND_BASE_URL=${EXPO_PUBLIC_BACKEND_BASE_URL}"
|
|
198
|
+
echo "EXPO_PACKAGER_PROXY_URL=${EXPO_PACKAGER_PROXY_URL}"
|
|
199
|
+
echo "EXPO_PUBLIC_COZE_PROJECT_ID=${EXPO_PUBLIC_COZE_PROJECT_ID}"
|
|
200
|
+
if [ -z "${EXPO_PID}" ]; then
|
|
201
|
+
echo "无法获取 Expo 后台进程 PID"
|
|
202
|
+
fi
|
|
203
|
+
|
|
204
|
+
echo "所有服务已启动。Server PID: ${SERVER_PID}, Expo PID: ${EXPO_PID}"
|
|
205
|
+
|
|
206
|
+
echo "检查 Server 服务端口:$SERVER_HOST:$SERVER_PORT"
|
|
207
|
+
if wait_port_connectable "$SERVER_HOST" "$SERVER_PORT" 10 2; then
|
|
208
|
+
echo "端口可连接:$SERVER_HOST:$SERVER_PORT"
|
|
209
|
+
else
|
|
210
|
+
echo "端口不可连接:$SERVER_HOST:$SERVER_PORT 10 次)"
|
|
211
|
+
fi
|
|
212
|
+
|
|
213
|
+
echo "检查 Expo 服务端口:$EXPO_HOST:$EXPO_PORT"
|
|
214
|
+
if wait_port_connectable "$EXPO_HOST" "$EXPO_PORT" 10 2; then
|
|
215
|
+
echo "端口可连接:$EXPO_HOST:$EXPO_PORT"
|
|
216
|
+
else
|
|
217
|
+
echo "端口不可连接:$EXPO_HOST:$EXPO_PORT(已尝试 10 次)"
|
|
218
|
+
fi
|
|
219
|
+
|
|
220
|
+
echo "服务端口检查完成"
|
|
221
|
+
|
|
222
|
+
echo "检查根目录 post_run.py"
|
|
223
|
+
if [ -f "$ROOT_DIR/post_run.py" ]; then
|
|
224
|
+
echo "启动检查中"
|
|
225
|
+
python "$ROOT_DIR/post_run.py" --port "$EXPO_PORT" || echo "post_run.py 执行失败"
|
|
226
|
+
echo "启动检查结束"
|
|
227
|
+
fi
|
|
228
|
+
|
|
229
|
+
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 (server)"
|
|
44
|
+
(pushd "$ROOT_DIR/server" > /dev/null && pnpm run build; popd > /dev/null) || 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 (server)"
|
|
33
|
+
(pushd "$ROOT_DIR/server" > /dev/null && PORT="$PORT" pnpm run start; popd > /dev/null) || error "服务启动失败"
|
|
34
|
+
info "服务启动完成!\n"
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
ROOT_DIR="$(cd "$(dirname "$0")/../.." && pwd)"
|
|
4
|
+
SERVER_DIR="$ROOT_DIR/server"
|
|
5
|
+
LOG_DIR="${COZE_LOG_DIR:-$ROOT_DIR/logs}"
|
|
6
|
+
LOG_SERVER_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 clean_line timestamp
|
|
15
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
|
16
|
+
clean_line=$(printf '%s' "$line" | sed 's/\x1b\[[0-9;]*[mA-Za-z]//g')
|
|
17
|
+
if [ -n "$raw_log" ]; then
|
|
18
|
+
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
|
19
|
+
echo "[$timestamp] $clean_line" >> "$raw_log"
|
|
20
|
+
fi
|
|
21
|
+
printf '[%s] %s\n' "$source" "$clean_line"
|
|
22
|
+
done
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
kill_old_server() {
|
|
26
|
+
if command -v lsof &> /dev/null; then
|
|
27
|
+
local pids
|
|
28
|
+
pids=$(lsof -t -i tcp:"$SERVER_PORT" -sTCP:LISTEN 2>/dev/null || true)
|
|
29
|
+
if [ -n "$pids" ]; then
|
|
30
|
+
echo "正在关闭旧的 server 进程:$pids"
|
|
31
|
+
kill -9 $pids 2>/dev/null || echo "关闭进程失败:$pids"
|
|
32
|
+
sleep 1
|
|
33
|
+
fi
|
|
34
|
+
fi
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
echo "==================== Server Dev Run ===================="
|
|
38
|
+
echo "Server 目录:$SERVER_DIR"
|
|
39
|
+
echo "Server 端口:$SERVER_PORT"
|
|
40
|
+
echo "日志文件:$LOG_SERVER_FILE"
|
|
41
|
+
|
|
42
|
+
kill_old_server
|
|
43
|
+
|
|
44
|
+
echo "启动 server 服务..."
|
|
45
|
+
cd "$SERVER_DIR"
|
|
46
|
+
NODE_ENV=development PORT="$SERVER_PORT" npx tsx watch ./src/index.ts 2>&1 | pipe_to_log "SERVER" "$LOG_SERVER_FILE"
|
|
@@ -0,0 +1,74 @@
|
|
|
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
|
+
│ │ └── demo/ # demo 示例页面
|
|
23
|
+
│ │ ├── index.tsx # 页面组件实现
|
|
24
|
+
│ │ └── styles.ts # 页面样式
|
|
25
|
+
│ ├── components/ # 可复用组件
|
|
26
|
+
│ │ └── Screen.tsx # 页面容器组件(必用)
|
|
27
|
+
│ ├── hooks/ # 自定义 Hooks
|
|
28
|
+
│ ├── contexts/ # React Context 代码
|
|
29
|
+
│ ├── constants/ # 常量定义(如主题配置)
|
|
30
|
+
│ ├── utils/ # 工具函数
|
|
31
|
+
│ ├── assets/ # 静态资源
|
|
32
|
+
| └── package.json # Expo 应用 package.json
|
|
33
|
+
├── package.json
|
|
34
|
+
├── .cozeproj # 预置脚手架脚本(禁止修改)
|
|
35
|
+
└── .coze # 配置文件(禁止修改)
|
|
36
|
+
|
|
37
|
+
## 安装依赖
|
|
38
|
+
|
|
39
|
+
### 命令
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
pnpm i
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### 新增依赖约束
|
|
46
|
+
|
|
47
|
+
如果需要新增依赖,需在 client 和 server 各自的目录添加(原因:隔离前后端的依赖),禁止在根目录直接安装依赖
|
|
48
|
+
|
|
49
|
+
### 新增依赖标准流程
|
|
50
|
+
|
|
51
|
+
- 编辑 `client/package.json` 或 `server/package.json`
|
|
52
|
+
- 在根目录执行 `pnpm i`
|
|
53
|
+
|
|
54
|
+
## Expo 开发规范
|
|
55
|
+
|
|
56
|
+
### 路径别名
|
|
57
|
+
|
|
58
|
+
Expo 配置了 `@/` 路径别名指向 `client/` 目录:
|
|
59
|
+
|
|
60
|
+
```tsx
|
|
61
|
+
// 正确
|
|
62
|
+
import { Screen } from '@/components/Screen';
|
|
63
|
+
|
|
64
|
+
// 避免相对路径
|
|
65
|
+
import { Screen } from '../../../components/Screen';
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 本地开发
|
|
69
|
+
|
|
70
|
+
运行 coze dev 可以同时启动前端和后端服务,如果端口已占用,该命令会先杀掉占用端口的进程再启动,也可以用来重启前端和后端服务
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
coze dev
|
|
74
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
registry=https://registry.npmmirror.com
|
|
2
|
+
|
|
3
|
+
strictStorePkgContentCheck=false
|
|
4
|
+
verifyStoreIntegrity=false
|
|
5
|
+
|
|
6
|
+
# 网络优化
|
|
7
|
+
network-concurrency=16
|
|
8
|
+
fetch-retries=3
|
|
9
|
+
fetch-timeout=60000
|
|
10
|
+
|
|
11
|
+
# peerDependencies
|
|
12
|
+
strict-peer-dependencies=false
|
|
13
|
+
auto-install-peers=true
|
|
14
|
+
|
|
15
|
+
# lockfile 配置
|
|
16
|
+
lockfile=true
|
|
17
|
+
prefer-frozen-lockfile=true
|
|
18
|
+
|
|
19
|
+
# semver 选择最高版本
|
|
20
|
+
resolution-mode=highest
|