Skip to content

Commit f3e9686

Browse files
committed
chore: add scripts
1 parent 545212e commit f3e9686

3 files changed

Lines changed: 569 additions & 0 deletions

File tree

scripts/README.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
# 脚本使用说明
2+
3+
## sync-config.mjs - 配置同步脚本
4+
5+
这个脚本用于将 `config/` 目录下的配置文件同步到 [awsome-cloudbase-examples](https://github.com/TencentCloudBase/awsome-cloudbase-examples) 项目的各个模板中。
6+
7+
### 🚀 快速开始
8+
9+
1. **准备目标仓库**
10+
```bash
11+
cd ..
12+
git clone https://github.com/TencentCloudBase/awsome-cloudbase-examples.git
13+
cd cloudbase-turbo-delploy
14+
```
15+
16+
2. **运行同步脚本**
17+
```bash
18+
# 同步所有模板
19+
node scripts/sync-config.mjs
20+
21+
# 干运行模式(预览操作,不实际执行)
22+
node scripts/sync-config.mjs --dry-run
23+
```
24+
25+
### 📋 命令选项
26+
27+
| 选项 | 说明 |
28+
|-----|------|
29+
| `--help`, `-h` | 显示帮助信息 |
30+
| `--dry-run` | 干运行模式,只显示将要执行的操作 |
31+
| `--skip-git` | 跳过 Git 提交和推送操作 |
32+
| `--backup` | 创建备份(覆盖配置文件设置) |
33+
| `--filter <关键词>` | 只同步路径包含指定关键词的模板 |
34+
35+
### 💡 使用示例
36+
37+
```bash
38+
# 同步所有模板
39+
node scripts/sync-config.mjs
40+
41+
# 只同步包含 "web" 的模板
42+
node scripts/sync-config.mjs --filter web
43+
44+
# 只同步小程序模板
45+
node scripts/sync-config.mjs --filter miniprogram
46+
47+
# 干运行模式,查看将要同步的内容
48+
node scripts/sync-config.mjs --dry-run
49+
50+
# 同步但跳过 Git 操作
51+
node scripts/sync-config.mjs --skip-git
52+
53+
# 创建备份并同步
54+
node scripts/sync-config.mjs --backup
55+
```
56+
57+
### ⚙️ 配置文件
58+
59+
#### template-config.json
60+
61+
脚本的主要配置文件,结构简单明了:
62+
63+
```json
64+
{
65+
"description": "awsome-cloudbase-examples 项目模板路径配置",
66+
"version": "1.0.0",
67+
"templates": [
68+
"web/react-starter",
69+
"miniprogram/blog",
70+
"cloudbaserun/deepseek-agent",
71+
"..."
72+
],
73+
"excludePatterns": ["node_modules", ".DS_Store", "*.log"],
74+
"syncConfig": {
75+
"createBackup": false,
76+
"overwrite": true,
77+
"autoCommit": true,
78+
"commitMessage": "chore: sync config and rules from cloudbase-turbo-deploy"
79+
}
80+
}
81+
```
82+
83+
**配置说明:**
84+
- `templates`: 模板路径数组,每个路径对应 awsome-cloudbase-examples 中的一个模板目录
85+
- `excludePatterns`: 同步时需要排除的文件/目录模式
86+
- `syncConfig`: 同步相关配置
87+
- `createBackup`: 是否创建备份
88+
- `overwrite`: 是否覆盖已存在的文件
89+
- `autoCommit`: 是否自动提交和推送
90+
- `commitMessage`: 默认提交信息
91+
92+
### 🔧 工作流程
93+
94+
1. **读取配置**: 从 `template-config.json` 读取模板列表和配置
95+
2. **过滤模板**: 根据 `--filter` 参数过滤要同步的模板
96+
3. **检查环境**: 验证 `config/` 目录和目标仓库是否存在
97+
4. **同步文件**: 将 `config/` 下的内容复制到各个模板目录
98+
5. **Git 操作**: 自动提交更改并推送到远程仓库
99+
100+
### 📁 同步的内容
101+
102+
脚本会将 `config/` 目录下的所有内容同步到目标模板,包括:
103+
104+
- `.github/` - GitHub Actions 配置
105+
- `.rules/` - 规则配置文件
106+
- `.cursor/` - Cursor 编辑器配置
107+
- `.windsurf/` - Windsurf 编辑器配置
108+
- `.vscode/` - VSCode 配置
109+
- `.clinerules/` - CLI 规则配置
110+
- `.trae/` - Trae 配置
111+
112+
### 🔍 过滤功能
113+
114+
使用 `--filter` 参数可以只同步特定类型的模板:
115+
116+
```bash
117+
# 同步所有 web 相关模板
118+
node scripts/sync-config.mjs --filter web
119+
120+
# 同步所有小程序模板
121+
node scripts/sync-config.mjs --filter miniprogram
122+
123+
# 同步所有云函数模板
124+
node scripts/sync-config.mjs --filter cloudrunfunctions
125+
126+
# 同步所有 CloudBase Run 模板
127+
node scripts/sync-config.mjs --filter cloudbaserun
128+
```
129+
130+
### ⚠️ 注意事项
131+
132+
1. **权限要求**: 确保你有目标仓库的推送权限
133+
2. **备份建议**: 首次使用建议启用 `--backup` 选项
134+
3. **干运行**: 不确定操作结果时,先使用 `--dry-run` 预览
135+
4. **路径结构**: 目标仓库必须位于 `../awsome-cloudbase-examples/`
136+
137+
### 🐛 故障排除
138+
139+
**问题**: 目标目录不存在
140+
- **解决**: 确保已正确克隆目标仓库,且路径正确
141+
142+
**问题**: Git 操作失败
143+
- **解决**: 检查网络连接和仓库权限,可使用 `--skip-git` 跳过 Git 操作
144+
145+
**问题**: 配置文件读取失败
146+
- **解决**: 检查 `template-config.json` 格式是否正确
147+
148+
### 📝 日志输出
149+
150+
脚本会输出详细的操作日志,包括:
151+
- 📁 源目录信息
152+
- 📋 要处理的模板数量
153+
- 🔍 过滤条件(如果使用)
154+
- ✅ 成功同步的文件
155+
- ⚠️ 跳过的文件和原因
156+
- 📊 最终统计信息

0 commit comments

Comments
 (0)