momo-ai 1.0.10 → 1.0.12
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/README.md +4 -0
- package/package.json +1 -1
- package/src/_agent/trae/momo-taskplan.json +5 -0
- package/src/_template/PROMPT/trae/momo-task.ejs +1 -1
- package/src/_template/PROMPT/trae/momo-taskplan.ejs +8 -0
- package/src/commander/commit.json +12 -0
- package/src/commander/pull.json +6 -0
- package/src/commander/push.json +6 -0
- package/src/executor/executeAgent.js +28 -18
- package/src/executor/executeCommit.js +202 -0
- package/src/executor/executeProject.js +17 -1
- package/src/executor/executePull.js +127 -0
- package/src/executor/executePush.js +180 -0
- package/src/executor/index.js +7 -1
- /package/{.momo → src/_template/LAIN/.momo}/advanced/refer.json +0 -0
package/README.md
CHANGED
|
@@ -71,6 +71,10 @@ momo init # 初始化当前项目
|
|
|
71
71
|
momo repo -a https://xxx/repo.git # 克隆远程代码库 -> source/repo/develop-01(名称靠解析) -> git submodule
|
|
72
72
|
momo repo -a xxx -i 10 # 克隆远程代码库(10个副本)
|
|
73
73
|
|
|
74
|
+
momo pull # 从远程拉取最新代码 source/develop-xx
|
|
75
|
+
momo commit -m "提交信息" # 提交本地变更形成新的 commits
|
|
76
|
+
momo push # 推送本地 commits 到远程代码库
|
|
77
|
+
|
|
74
78
|
momo open # 交互式使用 TRAE / Lingma / Cursor / Kiro 打开当前项目
|
|
75
79
|
|
|
76
80
|
momo project -s "项目路径" # 将路径中的显示拷贝到当前项目的 reference 目录下,若不提供 -s 则直接列举所有支持的项目类型
|
package/package.json
CHANGED
|
@@ -135,25 +135,34 @@ module.exports = async (options) => {
|
|
|
135
135
|
|
|
136
136
|
// 如果没有提供 agent 参数,显示可用的 agents 并让用户选择
|
|
137
137
|
if (!agentName) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
138
|
+
while (true) {
|
|
139
|
+
Ec.waiting('可用的 Agents:');
|
|
140
|
+
agents.forEach((agent, index) => {
|
|
141
|
+
Ec.waiting(`${index + 1}. ${agent.argName.red.bold} (${agent.name}), id = ${agent.id}, uri = ${agent.uri}`);
|
|
142
|
+
});
|
|
143
|
+
Ec.waiting(`${agents.length + 1}. 退出`);
|
|
144
|
+
|
|
145
|
+
// 获取用户选择
|
|
146
|
+
const answer = await Ec.ask('请选择要使用的 Agent (输入编号): ');
|
|
147
|
+
const selectedIndex = parseInt(answer) - 1;
|
|
148
|
+
|
|
149
|
+
// 验证选择
|
|
150
|
+
if (isNaN(selectedIndex) || selectedIndex < 0 || selectedIndex > agents.length) {
|
|
151
|
+
Ec.error("❌ 无效的选择");
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// 检查是否选择退出
|
|
156
|
+
if (selectedIndex === agents.length) {
|
|
157
|
+
Ec.info("已退出 Agent 选择");
|
|
158
|
+
Ec.askClose();
|
|
159
|
+
process.exit(0);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// 使用选择的 agent
|
|
163
|
+
const selectedAgent = agents[selectedIndex];
|
|
164
|
+
return await _processAgent(selectedAgent);
|
|
152
165
|
}
|
|
153
|
-
|
|
154
|
-
// 使用选择的 agent
|
|
155
|
-
const selectedAgent = agents[selectedIndex];
|
|
156
|
-
return await _processAgent(selectedAgent);
|
|
157
166
|
}
|
|
158
167
|
|
|
159
168
|
// 查找指定的 agent
|
|
@@ -164,6 +173,7 @@ module.exports = async (options) => {
|
|
|
164
173
|
agents.forEach((a, index) => {
|
|
165
174
|
Ec.waiting(`${index + 1}. ${a.argName.red.bold} (${a.name}), id = ${a.id}, uri = ${a.uri}`);
|
|
166
175
|
});
|
|
176
|
+
Ec.waiting(`${agents.length + 1}. 退出`);
|
|
167
177
|
Ec.askClose();
|
|
168
178
|
process.exit(1);
|
|
169
179
|
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { exec } = require('child_process');
|
|
4
|
+
const util = require('util');
|
|
5
|
+
const Ec = require('../epic');
|
|
6
|
+
|
|
7
|
+
// 将 exec 转换为 Promise 版本
|
|
8
|
+
const execAsync = util.promisify(exec);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 检查目录是否为 Git 仓库
|
|
12
|
+
* @param {string} dirPath 目录路径
|
|
13
|
+
* @returns {Promise<boolean>} 是否为 Git 仓库
|
|
14
|
+
*/
|
|
15
|
+
const _isGitRepo = async (dirPath) => {
|
|
16
|
+
try {
|
|
17
|
+
await execAsync('git rev-parse --git-dir', { cwd: dirPath });
|
|
18
|
+
return true;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 检查是否有更改需要提交
|
|
26
|
+
* @param {string} dirPath 目录路径
|
|
27
|
+
* @returns {Promise<boolean>} 是否有更改
|
|
28
|
+
*/
|
|
29
|
+
const _hasChanges = async (dirPath) => {
|
|
30
|
+
try {
|
|
31
|
+
const { stdout } = await execAsync('git status --porcelain', { cwd: dirPath });
|
|
32
|
+
return stdout.trim() !== '';
|
|
33
|
+
} catch (error) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 添加所有更改
|
|
40
|
+
* @param {string} dirPath 目录路径
|
|
41
|
+
*/
|
|
42
|
+
const _addAllChanges = async (dirPath) => {
|
|
43
|
+
try {
|
|
44
|
+
Ec.waiting(`正在添加更改: ${dirPath}`);
|
|
45
|
+
const { stdout, stderr } = await execAsync('git add .', { cwd: dirPath });
|
|
46
|
+
|
|
47
|
+
if (stdout) {
|
|
48
|
+
Ec.waiting(`输出: ${stdout.trim()}`);
|
|
49
|
+
}
|
|
50
|
+
if (stderr) {
|
|
51
|
+
Ec.waiting(`进度: ${stderr.trim()}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
Ec.waiting(`✅ 成功添加更改: ${dirPath}`);
|
|
55
|
+
} catch (error) {
|
|
56
|
+
Ec.error(`❌ 添加更改失败 ${dirPath}: ${error.message}`);
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 提交更改
|
|
63
|
+
* @param {string} dirPath 目录路径
|
|
64
|
+
* @param {string} message 提交信息
|
|
65
|
+
*/
|
|
66
|
+
const _commitChanges = async (dirPath, message) => {
|
|
67
|
+
try {
|
|
68
|
+
Ec.waiting(`正在提交更改: ${dirPath}`);
|
|
69
|
+
const command = `git commit -m "${message}"`;
|
|
70
|
+
const { stdout, stderr } = await execAsync(command, { cwd: dirPath });
|
|
71
|
+
|
|
72
|
+
if (stdout) {
|
|
73
|
+
Ec.waiting(`输出: ${stdout.trim()}`);
|
|
74
|
+
}
|
|
75
|
+
if (stderr) {
|
|
76
|
+
Ec.waiting(`进度: ${stderr.trim()}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
Ec.waiting(`✅ 成功提交更改: ${dirPath}`);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
// 检查是否是因为没有更改导致的错误
|
|
82
|
+
if (error.message.includes('nothing to commit')) {
|
|
83
|
+
Ec.waiting(`⚠️ ${dirPath} 没有需要提交的更改`);
|
|
84
|
+
} else {
|
|
85
|
+
Ec.error(`❌ 提交更改失败 ${dirPath}: ${error.message}`);
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 提交 submodule 更改
|
|
93
|
+
* @param {string} dirPath 目录路径
|
|
94
|
+
* @param {string} message 提交信息
|
|
95
|
+
*/
|
|
96
|
+
const _commitSubmodules = async (dirPath, message) => {
|
|
97
|
+
try {
|
|
98
|
+
Ec.waiting(`正在提交 Submodule 更改: ${dirPath}`);
|
|
99
|
+
// 添加 submodule 更改
|
|
100
|
+
await execAsync('git add .', { cwd: dirPath });
|
|
101
|
+
// 提交更改
|
|
102
|
+
const command = `git commit -m "${message}"`;
|
|
103
|
+
const { stdout, stderr } = await execAsync(command, { cwd: dirPath });
|
|
104
|
+
|
|
105
|
+
if (stdout) {
|
|
106
|
+
Ec.waiting(`输出: ${stdout.trim()}`);
|
|
107
|
+
}
|
|
108
|
+
if (stderr) {
|
|
109
|
+
Ec.waiting(`进度: ${stderr.trim()}`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
Ec.waiting(`✅ 成功提交 Submodule 更改: ${dirPath}`);
|
|
113
|
+
} catch (error) {
|
|
114
|
+
// 检查是否是因为没有更改导致的错误
|
|
115
|
+
if (error.message.includes('nothing to commit')) {
|
|
116
|
+
Ec.waiting(`⚠️ ${dirPath} Submodule 没有需要提交的更改`);
|
|
117
|
+
} else {
|
|
118
|
+
Ec.error(`❌ 提交 Submodule 更改失败 ${dirPath}: ${error.message}`);
|
|
119
|
+
throw error;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
module.exports = async (options) => {
|
|
125
|
+
// 参数提取
|
|
126
|
+
const parsed = Ec.parseArgument(options);
|
|
127
|
+
const message = parsed.message || parsed.m;
|
|
128
|
+
|
|
129
|
+
// 验证参数
|
|
130
|
+
if (!message) {
|
|
131
|
+
Ec.error("❌ 请提供提交信息 (-m, --message)");
|
|
132
|
+
process.exit(1);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
// 获取 source 目录路径
|
|
137
|
+
const sourceDir = path.resolve(process.cwd(), 'source');
|
|
138
|
+
|
|
139
|
+
// 检查 source 目录是否存在
|
|
140
|
+
if (!fs.existsSync(sourceDir)) {
|
|
141
|
+
Ec.error("❌ 未找到 source 目录");
|
|
142
|
+
process.exit(1);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// 获取所有 develop-xx 目录
|
|
146
|
+
const files = fs.readdirSync(sourceDir);
|
|
147
|
+
const developDirs = files.filter(file =>
|
|
148
|
+
fs.statSync(path.join(sourceDir, file)).isDirectory() &&
|
|
149
|
+
file.match(/^develop-\d+$/)
|
|
150
|
+
).sort();
|
|
151
|
+
|
|
152
|
+
if (developDirs.length === 0) {
|
|
153
|
+
Ec.waiting("🔍 未找到任何 develop 副本目录");
|
|
154
|
+
process.exit(0);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
Ec.waiting(`共找到 ${developDirs.length} 个 develop 副本目录`);
|
|
158
|
+
|
|
159
|
+
// 遍历所有 develop 目录并提交更改
|
|
160
|
+
for (const dir of developDirs) {
|
|
161
|
+
const fullPath = path.join(sourceDir, dir);
|
|
162
|
+
|
|
163
|
+
// 添加分割线
|
|
164
|
+
Ec.waiting("--------------------------------------------------");
|
|
165
|
+
|
|
166
|
+
// 检查是否为 Git 仓库
|
|
167
|
+
const isGitRepo = await _isGitRepo(fullPath);
|
|
168
|
+
if (!isGitRepo) {
|
|
169
|
+
Ec.waiting(`⚠️ ${fullPath} 不是 Git 仓库,跳过`);
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// 检查是否有更改
|
|
174
|
+
const hasChange = await _hasChanges(fullPath);
|
|
175
|
+
if (!hasChange) {
|
|
176
|
+
Ec.waiting(`⚠️ ${fullPath} 没有需要提交的更改`);
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// 添加并提交更改
|
|
181
|
+
await _addAllChanges(fullPath);
|
|
182
|
+
await _commitChanges(fullPath, message);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// 添加分割线
|
|
186
|
+
Ec.waiting("--------------------------------------------------");
|
|
187
|
+
|
|
188
|
+
// 提交主仓库的 submodule 更新
|
|
189
|
+
const hasSubmoduleChanges = await _hasChanges(process.cwd());
|
|
190
|
+
if (hasSubmoduleChanges) {
|
|
191
|
+
await _commitSubmodules(process.cwd(), `Update submodules: ${message}`);
|
|
192
|
+
} else {
|
|
193
|
+
Ec.waiting("⚠️ 主仓库没有 submodule 更改需要提交");
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
Ec.info('✅ 所有副本更改提交完成!');
|
|
197
|
+
process.exit(0);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
Ec.error(`❌ 执行过程中发生错误: ${error.message}`);
|
|
200
|
+
process.exit(1);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
@@ -14,7 +14,7 @@ const fsAsync = {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* 获取 refer.json 配置文件路径
|
|
18
18
|
* @param {string} baseDir 项目根目录
|
|
19
19
|
* @returns {string} refer.json 文件路径
|
|
20
20
|
*/
|
|
@@ -22,11 +22,27 @@ const _getReferConfigPath = (baseDir) => {
|
|
|
22
22
|
return path.resolve(baseDir, '.momo', 'advanced', 'refer.json');
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* 获取模板中的 refer.json 配置文件路径
|
|
27
|
+
* @returns {string} 模板中 refer.json 文件路径
|
|
28
|
+
*/
|
|
29
|
+
const _getTemplateReferConfigPath = () => {
|
|
30
|
+
return path.resolve(__dirname, '../_template/LAIN/.momo/advanced/refer.json');
|
|
31
|
+
};
|
|
32
|
+
|
|
25
33
|
/**
|
|
26
34
|
* 获取默认的 refer 配置
|
|
27
35
|
* @returns {Object} 默认配置对象
|
|
28
36
|
*/
|
|
29
37
|
const _getDefaultReferConfig = () => {
|
|
38
|
+
// 从模板文件读取默认配置
|
|
39
|
+
const templateConfigPath = _getTemplateReferConfigPath();
|
|
40
|
+
if (fs.existsSync(templateConfigPath)) {
|
|
41
|
+
const content = fs.readFileSync(templateConfigPath, 'utf8');
|
|
42
|
+
return JSON.parse(content);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// 如果模板文件不存在,返回硬编码的默认配置
|
|
30
46
|
return {
|
|
31
47
|
maven: {
|
|
32
48
|
file: 'pom.xml',
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { exec } = require('child_process');
|
|
4
|
+
const util = require('util');
|
|
5
|
+
const Ec = require('../epic');
|
|
6
|
+
|
|
7
|
+
// 将 exec 转换为 Promise 版本
|
|
8
|
+
const execAsync = util.promisify(exec);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 检查目录是否为 Git 仓库
|
|
12
|
+
* @param {string} dirPath 目录路径
|
|
13
|
+
* @returns {Promise<boolean>} 是否为 Git 仓库
|
|
14
|
+
*/
|
|
15
|
+
const _isGitRepo = async (dirPath) => {
|
|
16
|
+
try {
|
|
17
|
+
await execAsync('git rev-parse --git-dir', { cwd: dirPath });
|
|
18
|
+
return true;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 从远程拉取最新代码
|
|
26
|
+
* @param {string} dirPath 目录路径
|
|
27
|
+
*/
|
|
28
|
+
const _pullRepo = async (dirPath) => {
|
|
29
|
+
try {
|
|
30
|
+
Ec.waiting(`正在从远程拉取代码: ${dirPath}`);
|
|
31
|
+
const { stdout, stderr } = await execAsync('git pull', { cwd: dirPath });
|
|
32
|
+
|
|
33
|
+
if (stdout) {
|
|
34
|
+
Ec.waiting(`输出: ${stdout.trim()}`);
|
|
35
|
+
}
|
|
36
|
+
if (stderr) {
|
|
37
|
+
Ec.waiting(`进度: ${stderr.trim()}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
Ec.waiting(`✅ 成功拉取代码: ${dirPath}`);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
Ec.error(`❌ 拉取代码失败 ${dirPath}: ${error.message}`);
|
|
43
|
+
throw error;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* 更新 submodule
|
|
49
|
+
* @param {string} dirPath 目录路径
|
|
50
|
+
*/
|
|
51
|
+
const _updateSubmodules = async (dirPath) => {
|
|
52
|
+
try {
|
|
53
|
+
Ec.waiting(`正在更新 Submodule: ${dirPath}`);
|
|
54
|
+
const { stdout, stderr } = await execAsync('git submodule update --remote --merge', { cwd: dirPath });
|
|
55
|
+
|
|
56
|
+
if (stdout) {
|
|
57
|
+
Ec.waiting(`输出: ${stdout.trim()}`);
|
|
58
|
+
}
|
|
59
|
+
if (stderr) {
|
|
60
|
+
Ec.waiting(`进度: ${stderr.trim()}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
Ec.waiting(`✅ 成功更新 Submodule: ${dirPath}`);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
Ec.error(`❌ 更新 Submodule 失败 ${dirPath}: ${error.message}`);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
module.exports = async (options) => {
|
|
71
|
+
// 参数提取
|
|
72
|
+
const parsed = Ec.parseArgument(options);
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
// 获取 source 目录路径
|
|
76
|
+
const sourceDir = path.resolve(process.cwd(), 'source');
|
|
77
|
+
|
|
78
|
+
// 检查 source 目录是否存在
|
|
79
|
+
if (!fs.existsSync(sourceDir)) {
|
|
80
|
+
Ec.error("❌ 未找到 source 目录");
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// 获取所有 develop-xx 目录
|
|
85
|
+
const files = fs.readdirSync(sourceDir);
|
|
86
|
+
const developDirs = files.filter(file =>
|
|
87
|
+
fs.statSync(path.join(sourceDir, file)).isDirectory() &&
|
|
88
|
+
file.match(/^develop-\d+$/)
|
|
89
|
+
).sort();
|
|
90
|
+
|
|
91
|
+
if (developDirs.length === 0) {
|
|
92
|
+
Ec.waiting("🔍 未找到任何 develop 副本目录");
|
|
93
|
+
process.exit(0);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
Ec.waiting(`共找到 ${developDirs.length} 个 develop 副本目录`);
|
|
97
|
+
|
|
98
|
+
// 遍历所有 develop 目录并拉取代码
|
|
99
|
+
for (const dir of developDirs) {
|
|
100
|
+
const fullPath = path.join(sourceDir, dir);
|
|
101
|
+
|
|
102
|
+
// 添加分割线
|
|
103
|
+
Ec.waiting("--------------------------------------------------");
|
|
104
|
+
|
|
105
|
+
// 检查是否为 Git 仓库
|
|
106
|
+
const isGitRepo = await _isGitRepo(fullPath);
|
|
107
|
+
if (!isGitRepo) {
|
|
108
|
+
Ec.waiting(`⚠️ ${fullPath} 不是 Git 仓库,跳过`);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// 拉取最新代码
|
|
113
|
+
await _pullRepo(fullPath);
|
|
114
|
+
|
|
115
|
+
// 更新 submodule
|
|
116
|
+
await _updateSubmodules(fullPath);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// 添加结束分割线
|
|
120
|
+
Ec.waiting("--------------------------------------------------");
|
|
121
|
+
Ec.info('✅ 所有副本代码拉取完成!');
|
|
122
|
+
process.exit(0);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
Ec.error(`❌ 执行过程中发生错误: ${error.message}`);
|
|
125
|
+
process.exit(1);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { exec } = require('child_process');
|
|
4
|
+
const util = require('util');
|
|
5
|
+
const Ec = require('../epic');
|
|
6
|
+
|
|
7
|
+
// 将 exec 转换为 Promise 版本
|
|
8
|
+
const execAsync = util.promisify(exec);
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 检查目录是否为 Git 仓库
|
|
12
|
+
* @param {string} dirPath 目录路径
|
|
13
|
+
* @returns {Promise<boolean>} 是否为 Git 仓库
|
|
14
|
+
*/
|
|
15
|
+
const _isGitRepo = async (dirPath) => {
|
|
16
|
+
try {
|
|
17
|
+
await execAsync('git rev-parse --git-dir', { cwd: dirPath });
|
|
18
|
+
return true;
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 从远程拉取最新代码
|
|
26
|
+
* @param {string} dirPath 目录路径
|
|
27
|
+
*/
|
|
28
|
+
const _pullRepo = async (dirPath) => {
|
|
29
|
+
try {
|
|
30
|
+
Ec.waiting(`正在从远程拉取代码: ${dirPath}`);
|
|
31
|
+
const { stdout, stderr } = await execAsync('git pull', { cwd: dirPath });
|
|
32
|
+
|
|
33
|
+
if (stdout) {
|
|
34
|
+
Ec.waiting(`输出: ${stdout.trim()}`);
|
|
35
|
+
}
|
|
36
|
+
if (stderr) {
|
|
37
|
+
Ec.waiting(`进度: ${stderr.trim()}`);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
Ec.waiting(`✅ 成功拉取代码: ${dirPath}`);
|
|
41
|
+
return true;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
Ec.error(`❌ 拉取代码失败 ${dirPath}: ${error.message}`);
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* 推送更改到远程仓库
|
|
50
|
+
* @param {string} dirPath 目录路径
|
|
51
|
+
*/
|
|
52
|
+
const _pushRepo = async (dirPath) => {
|
|
53
|
+
try {
|
|
54
|
+
Ec.waiting(`正在推送更改到远程: ${dirPath}`);
|
|
55
|
+
const { stdout, stderr } = await execAsync('git push', { cwd: dirPath });
|
|
56
|
+
|
|
57
|
+
if (stdout) {
|
|
58
|
+
Ec.waiting(`输出: ${stdout.trim()}`);
|
|
59
|
+
}
|
|
60
|
+
if (stderr) {
|
|
61
|
+
Ec.waiting(`进度: ${stderr.trim()}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Ec.waiting(`✅ 成功推送更改: ${dirPath}`);
|
|
65
|
+
return true;
|
|
66
|
+
} catch (error) {
|
|
67
|
+
Ec.error(`❌ 推送更改失败 ${dirPath}: ${error.message}`);
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 推送 submodule 更改
|
|
74
|
+
* @param {string} dirPath 目录路径
|
|
75
|
+
*/
|
|
76
|
+
const _pushSubmodules = async (dirPath) => {
|
|
77
|
+
try {
|
|
78
|
+
Ec.waiting(`正在推送 Submodule 更改: ${dirPath}`);
|
|
79
|
+
const { stdout, stderr } = await execAsync('git push', { cwd: dirPath });
|
|
80
|
+
|
|
81
|
+
if (stdout) {
|
|
82
|
+
Ec.waiting(`输出: ${stdout.trim()}`);
|
|
83
|
+
}
|
|
84
|
+
if (stderr) {
|
|
85
|
+
Ec.waiting(`进度: ${stderr.trim()}`);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
Ec.waiting(`✅ 成功推送 Submodule 更改: ${dirPath}`);
|
|
89
|
+
return true;
|
|
90
|
+
} catch (error) {
|
|
91
|
+
Ec.error(`❌ 推送 Submodule 更改失败 ${dirPath}: ${error.message}`);
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
module.exports = async (options) => {
|
|
97
|
+
// 参数提取
|
|
98
|
+
const parsed = Ec.parseArgument(options);
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
// 获取 source 目录路径
|
|
102
|
+
const sourceDir = path.resolve(process.cwd(), 'source');
|
|
103
|
+
|
|
104
|
+
// 检查 source 目录是否存在
|
|
105
|
+
if (!fs.existsSync(sourceDir)) {
|
|
106
|
+
Ec.error("❌ 未找到 source 目录");
|
|
107
|
+
process.exit(1);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 获取所有 develop-xx 目录
|
|
111
|
+
const files = fs.readdirSync(sourceDir);
|
|
112
|
+
const developDirs = files.filter(file =>
|
|
113
|
+
fs.statSync(path.join(sourceDir, file)).isDirectory() &&
|
|
114
|
+
file.match(/^develop-\d+$/)
|
|
115
|
+
).sort();
|
|
116
|
+
|
|
117
|
+
if (developDirs.length === 0) {
|
|
118
|
+
Ec.waiting("🔍 未找到任何 develop 副本目录");
|
|
119
|
+
process.exit(0);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
Ec.waiting(`共找到 ${developDirs.length} 个 develop 副本目录`);
|
|
123
|
+
|
|
124
|
+
let successCount = 0;
|
|
125
|
+
let failCount = 0;
|
|
126
|
+
|
|
127
|
+
// 遍历所有 develop 目录并推送更改
|
|
128
|
+
for (const dir of developDirs) {
|
|
129
|
+
const fullPath = path.join(sourceDir, dir);
|
|
130
|
+
|
|
131
|
+
// 添加分割线
|
|
132
|
+
Ec.waiting("--------------------------------------------------");
|
|
133
|
+
|
|
134
|
+
// 检查是否为 Git 仓库
|
|
135
|
+
const isGitRepo = await _isGitRepo(fullPath);
|
|
136
|
+
if (!isGitRepo) {
|
|
137
|
+
Ec.waiting(`⚠️ ${fullPath} 不是 Git 仓库,跳过`);
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// 先拉取最新代码
|
|
142
|
+
const pullSuccess = await _pullRepo(fullPath);
|
|
143
|
+
if (!pullSuccess) {
|
|
144
|
+
Ec.error(`❌ 拉取代码失败,跳过推送: ${fullPath}`);
|
|
145
|
+
failCount++;
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// 推送更改
|
|
150
|
+
const pushSuccess = await _pushRepo(fullPath);
|
|
151
|
+
if (pushSuccess) {
|
|
152
|
+
successCount++;
|
|
153
|
+
} else {
|
|
154
|
+
failCount++;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// 添加分割线
|
|
159
|
+
Ec.waiting("--------------------------------------------------");
|
|
160
|
+
|
|
161
|
+
// 推送主仓库的 submodule 更新
|
|
162
|
+
const pushSubSuccess = await _pushSubmodules(process.cwd());
|
|
163
|
+
if (pushSubSuccess) {
|
|
164
|
+
successCount++;
|
|
165
|
+
} else {
|
|
166
|
+
failCount++;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (failCount === 0) {
|
|
170
|
+
Ec.info(`✅ 所有副本推送完成!成功: ${successCount}, 失败: ${failCount}`);
|
|
171
|
+
process.exit(0);
|
|
172
|
+
} else {
|
|
173
|
+
Ec.error(`❌ 推送完成,但有 ${failCount} 个副本失败!成功: ${successCount}, 失败: ${failCount}`);
|
|
174
|
+
process.exit(1);
|
|
175
|
+
}
|
|
176
|
+
} catch (error) {
|
|
177
|
+
Ec.error(`❌ 执行过程中发生错误: ${error.message}`);
|
|
178
|
+
process.exit(1);
|
|
179
|
+
}
|
|
180
|
+
};
|
package/src/executor/index.js
CHANGED
|
@@ -18,6 +18,9 @@ const executeProject = require('./executeProject');
|
|
|
18
18
|
const executeAgentCfg = require('./executeAgentCfg');
|
|
19
19
|
const executeAgent = require('./executeAgent');
|
|
20
20
|
const executeConsole = require('./executeConsole');
|
|
21
|
+
const executePull = require('./executePull');
|
|
22
|
+
const executeCommit = require('./executeCommit');
|
|
23
|
+
const executePush = require('./executePush');
|
|
21
24
|
|
|
22
25
|
const exported = {
|
|
23
26
|
executeHelp,
|
|
@@ -39,6 +42,9 @@ const exported = {
|
|
|
39
42
|
executeProject,
|
|
40
43
|
executeAgentCfg,
|
|
41
44
|
executeAgent,
|
|
42
|
-
executeConsole
|
|
45
|
+
executeConsole,
|
|
46
|
+
executePull,
|
|
47
|
+
executeCommit,
|
|
48
|
+
executePush
|
|
43
49
|
};
|
|
44
50
|
module.exports = exported;
|
|
File without changes
|