stigmergy 1.1.2 → 1.1.4
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/package.json +2 -3
- package/scripts/build.js +2 -2
- package/scripts/publish.js +267 -267
- package/scripts/simple-publish.js +58 -58
- package/src/cli/router.js +49 -11
- package/src/core/coordination/nodejs/HookDeploymentManager.js +1 -1
- package/test/fibonacci.test.js +178 -0
- package/test/hook-system-integration-test.js +306 -306
- package/test/system-compatibility-test.js +1 -1
- package/test/tool-selection-integration-test.js +1 -1
- package/src/main.js +0 -1338
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stigmergy",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "Stigmergy CLI - Multi-Agents Cross-AI CLI Tools Collaboration System",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -81,7 +81,6 @@
|
|
|
81
81
|
"child_process": "^1.0.2",
|
|
82
82
|
"chokidar": "^3.5.3",
|
|
83
83
|
"commander": "^12.0.0",
|
|
84
|
-
"crypto": "^1.0.1",
|
|
85
84
|
"events": "^3.3.0",
|
|
86
85
|
"figures": "^3.2.0",
|
|
87
86
|
"fs-extra": "^11.1.1",
|
|
@@ -115,4 +114,4 @@
|
|
|
115
114
|
"bugs": {
|
|
116
115
|
"url": "https://github.com/ptreezh/stigmergy-CLI-Multi-Agents/issues"
|
|
117
116
|
}
|
|
118
|
-
}
|
|
117
|
+
}
|
package/scripts/build.js
CHANGED
|
@@ -22,7 +22,7 @@ console.log(`Building version ${pkg.version} of ${pkg.name}`);
|
|
|
22
22
|
|
|
23
23
|
// Verify required files exist
|
|
24
24
|
const requiredFiles = [
|
|
25
|
-
'src/
|
|
25
|
+
'src/index.js',
|
|
26
26
|
'package.json',
|
|
27
27
|
'README.md',
|
|
28
28
|
'LICENSE'
|
|
@@ -49,7 +49,7 @@ try {
|
|
|
49
49
|
// Run basic syntax check
|
|
50
50
|
console.log('\nRunning syntax checks...');
|
|
51
51
|
try {
|
|
52
|
-
execSync('node -c src/
|
|
52
|
+
execSync('node -c src/index.js', { stdio: 'inherit' });
|
|
53
53
|
console.log('✅ Main file syntax is valid');
|
|
54
54
|
} catch (error) {
|
|
55
55
|
console.error('❌ Syntax error in main file:', error.message);
|
package/scripts/publish.js
CHANGED
|
@@ -1,268 +1,268 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Stigmergy CLI 发布脚本
|
|
5
|
-
* 自动化发布流程到npm
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { execSync } from 'child_process';
|
|
9
|
-
import { readFile, writeFile } from 'fs/promises';
|
|
10
|
-
import { join } from 'path';
|
|
11
|
-
import { fileURLToPath } from 'url';
|
|
12
|
-
|
|
13
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
-
const __dirname = join(__filename, '..');
|
|
15
|
-
|
|
16
|
-
class NPMPublisher {
|
|
17
|
-
constructor() {
|
|
18
|
-
this.rootDir = __dirname;
|
|
19
|
-
this.packagePath = join(this.rootDir, 'package.json');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
log(message, type = 'info') {
|
|
23
|
-
const timestamp = new Date().toISOString();
|
|
24
|
-
const prefix = {
|
|
25
|
-
'info': '📦 ',
|
|
26
|
-
'success': '✅ ',
|
|
27
|
-
'error': '❌ ',
|
|
28
|
-
'warning': '⚠️ '
|
|
29
|
-
}[type] || '📦 ';
|
|
30
|
-
|
|
31
|
-
console.log(`${timestamp} ${prefix}${message}`);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async readPackage() {
|
|
35
|
-
try {
|
|
36
|
-
const content = await readFile(this.packagePath, 'utf8');
|
|
37
|
-
return JSON.parse(content);
|
|
38
|
-
} catch (error) {
|
|
39
|
-
this.log(`读取package.json失败: ${error.message}`, 'error');
|
|
40
|
-
throw error;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
async checkRequirements() {
|
|
45
|
-
this.log('检查发布要求...', 'info');
|
|
46
|
-
|
|
47
|
-
const pkg = await this.readPackage();
|
|
48
|
-
|
|
49
|
-
// 检查必要字段
|
|
50
|
-
const required = ['name', 'version', 'description', 'main', 'bin', 'repository'];
|
|
51
|
-
for (const field of required) {
|
|
52
|
-
if (!pkg[field]) {
|
|
53
|
-
throw new Error(`缺少必要字段: ${field}`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// 检查版本格式
|
|
58
|
-
if (!/^\d+\.\d+\.\d+$/.test(pkg.version)) {
|
|
59
|
-
throw new Error(`版本格式不正确: ${pkg.version}`);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// 检查仓库URL
|
|
63
|
-
if (!pkg.repository?.url) {
|
|
64
|
-
throw new Error('缺少repository.url');
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
this.log('所有检查通过', 'success');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async buildProject() {
|
|
71
|
-
this.log('构建项目...', 'info');
|
|
72
|
-
|
|
73
|
-
try {
|
|
74
|
-
// 清理之前的构建
|
|
75
|
-
execSync('rm -rf dist', { cwd: this.rootDir });
|
|
76
|
-
|
|
77
|
-
// 创建dist目录
|
|
78
|
-
execSync('mkdir -p dist', { cwd: this.rootDir });
|
|
79
|
-
|
|
80
|
-
// 复制必要文件
|
|
81
|
-
const filesToCopy = [
|
|
82
|
-
'src/
|
|
83
|
-
'src/adapters/',
|
|
84
|
-
'src/templates/',
|
|
85
|
-
'package.json',
|
|
86
|
-
'README.md',
|
|
87
|
-
'LICENSE'
|
|
88
|
-
];
|
|
89
|
-
|
|
90
|
-
for (const file of filesToCopy) {
|
|
91
|
-
if (file.endsWith('/')) {
|
|
92
|
-
execSync(`cp -r ${file} dist/`, { cwd: this.rootDir });
|
|
93
|
-
} else {
|
|
94
|
-
execSync(`cp ${file} dist/`, { cwd: this.rootDir });
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// 复制bin文件
|
|
99
|
-
execSync('mkdir -p dist/bin', { cwd: this.rootDir });
|
|
100
|
-
execSync('cp bin/* dist/bin/', { cwd: this.rootDir });
|
|
101
|
-
|
|
102
|
-
// 生成package.json用于发布
|
|
103
|
-
const publishPackage = await this.readPackage();
|
|
104
|
-
const publishConfig = {
|
|
105
|
-
...publishPackage,
|
|
106
|
-
files: [
|
|
107
|
-
'src/
|
|
108
|
-
'src/adapters/**',
|
|
109
|
-
'src/templates/**',
|
|
110
|
-
'bin/**',
|
|
111
|
-
'README.md',
|
|
112
|
-
'LICENSE'
|
|
113
|
-
],
|
|
114
|
-
main: 'src/
|
|
115
|
-
bin: {
|
|
116
|
-
'stigmergy-cli': 'src/
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
await writeFile(
|
|
121
|
-
join(this.rootDir, 'dist/package.json'),
|
|
122
|
-
JSON.stringify(publishConfig, null, 2),
|
|
123
|
-
'utf8'
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
this.log('构建完成', 'success');
|
|
127
|
-
} catch (error) {
|
|
128
|
-
this.log(`构建失败: ${error.message}`, 'error');
|
|
129
|
-
throw error;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
async runTests() {
|
|
134
|
-
this.log('运行测试...', 'info');
|
|
135
|
-
|
|
136
|
-
try {
|
|
137
|
-
execSync('npm test', { cwd: this.rootDir, stdio: 'inherit' });
|
|
138
|
-
this.log('测试通过', 'success');
|
|
139
|
-
} catch (error) {
|
|
140
|
-
this.log(`测试失败: ${error.message}`, 'error');
|
|
141
|
-
throw error;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
async publishToNPM(dryRun = false) {
|
|
146
|
-
this.log('准备发布到npm...', 'info');
|
|
147
|
-
|
|
148
|
-
try {
|
|
149
|
-
// 检查是否已登录npm
|
|
150
|
-
try {
|
|
151
|
-
execSync('npm whoami', { stdio: 'pipe' });
|
|
152
|
-
this.log('npm登录状态: 已登录', 'success');
|
|
153
|
-
} catch {
|
|
154
|
-
this.log('请先登录npm: npm login', 'warning');
|
|
155
|
-
throw new Error('需要先登录npm');
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// 检查包名是否可用
|
|
159
|
-
const pkg = await this.readPackage();
|
|
160
|
-
try {
|
|
161
|
-
execSync(`npm view ${pkg.name}`, { stdio: 'pipe' });
|
|
162
|
-
this.log(`包名 ${pkg.name} 已存在,将覆盖发布`, 'warning');
|
|
163
|
-
} catch {
|
|
164
|
-
this.log(`包名 ${pkg.name} 可用`, 'success');
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// 发布命令
|
|
168
|
-
const publishCmd = dryRun ? 'npm publish --dry-run' : 'npm publish --access public';
|
|
169
|
-
|
|
170
|
-
if (dryRun) {
|
|
171
|
-
this.log('模拟发布中...', 'info');
|
|
172
|
-
execSync(publishCmd, { cwd: join(this.rootDir, 'dist'), stdio: 'inherit' });
|
|
173
|
-
this.log('模拟发布完成', 'success');
|
|
174
|
-
} else {
|
|
175
|
-
this.log('发布到npm...', 'info');
|
|
176
|
-
execSync(publishCmd, { cwd: join(this.rootDir, 'dist'), stdio: 'inherit' });
|
|
177
|
-
this.log('发布成功!', 'success');
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
} catch (error) {
|
|
181
|
-
this.log(`发布失败: ${error.message}`, 'error');
|
|
182
|
-
throw error;
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
async versionUpdate(type = 'patch') {
|
|
187
|
-
this.log(`更新版本 (${type})...`, 'info');
|
|
188
|
-
|
|
189
|
-
try {
|
|
190
|
-
execSync(`npm version ${type}`, { cwd: this.rootDir, stdio: 'inherit' });
|
|
191
|
-
this.log('版本更新完成', 'success');
|
|
192
|
-
} catch (error) {
|
|
193
|
-
this.log(`版本更新失败: ${error.message}`, 'error');
|
|
194
|
-
throw error;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
async showHelp() {
|
|
199
|
-
console.log(`
|
|
200
|
-
🚀 Stigmergy CLI 发布工具
|
|
201
|
-
|
|
202
|
-
用法: node scripts/publish.js [选项]
|
|
203
|
-
|
|
204
|
-
选项:
|
|
205
|
-
--dry-run 模拟发布,不实际上传到npm
|
|
206
|
-
--patch 更新补丁版本 (默认)
|
|
207
|
-
--minor 更新次版本
|
|
208
|
-
--major 更新主版本
|
|
209
|
-
--help, -h 显示帮助信息
|
|
210
|
-
|
|
211
|
-
示例:
|
|
212
|
-
node scripts/publish.js # 发布到npm
|
|
213
|
-
node scripts/publish.js --dry-run # 模拟发布
|
|
214
|
-
node scripts/publish.js --minor # 更新次版本并发布
|
|
215
|
-
node scripts/publish.js --help # 显示帮助
|
|
216
|
-
|
|
217
|
-
工作流程:
|
|
218
|
-
1. 检查发布要求
|
|
219
|
-
2. 运行测试
|
|
220
|
-
3. 构建项目
|
|
221
|
-
4. 更新版本 (可选)
|
|
222
|
-
5. 发布到npm
|
|
223
|
-
`);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
async function main() {
|
|
228
|
-
const publisher = new NPMPublisher();
|
|
229
|
-
const args = process.argv.slice(2);
|
|
230
|
-
|
|
231
|
-
// 显示帮助
|
|
232
|
-
if (args.includes('--help') || args.includes('-h')) {
|
|
233
|
-
publisher.showHelp();
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
try {
|
|
238
|
-
// 检查发布要求
|
|
239
|
-
await publisher.checkRequirements();
|
|
240
|
-
|
|
241
|
-
// 运行测试
|
|
242
|
-
await publisher.runTests();
|
|
243
|
-
|
|
244
|
-
// 构建项目
|
|
245
|
-
await publisher.buildProject();
|
|
246
|
-
|
|
247
|
-
// 处理版本更新
|
|
248
|
-
let versionType = 'patch';
|
|
249
|
-
if (args.includes('--minor')) versionType = 'minor';
|
|
250
|
-
if (args.includes('--major')) versionType = 'major';
|
|
251
|
-
|
|
252
|
-
if (versionType !== 'patch') {
|
|
253
|
-
await publisher.versionUpdate(versionType);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// 发布到npm
|
|
257
|
-
const dryRun = args.includes('--dry-run');
|
|
258
|
-
await publisher.publishToNPM(dryRun);
|
|
259
|
-
|
|
260
|
-
} catch (error) {
|
|
261
|
-
console.error('发布失败:', error.message);
|
|
262
|
-
process.exit(1);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
267
|
-
main();
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Stigmergy CLI 发布脚本
|
|
5
|
+
* 自动化发布流程到npm
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { execSync } from 'child_process';
|
|
9
|
+
import { readFile, writeFile } from 'fs/promises';
|
|
10
|
+
import { join } from 'path';
|
|
11
|
+
import { fileURLToPath } from 'url';
|
|
12
|
+
|
|
13
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
14
|
+
const __dirname = join(__filename, '..');
|
|
15
|
+
|
|
16
|
+
class NPMPublisher {
|
|
17
|
+
constructor() {
|
|
18
|
+
this.rootDir = __dirname;
|
|
19
|
+
this.packagePath = join(this.rootDir, 'package.json');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
log(message, type = 'info') {
|
|
23
|
+
const timestamp = new Date().toISOString();
|
|
24
|
+
const prefix = {
|
|
25
|
+
'info': '📦 ',
|
|
26
|
+
'success': '✅ ',
|
|
27
|
+
'error': '❌ ',
|
|
28
|
+
'warning': '⚠️ '
|
|
29
|
+
}[type] || '📦 ';
|
|
30
|
+
|
|
31
|
+
console.log(`${timestamp} ${prefix}${message}`);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async readPackage() {
|
|
35
|
+
try {
|
|
36
|
+
const content = await readFile(this.packagePath, 'utf8');
|
|
37
|
+
return JSON.parse(content);
|
|
38
|
+
} catch (error) {
|
|
39
|
+
this.log(`读取package.json失败: ${error.message}`, 'error');
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async checkRequirements() {
|
|
45
|
+
this.log('检查发布要求...', 'info');
|
|
46
|
+
|
|
47
|
+
const pkg = await this.readPackage();
|
|
48
|
+
|
|
49
|
+
// 检查必要字段
|
|
50
|
+
const required = ['name', 'version', 'description', 'main', 'bin', 'repository'];
|
|
51
|
+
for (const field of required) {
|
|
52
|
+
if (!pkg[field]) {
|
|
53
|
+
throw new Error(`缺少必要字段: ${field}`);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// 检查版本格式
|
|
58
|
+
if (!/^\d+\.\d+\.\d+$/.test(pkg.version)) {
|
|
59
|
+
throw new Error(`版本格式不正确: ${pkg.version}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 检查仓库URL
|
|
63
|
+
if (!pkg.repository?.url) {
|
|
64
|
+
throw new Error('缺少repository.url');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
this.log('所有检查通过', 'success');
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async buildProject() {
|
|
71
|
+
this.log('构建项目...', 'info');
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
// 清理之前的构建
|
|
75
|
+
execSync('rm -rf dist', { cwd: this.rootDir });
|
|
76
|
+
|
|
77
|
+
// 创建dist目录
|
|
78
|
+
execSync('mkdir -p dist', { cwd: this.rootDir });
|
|
79
|
+
|
|
80
|
+
// 复制必要文件
|
|
81
|
+
const filesToCopy = [
|
|
82
|
+
'src/index.js',
|
|
83
|
+
'src/adapters/',
|
|
84
|
+
'src/templates/',
|
|
85
|
+
'package.json',
|
|
86
|
+
'README.md',
|
|
87
|
+
'LICENSE'
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
for (const file of filesToCopy) {
|
|
91
|
+
if (file.endsWith('/')) {
|
|
92
|
+
execSync(`cp -r ${file} dist/`, { cwd: this.rootDir });
|
|
93
|
+
} else {
|
|
94
|
+
execSync(`cp ${file} dist/`, { cwd: this.rootDir });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 复制bin文件
|
|
99
|
+
execSync('mkdir -p dist/bin', { cwd: this.rootDir });
|
|
100
|
+
execSync('cp bin/* dist/bin/', { cwd: this.rootDir });
|
|
101
|
+
|
|
102
|
+
// 生成package.json用于发布
|
|
103
|
+
const publishPackage = await this.readPackage();
|
|
104
|
+
const publishConfig = {
|
|
105
|
+
...publishPackage,
|
|
106
|
+
files: [
|
|
107
|
+
'src/index.js',
|
|
108
|
+
'src/adapters/**',
|
|
109
|
+
'src/templates/**',
|
|
110
|
+
'bin/**',
|
|
111
|
+
'README.md',
|
|
112
|
+
'LICENSE'
|
|
113
|
+
],
|
|
114
|
+
main: 'src/index.js',
|
|
115
|
+
bin: {
|
|
116
|
+
'stigmergy-cli': 'src/index.js'
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
await writeFile(
|
|
121
|
+
join(this.rootDir, 'dist/package.json'),
|
|
122
|
+
JSON.stringify(publishConfig, null, 2),
|
|
123
|
+
'utf8'
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
this.log('构建完成', 'success');
|
|
127
|
+
} catch (error) {
|
|
128
|
+
this.log(`构建失败: ${error.message}`, 'error');
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
async runTests() {
|
|
134
|
+
this.log('运行测试...', 'info');
|
|
135
|
+
|
|
136
|
+
try {
|
|
137
|
+
execSync('npm test', { cwd: this.rootDir, stdio: 'inherit' });
|
|
138
|
+
this.log('测试通过', 'success');
|
|
139
|
+
} catch (error) {
|
|
140
|
+
this.log(`测试失败: ${error.message}`, 'error');
|
|
141
|
+
throw error;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
async publishToNPM(dryRun = false) {
|
|
146
|
+
this.log('准备发布到npm...', 'info');
|
|
147
|
+
|
|
148
|
+
try {
|
|
149
|
+
// 检查是否已登录npm
|
|
150
|
+
try {
|
|
151
|
+
execSync('npm whoami', { stdio: 'pipe' });
|
|
152
|
+
this.log('npm登录状态: 已登录', 'success');
|
|
153
|
+
} catch {
|
|
154
|
+
this.log('请先登录npm: npm login', 'warning');
|
|
155
|
+
throw new Error('需要先登录npm');
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// 检查包名是否可用
|
|
159
|
+
const pkg = await this.readPackage();
|
|
160
|
+
try {
|
|
161
|
+
execSync(`npm view ${pkg.name}`, { stdio: 'pipe' });
|
|
162
|
+
this.log(`包名 ${pkg.name} 已存在,将覆盖发布`, 'warning');
|
|
163
|
+
} catch {
|
|
164
|
+
this.log(`包名 ${pkg.name} 可用`, 'success');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// 发布命令
|
|
168
|
+
const publishCmd = dryRun ? 'npm publish --dry-run' : 'npm publish --access public';
|
|
169
|
+
|
|
170
|
+
if (dryRun) {
|
|
171
|
+
this.log('模拟发布中...', 'info');
|
|
172
|
+
execSync(publishCmd, { cwd: join(this.rootDir, 'dist'), stdio: 'inherit' });
|
|
173
|
+
this.log('模拟发布完成', 'success');
|
|
174
|
+
} else {
|
|
175
|
+
this.log('发布到npm...', 'info');
|
|
176
|
+
execSync(publishCmd, { cwd: join(this.rootDir, 'dist'), stdio: 'inherit' });
|
|
177
|
+
this.log('发布成功!', 'success');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
} catch (error) {
|
|
181
|
+
this.log(`发布失败: ${error.message}`, 'error');
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async versionUpdate(type = 'patch') {
|
|
187
|
+
this.log(`更新版本 (${type})...`, 'info');
|
|
188
|
+
|
|
189
|
+
try {
|
|
190
|
+
execSync(`npm version ${type}`, { cwd: this.rootDir, stdio: 'inherit' });
|
|
191
|
+
this.log('版本更新完成', 'success');
|
|
192
|
+
} catch (error) {
|
|
193
|
+
this.log(`版本更新失败: ${error.message}`, 'error');
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
async showHelp() {
|
|
199
|
+
console.log(`
|
|
200
|
+
🚀 Stigmergy CLI 发布工具
|
|
201
|
+
|
|
202
|
+
用法: node scripts/publish.js [选项]
|
|
203
|
+
|
|
204
|
+
选项:
|
|
205
|
+
--dry-run 模拟发布,不实际上传到npm
|
|
206
|
+
--patch 更新补丁版本 (默认)
|
|
207
|
+
--minor 更新次版本
|
|
208
|
+
--major 更新主版本
|
|
209
|
+
--help, -h 显示帮助信息
|
|
210
|
+
|
|
211
|
+
示例:
|
|
212
|
+
node scripts/publish.js # 发布到npm
|
|
213
|
+
node scripts/publish.js --dry-run # 模拟发布
|
|
214
|
+
node scripts/publish.js --minor # 更新次版本并发布
|
|
215
|
+
node scripts/publish.js --help # 显示帮助
|
|
216
|
+
|
|
217
|
+
工作流程:
|
|
218
|
+
1. 检查发布要求
|
|
219
|
+
2. 运行测试
|
|
220
|
+
3. 构建项目
|
|
221
|
+
4. 更新版本 (可选)
|
|
222
|
+
5. 发布到npm
|
|
223
|
+
`);
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async function main() {
|
|
228
|
+
const publisher = new NPMPublisher();
|
|
229
|
+
const args = process.argv.slice(2);
|
|
230
|
+
|
|
231
|
+
// 显示帮助
|
|
232
|
+
if (args.includes('--help') || args.includes('-h')) {
|
|
233
|
+
publisher.showHelp();
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
try {
|
|
238
|
+
// 检查发布要求
|
|
239
|
+
await publisher.checkRequirements();
|
|
240
|
+
|
|
241
|
+
// 运行测试
|
|
242
|
+
await publisher.runTests();
|
|
243
|
+
|
|
244
|
+
// 构建项目
|
|
245
|
+
await publisher.buildProject();
|
|
246
|
+
|
|
247
|
+
// 处理版本更新
|
|
248
|
+
let versionType = 'patch';
|
|
249
|
+
if (args.includes('--minor')) versionType = 'minor';
|
|
250
|
+
if (args.includes('--major')) versionType = 'major';
|
|
251
|
+
|
|
252
|
+
if (versionType !== 'patch') {
|
|
253
|
+
await publisher.versionUpdate(versionType);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// 发布到npm
|
|
257
|
+
const dryRun = args.includes('--dry-run');
|
|
258
|
+
await publisher.publishToNPM(dryRun);
|
|
259
|
+
|
|
260
|
+
} catch (error) {
|
|
261
|
+
console.error('发布失败:', error.message);
|
|
262
|
+
process.exit(1);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
267
|
+
main();
|
|
268
268
|
}
|