forked from ZEGOCLOUD/docs_all
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·159 lines (142 loc) · 5.44 KB
/
setup.sh
File metadata and controls
executable file
·159 lines (142 loc) · 5.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
# 设置颜色输出
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} ZEGO 文档项目环境设置脚本${NC}"
echo -e "${BLUE}========================================${NC}"
echo ""
# 解析参数
WITH_HOOK=false
for arg in "$@"; do
case "$arg" in
--with-hook)
WITH_HOOK=true
;;
*)
;;
esac
done
# 1. 检查 Node.js 版本
echo -e "${YELLOW}1. 检查 Node.js 版本...${NC}"
if command -v node &> /dev/null; then
NODE_VERSION=$(node -v | cut -d'v' -f2)
NODE_MAJOR=$(echo $NODE_VERSION | cut -d'.' -f1)
echo -e "当前 Node.js 版本: ${GREEN}v$NODE_VERSION${NC}"
if [ "$NODE_MAJOR" -ge 19 ]; then
echo -e "${GREEN}✓ Node.js 版本满足要求 (>= 19)${NC}"
else
echo -e "${RED}✗ Node.js 版本过低,需要 >= 19,当前版本: $NODE_VERSION${NC}"
echo -e "${YELLOW}正在安装最新的 LTS 版本...${NC}"
# 检测操作系统并安装 Node.js
if [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
if command -v brew &> /dev/null; then
echo "使用 Homebrew 安装 Node.js..."
brew install node
else
echo -e "${RED}请先安装 Homebrew: https://brew.sh/${NC}"
echo "或者从 https://nodejs.org/ 下载最新的 LTS 版本"
exit 1
fi
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
# Linux
if command -v curl &> /dev/null; then
echo "使用 NodeSource 安装 Node.js..."
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
else
echo -e "${RED}请先安装 curl,然后从 https://nodejs.org/ 下载最新的 LTS 版本${NC}"
exit 1
fi
else
echo -e "${RED}不支持的操作系统,请手动安装 Node.js >= 19${NC}"
exit 1
fi
# 验证安装
if command -v node &> /dev/null; then
NEW_VERSION=$(node -v)
echo -e "${GREEN}✓ Node.js 安装成功: $NEW_VERSION${NC}"
else
echo -e "${RED}✗ Node.js 安装失败${NC}"
exit 1
fi
fi
else
echo -e "${RED}✗ 未找到 Node.js${NC}"
echo -e "${YELLOW}正在安装 Node.js...${NC}"
if [[ "$OSTYPE" == "darwin"* ]]; then
if command -v brew &> /dev/null; then
brew install node
else
echo -e "${RED}请先安装 Homebrew: https://brew.sh/${NC}"
exit 1
fi
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
if command -v curl &> /dev/null; then
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs
else
echo -e "${RED}请先安装 curl${NC}"
exit 1
fi
else
echo -e "${RED}请从 https://nodejs.org/ 下载并安装 Node.js >= 19${NC}"
exit 1
fi
fi
echo ""
# 2. 安装 Docuo CLI
echo -e "${YELLOW}2. 安装 Docuo CLI...${NC}"
if command -v docuo &> /dev/null; then
echo -e "${GREEN}✓ Docuo CLI 已安装${NC}"
else
echo -e "${YELLOW}正在安装 Docuo CLI...${NC}"
npm install -g @spreading/docuo
if command -v docuo &> /dev/null; then
echo -e "${GREEN}✓ Docuo CLI 安装成功${NC}"
else
echo -e "${RED}✗ Docuo CLI 安装失败${NC}"
echo -e "${YELLOW}请尝试手动安装: npm install -g @spreading/docuo${NC}"
fi
fi
echo ""
# 3. 将.hooks下的脚本在需要时复制到.git/hooks下
if [ "$WITH_HOOK" = true ]; then
echo -e "${YELLOW}3. 复制 Git Hooks...${NC}"
cp -f .hooks/* .git/hooks/
echo -e "${GREEN}✓ Git Hooks 复制成功${NC}"
else
echo -e "${YELLOW}3. 跳过 Git Hooks 复制(未使用 --with-hook)${NC}"
fi
echo ""
# 4. 提醒安装 VS Code 插件
echo -e "${YELLOW}4. 推荐的 VS Code 插件:${NC}"
echo -e "${BLUE}请安装以下插件以获得更好的开发体验:${NC}"
echo ""
echo -e "${GREEN}• Docuo:${NC} https://marketplace.visualstudio.com/items?itemName=spreading-docuo.docuo"
echo -e "${GREEN}• Markdown Table:${NC} https://marketplace.visualstudio.com/items?itemName=TakumiI.markdowntable"
echo -e "${GREEN}• GitLens:${NC} https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens"
echo -e "${GREEN}• MDX:${NC} https://marketplace.visualstudio.com/items?itemName=unifiedjs.vscode-mdx"
echo -e "${GREEN}• GitHub Pull Request:${NC} https://marketplace.visualstudio.com/items?itemName=GitHub.vscode-pull-request-github"
echo ""
# 5. 提醒查看详细使用说明
echo -e "${YELLOW}5. 详细使用说明:${NC}"
echo -e "${BLUE}请查看详细的使用指南:${NC}"
echo -e "${GREEN}https://zegocloud.feishu.cn/wiki/G3stwqUPYinrVEkkWkFctzdTnwb${NC}"
echo ""
# 6. 启动开发服务器
echo -e "${YELLOW}6. 启动开发服务器${NC}"
echo -e "${BLUE}环境设置完成!现在可以启动开发服务器:${NC}"
echo -e "${GREEN}docuo dev${NC}"
echo ""
echo -e "${YELLOW}提示:${NC}"
echo -e "• 如果遇到问题,可以运行: ${GREEN}docuo clear && docuo dev${NC}"
echo -e "• 如需拷贝 Git Hooks,请使用: ${GREEN}./setup.sh --with-hook${NC}"
echo ""
echo -e "${BLUE}========================================${NC}"
echo -e "${BLUE} 环境设置完成!${NC}"
echo -e "${BLUE}========================================${NC}"