@coze-arch/cli 0.0.1-alpha.517ceb → 0.0.1-alpha.5b771d
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/lib/__templates__/expo/.coze +7 -2
- package/lib/__templates__/expo/.cozeproj/scripts/{deploy_build.sh → dev_build.sh} +0 -7
- package/lib/__templates__/expo/.cozeproj/scripts/{deploy_run.sh → dev_run.sh} +12 -16
- package/lib/__templates__/expo/.cozeproj/scripts/prod_build.sh +47 -0
- package/lib/__templates__/expo/.cozeproj/scripts/prod_run.sh +35 -0
- package/lib/__templates__/expo/babel.config.js +10 -0
- package/lib/__templates__/expo/client/components/ThemedText.tsx +33 -0
- package/lib/__templates__/expo/client/components/ThemedView.tsx +38 -0
- package/lib/__templates__/expo/client/constants/theme.ts +779 -47
- package/lib/__templates__/expo/client/hooks/useTheme.ts +1 -1
- package/lib/__templates__/expo/metro.config.js +76 -8
- package/lib/__templates__/expo/package.json +13 -4
- package/lib/__templates__/expo/pnpm-lock.yaml +71 -516
- package/lib/__templates__/nextjs/package.json +1 -1
- package/lib/__templates__/nextjs/pnpm-lock.yaml +5 -5
- package/lib/__templates__/nextjs/scripts/dev.sh +7 -26
- package/lib/__templates__/nextjs/src/app/globals.css +99 -87
- package/lib/__templates__/vite/package.json +1 -1
- package/lib/__templates__/vite/pnpm-lock.yaml +120 -120
- package/lib/__templates__/vite/scripts/dev.sh +7 -26
- package/lib/__templates__/vite/vite.config.ts +3 -3
- package/lib/cli.js +1 -1
- package/package.json +5 -2
|
@@ -3,5 +3,10 @@ entrypoint = "server.js"
|
|
|
3
3
|
requires = ["nodejs-24"]
|
|
4
4
|
|
|
5
5
|
[dev]
|
|
6
|
-
build = ["bash", ".cozeproj/scripts/
|
|
7
|
-
run = ["bash", ".cozeproj/scripts/
|
|
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 = "."
|
|
@@ -49,13 +49,6 @@ fs.writeSync(fd, record+"\n", null, "utf8");
|
|
|
49
49
|
fs.fsyncSync(fd);
|
|
50
50
|
fs.closeSync(fd);
|
|
51
51
|
' "$LOG_FILE" "$level" "$msg"
|
|
52
|
-
|
|
53
|
-
case "$level" in
|
|
54
|
-
INFO) info "$msg" ;;
|
|
55
|
-
WARN) warn "$msg" ;;
|
|
56
|
-
ERROR) echo -e "\033[31m[ERROR] $msg\033[0m" ;;
|
|
57
|
-
*) info "$msg" ;;
|
|
58
|
-
esac
|
|
59
52
|
}
|
|
60
53
|
|
|
61
54
|
# ==================== 前置检查 ====================
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
2
|
+
PREVIEW_DIR="${COZE_PREVIEW_DIR:-$ROOT_DIR}"
|
|
2
3
|
LOG_DIR="${COZE_LOG_DIR:-$ROOT_DIR/logs}"
|
|
3
4
|
LOG_FILE="$LOG_DIR/app.log"
|
|
4
5
|
mkdir -p "$LOG_DIR"
|
|
@@ -10,7 +11,7 @@ SERVER_PORT="9091"
|
|
|
10
11
|
# Expo 项目配置
|
|
11
12
|
EXPO_HOST="0.0.0.0"
|
|
12
13
|
EXPO_DIR="expo"
|
|
13
|
-
EXPO_PORT="
|
|
14
|
+
EXPO_PORT="5000"
|
|
14
15
|
WEB_URL="${COZE_PROJECT_DOMAIN_DEFAULT:-http://127.0.0.1:${SERVER_PORT}}"
|
|
15
16
|
ASSUME_YES="1"
|
|
16
17
|
EXPO_PUBLIC_BACKEND_BASE_URL="${EXPO_PUBLIC_BACKEND_BASE_URL:-$WEB_URL}"
|
|
@@ -116,18 +117,12 @@ fs.writeSync(fd, record+"\n", null, "utf8");
|
|
|
116
117
|
fs.fsyncSync(fd);
|
|
117
118
|
fs.closeSync(fd);
|
|
118
119
|
' "$LOG_FILE" "$level" "$msg"
|
|
119
|
-
case "$level" in
|
|
120
|
-
INFO) echo -e "\033[32m[INFO] $msg\033[0m" ;;
|
|
121
|
-
WARN) echo -e "\033[33m[WARN] $msg\033[0m" ;;
|
|
122
|
-
ERROR) echo -e "\033[31m[ERROR] $msg\033[0m" ;;
|
|
123
|
-
*) echo -e "\033[32m[INFO] $msg\033[0m" ;;
|
|
124
|
-
esac
|
|
125
120
|
}
|
|
126
121
|
|
|
127
122
|
wait_port_connectable() {
|
|
128
123
|
local host=$1 port=$2 retries=${3:-10}
|
|
129
124
|
for _ in $(seq 1 "$retries"); do
|
|
130
|
-
nc -z "$host" "$port" && return 0
|
|
125
|
+
nc -z -w 1 "$host" "$port" >/dev/null 2>&1 && return 0
|
|
131
126
|
sleep 1
|
|
132
127
|
done
|
|
133
128
|
return 1
|
|
@@ -159,6 +154,15 @@ detect_expo_fetch_failed() {
|
|
|
159
154
|
}
|
|
160
155
|
|
|
161
156
|
# ==================== 前置检查 ====================
|
|
157
|
+
# 关掉nginx进程
|
|
158
|
+
ps -ef | grep nginx | grep -v grep | awk '{print $2}' | xargs -r kill -9
|
|
159
|
+
|
|
160
|
+
write_log "INFO" "检查根目录 pre_install.py"
|
|
161
|
+
if [ -f "$PREVIEW_DIR/pre_install.py" ]; then
|
|
162
|
+
write_log "INFO" "执行:python $PREVIEW_DIR/pre_install.py"
|
|
163
|
+
python "$PREVIEW_DIR/pre_install.py" || write_log "ERROR" "pre_install.py 执行失败"
|
|
164
|
+
fi
|
|
165
|
+
|
|
162
166
|
write_log "INFO" "==================== 开始启动 ===================="
|
|
163
167
|
write_log "INFO" "开始执行服务启动脚本(start_dev.sh)..."
|
|
164
168
|
write_log "INFO" "正在检查依赖命令和目录是否存在..."
|
|
@@ -176,14 +180,6 @@ ensure_port SERVER_PORT "$SERVER_PORT"
|
|
|
176
180
|
ensure_port EXPO_PORT "$EXPO_PORT"
|
|
177
181
|
|
|
178
182
|
# ==================== 启动 Server 服务 ====================
|
|
179
|
-
write_log "INFO" "检查 Nginx 端口 (5000)..."
|
|
180
|
-
if is_port_free 5000; then
|
|
181
|
-
write_log "INFO" "端口 5000 未被占用,正在启动 Nginx..."
|
|
182
|
-
service nginx start
|
|
183
|
-
else
|
|
184
|
-
write_log "INFO" "端口 5000 已被占用,跳过 Nginx 启动"
|
|
185
|
-
fi
|
|
186
|
-
|
|
187
183
|
write_log "INFO" "==================== 启动 server 服务 ===================="
|
|
188
184
|
write_log "INFO" "正在执行:npm run server"
|
|
189
185
|
PORT="$SERVER_PORT" nohup npm run server > logs/app.log 2>&1 &
|
|
@@ -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 server:build"
|
|
44
|
+
(cd "$ROOT_DIR" && pnpm run server:build) || error "dist打包失败"
|
|
45
|
+
info "==================== dist打包完成!====================\n"
|
|
46
|
+
|
|
47
|
+
info "下一步:执行 ./prod_run.sh 启动服务"
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# 产物部署使用
|
|
3
|
+
set -euo pipefail
|
|
4
|
+
|
|
5
|
+
ROOT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
HOST="${HOST:-0.0.0.0}"
|
|
9
|
+
PORT="${PORT:-5000}"
|
|
10
|
+
|
|
11
|
+
# ==================== 工具函数 ====================
|
|
12
|
+
info() {
|
|
13
|
+
echo "[INFO] $1"
|
|
14
|
+
}
|
|
15
|
+
warn() {
|
|
16
|
+
echo "[WARN] $1"
|
|
17
|
+
}
|
|
18
|
+
error() {
|
|
19
|
+
echo "[ERROR] $1"
|
|
20
|
+
exit 1
|
|
21
|
+
}
|
|
22
|
+
check_command() {
|
|
23
|
+
if ! command -v "$1" &> /dev/null; then
|
|
24
|
+
error "命令 $1 未找到,请先安装"
|
|
25
|
+
fi
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
# ============== 启动服务 ======================
|
|
29
|
+
# 检查核心命令
|
|
30
|
+
check_command "pnpm"
|
|
31
|
+
check_command "npm"
|
|
32
|
+
|
|
33
|
+
info "开始执行:pnpm run server:prod"
|
|
34
|
+
(cd "$ROOT_DIR" && PORT="$PORT" pnpm run server:prod) || error "服务启动失败"
|
|
35
|
+
info "服务启动完成!\n"
|
|
@@ -3,6 +3,16 @@ module.exports = function (api) {
|
|
|
3
3
|
return {
|
|
4
4
|
presets: ["babel-preset-expo"],
|
|
5
5
|
plugins: [
|
|
6
|
+
[
|
|
7
|
+
"module-resolver",
|
|
8
|
+
{
|
|
9
|
+
root: ["./"],
|
|
10
|
+
alias: {
|
|
11
|
+
"@": "./client",
|
|
12
|
+
},
|
|
13
|
+
extensions: [".ios.js", ".android.js", ".js", ".ts", ".tsx", ".json"],
|
|
14
|
+
},
|
|
15
|
+
],
|
|
6
16
|
"react-native-reanimated/plugin",
|
|
7
17
|
],
|
|
8
18
|
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Text, TextProps, TextStyle } from 'react-native';
|
|
3
|
+
import { useTheme } from '@/hooks/useTheme';
|
|
4
|
+
import { Typography } from '@/constants/theme';
|
|
5
|
+
|
|
6
|
+
type TypographyVariant = keyof typeof Typography;
|
|
7
|
+
|
|
8
|
+
interface ThemedTextProps extends TextProps {
|
|
9
|
+
variant?: TypographyVariant;
|
|
10
|
+
color?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function ThemedText({
|
|
14
|
+
variant = 'body',
|
|
15
|
+
color,
|
|
16
|
+
style,
|
|
17
|
+
children,
|
|
18
|
+
...props
|
|
19
|
+
}: ThemedTextProps) {
|
|
20
|
+
const { theme } = useTheme();
|
|
21
|
+
const typographyStyle = Typography[variant];
|
|
22
|
+
|
|
23
|
+
const textStyle: TextStyle = {
|
|
24
|
+
...typographyStyle,
|
|
25
|
+
color: color ?? theme.textPrimary,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<Text style={[textStyle, style]} {...props}>
|
|
30
|
+
{children}
|
|
31
|
+
</Text>
|
|
32
|
+
);
|
|
33
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View, ViewProps, ViewStyle } from 'react-native';
|
|
3
|
+
import { useTheme } from '@/hooks/useTheme';
|
|
4
|
+
|
|
5
|
+
type BackgroundLevel = 'root' | 'default' | 'secondary' | 'tertiary';
|
|
6
|
+
|
|
7
|
+
interface ThemedViewProps extends ViewProps {
|
|
8
|
+
level?: BackgroundLevel;
|
|
9
|
+
backgroundColor?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const backgroundMap: Record<BackgroundLevel, string> = {
|
|
13
|
+
root: 'backgroundRoot',
|
|
14
|
+
default: 'backgroundDefault',
|
|
15
|
+
secondary: 'backgroundSecondary',
|
|
16
|
+
tertiary: 'backgroundTertiary',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function ThemedView({
|
|
20
|
+
level = 'root',
|
|
21
|
+
backgroundColor,
|
|
22
|
+
style,
|
|
23
|
+
children,
|
|
24
|
+
...props
|
|
25
|
+
}: ThemedViewProps) {
|
|
26
|
+
const { theme } = useTheme();
|
|
27
|
+
const bgColor = backgroundColor ?? (theme as any)[backgroundMap[level]];
|
|
28
|
+
|
|
29
|
+
const viewStyle: ViewStyle = {
|
|
30
|
+
backgroundColor: bgColor,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<View style={[viewStyle, style]} {...props}>
|
|
35
|
+
{children}
|
|
36
|
+
</View>
|
|
37
|
+
);
|
|
38
|
+
}
|