openclawsetup 1.0.2 → 1.0.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/bin/cli.mjs +74 -6
- package/install.bat +20 -0
- package/package.json +2 -1
package/bin/cli.mjs
CHANGED
|
@@ -195,27 +195,95 @@ function detectExistingInstall() {
|
|
|
195
195
|
return { installed: false };
|
|
196
196
|
}
|
|
197
197
|
|
|
198
|
+
// 带进度动画的命令执行
|
|
199
|
+
function execWithProgress(cmd, message, options = {}) {
|
|
200
|
+
return new Promise((resolve) => {
|
|
201
|
+
const frames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
202
|
+
let frameIndex = 0;
|
|
203
|
+
let seconds = 0;
|
|
204
|
+
|
|
205
|
+
// 显示进度动画
|
|
206
|
+
const spinner = setInterval(() => {
|
|
207
|
+
process.stdout.write(`\r${colors.cyan(frames[frameIndex])} ${message} ${colors.gray(`(${seconds}s)`)}`);
|
|
208
|
+
frameIndex = (frameIndex + 1) % frames.length;
|
|
209
|
+
}, 100);
|
|
210
|
+
|
|
211
|
+
// 计时器
|
|
212
|
+
const timer = setInterval(() => {
|
|
213
|
+
seconds++;
|
|
214
|
+
}, 1000);
|
|
215
|
+
|
|
216
|
+
// 执行命令
|
|
217
|
+
const child = spawn('sh', ['-c', cmd], {
|
|
218
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
219
|
+
...options,
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
let stdout = '';
|
|
223
|
+
let stderr = '';
|
|
224
|
+
|
|
225
|
+
child.stdout?.on('data', (data) => {
|
|
226
|
+
stdout += data.toString();
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
child.stderr?.on('data', (data) => {
|
|
230
|
+
stderr += data.toString();
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
child.on('close', (code) => {
|
|
234
|
+
clearInterval(spinner);
|
|
235
|
+
clearInterval(timer);
|
|
236
|
+
// 清除当前行
|
|
237
|
+
process.stdout.write('\r' + ' '.repeat(60) + '\r');
|
|
238
|
+
|
|
239
|
+
if (code === 0) {
|
|
240
|
+
resolve({ ok: true, output: stdout.trim(), seconds });
|
|
241
|
+
} else {
|
|
242
|
+
resolve({ ok: false, error: stderr || stdout, stderr, stdout, seconds });
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
child.on('error', (err) => {
|
|
247
|
+
clearInterval(spinner);
|
|
248
|
+
clearInterval(timer);
|
|
249
|
+
process.stdout.write('\r' + ' '.repeat(60) + '\r');
|
|
250
|
+
resolve({ ok: false, error: err.message, seconds });
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
|
|
198
255
|
// 安装 OpenClaw CLI
|
|
199
|
-
function installOpenClaw() {
|
|
256
|
+
async function installOpenClaw() {
|
|
200
257
|
log.step(1, '安装 OpenClaw CLI...');
|
|
258
|
+
log.detail('正在从 npm 下载,请稍候...');
|
|
259
|
+
|
|
260
|
+
const result = await execWithProgress(
|
|
261
|
+
'npm install -g openclaw@latest',
|
|
262
|
+
'正在安装 openclaw...',
|
|
263
|
+
{ timeout: 300000 }
|
|
264
|
+
);
|
|
201
265
|
|
|
202
|
-
const result = safeExec('npm install -g openclaw@latest', { timeout: 300000 });
|
|
203
266
|
if (!result.ok) {
|
|
204
267
|
// 尝试 clawdbot 作为备选
|
|
205
268
|
log.warn('openclaw 安装失败,尝试 clawdbot...');
|
|
206
|
-
const fallback =
|
|
269
|
+
const fallback = await execWithProgress(
|
|
270
|
+
'npm install -g clawdbot@latest',
|
|
271
|
+
'正在安装 clawdbot...',
|
|
272
|
+
{ timeout: 300000 }
|
|
273
|
+
);
|
|
207
274
|
if (!fallback.ok) {
|
|
208
|
-
exitWithError('NPM_INSTALL_FAILED', result.
|
|
275
|
+
exitWithError('NPM_INSTALL_FAILED', result.error || result.stderr, [
|
|
209
276
|
'检查网络连接',
|
|
210
277
|
'尝试使用代理: npm config set proxy http://proxy:port',
|
|
211
278
|
'手动安装: npm install -g openclaw@latest',
|
|
212
279
|
'检查 npm 权限,可能需要 sudo (Linux/macOS)',
|
|
213
280
|
]);
|
|
214
281
|
}
|
|
282
|
+
log.success(`clawdbot 安装完成 (${fallback.seconds}s)`);
|
|
215
283
|
return 'clawdbot';
|
|
216
284
|
}
|
|
217
285
|
|
|
218
|
-
log.success(
|
|
286
|
+
log.success(`OpenClaw CLI 安装完成 (${result.seconds}s)`);
|
|
219
287
|
return 'openclaw';
|
|
220
288
|
}
|
|
221
289
|
|
|
@@ -480,7 +548,7 @@ async function main() {
|
|
|
480
548
|
}
|
|
481
549
|
|
|
482
550
|
// 安装 CLI
|
|
483
|
-
const cliName = installOpenClaw();
|
|
551
|
+
const cliName = await installOpenClaw();
|
|
484
552
|
|
|
485
553
|
// 创建配置
|
|
486
554
|
const config = createConfig(options);
|
package/install.bat
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
@echo off
|
|
2
|
+
chcp 65001 >nul 2>&1
|
|
3
|
+
echo.
|
|
4
|
+
echo ========================================
|
|
5
|
+
echo OpenClaw 安装提示
|
|
6
|
+
echo ========================================
|
|
7
|
+
echo.
|
|
8
|
+
echo Windows CMD 不支持一键安装脚本。
|
|
9
|
+
echo.
|
|
10
|
+
echo 请使用 Windows PowerShell 运行以下命令:
|
|
11
|
+
echo.
|
|
12
|
+
echo irm https://unpkg.com/openclawsetup/install.ps1 ^| iex
|
|
13
|
+
echo.
|
|
14
|
+
echo 打开 PowerShell 的方法:
|
|
15
|
+
echo 1. 按 Win+X,选择 "Windows PowerShell"
|
|
16
|
+
echo 2. 或在开始菜单搜索 "PowerShell"
|
|
17
|
+
echo.
|
|
18
|
+
echo ========================================
|
|
19
|
+
echo.
|
|
20
|
+
pause
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openclawsetup",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "一键安装 OpenClaw - 自动完成基础部署,无需交互",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"bin/",
|
|
14
14
|
"install.sh",
|
|
15
15
|
"install.ps1",
|
|
16
|
+
"install.bat",
|
|
16
17
|
"README.md",
|
|
17
18
|
"使用说明.md"
|
|
18
19
|
],
|