befly 2.0.14 → 2.1.1
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/.gitignore +1 -0
- package/checks/table.js +106 -81
- package/config/env.js +1 -0
- package/main.js +43 -60
- package/package.json +10 -13
- package/plugins/db.js +137 -178
- package/scripts/syncDb.js +367 -0
- package/tables/common.json +14 -14
- package/tables/tool.json +4 -4
- package/utils/util.js +117 -19
- package/utils/validate.js +18 -119
- package/USEAGE.md +0 -5
- package/bin/befly.js +0 -176
- package/scripts/dbSync.js +0 -714
- package/scripts/release.js +0 -258
package/scripts/release.js
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { readFileSync, writeFileSync } from 'fs';
|
|
4
|
-
import { execSync } from 'child_process';
|
|
5
|
-
import { join } from 'path';
|
|
6
|
-
import { __filename, __dirname } from '../system.js';
|
|
7
|
-
|
|
8
|
-
// 获取 package.json 路径
|
|
9
|
-
const packagePath = join(__dirname, 'package.json');
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 解析命令行参数
|
|
13
|
-
*/
|
|
14
|
-
function parseArguments() {
|
|
15
|
-
const args = process.argv.slice(2);
|
|
16
|
-
|
|
17
|
-
if (args.includes('-h') || args.includes('--help')) {
|
|
18
|
-
console.log(`
|
|
19
|
-
发布脚本使用说明:
|
|
20
|
-
bun run scripts/release.js -a 发布大版本 (major)
|
|
21
|
-
bun run scripts/release.js -b 发布次要版本 (minor)
|
|
22
|
-
bun run scripts/release.js -c 发布补丁版本 (patch)
|
|
23
|
-
bun run scripts/release.js -h 显示帮助信息
|
|
24
|
-
|
|
25
|
-
或者使用快捷命令:
|
|
26
|
-
bun run ra 发布大版本
|
|
27
|
-
bun run rb 发布次要版本
|
|
28
|
-
bun run rc 发布补丁版本
|
|
29
|
-
`);
|
|
30
|
-
process.exit(0);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (args.includes('-a')) return 'major';
|
|
34
|
-
if (args.includes('-b')) return 'minor';
|
|
35
|
-
if (args.includes('-c')) return 'patch';
|
|
36
|
-
|
|
37
|
-
console.error('错误: 请指定版本类型参数');
|
|
38
|
-
console.log('使用 -h 或 --help 查看帮助信息');
|
|
39
|
-
process.exit(1);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 读取 package.json
|
|
44
|
-
*/
|
|
45
|
-
function readPackageJson() {
|
|
46
|
-
try {
|
|
47
|
-
const content = readFileSync(packagePath, 'utf8');
|
|
48
|
-
return JSON.parse(content);
|
|
49
|
-
} catch (error) {
|
|
50
|
-
console.error('错误: 无法读取 package.json:', error.message);
|
|
51
|
-
process.exit(1);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* 写入 package.json
|
|
57
|
-
*/
|
|
58
|
-
function writePackageJson(packageData) {
|
|
59
|
-
try {
|
|
60
|
-
const content = JSON.stringify(packageData, null, 4);
|
|
61
|
-
writeFileSync(packagePath, content, 'utf8');
|
|
62
|
-
console.log('✓ package.json 已更新');
|
|
63
|
-
} catch (error) {
|
|
64
|
-
console.error('错误: 无法写入 package.json:', error.message);
|
|
65
|
-
process.exit(1);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* 更新版本号
|
|
71
|
-
*/
|
|
72
|
-
function updateVersion(currentVersion, type) {
|
|
73
|
-
const versionParts = currentVersion.split('.').map(Number);
|
|
74
|
-
|
|
75
|
-
if (versionParts.length !== 3) {
|
|
76
|
-
console.error('错误: 版本号格式不正确,应为 x.y.z 格式');
|
|
77
|
-
process.exit(1);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
let [major, minor, patch] = versionParts;
|
|
81
|
-
|
|
82
|
-
switch (type) {
|
|
83
|
-
case 'major':
|
|
84
|
-
major += 1;
|
|
85
|
-
minor = 0;
|
|
86
|
-
patch = 0;
|
|
87
|
-
break;
|
|
88
|
-
case 'minor':
|
|
89
|
-
minor += 1;
|
|
90
|
-
patch = 0;
|
|
91
|
-
break;
|
|
92
|
-
case 'patch':
|
|
93
|
-
patch += 1;
|
|
94
|
-
break;
|
|
95
|
-
default:
|
|
96
|
-
console.error('错误: 未知的版本类型');
|
|
97
|
-
process.exit(1);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return `${major}.${minor}.${patch}`;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* 执行 Git 命令(必须成功)
|
|
105
|
-
*/
|
|
106
|
-
function executeGitCommand(command, description) {
|
|
107
|
-
try {
|
|
108
|
-
console.log(`正在执行: ${description}`);
|
|
109
|
-
console.log(`命令: ${command}`);
|
|
110
|
-
|
|
111
|
-
const result = execSync(command, {
|
|
112
|
-
encoding: 'utf8',
|
|
113
|
-
stdio: 'inherit',
|
|
114
|
-
cwd: __dirname
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
console.log(`✓ ${description} 完成`);
|
|
118
|
-
return result;
|
|
119
|
-
} catch (error) {
|
|
120
|
-
console.error(`错误: ${description} 失败:`, error.message);
|
|
121
|
-
console.error('Git 操作失败,发布已取消!');
|
|
122
|
-
process.exit(1);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* 执行命令(必须成功)
|
|
128
|
-
*/
|
|
129
|
-
function executeCommand(command, description) {
|
|
130
|
-
try {
|
|
131
|
-
console.log(`正在执行: ${description}`);
|
|
132
|
-
console.log(`命令: ${command}`);
|
|
133
|
-
|
|
134
|
-
const result = execSync(command, {
|
|
135
|
-
encoding: 'utf8',
|
|
136
|
-
stdio: 'inherit',
|
|
137
|
-
cwd: __dirname
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
console.log(`✓ ${description} 完成`);
|
|
141
|
-
return result;
|
|
142
|
-
} catch (error) {
|
|
143
|
-
console.error(`错误: ${description} 失败:`, error.message);
|
|
144
|
-
process.exit(1);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* 检查 Git 状态
|
|
150
|
-
*/
|
|
151
|
-
function checkGitStatus() {
|
|
152
|
-
try {
|
|
153
|
-
const status = execSync('git status --porcelain', {
|
|
154
|
-
encoding: 'utf8',
|
|
155
|
-
cwd: __dirname
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
if (status.trim()) {
|
|
159
|
-
console.error('错误: 工作目录有未提交的更改');
|
|
160
|
-
console.log('未提交的文件:');
|
|
161
|
-
console.log(status);
|
|
162
|
-
console.log('\n请先提交所有更改后再发布!');
|
|
163
|
-
return false;
|
|
164
|
-
}
|
|
165
|
-
return true;
|
|
166
|
-
} catch (error) {
|
|
167
|
-
console.error('错误: 无法检查 Git 状态:', error.message);
|
|
168
|
-
console.error('请确保当前目录是一个有效的 Git 仓库!');
|
|
169
|
-
return false;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* 检查必要文件是否存在
|
|
175
|
-
*/
|
|
176
|
-
function checkRequiredFiles() {
|
|
177
|
-
const requiredFiles = ['main.js', 'system.js', 'package.json', 'README.md', 'LICENSE'];
|
|
178
|
-
|
|
179
|
-
const missingFiles = [];
|
|
180
|
-
|
|
181
|
-
for (const file of requiredFiles) {
|
|
182
|
-
try {
|
|
183
|
-
const filePath = join(__dirname, file);
|
|
184
|
-
readFileSync(filePath);
|
|
185
|
-
} catch (error) {
|
|
186
|
-
missingFiles.push(file);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (missingFiles.length > 0) {
|
|
191
|
-
console.error('错误: 以下必要文件缺失:');
|
|
192
|
-
missingFiles.forEach((file) => console.error(` - ${file}`));
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
console.log('✓ 所有必要文件检查通过');
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* 主函数
|
|
202
|
-
*/
|
|
203
|
-
function main() {
|
|
204
|
-
// 解析参数(如果是帮助命令会直接退出)
|
|
205
|
-
const versionType = parseArguments();
|
|
206
|
-
|
|
207
|
-
console.log('🚀 开始发布流程...\n');
|
|
208
|
-
console.log(`版本类型: ${versionType}`);
|
|
209
|
-
|
|
210
|
-
// 检查必要文件
|
|
211
|
-
console.log('\n--- 检查必要文件 ---');
|
|
212
|
-
if (!checkRequiredFiles()) {
|
|
213
|
-
console.log('\n发布已取消');
|
|
214
|
-
process.exit(1);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// 检查 Git 状态
|
|
218
|
-
console.log('\n--- 检查 Git 状态 ---');
|
|
219
|
-
if (!checkGitStatus()) {
|
|
220
|
-
console.log('\n发布已取消');
|
|
221
|
-
process.exit(1);
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// 读取当前版本
|
|
225
|
-
const packageData = readPackageJson();
|
|
226
|
-
const currentVersion = packageData.version;
|
|
227
|
-
console.log(`当前版本: ${currentVersion}`);
|
|
228
|
-
|
|
229
|
-
// 计算新版本
|
|
230
|
-
const newVersion = updateVersion(currentVersion, versionType);
|
|
231
|
-
console.log(`新版本: ${newVersion}\n`);
|
|
232
|
-
|
|
233
|
-
// 更新版本号
|
|
234
|
-
packageData.version = newVersion;
|
|
235
|
-
writePackageJson(packageData);
|
|
236
|
-
|
|
237
|
-
// 提交版本更新
|
|
238
|
-
console.log('\n--- Git 操作 ---');
|
|
239
|
-
executeGitCommand('git add package.json', '添加 package.json 到 Git');
|
|
240
|
-
executeGitCommand(`git commit -m "chore: bump version to ${newVersion}"`, '提交版本更新');
|
|
241
|
-
executeGitCommand(`git tag v${newVersion}`, '创建版本标签');
|
|
242
|
-
|
|
243
|
-
// 发布到 npm
|
|
244
|
-
console.log('\n--- NPM 发布 ---');
|
|
245
|
-
executeCommand('bun publish --registry=https://registry.npmjs.org --access=public', '发布到 npm');
|
|
246
|
-
|
|
247
|
-
// 推送到远程仓库
|
|
248
|
-
console.log('\n--- 推送到远程仓库 ---');
|
|
249
|
-
executeGitCommand('git push', '推送代码到远程仓库');
|
|
250
|
-
executeGitCommand('git push --tags', '推送标签到远程仓库');
|
|
251
|
-
|
|
252
|
-
console.log(`\n🎉 版本 ${newVersion} 发布成功!`);
|
|
253
|
-
console.log(`📦 包名: ${packageData.name}`);
|
|
254
|
-
console.log(`🔗 npm: https://www.npmjs.com/package/${packageData.name}`);
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
// 启动主函数
|
|
258
|
-
main();
|