@coze-arch/cli 0.0.1-alpha.035e0e

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 (156) hide show
  1. package/README.md +142 -0
  2. package/bin/main +2 -0
  3. package/lib/__templates__/expo/.coze +12 -0
  4. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +46 -0
  5. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +220 -0
  6. package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +47 -0
  7. package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +34 -0
  8. package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +45 -0
  9. package/lib/__templates__/expo/README.md +72 -0
  10. package/lib/__templates__/expo/_gitignore +11 -0
  11. package/lib/__templates__/expo/_npmrc +20 -0
  12. package/lib/__templates__/expo/client/app/_layout.tsx +33 -0
  13. package/lib/__templates__/expo/client/app/demo.tsx +1 -0
  14. package/lib/__templates__/expo/client/app/index.tsx +1 -0
  15. package/lib/__templates__/expo/client/app.config.ts +75 -0
  16. package/lib/__templates__/expo/client/assets/fonts/SpaceMono-Regular.ttf +0 -0
  17. package/lib/__templates__/expo/client/assets/images/adaptive-icon.png +0 -0
  18. package/lib/__templates__/expo/client/assets/images/default-avatar.png +0 -0
  19. package/lib/__templates__/expo/client/assets/images/favicon.png +0 -0
  20. package/lib/__templates__/expo/client/assets/images/icon.png +0 -0
  21. package/lib/__templates__/expo/client/assets/images/partial-react-logo.png +0 -0
  22. package/lib/__templates__/expo/client/assets/images/react-logo.png +0 -0
  23. package/lib/__templates__/expo/client/assets/images/react-logo@2x.png +0 -0
  24. package/lib/__templates__/expo/client/assets/images/react-logo@3x.png +0 -0
  25. package/lib/__templates__/expo/client/assets/images/splash-icon.png +0 -0
  26. package/lib/__templates__/expo/client/components/Screen.tsx +330 -0
  27. package/lib/__templates__/expo/client/components/SmartDateInput.tsx +238 -0
  28. package/lib/__templates__/expo/client/components/ThemedText.tsx +33 -0
  29. package/lib/__templates__/expo/client/components/ThemedView.tsx +38 -0
  30. package/lib/__templates__/expo/client/constants/theme.ts +854 -0
  31. package/lib/__templates__/expo/client/contexts/AuthContext.tsx +49 -0
  32. package/lib/__templates__/expo/client/declarations.d.ts +5 -0
  33. package/lib/__templates__/expo/client/eslint-formatter-simple.mjs +49 -0
  34. package/lib/__templates__/expo/client/eslint.config.mjs +98 -0
  35. package/lib/__templates__/expo/client/hooks/useColorScheme.ts +34 -0
  36. package/lib/__templates__/expo/client/hooks/useTheme.ts +13 -0
  37. package/lib/__templates__/expo/client/metro.config.js +121 -0
  38. package/lib/__templates__/expo/client/package.json +93 -0
  39. package/lib/__templates__/expo/client/screens/demo/index.tsx +25 -0
  40. package/lib/__templates__/expo/client/screens/demo/styles.ts +28 -0
  41. package/lib/__templates__/expo/client/scripts/install-missing-deps.js +104 -0
  42. package/lib/__templates__/expo/client/tsconfig.json +24 -0
  43. package/lib/__templates__/expo/client/utils/index.ts +54 -0
  44. package/lib/__templates__/expo/package.json +22 -0
  45. package/lib/__templates__/expo/pnpm-lock.yaml +13975 -0
  46. package/lib/__templates__/expo/pnpm-workspace.yaml +3 -0
  47. package/lib/__templates__/expo/server/package.json +32 -0
  48. package/lib/__templates__/expo/server/src/index.ts +18 -0
  49. package/lib/__templates__/expo/server/tsconfig.json +24 -0
  50. package/lib/__templates__/expo/template.config.js +50 -0
  51. package/lib/__templates__/expo/tsconfig.json +1 -0
  52. package/lib/__templates__/nextjs/.coze +12 -0
  53. package/lib/__templates__/nextjs/README.md +358 -0
  54. package/lib/__templates__/nextjs/_gitignore +99 -0
  55. package/lib/__templates__/nextjs/_npmrc +23 -0
  56. package/lib/__templates__/nextjs/components.json +21 -0
  57. package/lib/__templates__/nextjs/eslint.config.mjs +18 -0
  58. package/lib/__templates__/nextjs/next-env.d.ts +6 -0
  59. package/lib/__templates__/nextjs/next.config.ts +19 -0
  60. package/lib/__templates__/nextjs/package.json +86 -0
  61. package/lib/__templates__/nextjs/pnpm-lock.yaml +10493 -0
  62. package/lib/__templates__/nextjs/postcss.config.mjs +7 -0
  63. package/lib/__templates__/nextjs/public/file.svg +1 -0
  64. package/lib/__templates__/nextjs/public/globe.svg +1 -0
  65. package/lib/__templates__/nextjs/public/next.svg +1 -0
  66. package/lib/__templates__/nextjs/public/vercel.svg +1 -0
  67. package/lib/__templates__/nextjs/public/window.svg +1 -0
  68. package/lib/__templates__/nextjs/scripts/build.sh +14 -0
  69. package/lib/__templates__/nextjs/scripts/dev.sh +33 -0
  70. package/lib/__templates__/nextjs/scripts/prepare.sh +9 -0
  71. package/lib/__templates__/nextjs/scripts/start.sh +15 -0
  72. package/lib/__templates__/nextjs/src/app/favicon.ico +0 -0
  73. package/lib/__templates__/nextjs/src/app/globals.css +137 -0
  74. package/lib/__templates__/nextjs/src/app/layout.tsx +72 -0
  75. package/lib/__templates__/nextjs/src/app/page.tsx +78 -0
  76. package/lib/__templates__/nextjs/src/app/robots.ts +11 -0
  77. package/lib/__templates__/nextjs/src/components/ui/accordion.tsx +66 -0
  78. package/lib/__templates__/nextjs/src/components/ui/alert-dialog.tsx +157 -0
  79. package/lib/__templates__/nextjs/src/components/ui/alert.tsx +66 -0
  80. package/lib/__templates__/nextjs/src/components/ui/aspect-ratio.tsx +11 -0
  81. package/lib/__templates__/nextjs/src/components/ui/avatar.tsx +53 -0
  82. package/lib/__templates__/nextjs/src/components/ui/badge.tsx +46 -0
  83. package/lib/__templates__/nextjs/src/components/ui/breadcrumb.tsx +109 -0
  84. package/lib/__templates__/nextjs/src/components/ui/button-group.tsx +83 -0
  85. package/lib/__templates__/nextjs/src/components/ui/button.tsx +62 -0
  86. package/lib/__templates__/nextjs/src/components/ui/calendar.tsx +220 -0
  87. package/lib/__templates__/nextjs/src/components/ui/card.tsx +92 -0
  88. package/lib/__templates__/nextjs/src/components/ui/carousel.tsx +241 -0
  89. package/lib/__templates__/nextjs/src/components/ui/chart.tsx +357 -0
  90. package/lib/__templates__/nextjs/src/components/ui/checkbox.tsx +32 -0
  91. package/lib/__templates__/nextjs/src/components/ui/collapsible.tsx +33 -0
  92. package/lib/__templates__/nextjs/src/components/ui/command.tsx +184 -0
  93. package/lib/__templates__/nextjs/src/components/ui/context-menu.tsx +252 -0
  94. package/lib/__templates__/nextjs/src/components/ui/dialog.tsx +143 -0
  95. package/lib/__templates__/nextjs/src/components/ui/drawer.tsx +135 -0
  96. package/lib/__templates__/nextjs/src/components/ui/dropdown-menu.tsx +257 -0
  97. package/lib/__templates__/nextjs/src/components/ui/empty.tsx +104 -0
  98. package/lib/__templates__/nextjs/src/components/ui/field.tsx +248 -0
  99. package/lib/__templates__/nextjs/src/components/ui/form.tsx +167 -0
  100. package/lib/__templates__/nextjs/src/components/ui/hover-card.tsx +44 -0
  101. package/lib/__templates__/nextjs/src/components/ui/input-group.tsx +170 -0
  102. package/lib/__templates__/nextjs/src/components/ui/input-otp.tsx +77 -0
  103. package/lib/__templates__/nextjs/src/components/ui/input.tsx +21 -0
  104. package/lib/__templates__/nextjs/src/components/ui/item.tsx +193 -0
  105. package/lib/__templates__/nextjs/src/components/ui/kbd.tsx +28 -0
  106. package/lib/__templates__/nextjs/src/components/ui/label.tsx +24 -0
  107. package/lib/__templates__/nextjs/src/components/ui/menubar.tsx +276 -0
  108. package/lib/__templates__/nextjs/src/components/ui/navigation-menu.tsx +168 -0
  109. package/lib/__templates__/nextjs/src/components/ui/pagination.tsx +127 -0
  110. package/lib/__templates__/nextjs/src/components/ui/popover.tsx +48 -0
  111. package/lib/__templates__/nextjs/src/components/ui/progress.tsx +31 -0
  112. package/lib/__templates__/nextjs/src/components/ui/radio-group.tsx +45 -0
  113. package/lib/__templates__/nextjs/src/components/ui/resizable.tsx +63 -0
  114. package/lib/__templates__/nextjs/src/components/ui/scroll-area.tsx +58 -0
  115. package/lib/__templates__/nextjs/src/components/ui/select.tsx +190 -0
  116. package/lib/__templates__/nextjs/src/components/ui/separator.tsx +28 -0
  117. package/lib/__templates__/nextjs/src/components/ui/sheet.tsx +139 -0
  118. package/lib/__templates__/nextjs/src/components/ui/sidebar.tsx +724 -0
  119. package/lib/__templates__/nextjs/src/components/ui/skeleton.tsx +13 -0
  120. package/lib/__templates__/nextjs/src/components/ui/slider.tsx +63 -0
  121. package/lib/__templates__/nextjs/src/components/ui/sonner.tsx +40 -0
  122. package/lib/__templates__/nextjs/src/components/ui/spinner.tsx +16 -0
  123. package/lib/__templates__/nextjs/src/components/ui/switch.tsx +31 -0
  124. package/lib/__templates__/nextjs/src/components/ui/table.tsx +116 -0
  125. package/lib/__templates__/nextjs/src/components/ui/tabs.tsx +66 -0
  126. package/lib/__templates__/nextjs/src/components/ui/textarea.tsx +18 -0
  127. package/lib/__templates__/nextjs/src/components/ui/toggle-group.tsx +83 -0
  128. package/lib/__templates__/nextjs/src/components/ui/toggle.tsx +47 -0
  129. package/lib/__templates__/nextjs/src/components/ui/tooltip.tsx +61 -0
  130. package/lib/__templates__/nextjs/src/hooks/use-mobile.ts +19 -0
  131. package/lib/__templates__/nextjs/src/lib/utils.ts +6 -0
  132. package/lib/__templates__/nextjs/template.config.js +85 -0
  133. package/lib/__templates__/nextjs/tsconfig.json +34 -0
  134. package/lib/__templates__/templates.json +87 -0
  135. package/lib/__templates__/vite/.coze +12 -0
  136. package/lib/__templates__/vite/README.md +239 -0
  137. package/lib/__templates__/vite/_gitignore +66 -0
  138. package/lib/__templates__/vite/_npmrc +23 -0
  139. package/lib/__templates__/vite/eslint.config.mjs +9 -0
  140. package/lib/__templates__/vite/index.html +13 -0
  141. package/lib/__templates__/vite/package.json +28 -0
  142. package/lib/__templates__/vite/pnpm-lock.yaml +4716 -0
  143. package/lib/__templates__/vite/postcss.config.js +6 -0
  144. package/lib/__templates__/vite/scripts/build.sh +14 -0
  145. package/lib/__templates__/vite/scripts/dev.sh +32 -0
  146. package/lib/__templates__/vite/scripts/prepare.sh +9 -0
  147. package/lib/__templates__/vite/scripts/start.sh +15 -0
  148. package/lib/__templates__/vite/src/index.css +21 -0
  149. package/lib/__templates__/vite/src/index.ts +5 -0
  150. package/lib/__templates__/vite/src/main.ts +64 -0
  151. package/lib/__templates__/vite/tailwind.config.js +9 -0
  152. package/lib/__templates__/vite/template.config.js +90 -0
  153. package/lib/__templates__/vite/tsconfig.json +16 -0
  154. package/lib/__templates__/vite/vite.config.ts +15 -0
  155. package/lib/cli.js +1916 -0
  156. package/package.json +77 -0
@@ -0,0 +1,49 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * 通用认证上下文
4
+ *
5
+ * 基于固定的 API 接口实现,可复用到其他项目
6
+ * 其他项目使用时,只需修改 @api 的导入路径指向项目的 api 模块
7
+ *
8
+ * 注意:
9
+ * - 如果需要登录/鉴权场景,请扩展本文件,完善 login/logout、token 管理、用户信息获取与刷新等逻辑
10
+ * - 将示例中的占位实现替换为项目实际的接口调用与状态管理
11
+ */
12
+ import React, { createContext, useContext, ReactNode } from "react";
13
+
14
+ interface UserOut {
15
+
16
+ }
17
+
18
+ interface AuthContextType {
19
+ user: UserOut | null;
20
+ token: string | null;
21
+ isAuthenticated: boolean;
22
+ isLoading: boolean;
23
+ login: (token: string) => Promise<void>;
24
+ logout: () => Promise<void>;
25
+ updateUser: (userData: Partial<UserOut>) => void;
26
+ }
27
+
28
+ const AuthContext = createContext<AuthContextType | undefined>(undefined);
29
+
30
+ export const AuthProvider: React.FC<{ children: ReactNode }> = ({ children }) => {
31
+ const value: AuthContextType = {
32
+ user: null,
33
+ token: null,
34
+ isAuthenticated: false,
35
+ isLoading: false,
36
+ login: async (token: string) => {},
37
+ logout: async () => {},
38
+ updateUser: () => {},
39
+ };
40
+ return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
41
+ };
42
+
43
+ export const useAuth = (): AuthContextType => {
44
+ const context = useContext(AuthContext);
45
+ if (context === undefined) {
46
+ throw new Error("useAuth must be used within an AuthProvider");
47
+ }
48
+ return context;
49
+ };
@@ -0,0 +1,5 @@
1
+ // declarations.d.ts
2
+
3
+ declare module 'expo-file-system/legacy' {
4
+ export * from 'expo-file-system';
5
+ }
@@ -0,0 +1,49 @@
1
+ export default function (results) {
2
+
3
+ return results
4
+ .flatMap(file =>
5
+ file.messages.map(m => {
6
+ // split into lines
7
+ const lines = m.message.split('\n');
8
+
9
+ // 第一行(句子):直接用
10
+ const first = lines[0];
11
+
12
+ // 附加解释:过滤掉所有 codeframe/箭头/行号/重复路径
13
+ const details = lines
14
+ .slice(1)
15
+ .filter(l => {
16
+ // 移除空行
17
+ if (!l.trim()) return false;
18
+
19
+ // 移除 "58 | xxx" 这样的行
20
+ if (/^\s*\d+\s*\|/.test(l)) return false;
21
+
22
+ // 移除 "> 60 | ..." 这样的箭头行
23
+ if (/^\s*>/.test(l)) return false;
24
+
25
+ // 移除只有箭头提示的行,如 "| ^^^^^"
26
+ if (/^\s*\|/.test(l)) return false;
27
+
28
+ // 移除 "…" 省略号行
29
+ if (/^\s*…/.test(l)) return false;
30
+
31
+ // 移除重复路径行(eslint message 有时夹带 file:line)
32
+ if (/\.tsx:\d+:\d+/.test(l)) return false;
33
+
34
+ return true;
35
+ })
36
+ .join('\n')
37
+ .trim();
38
+
39
+ let output = `${file.filePath}:${m.line}:${m.column} ${
40
+ m.severity === 2 ? 'error' : 'warn'
41
+ } ${first}`;
42
+
43
+ if (details) output += `\n${details}\n`;
44
+
45
+ return output;
46
+ })
47
+ )
48
+ .join('\n');
49
+ };
@@ -0,0 +1,98 @@
1
+ import js from "@eslint/js";
2
+ import globals from "globals";
3
+ import tseslint from "typescript-eslint";
4
+ import pluginReact from "eslint-plugin-react";
5
+ import reactHooks from "eslint-plugin-react-hooks";
6
+ import regexp from "eslint-plugin-regexp";
7
+ import pluginImport from "eslint-plugin-import";
8
+
9
+ export default [
10
+ {
11
+ ignores: [
12
+ '**/dist/**',
13
+ '**/node_modules/**',
14
+ 'api/**', // 排除自动生成的 API 代码
15
+ 'src/api/**', // 排除 src 下的自动生成 API
16
+ '.expo/**', // 排除 Expo 自动生成的文件
17
+ 'tailwind.config.js', // 排除 Tailwind 配置文件
18
+ ],
19
+ },
20
+ regexp.configs["flat/recommended"],
21
+ js.configs.recommended,
22
+ ...tseslint.configs.recommended,
23
+
24
+ // React 的推荐配置
25
+ pluginReact.configs.flat.recommended,
26
+ pluginReact.configs.flat['jsx-runtime'],
27
+ reactHooks.configs.flat.recommended,
28
+ {
29
+ files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
30
+
31
+ // 语言选项:设置全局变量
32
+ languageOptions: {
33
+ globals: {
34
+ ...globals.browser,
35
+ ...globals.es2021,
36
+ '__DEV__': 'readonly',
37
+ },
38
+ },
39
+
40
+ // React 版本自动检测
41
+ settings: {
42
+ react: {
43
+ version: 'detect',
44
+ },
45
+ 'import/resolver': {
46
+ typescript: {
47
+ project: ['./tsconfig.json'],
48
+ alwaysTryTypes: true,
49
+ },
50
+ },
51
+ },
52
+
53
+ plugins: {
54
+ import: pluginImport,
55
+ },
56
+ rules: {
57
+ // 关闭代码风格规则
58
+ 'semi': 'off',
59
+ 'quotes': 'off',
60
+ 'indent': 'off',
61
+ "no-empty": ["error", { "allowEmptyCatch": true }],
62
+ "no-unused-expressions": "warn",
63
+ "no-useless-escape": "warn",
64
+ 'import/no-unresolved': 'error',
65
+ '@typescript-eslint/no-require-imports': 'off',
66
+ '@typescript-eslint/no-unused-vars': 'off',
67
+ '@typescript-eslint/no-explicit-any': 'off',
68
+ '@typescript-eslint/ban-ts-comment': 'off',
69
+ '@typescript-eslint/no-empty-object-type': 'off',
70
+ 'no-prototype-builtins': 'off',
71
+ 'react/react-in-jsx-scope': 'off',
72
+ 'react/jsx-uses-react': 'off',
73
+ },
74
+ },
75
+
76
+ {
77
+ files: [
78
+ "metro.config.js",
79
+ "scripts/**/*.js",
80
+ "expo/scripts/**/*.js",
81
+ "eslint.config.js",
82
+ "babel.config.js",
83
+ "server/**/*.js"
84
+ ],
85
+ languageOptions: {
86
+ globals: {
87
+ ...globals.node,
88
+ },
89
+ },
90
+ rules: {
91
+ // 在 .js 文件中关闭 TS 规则
92
+ '@typescript-eslint/no-require-imports': 'off',
93
+ // 在 Node.js 文件中允许 require
94
+ '@typescript-eslint/no-var-requires': 'off',
95
+ 'no-undef': 'off',
96
+ },
97
+ },
98
+ ];
@@ -0,0 +1,34 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { ColorSchemeName, useColorScheme as useReactNativeColorScheme, Platform } from 'react-native';
3
+
4
+ export function useColorScheme() {
5
+ const systemColorScheme = useReactNativeColorScheme();
6
+ const [colorScheme, setColorScheme] = useState<ColorSchemeName>(systemColorScheme);
7
+
8
+ useEffect(() => {
9
+ setColorScheme(systemColorScheme);
10
+ }, [systemColorScheme])
11
+
12
+ useEffect(() => {
13
+ function handleMessage(e: MessageEvent<{ event: string; colorScheme: ColorSchemeName; } | undefined>) {
14
+ if (e.data?.event === 'coze.workbench.colorScheme') {
15
+ const cs = e.data.colorScheme;
16
+ if (typeof cs === 'string') {
17
+ setColorScheme(cs);
18
+ }
19
+ }
20
+ }
21
+
22
+ if (Platform.OS === 'web') {
23
+ window.addEventListener('message', handleMessage, false);
24
+ }
25
+
26
+ return () => {
27
+ if (Platform.OS === 'web') {
28
+ window.removeEventListener('message', handleMessage, false);
29
+ }
30
+ }
31
+ }, []);
32
+
33
+ return colorScheme;
34
+ }
@@ -0,0 +1,13 @@
1
+ import { Colors } from "@/constants/theme";
2
+ import { useColorScheme } from "@/hooks/useColorScheme";
3
+
4
+ export function useTheme() {
5
+ const colorScheme = useColorScheme();
6
+ const isDark = colorScheme === "dark";
7
+ const theme = Colors[(colorScheme as "light" | "dark") ?? "light"];
8
+
9
+ return {
10
+ theme,
11
+ isDark,
12
+ };
13
+ }
@@ -0,0 +1,121 @@
1
+ const { getDefaultConfig } = require('expo/metro-config');
2
+ const { createProxyMiddleware } = require('http-proxy-middleware');
3
+ const connect = require('connect');
4
+
5
+ const config = getDefaultConfig(__dirname);
6
+
7
+ // 安全地获取 Expo 的默认排除列表
8
+ const existingBlockList = [].concat(config.resolver.blockList || []);
9
+
10
+ config.resolver.blockList = [
11
+ ...existingBlockList,
12
+ /.*\/\.expo\/.*/, // Expo 的缓存和构建产物目录
13
+
14
+ // 1. 原生代码 (Java/C++/Objective-C)
15
+ /.*\/react-native\/ReactAndroid\/.*/,
16
+ /.*\/react-native\/ReactCommon\/.*/,
17
+
18
+ // 2. 纯开发和调试工具
19
+ // 这些工具只在开发电脑上运行,不会被打包到应用中
20
+ /.*\/@typescript-eslint\/eslint-plugin\/.*/,
21
+
22
+ // 3. 构建时数据
23
+ // 这个数据库只在打包过程中使用,应用运行时不需要
24
+ /.*\/caniuse-lite\/data\/.*/,
25
+
26
+ // 4. 通用规则
27
+ /.*\/__tests__\/.*/, // 排除所有测试目录
28
+ /.*\.git\/.*/, // 排除 Git 目录
29
+ ];
30
+
31
+ const BACKEND_TARGET = 'http://localhost:9091';
32
+
33
+ const apiProxy = createProxyMiddleware({
34
+ target: BACKEND_TARGET,
35
+ changeOrigin: true,
36
+ logLevel: 'debug',
37
+ proxyTimeout: 86400000,
38
+ onProxyReq: (proxyReq, req) => {
39
+ const accept = req.headers.accept || '';
40
+ if (accept.includes('text/event-stream')) {
41
+ proxyReq.setHeader('accept-encoding', 'identity');
42
+ }
43
+ },
44
+ onProxyRes: (proxyRes, req, res) => {
45
+ const contentType = proxyRes.headers['content-type'] || '';
46
+ if (contentType.includes('text/event-stream') || contentType.includes('application/stream')) {
47
+ res.setHeader('Cache-Control', 'no-cache');
48
+ res.setHeader('Connection', 'keep-alive');
49
+ res.setHeader('X-Accel-Buffering', 'no');
50
+ if (typeof res.flushHeaders === 'function') {
51
+ try { res.flushHeaders(); } catch {}
52
+ }
53
+ }
54
+ },
55
+ });
56
+
57
+ const streamProxy = createProxyMiddleware({
58
+ target: BACKEND_TARGET,
59
+ changeOrigin: true,
60
+ logLevel: 'debug',
61
+ ws: true,
62
+ proxyTimeout: 86400000,
63
+ onProxyReq: (proxyReq, req) => {
64
+ const upgrade = req.headers.upgrade;
65
+ const accept = req.headers.accept || '';
66
+ if (upgrade && upgrade.toLowerCase() === 'websocket') {
67
+ proxyReq.setHeader('Connection', 'upgrade');
68
+ proxyReq.setHeader('Upgrade', req.headers.upgrade);
69
+ } else if (accept.includes('text/event-stream')) {
70
+ proxyReq.setHeader('accept-encoding', 'identity');
71
+ proxyReq.setHeader('Connection', 'keep-alive');
72
+ }
73
+ },
74
+ onProxyRes: (proxyRes, req, res) => {
75
+ const contentType = proxyRes.headers['content-type'] || '';
76
+ if (contentType.includes('text/event-stream') || contentType.includes('application/stream')) {
77
+ res.setHeader('Cache-Control', 'no-cache');
78
+ res.setHeader('Connection', 'keep-alive');
79
+ res.setHeader('X-Accel-Buffering', 'no');
80
+ if (typeof res.flushHeaders === 'function') {
81
+ try { res.flushHeaders(); } catch {}
82
+ }
83
+ }
84
+ },
85
+ });
86
+
87
+ const shouldProxyToBackend = (url) => {
88
+ if (!url) return false;
89
+ if (/^\/api\/v\d+\//.test(url)) {
90
+ return true;
91
+ }
92
+ return false;
93
+ };
94
+
95
+ const isWebSocketRequest = (req) =>
96
+ !!(req.headers.upgrade && req.headers.upgrade.toLowerCase() === 'websocket');
97
+ const isSSERequest = (req) => {
98
+ const accept = req.headers.accept || '';
99
+ return accept.includes('text/event-stream');
100
+ };
101
+
102
+ config.server = {
103
+ ...config.server,
104
+ enhanceMiddleware: (metroMiddleware, metroServer) => {
105
+ return connect()
106
+ .use((req, res, next) => {
107
+ if (shouldProxyToBackend(req.url)) {
108
+ console.log(`[Metro Proxy] Forwarding ${req.method} ${req.url}`);
109
+
110
+ if (isWebSocketRequest(req) || isSSERequest(req)) {
111
+ return streamProxy(req, res, next);
112
+ }
113
+ return apiProxy(req, res, next);
114
+ }
115
+ next();
116
+ })
117
+ .use(metroMiddleware);
118
+ },
119
+ };
120
+
121
+ module.exports = config;
@@ -0,0 +1,93 @@
1
+ {
2
+ "name": "expo-app",
3
+ "description": "<%= appName %>",
4
+ "main": "expo-router/entry",
5
+ "private": true,
6
+ "scripts": {
7
+ "check-deps": "npx depcheck",
8
+ "postinstall": "npm run install-missing",
9
+ "install-missing": "node ./scripts/install-missing-deps.js",
10
+ "lint": "expo lint",
11
+ "start": "expo start --web --clear",
12
+ "test": "jest --watchAll"
13
+ },
14
+ "jest": {
15
+ "preset": "jest-expo"
16
+ },
17
+ "dependencies": {
18
+ "@expo/metro-runtime": "^6.1.2",
19
+ "@expo/vector-icons": "^15.0.0",
20
+ "@react-native-async-storage/async-storage": "^2.2.0",
21
+ "@react-native-community/datetimepicker": "^8.5.0",
22
+ "@react-native-community/slider": "^5.0.1",
23
+ "@react-native-masked-view/masked-view": "^0.3.2",
24
+ "@react-native-picker/picker": "^2.11.0",
25
+ "@react-navigation/bottom-tabs": "^7.2.0",
26
+ "@react-navigation/native": "^7.0.14",
27
+ "dayjs": "^1.11.19",
28
+ "expo": "^54.0.7",
29
+ "expo-auth-session": "^7.0.9",
30
+ "expo-av": "~16.0.6",
31
+ "expo-blur": "~15.0.6",
32
+ "expo-camera": "~17.0.10",
33
+ "expo-constants": "~18.0.8",
34
+ "expo-crypto": "^15.0.7",
35
+ "expo-font": "~14.0.7",
36
+ "expo-haptics": "~15.0.6",
37
+ "expo-image-picker": "~17.0.7",
38
+ "expo-linear-gradient": "~15.0.6",
39
+ "expo-linking": "~8.0.7",
40
+ "expo-location": "~19.0.7",
41
+ "expo-image": "^3.0.11",
42
+ "expo-router": "~6.0.0",
43
+ "expo-splash-screen": "~31.0.8",
44
+ "expo-status-bar": "~3.0.7",
45
+ "expo-symbols": "~1.0.6",
46
+ "expo-system-ui": "~6.0.9",
47
+ "expo-web-browser": "~15.0.10",
48
+ "react": "19.1.0",
49
+ "react-dom": "19.1.0",
50
+ "react-native": "0.81.5",
51
+ "react-native-chart-kit": "^6.12.0",
52
+ "react-native-gesture-handler": "~2.28.0",
53
+ "react-native-keyboard-aware-scroll-view": "^0.9.5",
54
+ "react-native-modal-datetime-picker": "18.0.0",
55
+ "react-native-reanimated": "~4.1.0",
56
+ "react-native-safe-area-context": "~5.6.0",
57
+ "react-native-screens": "~4.16.0",
58
+ "react-native-svg": "15.15.0",
59
+ "react-native-toast-message": "^2.3.3",
60
+ "react-native-web": "^0.21.2",
61
+ "react-native-webview": "~13.15.0",
62
+ "react-native-worklets": "0.5.1",
63
+ "zod": "^4.2.1"
64
+ },
65
+ "devDependencies": {
66
+ "@babel/core": "^7.25.2",
67
+ "babel-plugin-module-resolver": "^5.0.2",
68
+ "babel-preset-expo": "^54.0.9",
69
+ "@eslint/js": "^9.27.0",
70
+ "@types/jest": "^29.5.12",
71
+ "@types/react": "~19.1.0",
72
+ "@types/react-test-renderer": "19.1.0",
73
+ "chalk": "^4.1.2",
74
+ "depcheck": "^1.4.7",
75
+ "esbuild": "0.27.2",
76
+ "eslint": "^9.39.2",
77
+ "eslint-formatter-compact": "^9.0.1",
78
+ "eslint-import-resolver-typescript": "^4.4.4",
79
+ "eslint-plugin-import": "^2.32.0",
80
+ "eslint-plugin-react": "^7.37.5",
81
+ "eslint-plugin-react-hooks": "^7.0.1",
82
+ "eslint-plugin-regexp": "^2.10.0",
83
+ "globals": "^16.1.0",
84
+ "jest": "^29.2.1",
85
+ "jest-expo": "~54.0.10",
86
+ "react-test-renderer": "19.1.0",
87
+ "tsx": "^4.21.0",
88
+ "typescript": "^5.8.3",
89
+ "typescript-eslint": "^8.32.1",
90
+ "connect": "^3.7.0",
91
+ "http-proxy-middleware": "^3.0.5"
92
+ }
93
+ }
@@ -0,0 +1,25 @@
1
+ import { View, Text } from 'react-native';
2
+ import { Image } from 'expo-image';
3
+
4
+ import { useTheme } from '@/hooks/useTheme';
5
+ import { Screen } from '@/components/Screen';
6
+ import { styles } from './styles';
7
+
8
+ export default function DemoPage() {
9
+ const { theme, isDark } = useTheme();
10
+
11
+ return (
12
+ <Screen backgroundColor={theme.backgroundRoot} statusBarStyle={isDark ? 'light' : 'dark'}>
13
+ <View
14
+ style={styles.container}
15
+ >
16
+ <Image
17
+ style={styles.logo}
18
+ source="https://lf-coze-web-cdn.coze.cn/obj/eden-cn/lm-lgvj/ljhwZthlaukjlkulzlp/coze-coding/expo/coze-loading.gif"
19
+ ></Image>
20
+ <Text style={{...styles.title, color: theme.textPrimary}}>APP 开发中</Text>
21
+ <Text style={{...styles.description, color: theme.textSecondary}}>即将为您呈现应用界面</Text>
22
+ </View>
23
+ </Screen>
24
+ );
25
+ }
@@ -0,0 +1,28 @@
1
+ import { Spacing } from '@/constants/theme';
2
+ import { StyleSheet } from 'react-native';
3
+
4
+ export const styles = StyleSheet.create({
5
+ container: {
6
+ position: 'absolute',
7
+ top: 0,
8
+ left: 0,
9
+ width: '100%',
10
+ height: '100%',
11
+ display: 'flex',
12
+ flexDirection: 'column',
13
+ alignItems: 'center',
14
+ justifyContent: 'center',
15
+ },
16
+ logo: {
17
+ width: 130,
18
+ height: 109,
19
+ },
20
+ title: {
21
+ fontSize: 16,
22
+ fontWeight: 'bold',
23
+ },
24
+ description: {
25
+ fontSize: 14,
26
+ marginTop: Spacing.sm,
27
+ },
28
+ });
@@ -0,0 +1,104 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * 自动检测并安装缺失的依赖
5
+ * 使用方法: node scripts/install-missing-deps.js
6
+ */
7
+
8
+ const { execSync } = require('child_process');
9
+ const fs = require('fs');
10
+ const path = require('path');
11
+
12
+ console.log('🔍 检测缺失的依赖...\n');
13
+
14
+ try {
15
+ // 运行 depcheck 并获取 JSON 输出
16
+ // 注意:depcheck 发现问题时会返回非零退出码,但这不是错误
17
+ let depcheckOutput;
18
+ try {
19
+ depcheckOutput = execSync('npx depcheck --json', {
20
+ encoding: 'utf-8',
21
+ stdio: ['pipe', 'pipe', 'pipe'],
22
+ });
23
+ } catch (execError) {
24
+ // depcheck 返回非零退出码时仍然有输出
25
+ if (execError.stdout) {
26
+ depcheckOutput = execError.stdout;
27
+ } else {
28
+ throw execError;
29
+ }
30
+ }
31
+
32
+ const result = JSON.parse(depcheckOutput);
33
+
34
+ // 获取缺失的依赖
35
+ const missing = result.missing || {};
36
+
37
+ // 需要忽略的文件模式
38
+ const ignoreFilePatterns = [
39
+ /template\.config\.(ts|js)$/, // 模板配置文件
40
+ /\.template\./, // 其他模板文件
41
+ ];
42
+
43
+ // 过滤包:排除内部别名和只被模板文件引用的包
44
+ const missingPackages = Object.keys(missing).filter(pkg => {
45
+ // 排除内部路径别名
46
+ if (pkg.startsWith('@api/') || pkg.startsWith('@/') || pkg === '@api') {
47
+ return false;
48
+ }
49
+
50
+ // 获取引用该包的文件列表
51
+ const referencingFiles = missing[pkg] || [];
52
+
53
+ // 过滤掉模板配置文件
54
+ const nonTemplateFiles = referencingFiles.filter(file => {
55
+ return !ignoreFilePatterns.some(pattern => pattern.test(file));
56
+ });
57
+
58
+ // 只有当存在非模板文件引用时才保留该包
59
+ return nonTemplateFiles.length > 0;
60
+ });
61
+
62
+ if (missingPackages.length === 0) {
63
+ console.log('✅ 没有发现缺失的依赖!');
64
+ process.exit(0);
65
+ }
66
+
67
+ console.log('📦 发现以下缺失的依赖:');
68
+ missingPackages.forEach((pkg, index) => {
69
+ const files = missing[pkg];
70
+ console.log(` ${index + 1}. ${pkg}`);
71
+ console.log(
72
+ ` 被引用于: ${files.slice(0, 2).join(', ')}${files.length > 2 ? ' ...' : ''}`,
73
+ );
74
+ });
75
+
76
+ console.log('\n🚀 开始安装...\n');
77
+
78
+ // 使用 expo install 安装所有缺失的包
79
+ const packagesToInstall = missingPackages.join(' ');
80
+
81
+ try {
82
+ execSync(`pnpm expo install ${packagesToInstall}`, {
83
+ stdio: 'inherit',
84
+ });
85
+
86
+ console.log('\n✅ 所有缺失的依赖已安装完成!');
87
+ } catch (installError) {
88
+ console.log('\n⚠️ expo install 失败,尝试使用 npm install...\n');
89
+
90
+ execSync(`npm install ${packagesToInstall}`, {
91
+ stdio: 'inherit',
92
+ });
93
+
94
+ console.log('\n✅ 所有缺失的依赖已通过 npm 安装完成!');
95
+ }
96
+ } catch (error) {
97
+ if (error.message.includes('depcheck')) {
98
+ console.error('❌ depcheck 未安装或运行失败');
99
+ console.log('💡 尝试运行: npm install -g depcheck');
100
+ } else {
101
+ console.error('❌ 发生错误:', error.message);
102
+ }
103
+ process.exit(1);
104
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "extends": "expo/tsconfig.base",
3
+ "compilerOptions": {
4
+ "skipLibCheck": true,
5
+ "jsx": "react-jsx",
6
+ "baseUrl": ".",
7
+ "strict": true,
8
+ "noEmit": true,
9
+ "paths": {
10
+ "@/*": ["./*"]
11
+ }
12
+ },
13
+ "include": ["**/*.ts", "**/*.tsx", ".expo/types/**/*.ts", "expo-env.d.ts"],
14
+ "exclude": [
15
+ "node_modules",
16
+ "**/*.spec.ts",
17
+ "**/*.test.ts",
18
+ "**/*.spec.tsx",
19
+ "**/*.test.tsx",
20
+ "dist",
21
+ "build",
22
+ ".expo"
23
+ ]
24
+ }