@coze-arch/cli 0.0.1-alpha.912cd5 → 0.0.1-alpha.9c9bba

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 (64) hide show
  1. package/lib/__templates__/expo/.coze +7 -2
  2. package/lib/__templates__/expo/.cozeproj/scripts/dev_build.sh +86 -0
  3. package/lib/__templates__/expo/.cozeproj/scripts/{deploy_run.sh → dev_run.sh} +45 -63
  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/README.md +66 -7
  7. package/lib/__templates__/expo/_gitignore +1 -1
  8. package/lib/__templates__/expo/_npmrc +3 -5
  9. package/lib/__templates__/expo/client/app/_layout.tsx +1 -1
  10. package/lib/__templates__/expo/client/app/home.tsx +1 -0
  11. package/lib/__templates__/expo/client/app/index.tsx +1 -0
  12. package/lib/__templates__/expo/client/app.config.ts +71 -0
  13. package/lib/__templates__/expo/client/components/ThemedText.tsx +33 -0
  14. package/lib/__templates__/expo/client/components/ThemedView.tsx +38 -0
  15. package/lib/__templates__/expo/client/constants/theme.ts +779 -47
  16. package/lib/__templates__/expo/client/contexts/AuthContext.tsx +14 -107
  17. package/lib/__templates__/expo/client/hooks/useTheme.ts +1 -1
  18. package/lib/__templates__/expo/client/metro.config.js +121 -0
  19. package/lib/__templates__/expo/client/package.json +92 -0
  20. package/lib/__templates__/expo/client/screens/home/index.tsx +1 -5
  21. package/lib/__templates__/expo/client/screens/home/styles.ts +1 -273
  22. package/lib/__templates__/expo/client/tsconfig.json +24 -0
  23. package/lib/__templates__/expo/client/utils/index.ts +1 -2
  24. package/lib/__templates__/expo/package.json +13 -101
  25. package/lib/__templates__/expo/pnpm-lock.yaml +475 -861
  26. package/lib/__templates__/expo/pnpm-workspace.yaml +3 -0
  27. package/lib/__templates__/expo/server/package.json +30 -0
  28. package/lib/__templates__/expo/{src → server/src}/index.ts +2 -2
  29. package/lib/__templates__/expo/server/tsconfig.json +24 -0
  30. package/lib/__templates__/expo/template.config.js +1 -1
  31. package/lib/__templates__/expo/tsconfig.json +1 -24
  32. package/lib/__templates__/nextjs/.coze +3 -3
  33. package/lib/__templates__/nextjs/_npmrc +1 -1
  34. package/lib/__templates__/nextjs/next.config.ts +1 -0
  35. package/lib/__templates__/nextjs/package.json +9 -3
  36. package/lib/__templates__/nextjs/pnpm-lock.yaml +2501 -1120
  37. package/lib/__templates__/nextjs/scripts/dev.sh +8 -27
  38. package/lib/__templates__/nextjs/src/app/globals.css +99 -87
  39. package/lib/__templates__/nextjs/src/app/layout.tsx +18 -22
  40. package/lib/__templates__/nextjs/template.config.js +1 -1
  41. package/lib/__templates__/templates.json +7 -0
  42. package/lib/__templates__/vite/.coze +3 -3
  43. package/lib/__templates__/vite/README.md +204 -26
  44. package/lib/__templates__/vite/_npmrc +1 -1
  45. package/lib/__templates__/vite/package.json +1 -1
  46. package/lib/__templates__/vite/pnpm-lock.yaml +120 -120
  47. package/lib/__templates__/vite/scripts/dev.sh +7 -26
  48. package/lib/__templates__/vite/template.config.js +10 -1
  49. package/lib/__templates__/vite/vite.config.ts +3 -3
  50. package/lib/cli.js +567 -294
  51. package/package.json +10 -4
  52. package/lib/__templates__/expo/.cozeproj/scripts/deploy_build.sh +0 -109
  53. package/lib/__templates__/expo/app.json +0 -63
  54. package/lib/__templates__/expo/babel.config.js +0 -9
  55. package/lib/__templates__/expo/client/app/(tabs)/_layout.tsx +0 -43
  56. package/lib/__templates__/expo/client/app/(tabs)/home.tsx +0 -1
  57. package/lib/__templates__/expo/client/app/(tabs)/index.tsx +0 -7
  58. package/lib/__templates__/expo/client/app/+not-found.tsx +0 -79
  59. package/lib/__templates__/expo/client/index.js +0 -12
  60. package/lib/__templates__/expo/metro.config.js +0 -53
  61. package/lib/__templates__/nextjs/.babelrc +0 -15
  62. package/lib/__templates__/nextjs/server.mjs +0 -50
  63. /package/lib/__templates__/expo/{eslint-formatter-simple.mjs → client/eslint-formatter-simple.mjs} +0 -0
  64. /package/lib/__templates__/expo/{eslint.config.mjs → client/eslint.config.mjs} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coze-arch/cli",
3
- "version": "0.0.1-alpha.912cd5",
3
+ "version": "0.0.1-alpha.9c9bba",
4
4
  "private": false,
5
5
  "description": "coze coding devtools cli",
6
6
  "license": "MIT",
@@ -19,13 +19,13 @@
19
19
  "scripts": {
20
20
  "prebuild": "tsx scripts/prebuild.ts",
21
21
  "build": "tsx scripts/build.ts",
22
- "generate-templates": "tsx scripts/generate-templates-config.ts",
22
+ "create": "tsx scripts/create-template.ts",
23
23
  "lint": "eslint ./ --cache",
24
24
  "postpublish": "bash scripts/sync-npmmirror.sh",
25
25
  "test": "vitest --run --passWithNoTests",
26
26
  "test:all": "bash scripts/test-coverage.sh",
27
27
  "test:cov": "vitest --run --passWithNoTests --coverage",
28
- "test:e2e": "bash scripts/e2e.sh",
28
+ "test:e2e": "NODE_ENV=test bash scripts/e2e.sh",
29
29
  "test:perf": "vitest bench --run --config vitest.perf.config.ts",
30
30
  "test:perf:compare": "bash scripts/compare-perf.sh",
31
31
  "test:perf:save": "bash scripts/run-perf-with-output.sh"
@@ -38,6 +38,7 @@
38
38
  "commander": "~12.1.0",
39
39
  "ejs": "^3.1.10",
40
40
  "js-yaml": "^4.1.0",
41
+ "minimist": "^1.2.5",
41
42
  "shelljs": "^0.10.0"
42
43
  },
43
44
  "devDependencies": {
@@ -48,20 +49,25 @@
48
49
  "@coze-arch/ts-config": "workspace:*",
49
50
  "@coze-arch/vitest-config": "workspace:*",
50
51
  "@coze-coding/lambda": "workspace:*",
52
+ "@inquirer/prompts": "^3.2.0",
51
53
  "@types/ejs": "^3.1.5",
52
54
  "@types/iarna__toml": "^2.0.5",
53
55
  "@types/js-yaml": "^4.0.9",
56
+ "@types/minimatch": "^5.1.2",
57
+ "@types/minimist": "^1.2.5",
54
58
  "@types/node": "^24",
55
59
  "@types/shelljs": "^0.10.0",
56
60
  "@vitest/coverage-v8": "~4.0.16",
57
61
  "json-schema-to-typescript": "^15.0.3",
62
+ "minimatch": "^10.0.1",
58
63
  "rollup": "^4.41.1",
59
64
  "sucrase": "^3.35.0",
60
65
  "tsx": "^4.20.6",
61
66
  "vitest": "~4.0.16"
62
67
  },
63
68
  "publishConfig": {
64
- "access": "public"
69
+ "access": "public",
70
+ "registry": "https://registry.npmjs.org"
65
71
  },
66
72
  "cozePublishConfig": {
67
73
  "bin": {
@@ -1,109 +0,0 @@
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
- LOG_DIR="${COZE_LOG_DIR:-$ROOT_DIR/logs}"
6
- LOG_FILE="$LOG_DIR/app.log"
7
- mkdir -p "$LOG_DIR"
8
-
9
- # ==================== 配置项 ====================
10
- SERVER_DIR="app"
11
- EXPO_DIR="expo"
12
- CHECK_HASH_SCRIPT="$ROOT_DIR/check_hash.py"
13
- # ==================== 工具函数 ====================
14
- info() {
15
- echo -e "\033[32m[INFO] $1\033[0m"
16
- }
17
- warn() {
18
- echo -e "\033[33m[WARN] $1\033[0m"
19
- }
20
- error() {
21
- echo -e "\033[31m[ERROR] $1\033[0m"
22
- exit 1
23
- }
24
- check_command() {
25
- if ! command -v "$1" &> /dev/null; then
26
- error "命令 $1 未找到,请先安装"
27
- fi
28
- }
29
- write_log() {
30
- local level="${1:-INFO}"
31
- local msg="${2:-}"
32
- python - "$LOG_FILE" "$level" "$msg" <<'PY'
33
- import os,sys,json,time
34
- from datetime import datetime, timezone, timedelta
35
- path, level, msg = sys.argv[1], sys.argv[2].upper(), sys.argv[3]
36
- ts = int(time.time()*1000)
37
- tz = timezone(timedelta(hours=8))
38
- dt_str = datetime.now(tz).strftime('%Y-%m-%d %H:%M:%S')
39
- msg = msg.replace('\\n', '\n')
40
- msg = f"{dt_str} [{level}] {msg}"
41
- with open(path,'a',encoding='utf-8',buffering=1) as f:
42
- f.write(json.dumps({"level":level,"message":msg,"timestamp":ts},ensure_ascii=False)+'\n')
43
- f.flush(); os.fsync(f.fileno())
44
- PY
45
-
46
- case "$level" in
47
- INFO) info "$msg" ;;
48
- WARN) warn "$msg" ;;
49
- ERROR) echo -e "\033[31m[ERROR] $msg\033[0m" ;;
50
- *) info "$msg" ;;
51
- esac
52
- }
53
-
54
- # ==================== 前置检查 ====================
55
- write_log "INFO" "==================== 开始构建 ===================="
56
-
57
- write_log "INFO" "检查根目录 pre_install.py"
58
- if [ -f "$ROOT_DIR/pre_install.py" ]; then
59
- write_log "INFO" "执行:python $ROOT_DIR/pre_install.py"
60
- python "$ROOT_DIR/pre_install.py" || write_log "ERROR" "pre_install.py 执行失败"
61
- fi
62
-
63
- write_log "INFO" "开始执行构建脚本(build_dev.sh)..."
64
- write_log "INFO" "正在检查依赖命令是否存在..."
65
- # 检查核心命令
66
- check_command "pip"
67
- check_command "python"
68
- check_command "pnpm"
69
- check_command "npm"
70
-
71
- # ==================== 步骤 1:安装项目依赖 ====================
72
- write_log "INFO" "==================== 安装项目依赖 ===================="
73
- if [ ! -f "package.json" ]; then
74
- write_log "ERROR" "项目目录下无 package.json,不是合法的 Node.js 项目"
75
- fi
76
- # 步骤 2.1/2.2:安装 Expo 项目依赖(按哈希变化执行)
77
- if [ -f "$CHECK_HASH_SCRIPT" ]; then
78
- write_log "INFO" "检测 package.json 哈希是否变化"
79
- set +e
80
- python "$CHECK_HASH_SCRIPT" --config "package.json" --check
81
- rc_node=$?
82
- set -e
83
- if [ $rc_node -eq 1 ]; then
84
- write_log "INFO" "依赖哈希已变化,执行:pnpm install"
85
- pnpm install --registry=https://registry.npmmirror.com || write_log "ERROR" "Expo 项目依赖安装失败(pnpm 执行出错)"
86
-
87
- write_log "INFO" "依赖哈希已变化,执行:npm run install-missing"
88
- npm run install-missing || write_log "ERROR" "npm run install-missing 执行失败,请检查 package.json 中的脚本配置"
89
-
90
- set +e
91
- python "$CHECK_HASH_SCRIPT" --config "package.json" --update
92
- set -e
93
- else
94
- write_log "INFO" "跳过 pnpm install 与 npm run install-missing"
95
- fi
96
- else
97
- write_log "WARN" "未找到 check_hash.py,默认执行:pnpm install 与 npm run install-missing"
98
- pnpm install --registry=https://registry.npmmirror.com || write_log "ERROR" "Expo 项目依赖安装失败(pnpm 执行出错)"
99
- npm run install-missing || write_log "ERROR" "npm run install-missing 执行失败,请检查 package.json 中的脚本配置"
100
- fi
101
-
102
- write_log "INFO" "检查根目录 post_install.py"
103
- if [ -f "$ROOT_DIR/post_install.py" ]; then
104
- write_log "INFO" "执行:python $ROOT_DIR/post_install.py"
105
- python "$ROOT_DIR/post_install.py" || write_log "ERROR" "post_install.py 执行失败"
106
- fi
107
-
108
- write_log "INFO" "==================== 依赖安装完成!====================\n"
109
- write_log "INFO" "下一步:执行 ./deploy_run.sh 启动服务"
@@ -1,63 +0,0 @@
1
- {
2
- "expo": {
3
- "name": "${app_name}",
4
- "slug": "${slug}",
5
- "version": "1.0.0",
6
- "orientation": "portrait",
7
- "icon": "./client/assets/images/icon.png",
8
- "scheme": "myapp",
9
- "userInterfaceStyle": "automatic",
10
- "newArchEnabled": true,
11
- "ios": {
12
- "supportsTablet": true
13
- },
14
- "android": {
15
- "adaptiveIcon": {
16
- "foregroundImage": "./client/assets/images/adaptive-icon.png",
17
- "backgroundColor": "#ffffff"
18
- }
19
- },
20
- "web": {
21
- "bundler": "metro",
22
- "output": "single",
23
- "favicon": "./client/assets/images/favicon.png"
24
- },
25
- "plugins": [
26
- "expo-router",
27
- [
28
- "expo-splash-screen",
29
- {
30
- "image": "./client/assets/images/splash-icon.png",
31
- "imageWidth": 200,
32
- "resizeMode": "contain",
33
- "backgroundColor": "#ffffff"
34
- }
35
- ],
36
- [
37
- "expo-image-picker",
38
- {
39
- "photosPermission": "允许${app_name}访问您的相册,以便您上传或保存图片。",
40
- "cameraPermission": "允许${app_name}使用您的相机,以便您直接拍摄照片上传。",
41
- "microphonePermission": "允许${app_name}访问您的麦克风,以便您拍摄带有声音的视频。"
42
- }
43
- ],
44
- [
45
- "expo-location",
46
- {
47
- "locationWhenInUsePermission": "${app_name}需要访问您的位置以提供周边服务及导航功能。"
48
- }
49
- ],
50
- [
51
- "expo-camera",
52
- {
53
- "cameraPermission": "${app_name}需要访问相机以拍摄照片和视频。",
54
- "microphonePermission": "${app_name}需要访问麦克风以录制视频声音。",
55
- "recordAudioAndroid": true
56
- }
57
- ]
58
- ],
59
- "experiments": {
60
- "typedRoutes": true
61
- }
62
- }
63
- }
@@ -1,9 +0,0 @@
1
- module.exports = function (api) {
2
- api.cache(true);
3
- return {
4
- presets: ["babel-preset-expo"],
5
- plugins: [
6
- "react-native-reanimated/plugin",
7
- ],
8
- };
9
- };
@@ -1,43 +0,0 @@
1
- import { Tabs } from 'expo-router';
2
- import { FontAwesome6 } from '@expo/vector-icons';
3
- import { useSafeAreaInsets } from 'react-native-safe-area-context';
4
- import { useTheme } from '@/hooks/useTheme';
5
-
6
- export default function TabLayout() {
7
- const insets = useSafeAreaInsets();
8
- const { theme } = useTheme();
9
- const tabBarHeight = 56 + Math.max(insets.bottom, 8);
10
-
11
- return (
12
- <Tabs
13
- backBehavior='history'
14
- screenOptions={{
15
- headerShown: false,
16
- tabBarActiveTintColor: theme.tabIconSelected,
17
- tabBarInactiveTintColor: theme.tabIconDefault,
18
- tabBarStyle: {
19
- backgroundColor: theme.backgroundRoot,
20
- borderTopColor: theme.backgroundSecondary,
21
- borderTopWidth: 1,
22
- height: tabBarHeight,
23
- paddingBottom: Math.max(insets.bottom, 8),
24
- paddingTop: 6,
25
- },
26
- }}
27
- >
28
- <Tabs.Screen
29
- name='index'
30
- options={{ href: null }}
31
- />
32
- <Tabs.Screen
33
- name='home'
34
- options={{
35
- title: '首页',
36
- tabBarIcon: ({ color }) => (
37
- <FontAwesome6 name='house' size={20} color={color} />
38
- ),
39
- }}
40
- />
41
- </Tabs>
42
- );
43
- }
@@ -1 +0,0 @@
1
- export { default } from "@/screens/home";
@@ -1,7 +0,0 @@
1
- import { Redirect } from 'expo-router';
2
-
3
- const Index = () => {
4
- return <Redirect href="./home" relativeToDirectory />;
5
- };
6
-
7
- export default Index;
@@ -1,79 +0,0 @@
1
- import { useRouter } from 'expo-router';
2
- import { StyleSheet, View, Text, Pressable, Platform } from 'react-native';
3
-
4
- export default function NotFoundScreen() {
5
- const router = useRouter();
6
-
7
- const goBack = () => {
8
- if (router.canGoBack()) {
9
- router.back();
10
- }
11
- };
12
-
13
- return (
14
- <View style={styles.container}>
15
- <Text style={styles.heading}>404</Text>
16
- <Text style={styles.textStyle}>页面未找到</Text>
17
- <Text style={styles.subTextStyle}>
18
- 抱歉!您访问的页面不存在,当前页面功能待完善。
19
- </Text>
20
- <Pressable onPress={goBack} style={styles.button}>
21
- <Text style={styles.buttonText}>返回上一页</Text>
22
- </Pressable>
23
- </View>
24
- );
25
- }
26
-
27
- const styles = StyleSheet.create({
28
- container: {
29
- flex: 1,
30
- alignItems: 'center',
31
- justifyContent: 'center',
32
- backgroundColor: '#f3f5ff',
33
- padding: 16,
34
- },
35
- heading: {
36
- fontSize: 120,
37
- fontWeight: '900',
38
- color: '#4a5568',
39
- textShadowColor: 'rgba(0, 0, 0, 0.05)',
40
- textShadowOffset: { width: 0, height: 4 },
41
- textShadowRadius: 8,
42
- },
43
- textStyle: {
44
- fontSize: 24,
45
- fontWeight: '500',
46
- marginTop: -16,
47
- marginBottom: 16,
48
- color: '#4a5568',
49
- },
50
- subTextStyle: {
51
- fontSize: 16,
52
- color: '#718096',
53
- marginBottom: 32,
54
- maxWidth: 400,
55
- textAlign: 'center',
56
- },
57
- button: {
58
- paddingVertical: 12,
59
- paddingHorizontal: 24,
60
- backgroundColor: '#6366f1',
61
- borderRadius: 9999,
62
- ...Platform.select({
63
- ios: {
64
- shadowColor: 'rgba(0, 0, 0, 0.1)',
65
- shadowOffset: { width: 0, height: 10 },
66
- shadowOpacity: 1,
67
- shadowRadius: 15,
68
- },
69
- android: {
70
- elevation: 5,
71
- },
72
- }),
73
- },
74
- buttonText: {
75
- fontSize: 16,
76
- fontWeight: '600',
77
- color: '#ffffff',
78
- },
79
- });
@@ -1,12 +0,0 @@
1
- import '@expo/metro-runtime';
2
- import { registerRootComponent } from 'expo';
3
- import { ExpoRoot } from 'expo-router';
4
-
5
- // 显式定义 App 组件
6
- export function App() {
7
- // eslint-disable-next-line no-undef
8
- const ctx = require.context('./app');
9
- return <ExpoRoot context={ctx} />;
10
- }
11
-
12
- registerRootComponent(App);
@@ -1,53 +0,0 @@
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
- /*
32
- const apiProxy = createProxyMiddleware({
33
- target: 'http://localhost:5000',
34
- logLevel: 'debug',
35
- });
36
-
37
- config.server = {
38
- ...config.server,
39
- enhanceMiddleware: (metroMiddleware, metroServer) => {
40
- return connect()
41
- .use((req, res, next) => {
42
- if (req.url && req.url.startsWith('/api')) {
43
- console.log(`[Metro Proxy] Forwarding ${req.method} ${req.url}`);
44
- return apiProxy(req, res, next);
45
- }
46
- next();
47
- })
48
- .use(metroMiddleware);
49
- },
50
- }
51
- */
52
-
53
- module.exports = config;
@@ -1,15 +0,0 @@
1
- {
2
- "presets": [
3
- [
4
- "next/babel",
5
- {
6
- "preset-react": {
7
- "development": true
8
- }
9
- }
10
- ]
11
- ],
12
- "plugins": [
13
- "@react-dev-inspector/babel-plugin"
14
- ]
15
- }
@@ -1,50 +0,0 @@
1
- import { createServer } from 'node:http';
2
- import next from 'next';
3
- import { launchEditorMiddleware } from '@react-dev-inspector/middleware';
4
-
5
- const dev = process.env.NODE_ENV !== 'production';
6
- const hostname = process.env.HOSTNAME || 'localhost';
7
- const port = parseInt(process.env.PORT || '3000', 10);
8
-
9
- const app = next({ dev, hostname, port });
10
- const handle = app.getRequestHandler();
11
-
12
- app.prepare().then(() => {
13
- createServer((req, res) => {
14
- /**
15
- * Middlewares, from top to bottom
16
- */
17
- const middlewares = [
18
- /**
19
- * react-dev-inspector middleware for launching editor
20
- * Only active in development mode
21
- */
22
- ...(dev ? [launchEditorMiddleware] : []),
23
-
24
- /**
25
- * Next.js default app handler
26
- */
27
- (req, res) => handle(req, res),
28
- ];
29
-
30
- /**
31
- * Build middleware pipeline using reduceRight
32
- * Executes middlewares from top to bottom
33
- */
34
- const middlewarePipeline = middlewares.reduceRight(
35
- (next, middleware) => () => {
36
- middleware(req, res, next);
37
- },
38
- () => {},
39
- );
40
-
41
- middlewarePipeline();
42
- })
43
- .once('error', (err) => {
44
- console.error(err);
45
- process.exit(1);
46
- })
47
- .listen(port, () => {
48
- console.log(`> Ready on http://${hostname}:${port}`);
49
- });
50
- });