galaxy-opc 0.3.8 → 0.3.9
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/bin/cli.mjs +39 -9
- package/package.json +1 -1
package/bin/cli.mjs
CHANGED
|
@@ -165,6 +165,31 @@ ${bold(cyan(" ╚════════════════════
|
|
|
165
165
|
}
|
|
166
166
|
console.log(green(` ✓ Node.js v${process.versions.node}`));
|
|
167
167
|
|
|
168
|
+
// 检查 git 是否可用(macOS 没装 Xcode CLT 时 git 会失败)
|
|
169
|
+
const hasGit = checkTool("git");
|
|
170
|
+
if (!hasGit) {
|
|
171
|
+
if (process.platform === "darwin") {
|
|
172
|
+
console.log(yellow("\n ! git 未安装 — macOS 需要先安装 Xcode Command Line Tools"));
|
|
173
|
+
console.log(dim(" 正在尝试自动安装(弹窗后点击「安装」,等待完成)...\n"));
|
|
174
|
+
try {
|
|
175
|
+
execSync("xcode-select --install 2>/dev/null", { stdio: "inherit" });
|
|
176
|
+
} catch { /* 已安装时会报错,忽略 */ }
|
|
177
|
+
// 再次检测
|
|
178
|
+
if (!checkTool("git")) {
|
|
179
|
+
console.error(red("\n ✗ git 仍不可用,请手动执行后重试:"));
|
|
180
|
+
console.error(gray(" xcode-select --install\n"));
|
|
181
|
+
process.exit(1);
|
|
182
|
+
}
|
|
183
|
+
console.log(green(" ✓ git 已就绪"));
|
|
184
|
+
} else {
|
|
185
|
+
console.error(red("\n ✗ git 未安装,请先安装 git:"));
|
|
186
|
+
console.error(gray(" https://git-scm.com/downloads\n"));
|
|
187
|
+
process.exit(1);
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
console.log(green(" ✓ git 已安装"));
|
|
191
|
+
}
|
|
192
|
+
|
|
168
193
|
// ── 步骤 2:安装 openclaw ────────────────────────────────────────────────
|
|
169
194
|
separator();
|
|
170
195
|
console.log(bold(" 步骤 2 / 4 安装 OpenClaw 核心"));
|
|
@@ -175,18 +200,23 @@ ${bold(cyan(" ╚════════════════════
|
|
|
175
200
|
console.log(green(` ✓ OpenClaw 已安装 (${ocVersion})`));
|
|
176
201
|
} else {
|
|
177
202
|
console.log(dim(" 正在安装 OpenClaw(首次安装约 80MB+,使用国内镜像加速)...\n"));
|
|
178
|
-
// 临时覆盖 git url rewrite
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
203
|
+
// 临时覆盖 git url rewrite(强制 SSH 协议转 HTTPS,覆盖两种格式)
|
|
204
|
+
const gitRewrites = [
|
|
205
|
+
["url.https://github.com/.insteadOf", "git@github.com:"],
|
|
206
|
+
["url.https://github.com/.insteadOf", "ssh://git@github.com/"],
|
|
207
|
+
];
|
|
208
|
+
const gitRewritesSet = [];
|
|
209
|
+
for (const [key, val] of gitRewrites) {
|
|
210
|
+
try {
|
|
211
|
+
execSync(`git config --global ${key} "${val}"`, { stdio: "ignore" });
|
|
212
|
+
gitRewritesSet.push(key);
|
|
213
|
+
} catch { /* ignore */ }
|
|
214
|
+
}
|
|
184
215
|
|
|
185
216
|
try {
|
|
186
217
|
await runCommand("npm", [
|
|
187
218
|
"install", "-g", "openclaw@latest",
|
|
188
219
|
"--registry", "https://registry.npmmirror.com",
|
|
189
|
-
"--git-protocol", "https",
|
|
190
220
|
]);
|
|
191
221
|
console.log(green("\n ✓ OpenClaw 安装完成"));
|
|
192
222
|
} catch {
|
|
@@ -195,8 +225,8 @@ ${bold(cyan(" ╚════════════════════
|
|
|
195
225
|
process.exit(1);
|
|
196
226
|
} finally {
|
|
197
227
|
// 还原 git 配置
|
|
198
|
-
|
|
199
|
-
try { execSync(
|
|
228
|
+
for (const key of gitRewritesSet) {
|
|
229
|
+
try { execSync(`git config --global --unset-all ${key}`, { stdio: "ignore" }); } catch { /* ignore */ }
|
|
200
230
|
}
|
|
201
231
|
}
|
|
202
232
|
}
|