@coze-arch/cli 0.0.1-alpha.d5effa → 0.0.1-alpha.de5a13

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 (130) hide show
  1. package/lib/__templates__/expo/.coze +7 -2
  2. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +46 -0
  3. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +229 -0
  4. package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +47 -0
  5. package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +34 -0
  6. package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +46 -0
  7. package/lib/__templates__/expo/README.md +68 -7
  8. package/lib/__templates__/expo/_gitignore +1 -1
  9. package/lib/__templates__/expo/_npmrc +2 -4
  10. package/lib/__templates__/expo/client/app/+not-found.tsx +15 -64
  11. package/lib/__templates__/expo/client/app/_layout.tsx +15 -12
  12. package/lib/__templates__/expo/client/app/index.tsx +1 -0
  13. package/lib/__templates__/expo/client/app.config.ts +76 -0
  14. package/lib/__templates__/expo/client/components/Screen.tsx +1 -17
  15. package/lib/__templates__/expo/client/components/ThemedText.tsx +33 -0
  16. package/lib/__templates__/expo/client/components/ThemedView.tsx +37 -0
  17. package/lib/__templates__/expo/client/constants/theme.ts +117 -58
  18. package/lib/__templates__/expo/client/declarations.d.ts +5 -0
  19. package/lib/__templates__/expo/{eslint.config.mjs → client/eslint.config.mjs} +33 -10
  20. package/lib/__templates__/expo/client/hooks/useColorScheme.tsx +48 -0
  21. package/lib/__templates__/expo/client/hooks/useSafeRouter.ts +152 -0
  22. package/lib/__templates__/expo/client/hooks/useTheme.ts +26 -6
  23. package/lib/__templates__/expo/client/metro.config.js +121 -0
  24. package/lib/__templates__/expo/client/package.json +95 -0
  25. package/lib/__templates__/expo/client/screens/demo/index.tsx +25 -0
  26. package/lib/__templates__/expo/client/screens/demo/styles.ts +28 -0
  27. package/lib/__templates__/expo/client/scripts/install-missing-deps.js +1 -0
  28. package/lib/__templates__/expo/client/tsconfig.json +24 -0
  29. package/lib/__templates__/expo/client/utils/index.ts +22 -0
  30. package/lib/__templates__/expo/eslint-plugins/fontawesome6/index.js +9 -0
  31. package/lib/__templates__/expo/eslint-plugins/fontawesome6/names.js +1889 -0
  32. package/lib/__templates__/expo/eslint-plugins/fontawesome6/rule.js +174 -0
  33. package/lib/__templates__/expo/eslint-plugins/fontawesome6/v5-only-names.js +388 -0
  34. package/lib/__templates__/expo/eslint-plugins/react-native/index.js +9 -0
  35. package/lib/__templates__/expo/eslint-plugins/react-native/rule.js +64 -0
  36. package/lib/__templates__/expo/eslint-plugins/reanimated/index.js +9 -0
  37. package/lib/__templates__/expo/eslint-plugins/reanimated/rule.js +88 -0
  38. package/lib/__templates__/expo/package.json +16 -103
  39. package/lib/__templates__/expo/patches/expo@54.0.33.patch +45 -0
  40. package/lib/__templates__/expo/pnpm-lock.yaml +1436 -3173
  41. package/lib/__templates__/expo/pnpm-workspace.yaml +3 -0
  42. package/lib/__templates__/expo/server/build.js +21 -0
  43. package/lib/__templates__/expo/server/package.json +34 -0
  44. package/lib/__templates__/expo/server/src/index.ts +20 -0
  45. package/lib/__templates__/expo/server/tsconfig.json +24 -0
  46. package/lib/__templates__/expo/template.config.js +57 -0
  47. package/lib/__templates__/expo/tsconfig.json +1 -24
  48. package/lib/__templates__/nextjs/.babelrc +12 -0
  49. package/lib/__templates__/nextjs/.coze +1 -0
  50. package/lib/__templates__/nextjs/_npmrc +1 -0
  51. package/lib/__templates__/nextjs/next.config.ts +12 -0
  52. package/lib/__templates__/nextjs/package.json +13 -2
  53. package/lib/__templates__/nextjs/pnpm-lock.yaml +2679 -1786
  54. package/lib/__templates__/nextjs/scripts/prepare.sh +9 -0
  55. package/lib/__templates__/nextjs/src/app/globals.css +109 -89
  56. package/lib/__templates__/nextjs/src/app/layout.tsx +5 -14
  57. package/lib/__templates__/nextjs/src/app/page.tsx +18 -48
  58. package/lib/__templates__/nextjs/src/components/ui/resizable.tsx +29 -22
  59. package/lib/__templates__/nextjs/src/components/ui/sidebar.tsx +228 -230
  60. package/lib/__templates__/nextjs/template.config.js +67 -2
  61. package/lib/__templates__/taro/.coze +14 -0
  62. package/lib/__templates__/taro/.cozeproj/scripts/deploy_build.sh +19 -0
  63. package/lib/__templates__/taro/.cozeproj/scripts/deploy_run.sh +14 -0
  64. package/lib/__templates__/taro/.cozeproj/scripts/dev_build.sh +2 -0
  65. package/lib/__templates__/taro/.cozeproj/scripts/dev_run.sh +81 -0
  66. package/lib/__templates__/taro/.cozeproj/scripts/init_env.sh +5 -0
  67. package/lib/__templates__/taro/.cozeproj/scripts/pack.sh +1 -0
  68. package/lib/__templates__/taro/README.md +687 -0
  69. package/lib/__templates__/taro/_gitignore +40 -0
  70. package/lib/__templates__/taro/_npmrc +18 -0
  71. package/lib/__templates__/taro/babel.config.js +12 -0
  72. package/lib/__templates__/taro/config/dev.ts +9 -0
  73. package/lib/__templates__/taro/config/index.ts +173 -0
  74. package/lib/__templates__/taro/config/prod.ts +35 -0
  75. package/lib/__templates__/taro/eslint.config.mjs +57 -0
  76. package/lib/__templates__/taro/key/private.appid.key +0 -0
  77. package/lib/__templates__/taro/package.json +96 -0
  78. package/lib/__templates__/taro/pnpm-lock.yaml +22428 -0
  79. package/lib/__templates__/taro/pnpm-workspace.yaml +2 -0
  80. package/lib/__templates__/taro/project.config.json +15 -0
  81. package/lib/__templates__/taro/server/nest-cli.json +10 -0
  82. package/lib/__templates__/taro/server/package.json +38 -0
  83. package/lib/__templates__/taro/server/src/app.controller.ts +23 -0
  84. package/lib/__templates__/taro/server/src/app.module.ts +10 -0
  85. package/lib/__templates__/taro/server/src/app.service.ts +8 -0
  86. package/lib/__templates__/taro/server/src/interceptors/http-status.interceptor.ts +23 -0
  87. package/lib/__templates__/taro/server/src/main.ts +49 -0
  88. package/lib/__templates__/taro/server/tsconfig.json +24 -0
  89. package/lib/__templates__/taro/src/app.config.ts +11 -0
  90. package/lib/__templates__/taro/src/app.css +63 -0
  91. package/lib/__templates__/taro/src/app.ts +14 -0
  92. package/lib/__templates__/taro/src/index.html +39 -0
  93. package/lib/__templates__/taro/src/network.ts +39 -0
  94. package/lib/__templates__/taro/src/pages/index/index.config.ts +3 -0
  95. package/lib/__templates__/taro/src/pages/index/index.css +1 -0
  96. package/lib/__templates__/taro/src/pages/index/index.tsx +33 -0
  97. package/lib/__templates__/taro/src/utils/h5-styles.ts +22 -0
  98. package/lib/__templates__/taro/src/utils/wx-debug.ts +23 -0
  99. package/lib/__templates__/taro/stylelint.config.mjs +4 -0
  100. package/lib/__templates__/taro/template.config.js +68 -0
  101. package/lib/__templates__/taro/tsconfig.json +29 -0
  102. package/lib/__templates__/taro/types/global.d.ts +32 -0
  103. package/lib/__templates__/templates.json +93 -43
  104. package/lib/__templates__/vite/.coze +1 -0
  105. package/lib/__templates__/vite/_npmrc +1 -0
  106. package/lib/__templates__/vite/eslint.config.mjs +9 -0
  107. package/lib/__templates__/vite/package.json +13 -2
  108. package/lib/__templates__/vite/pnpm-lock.yaml +1694 -222
  109. package/lib/__templates__/vite/scripts/prepare.sh +9 -0
  110. package/lib/__templates__/vite/src/main.ts +17 -48
  111. package/lib/__templates__/vite/template.config.js +67 -6
  112. package/lib/__templates__/vite/vite.config.ts +0 -1
  113. package/lib/cli.js +986 -148
  114. package/package.json +8 -3
  115. package/lib/__templates__/expo/.cozeproj/scripts/deploy_build.sh +0 -116
  116. package/lib/__templates__/expo/.cozeproj/scripts/deploy_run.sh +0 -239
  117. package/lib/__templates__/expo/app.json +0 -63
  118. package/lib/__templates__/expo/babel.config.js +0 -9
  119. package/lib/__templates__/expo/client/app/(tabs)/_layout.tsx +0 -43
  120. package/lib/__templates__/expo/client/app/(tabs)/home.tsx +0 -1
  121. package/lib/__templates__/expo/client/app/(tabs)/index.tsx +0 -7
  122. package/lib/__templates__/expo/client/hooks/useColorScheme.ts +0 -1
  123. package/lib/__templates__/expo/client/index.js +0 -12
  124. package/lib/__templates__/expo/client/screens/home/index.tsx +0 -51
  125. package/lib/__templates__/expo/client/screens/home/styles.ts +0 -60
  126. package/lib/__templates__/expo/metro.config.js +0 -53
  127. package/lib/__templates__/expo/src/index.ts +0 -12
  128. package/lib/__templates__/nextjs/.vscode/settings.json +0 -121
  129. package/lib/__templates__/vite/.vscode/settings.json +0 -7
  130. /package/lib/__templates__/expo/{eslint-formatter-simple.mjs → client/eslint-formatter-simple.mjs} +0 -0
@@ -1,13 +1,33 @@
1
- import { Colors } from "@/constants/theme";
2
- import { useColorScheme } from "@/hooks/useColorScheme";
1
+ import { Colors } from '@/constants/theme';
2
+ import { useColorScheme } from '@/hooks/useColorScheme';
3
3
 
4
- export function useTheme() {
5
- const colorScheme = useColorScheme();
6
- const isDark = colorScheme === "dark";
7
- const theme = Colors[colorScheme ?? "light"];
4
+ enum COLOR_SCHEME_CHOICE {
5
+ FOLLOW_SYSTEM = 'follow-system', // 跟随系统自动变化
6
+ DARK = 'dark', // 固定为 dark 主题,不随系统变化
7
+ LIGHT = 'light', // 固定为 light 主题,不随系统变化
8
+ };
9
+
10
+ const userPreferColorScheme: COLOR_SCHEME_CHOICE = COLOR_SCHEME_CHOICE.FOLLOW_SYSTEM;
11
+
12
+ function getTheme(colorScheme?: 'dark' | 'light' | null) {
13
+ const isDark = colorScheme === 'dark';
14
+ const theme = Colors[colorScheme ?? 'light'];
8
15
 
9
16
  return {
10
17
  theme,
11
18
  isDark,
12
19
  };
13
20
  }
21
+
22
+ function useTheme() {
23
+ const systemColorScheme = useColorScheme()
24
+ const colorScheme = userPreferColorScheme === COLOR_SCHEME_CHOICE.FOLLOW_SYSTEM ?
25
+ systemColorScheme :
26
+ userPreferColorScheme;
27
+
28
+ return getTheme(colorScheme);
29
+ }
30
+
31
+ export {
32
+ useTheme,
33
+ }
@@ -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,95 @@
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.3",
20
+ "@react-native-async-storage/async-storage": "2.2.0",
21
+ "@react-native-community/datetimepicker": "8.4.4",
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.1",
25
+ "@react-navigation/bottom-tabs": "^7.2.0",
26
+ "@react-navigation/native": "^7.0.14",
27
+ "dayjs": "^1.11.19",
28
+ "expo": "54.0.33",
29
+ "expo-auth-session": "~7.0.10",
30
+ "expo-av": "~16.0.8",
31
+ "expo-blur": "~15.0.8",
32
+ "expo-camera": "~17.0.10",
33
+ "expo-constants": "~18.0.13",
34
+ "expo-crypto": "~15.0.8",
35
+ "expo-file-system": "~19.0.21",
36
+ "expo-font": "~14.0.11",
37
+ "expo-haptics": "~15.0.8",
38
+ "expo-image": "~3.0.11",
39
+ "expo-image-picker": "~17.0.10",
40
+ "expo-linear-gradient": "~15.0.8",
41
+ "expo-linking": "~8.0.11",
42
+ "expo-location": "~19.0.8",
43
+ "expo-router": "~6.0.23",
44
+ "expo-splash-screen": "~31.0.13",
45
+ "expo-status-bar": "~3.0.9",
46
+ "expo-symbols": "~1.0.8",
47
+ "expo-system-ui": "~6.0.9",
48
+ "expo-web-browser": "~15.0.10",
49
+ "js-base64": "^3.7.7",
50
+ "react": "19.1.0",
51
+ "react-dom": "19.1.0",
52
+ "react-native": "0.81.5",
53
+ "react-native-chart-kit": "^6.12.0",
54
+ "react-native-gesture-handler": "~2.28.0",
55
+ "react-native-keyboard-aware-scroll-view": "^0.9.5",
56
+ "react-native-modal-datetime-picker": "18.0.0",
57
+ "react-native-reanimated": "~4.1.1",
58
+ "react-native-safe-area-context": "~5.6.0",
59
+ "react-native-screens": "~4.16.0",
60
+ "react-native-svg": "15.12.1",
61
+ "react-native-toast-message": "^2.3.3",
62
+ "react-native-web": "~0.21.0",
63
+ "react-native-webview": "13.15.0",
64
+ "react-native-worklets": "0.5.1",
65
+ "zod": "^4.2.1"
66
+ },
67
+ "devDependencies": {
68
+ "@babel/core": "^7.25.2",
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
+ "babel-plugin-module-resolver": "^5.0.2",
74
+ "babel-preset-expo": "^54.0.9",
75
+ "chalk": "^4.1.2",
76
+ "connect": "^3.7.0",
77
+ "depcheck": "^1.4.7",
78
+ "esbuild": "0.27.2",
79
+ "eslint": "^9.39.2",
80
+ "eslint-formatter-compact": "^9.0.1",
81
+ "eslint-import-resolver-typescript": "^4.4.4",
82
+ "eslint-plugin-import": "^2.32.0",
83
+ "eslint-plugin-react": "^7.37.5",
84
+ "eslint-plugin-react-hooks": "^7.0.1",
85
+ "eslint-plugin-regexp": "^2.10.0",
86
+ "globals": "^16.1.0",
87
+ "http-proxy-middleware": "^3.0.5",
88
+ "jest": "^29.2.1",
89
+ "jest-expo": "~54.0.17",
90
+ "react-test-renderer": "19.1.0",
91
+ "tsx": "^4.21.0",
92
+ "typescript": "^5.8.3",
93
+ "typescript-eslint": "^8.32.1"
94
+ }
95
+ }
@@ -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/icon/coze-coding.gif"
19
+ ></Image>
20
+ <Text style={{...styles.title, color: theme.textPrimary}}>应用开发中</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
+ });
@@ -38,6 +38,7 @@ try {
38
38
  const ignoreFilePatterns = [
39
39
  /template\.config\.(ts|js)$/, // 模板配置文件
40
40
  /\.template\./, // 其他模板文件
41
+ /declarations\.d\.ts$/, // 项目配置文件
41
42
  ];
42
43
 
43
44
  // 过滤包:排除内部别名和只被模板文件引用的包
@@ -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
+ }
@@ -1,9 +1,31 @@
1
+ import { Platform } from 'react-native';
1
2
  import dayjs from 'dayjs';
2
3
  import utc from 'dayjs/plugin/utc';
3
4
  dayjs.extend(utc);
4
5
 
5
6
  const API_BASE = (process.env.EXPO_PUBLIC_API_BASE ?? '').replace(/\/$/, '');
6
7
 
8
+ /**
9
+ * 创建跨平台兼容的文件对象,用于 FormData.append()
10
+ * - Web 端返回 File 对象
11
+ * - 移动端返回 { uri, type, name } 对象(RN fetch 会自动处理)
12
+ * @param fileUri Expo 媒体库(如 expo-image-picker、expo-camera)返回的 uri
13
+ * @param fileName 上传时的文件名,如 'photo.jpg'
14
+ * @param mimeType 文件 MIME 类型,如 'image/jpeg'、'audio/mpeg'
15
+ */
16
+ export async function createFormDataFile(
17
+ fileUri: string,
18
+ fileName: string,
19
+ mimeType: string
20
+ ): Promise<File | { uri: string; type: string; name: string }> {
21
+ if (Platform.OS === 'web') {
22
+ const response = await fetch(fileUri);
23
+ const blob = await response.blob();
24
+ return new File([blob], fileName, { type: mimeType });
25
+ }
26
+ return { uri: fileUri, type: mimeType, name: fileName };
27
+ }
28
+
7
29
  /**
8
30
  * 构建文件或图片完整的URL
9
31
  * @param url 相对或绝对路径
@@ -0,0 +1,9 @@
1
+ const validName = require('./rule')
2
+
3
+ const plugin = {
4
+ rules: {
5
+ 'valid-name': validName,
6
+ },
7
+ };
8
+
9
+ module.exports = plugin