@coze-arch/cli 0.0.1-alpha.ee5d83 → 0.0.1-alpha.f11735

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 (42) hide show
  1. package/lib/__templates__/expo/.cozeproj/scripts/dev_run.sh +10 -10
  2. package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +2 -2
  3. package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +2 -2
  4. package/lib/__templates__/expo/.cozeproj/scripts/server_dev_run.sh +45 -0
  5. package/lib/__templates__/expo/README.md +2 -0
  6. package/lib/__templates__/expo/client/app/_layout.tsx +15 -12
  7. package/lib/__templates__/expo/client/app/index.tsx +1 -1
  8. package/lib/__templates__/expo/client/app.config.ts +4 -3
  9. package/lib/__templates__/expo/client/components/Screen.tsx +1 -17
  10. package/lib/__templates__/expo/client/components/ThemedView.tsx +1 -2
  11. package/lib/__templates__/expo/client/constants/theme.ts +21 -698
  12. package/lib/__templates__/expo/client/declarations.d.ts +5 -0
  13. package/lib/__templates__/expo/client/eslint.config.mjs +17 -10
  14. package/lib/__templates__/expo/client/hooks/{useColorScheme.ts → useColorScheme.tsx} +20 -6
  15. package/lib/__templates__/expo/client/hooks/useTheme.ts +26 -6
  16. package/lib/__templates__/expo/client/screens/{home → demo}/index.tsx +1 -1
  17. package/lib/__templates__/expo/client/scripts/install-missing-deps.js +1 -0
  18. package/lib/__templates__/expo/client/utils/index.ts +22 -0
  19. package/lib/__templates__/expo/eslint-plugins/fontawesome6/index.js +9 -0
  20. package/lib/__templates__/expo/eslint-plugins/fontawesome6/names.js +1889 -0
  21. package/lib/__templates__/expo/eslint-plugins/fontawesome6/rule.js +174 -0
  22. package/lib/__templates__/expo/eslint-plugins/fontawesome6/v5-only-names.js +388 -0
  23. package/lib/__templates__/expo/eslint-plugins/reanimated/index.js +9 -0
  24. package/lib/__templates__/expo/eslint-plugins/reanimated/rule.js +88 -0
  25. package/lib/__templates__/expo/server/build.js +21 -0
  26. package/lib/__templates__/expo/server/package.json +2 -2
  27. package/lib/__templates__/expo/server/src/index.ts +2 -1
  28. package/lib/__templates__/nextjs/.babelrc +15 -0
  29. package/lib/__templates__/nextjs/next.config.ts +2 -2
  30. package/lib/__templates__/nextjs/package.json +9 -1
  31. package/lib/__templates__/nextjs/pnpm-lock.yaml +2485 -1714
  32. package/lib/__templates__/nextjs/src/app/layout.tsx +5 -3
  33. package/lib/__templates__/nextjs/src/app/page.tsx +2 -2
  34. package/lib/__templates__/nextjs/template.config.js +5 -5
  35. package/lib/__templates__/vite/package.json +6 -1
  36. package/lib/__templates__/vite/pnpm-lock.yaml +504 -982
  37. package/lib/__templates__/vite/src/main.ts +1 -2
  38. package/lib/__templates__/vite/template.config.js +6 -4
  39. package/lib/cli.js +258 -14
  40. package/package.json +1 -1
  41. package/lib/__templates__/expo/client/app/home.tsx +0 -1
  42. /package/lib/__templates__/expo/client/screens/{home → demo}/styles.ts +0 -0
@@ -0,0 +1,5 @@
1
+ // declarations.d.ts
2
+
3
+ declare module 'expo-file-system/legacy' {
4
+ export * from 'expo-file-system';
5
+ }
@@ -1,10 +1,12 @@
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";
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
+ import fontawesome6 from '../eslint-plugins/fontawesome6/index.js';
9
+ import reanimated from '../eslint-plugins/reanimated/index.js'
8
10
 
9
11
  export default [
10
12
  {
@@ -15,19 +17,20 @@ export default [
15
17
  'src/api/**', // 排除 src 下的自动生成 API
16
18
  '.expo/**', // 排除 Expo 自动生成的文件
17
19
  'tailwind.config.js', // 排除 Tailwind 配置文件
20
+ '**/*.d.ts',
18
21
  ],
19
22
  },
20
23
  regexp.configs["flat/recommended"],
21
24
  js.configs.recommended,
22
25
  ...tseslint.configs.recommended,
23
-
26
+
24
27
  // React 的推荐配置
25
28
  pluginReact.configs.flat.recommended,
26
29
  pluginReact.configs.flat['jsx-runtime'],
27
30
  reactHooks.configs.flat.recommended,
28
31
  {
29
32
  files: ["**/*.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"],
30
-
33
+
31
34
  // 语言选项:设置全局变量
32
35
  languageOptions: {
33
36
  globals: {
@@ -52,6 +55,8 @@ export default [
52
55
 
53
56
  plugins: {
54
57
  import: pluginImport,
58
+ fontawesome6,
59
+ reanimated,
55
60
  },
56
61
  rules: {
57
62
  // 关闭代码风格规则
@@ -70,6 +75,8 @@ export default [
70
75
  'no-prototype-builtins': 'off',
71
76
  'react/react-in-jsx-scope': 'off',
72
77
  'react/jsx-uses-react': 'off',
78
+ 'fontawesome6/valid-name': 'error',
79
+ 'reanimated/ban-mix-use': 'error',
73
80
  },
74
81
  },
75
82
 
@@ -91,7 +98,7 @@ export default [
91
98
  // 在 .js 文件中关闭 TS 规则
92
99
  '@typescript-eslint/no-require-imports': 'off',
93
100
  // 在 Node.js 文件中允许 require
94
- '@typescript-eslint/no-var-requires': 'off',
101
+ '@typescript-eslint/no-var-requires': 'off',
95
102
  'no-undef': 'off',
96
103
  },
97
104
  },
@@ -1,19 +1,21 @@
1
- import { useEffect, useState } from 'react';
1
+ import { createContext, Dispatch, ReactNode, SetStateAction, useContext, useEffect, useState } from 'react';
2
2
  import { ColorSchemeName, useColorScheme as useReactNativeColorScheme, Platform } from 'react-native';
3
3
 
4
- export function useColorScheme() {
4
+ const ColorSchemeContext = createContext<'light' | 'dark' | null | undefined>(null);
5
+
6
+ const ColorSchemeProvider = function ({ children }: { children?: ReactNode }) {
5
7
  const systemColorScheme = useReactNativeColorScheme();
6
- const [colorScheme, setColorScheme] = useState<ColorSchemeName>(systemColorScheme);
8
+ const [colorScheme, setColorScheme] = useState(systemColorScheme);
7
9
 
8
10
  useEffect(() => {
9
11
  setColorScheme(systemColorScheme);
10
- }, [systemColorScheme])
12
+ }, [systemColorScheme]);
11
13
 
12
14
  useEffect(() => {
13
15
  function handleMessage(e: MessageEvent<{ event: string; colorScheme: ColorSchemeName; } | undefined>) {
14
16
  if (e.data?.event === 'coze.workbench.colorScheme') {
15
17
  const cs = e.data.colorScheme;
16
- if (typeof cs === 'string') {
18
+ if (typeof cs === 'string' && typeof setColorScheme === 'function') {
17
19
  setColorScheme(cs);
18
20
  }
19
21
  }
@@ -28,7 +30,19 @@ export function useColorScheme() {
28
30
  window.removeEventListener('message', handleMessage, false);
29
31
  }
30
32
  }
31
- }, []);
33
+ }, [setColorScheme]);
34
+
35
+ return <ColorSchemeContext.Provider value={colorScheme}>
36
+ {children}
37
+ </ColorSchemeContext.Provider>
38
+ };
32
39
 
40
+ function useColorScheme() {
41
+ const colorScheme = useContext(ColorSchemeContext);
33
42
  return colorScheme;
34
43
  }
44
+
45
+ export {
46
+ ColorSchemeProvider,
47
+ useColorScheme,
48
+ }
@@ -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 as "light" | "dark") ?? "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
+ }
@@ -5,7 +5,7 @@ import { useTheme } from '@/hooks/useTheme';
5
5
  import { Screen } from '@/components/Screen';
6
6
  import { styles } from './styles';
7
7
 
8
- export default function HomeScreen() {
8
+ export default function DemoPage() {
9
9
  const { theme, isDark } = useTheme();
10
10
 
11
11
  return (
@@ -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
  // 过滤包:排除内部别名和只被模板文件引用的包
@@ -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