pumpkinai-config 1.0.4 → 1.0.5
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/claude-setup.js +190 -32
- package/codex-setup.js +20 -30
- package/package.json +1 -1
- package/templates/config.toml +1 -1
- package/claude-au.js +0 -237
package/claude-setup.js
CHANGED
|
@@ -230,6 +230,158 @@ async function configureEnvironment() {
|
|
|
230
230
|
return createClaudeConfig(apiKey);
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
+
// 配置环境变量到系统
|
|
234
|
+
function setupEnvironmentVariable() {
|
|
235
|
+
log('\n[配置] 设置系统环境变量...', 'cyan');
|
|
236
|
+
|
|
237
|
+
const osType = getOS();
|
|
238
|
+
let homeDir;
|
|
239
|
+
if (process.platform !== 'win32' && process.env.SUDO_USER) {
|
|
240
|
+
const actualUser = process.env.SUDO_USER;
|
|
241
|
+
homeDir = process.platform === 'darwin' ? `/Users/${actualUser}` : `/home/${actualUser}`;
|
|
242
|
+
} else {
|
|
243
|
+
homeDir = os.homedir();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const envVarLine = 'export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS="1"';
|
|
247
|
+
|
|
248
|
+
try {
|
|
249
|
+
if (osType === 'windows') {
|
|
250
|
+
// Windows: 使用 setx 设置用户环境变量(永久生效)
|
|
251
|
+
try {
|
|
252
|
+
execSync('setx CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS "1"', { stdio: 'pipe' });
|
|
253
|
+
log('[成功] 已设置 Windows 用户环境变量', 'green');
|
|
254
|
+
log('[提示] 请重新打开终端使环境变量生效', 'yellow');
|
|
255
|
+
return true;
|
|
256
|
+
} catch (error) {
|
|
257
|
+
log('[警告] 无法使用 setx 设置环境变量', 'yellow');
|
|
258
|
+
|
|
259
|
+
// 创建 PowerShell Profile 配置
|
|
260
|
+
try {
|
|
261
|
+
const psProfileCmd = 'echo $PROFILE';
|
|
262
|
+
const profilePath = execSync(psProfileCmd, { encoding: 'utf8', shell: 'powershell.exe' }).trim();
|
|
263
|
+
|
|
264
|
+
// 确保 Profile 目录存在
|
|
265
|
+
const profileDir = path.dirname(profilePath);
|
|
266
|
+
if (!fs.existsSync(profileDir)) {
|
|
267
|
+
fs.mkdirSync(profileDir, { recursive: true });
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// 读取现有 Profile 内容
|
|
271
|
+
let profileContent = '';
|
|
272
|
+
if (fs.existsSync(profilePath)) {
|
|
273
|
+
profileContent = fs.readFileSync(profilePath, 'utf8');
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// 检查是否已存在该环境变量配置
|
|
277
|
+
const psEnvLine = '$env:CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS = "1"';
|
|
278
|
+
if (!profileContent.includes('CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS')) {
|
|
279
|
+
// 追加环境变量到 Profile
|
|
280
|
+
const newContent = profileContent + (profileContent ? '\n' : '') +
|
|
281
|
+
'# Claude Code 环境变量\n' + psEnvLine + '\n';
|
|
282
|
+
fs.writeFileSync(profilePath, newContent, 'utf8');
|
|
283
|
+
log(`[成功] 已添加环境变量到 PowerShell Profile: ${profilePath}`, 'green');
|
|
284
|
+
log('[提示] 请重新打开 PowerShell 使环境变量生效', 'yellow');
|
|
285
|
+
} else {
|
|
286
|
+
log('[提示] PowerShell Profile 中已存在该环境变量', 'yellow');
|
|
287
|
+
}
|
|
288
|
+
return true;
|
|
289
|
+
} catch (psError) {
|
|
290
|
+
log(`[警告] PowerShell Profile 配置失败: ${psError.message}`, 'yellow');
|
|
291
|
+
log('[提示] 请联系淘宝或者技术客服解决', 'yellow');
|
|
292
|
+
return false;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
} else if (osType === 'mac') {
|
|
297
|
+
// macOS: 写入 ~/.zshrc
|
|
298
|
+
const zshrcPath = path.join(homeDir, '.zshrc');
|
|
299
|
+
|
|
300
|
+
// 读取现有内容
|
|
301
|
+
let zshrcContent = '';
|
|
302
|
+
if (fs.existsSync(zshrcPath)) {
|
|
303
|
+
zshrcContent = fs.readFileSync(zshrcPath, 'utf8');
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
// 检查是否已存在该环境变量
|
|
307
|
+
if (!zshrcContent.includes('CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS')) {
|
|
308
|
+
// 追加环境变量
|
|
309
|
+
const newContent = zshrcContent + (zshrcContent && !zshrcContent.endsWith('\n') ? '\n' : '') +
|
|
310
|
+
'# Claude Code 环境变量\n' + envVarLine + '\n';
|
|
311
|
+
fs.writeFileSync(zshrcPath, newContent, 'utf8');
|
|
312
|
+
log(`[成功] 已添加环境变量到: ${zshrcPath}`, 'green');
|
|
313
|
+
|
|
314
|
+
// 如果是通过 sudo 运行的,修改文件所有者
|
|
315
|
+
if (process.env.SUDO_USER) {
|
|
316
|
+
const actualUser = process.env.SUDO_USER;
|
|
317
|
+
try {
|
|
318
|
+
execSync(`chown ${actualUser}:staff ${zshrcPath}`);
|
|
319
|
+
} catch (error) {
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// 自动执行 source 使环境变量在当前进程中立即生效
|
|
324
|
+
try {
|
|
325
|
+
log('[配置] 正在使环境变量立即生效...', 'cyan');
|
|
326
|
+
execSync(`source ${zshrcPath}`, { shell: '/bin/zsh' });
|
|
327
|
+
log('[成功] 环境变量已在当前会话中生效', 'green');
|
|
328
|
+
} catch (error) {
|
|
329
|
+
// source 命令可能在某些情况下失败,提示用户手动执行
|
|
330
|
+
log('[提示] 如需在当前终端立即生效,请运行: source ~/.zshrc', 'yellow');
|
|
331
|
+
}
|
|
332
|
+
} else {
|
|
333
|
+
log('[提示] ~/.zshrc 中已存在该环境变量', 'yellow');
|
|
334
|
+
}
|
|
335
|
+
return true;
|
|
336
|
+
|
|
337
|
+
} else {
|
|
338
|
+
// Linux: 写入 ~/.bashrc
|
|
339
|
+
const bashrcPath = path.join(homeDir, '.bashrc');
|
|
340
|
+
|
|
341
|
+
// 读取现有内容
|
|
342
|
+
let bashrcContent = '';
|
|
343
|
+
if (fs.existsSync(bashrcPath)) {
|
|
344
|
+
bashrcContent = fs.readFileSync(bashrcPath, 'utf8');
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
// 检查是否已存在该环境变量
|
|
348
|
+
if (!bashrcContent.includes('CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS')) {
|
|
349
|
+
// 追加环境变量
|
|
350
|
+
const newContent = bashrcContent + (bashrcContent && !bashrcContent.endsWith('\n') ? '\n' : '') +
|
|
351
|
+
'# Claude Code 环境变量\n' + envVarLine + '\n';
|
|
352
|
+
fs.writeFileSync(bashrcPath, newContent, 'utf8');
|
|
353
|
+
log(`[成功] 已添加环境变量到: ${bashrcPath}`, 'green');
|
|
354
|
+
|
|
355
|
+
// 如果是通过 sudo 运行的,修改文件所有者
|
|
356
|
+
if (process.env.SUDO_USER) {
|
|
357
|
+
const actualUser = process.env.SUDO_USER;
|
|
358
|
+
try {
|
|
359
|
+
execSync(`chown ${actualUser}:${actualUser} ${bashrcPath}`);
|
|
360
|
+
} catch (error) {
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// 自动执行 source 使环境变量在当前进程中立即生效
|
|
365
|
+
try {
|
|
366
|
+
log('[配置] 正在使环境变量立即生效...', 'cyan');
|
|
367
|
+
execSync(`source ${bashrcPath}`, { shell: '/bin/bash' });
|
|
368
|
+
log('[成功] 环境变量已在当前会话中生效', 'green');
|
|
369
|
+
} catch (error) {
|
|
370
|
+
// source 命令可能在某些情况下失败,提示用户手动执行
|
|
371
|
+
log('[提示] 如需在当前终端立即生效,请运行: source ~/.bashrc', 'yellow');
|
|
372
|
+
}
|
|
373
|
+
} else {
|
|
374
|
+
log('[提示] ~/.bashrc 中已存在该环境变量', 'yellow');
|
|
375
|
+
}
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
} catch (error) {
|
|
380
|
+
log(`[错误] 设置环境变量失败: ${error.message}`, 'red');
|
|
381
|
+
return false;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
233
385
|
// 显示完成信息
|
|
234
386
|
function showCompletionInfo() {
|
|
235
387
|
const osType = getOS();
|
|
@@ -247,35 +399,37 @@ function showCompletionInfo() {
|
|
|
247
399
|
const configPath = path.join(claudeDir, 'config.json');
|
|
248
400
|
|
|
249
401
|
log('\n', 'reset');
|
|
250
|
-
log('
|
|
251
|
-
log('
|
|
252
|
-
log('
|
|
253
|
-
|
|
254
|
-
log('\n
|
|
255
|
-
log('
|
|
256
|
-
log('
|
|
257
|
-
log('
|
|
258
|
-
log('
|
|
259
|
-
|
|
260
|
-
log('
|
|
261
|
-
|
|
262
|
-
log(
|
|
263
|
-
log('
|
|
264
|
-
log(
|
|
265
|
-
log(`
|
|
266
|
-
|
|
267
|
-
log(
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
402
|
+
log('=' + '='.repeat(68) + '=', 'yellow');
|
|
403
|
+
log(' 欢迎使用 Claude 开始您的 AI 编程之旅', 'yellow');
|
|
404
|
+
log('=' + '='.repeat(68) + '=', 'yellow');
|
|
405
|
+
|
|
406
|
+
log('\n[已完成操作]', 'cyan');
|
|
407
|
+
log(' * 安装 @anthropic-ai/claude-code', 'green');
|
|
408
|
+
log(' * 创建配置文件 settings.json', 'green');
|
|
409
|
+
log(' * 创建配置文件 config.json', 'green');
|
|
410
|
+
log(' * 设置系统环境变量 CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1', 'green');
|
|
411
|
+
|
|
412
|
+
log('\n[配置文件路径]', 'cyan');
|
|
413
|
+
log(' settings.json (可在此处修改key和域名url):', 'reset');
|
|
414
|
+
log(` ${settingsPath}`, 'yellow');
|
|
415
|
+
log('', 'reset');
|
|
416
|
+
log(' config.json:', 'reset');
|
|
417
|
+
log(` ${configPath}`, 'yellow');
|
|
418
|
+
|
|
419
|
+
log('\n[启动方式]', 'cyan');
|
|
420
|
+
|
|
421
|
+
if (osType === 'windows') {
|
|
422
|
+
log(' 环境变量已设置,请重新打开终端后直接运行:', 'reset');
|
|
423
|
+
log(' claude', 'yellow');
|
|
424
|
+
log('', 'reset');
|
|
425
|
+
log(' 注意: 当前终端需要重新打开才能生效', 'yellow');
|
|
426
|
+
} else if (osType === 'mac') {
|
|
427
|
+
log(' 环境变量已自动生效,直接运行:', 'reset');
|
|
428
|
+
log(' claude', 'yellow');
|
|
429
|
+
} else {
|
|
430
|
+
log(' 环境变量已自动生效,直接运行:', 'reset');
|
|
431
|
+
log(' claude', 'yellow');
|
|
432
|
+
}
|
|
279
433
|
|
|
280
434
|
const claudeVersion = getClaudeVersion();
|
|
281
435
|
log('\n Claude Code 版本: v' + claudeVersion, 'reset');
|
|
@@ -306,13 +460,16 @@ async function main() {
|
|
|
306
460
|
log('\n[提示] 安装失败,但你可以继续配置环境变量', 'yellow');
|
|
307
461
|
}
|
|
308
462
|
|
|
309
|
-
// 2.
|
|
463
|
+
// 2. 配置 API Key
|
|
310
464
|
const configSuccess = await configureEnvironment();
|
|
311
465
|
if (!configSuccess) {
|
|
312
466
|
process.exit(1);
|
|
313
467
|
}
|
|
314
468
|
|
|
315
|
-
// 3.
|
|
469
|
+
// 3. 设置系统环境变量
|
|
470
|
+
setupEnvironmentVariable();
|
|
471
|
+
|
|
472
|
+
// 4. 显示完成信息
|
|
316
473
|
showCompletionInfo();
|
|
317
474
|
|
|
318
475
|
} catch (error) {
|
|
@@ -330,5 +487,6 @@ if (require.main === module) {
|
|
|
330
487
|
module.exports = {
|
|
331
488
|
main,
|
|
332
489
|
installClaude,
|
|
333
|
-
configureEnvironment
|
|
490
|
+
configureEnvironment,
|
|
491
|
+
setupEnvironmentVariable
|
|
334
492
|
};
|
package/codex-setup.js
CHANGED
|
@@ -478,36 +478,26 @@ function showCompletionInfo() {
|
|
|
478
478
|
const authPath = path.join(codexPath, 'auth.json');
|
|
479
479
|
|
|
480
480
|
log('\n', 'reset');
|
|
481
|
-
log('
|
|
482
|
-
log('
|
|
483
|
-
log('
|
|
484
|
-
|
|
485
|
-
log('\n
|
|
486
|
-
log('
|
|
487
|
-
log(
|
|
488
|
-
log(
|
|
489
|
-
log('
|
|
490
|
-
|
|
491
|
-
log('
|
|
492
|
-
log('
|
|
493
|
-
|
|
494
|
-
log('
|
|
495
|
-
log('
|
|
496
|
-
log(`
|
|
497
|
-
|
|
498
|
-
log('
|
|
499
|
-
log(
|
|
500
|
-
log(
|
|
501
|
-
log(' │', 'cyan');
|
|
502
|
-
log(' └─────────────────────────────────────────────', 'cyan');
|
|
503
|
-
|
|
504
|
-
log('\n ┌─ 使用方式', 'cyan');
|
|
505
|
-
log(' │', 'cyan');
|
|
506
|
-
log(' │ 在终端输入以下命令启动 Codex:', 'reset');
|
|
507
|
-
log(' │', 'cyan');
|
|
508
|
-
log(' │ codex', 'yellow');
|
|
509
|
-
log(' │', 'cyan');
|
|
510
|
-
log(' └─────────────────────────────────────────────', 'cyan');
|
|
481
|
+
log('=' + '='.repeat(68) + '=', 'yellow');
|
|
482
|
+
log(' 欢迎使用 Codex 开始您的 AI 编程之旅', 'yellow');
|
|
483
|
+
log('=' + '='.repeat(68) + '=', 'yellow');
|
|
484
|
+
|
|
485
|
+
log('\n[已完成操作]', 'cyan');
|
|
486
|
+
log(' * 安装 @openai/codex', 'green');
|
|
487
|
+
log(` * 创建目录 ${codexPath}`, 'green');
|
|
488
|
+
log(' * 创建配置文件 config.toml', 'green');
|
|
489
|
+
log(' * 创建认证文件 auth.json', 'green');
|
|
490
|
+
|
|
491
|
+
log('\n[配置文件路径]', 'cyan');
|
|
492
|
+
log(' config.toml (可在此处修改域名url):', 'reset');
|
|
493
|
+
log(` ${configPath}`, 'yellow');
|
|
494
|
+
log('', 'reset');
|
|
495
|
+
log(' auth.json (可在此处修改key):', 'reset');
|
|
496
|
+
log(` ${authPath}`, 'yellow');
|
|
497
|
+
|
|
498
|
+
log('\n[使用方式]', 'cyan');
|
|
499
|
+
log(' 在终端输入以下命令启动 Codex:', 'reset');
|
|
500
|
+
log(' codex', 'yellow');
|
|
511
501
|
|
|
512
502
|
const codexVersion = getCodexVersion();
|
|
513
503
|
log('\n Codex 版本: v' + codexVersion, 'reset');
|
package/package.json
CHANGED
package/templates/config.toml
CHANGED
package/claude-au.js
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Claude Code 自动更新禁用工具
|
|
5
|
-
* 功能:
|
|
6
|
-
* 1. 在 ~/.claude/settings.json 中添加禁用自动更新的配置
|
|
7
|
-
* 2. 安装指定版本的 @anthropic-ai/claude-code@2.0.25
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
const fs = require('fs');
|
|
11
|
-
const path = require('path');
|
|
12
|
-
const os = require('os');
|
|
13
|
-
const { execSync } = require('child_process');
|
|
14
|
-
|
|
15
|
-
// 颜色输出
|
|
16
|
-
const colors = {
|
|
17
|
-
red: '\x1b[31m',
|
|
18
|
-
green: '\x1b[32m',
|
|
19
|
-
yellow: '\x1b[33m',
|
|
20
|
-
blue: '\x1b[34m',
|
|
21
|
-
magenta: '\x1b[35m',
|
|
22
|
-
cyan: '\x1b[36m',
|
|
23
|
-
reset: '\x1b[0m'
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
function log(message, color = 'reset') {
|
|
27
|
-
console.log(`${colors[color]}${message}${colors.reset}`);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// 检测操作系统
|
|
31
|
-
function getOS() {
|
|
32
|
-
const platform = os.platform();
|
|
33
|
-
if (platform === 'win32') return 'windows';
|
|
34
|
-
if (platform === 'darwin') return 'mac';
|
|
35
|
-
return 'linux';
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// 获取用户 home 目录
|
|
39
|
-
function getHomeDir() {
|
|
40
|
-
let homeDir;
|
|
41
|
-
if (process.platform !== 'win32' && process.env.SUDO_USER) {
|
|
42
|
-
// Linux/Mac 使用 sudo 时,获取实际用户的 home 目录
|
|
43
|
-
const actualUser = process.env.SUDO_USER;
|
|
44
|
-
homeDir = process.platform === 'darwin' ? `/Users/${actualUser}` : `/home/${actualUser}`;
|
|
45
|
-
} else {
|
|
46
|
-
homeDir = os.homedir();
|
|
47
|
-
}
|
|
48
|
-
return homeDir;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// 更新 settings.json 配置(添加而不是覆盖)
|
|
52
|
-
function updateClaudeSettings() {
|
|
53
|
-
log('\n[配置] 更新 Claude settings.json...', 'cyan');
|
|
54
|
-
|
|
55
|
-
const homeDir = getHomeDir();
|
|
56
|
-
const claudeDir = path.join(homeDir, '.claude');
|
|
57
|
-
const settingsPath = path.join(claudeDir, 'settings.json');
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
// 确保 .claude 目录存在
|
|
61
|
-
if (!fs.existsSync(claudeDir)) {
|
|
62
|
-
fs.mkdirSync(claudeDir, { recursive: true });
|
|
63
|
-
log(`[成功] 创建目录: ${claudeDir}`, 'green');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// 读取现有配置
|
|
67
|
-
let settings = {};
|
|
68
|
-
if (fs.existsSync(settingsPath)) {
|
|
69
|
-
try {
|
|
70
|
-
const content = fs.readFileSync(settingsPath, 'utf8');
|
|
71
|
-
settings = JSON.parse(content);
|
|
72
|
-
log('[提示] 读取现有配置文件', 'yellow');
|
|
73
|
-
} catch (error) {
|
|
74
|
-
log('[警告] 无法解析现有配置文件,将创建新配置', 'yellow');
|
|
75
|
-
settings = {};
|
|
76
|
-
}
|
|
77
|
-
} else {
|
|
78
|
-
log('[提示] 配置文件不存在,将创建新文件', 'yellow');
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// 添加或更新自动更新配置
|
|
82
|
-
settings.autoUpdaterStatus = "disabled";
|
|
83
|
-
settings.autoUpdates = false;
|
|
84
|
-
|
|
85
|
-
// 写入配置文件
|
|
86
|
-
fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2), 'utf8');
|
|
87
|
-
log(`[成功] 更新配置文件: ${settingsPath}`, 'green');
|
|
88
|
-
log('[成功] 已添加配置:', 'green');
|
|
89
|
-
log(' - autoUpdaterStatus: "disabled"', 'green');
|
|
90
|
-
log(' - autoUpdates: false', 'green');
|
|
91
|
-
|
|
92
|
-
// 如果是通过 sudo 运行的,修改文件所有者
|
|
93
|
-
if (process.platform !== 'win32' && process.env.SUDO_USER) {
|
|
94
|
-
const actualUser = process.env.SUDO_USER;
|
|
95
|
-
const group = process.platform === 'darwin' ? 'staff' : actualUser;
|
|
96
|
-
try {
|
|
97
|
-
execSync(`chown -R ${actualUser}:${group} ${claudeDir}`);
|
|
98
|
-
log(`[成功] 设置文件所有者为: ${actualUser}`, 'green');
|
|
99
|
-
} catch (error) {
|
|
100
|
-
log(`[警告] 无法设置文件所有者: ${error.message}`, 'yellow');
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return true;
|
|
105
|
-
} catch (error) {
|
|
106
|
-
log(`[错误] 更新配置文件失败: ${error.message}`, 'red');
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// 安装指定版本的 claude-code
|
|
112
|
-
function installClaudeVersion() {
|
|
113
|
-
const osType = getOS();
|
|
114
|
-
const targetVersion = '2.0.25';
|
|
115
|
-
let command;
|
|
116
|
-
|
|
117
|
-
log('\n[安装] 安装 @anthropic-ai/claude-code@2.0.25...', 'cyan');
|
|
118
|
-
|
|
119
|
-
if (osType === 'windows') {
|
|
120
|
-
command = `npm install -g @anthropic-ai/claude-code@${targetVersion} --registry https://registry.npmmirror.com`;
|
|
121
|
-
} else {
|
|
122
|
-
// 检查是否已经是 root 用户(通过 sudo 运行或直接 root)
|
|
123
|
-
const isRoot = process.getuid && process.getuid() === 0;
|
|
124
|
-
if (isRoot) {
|
|
125
|
-
command = `npm install -g @anthropic-ai/claude-code@${targetVersion} --registry https://registry.npmmirror.com`;
|
|
126
|
-
} else {
|
|
127
|
-
command = `sudo npm install -g @anthropic-ai/claude-code@${targetVersion} --registry https://registry.npmmirror.com`;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
log(`[执行] ${command}`, 'yellow');
|
|
132
|
-
|
|
133
|
-
try {
|
|
134
|
-
execSync(command, { stdio: 'inherit' });
|
|
135
|
-
log(`[成功] @anthropic-ai/claude-code@${targetVersion} 安装成功`, 'green');
|
|
136
|
-
return true;
|
|
137
|
-
} catch (error) {
|
|
138
|
-
log(`[错误] @anthropic-ai/claude-code@${targetVersion} 安装失败`, 'red');
|
|
139
|
-
log('\n[错误详情]', 'red');
|
|
140
|
-
|
|
141
|
-
if (error.message) {
|
|
142
|
-
log(`错误信息: ${error.message}`, 'red');
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
if (error.status !== undefined) {
|
|
146
|
-
log(`退出码: ${error.status}`, 'red');
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
log('\n[提示] 你可以手动安装:', 'yellow');
|
|
150
|
-
log(` ${command}`, 'yellow');
|
|
151
|
-
return false;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// 显示完成信息
|
|
156
|
-
function showCompletionInfo() {
|
|
157
|
-
const homeDir = getHomeDir();
|
|
158
|
-
const settingsPath = path.join(homeDir, '.claude', 'settings.json');
|
|
159
|
-
|
|
160
|
-
log('\n', 'reset');
|
|
161
|
-
log('╔' + '═'.repeat(68) + '╗', 'yellow');
|
|
162
|
-
log('║' + ' '.repeat(15) + '配置完成 - 自动更新已禁用' + ' '.repeat(15) + '║', 'yellow');
|
|
163
|
-
log('╚' + '═'.repeat(68) + '╝', 'yellow');
|
|
164
|
-
|
|
165
|
-
log('\n ┌─ 已完成操作', 'cyan');
|
|
166
|
-
log(' │', 'cyan');
|
|
167
|
-
log(' │ ✓ 禁用 Claude Code 自动更新', 'green');
|
|
168
|
-
log(' │ ✓ 安装 @anthropic-ai/claude-code@2.0.25', 'green');
|
|
169
|
-
log(' │', 'cyan');
|
|
170
|
-
log(' └─────────────────────────────────────────────', 'cyan');
|
|
171
|
-
|
|
172
|
-
log('\n ┌─ 配置文件路径', 'cyan');
|
|
173
|
-
log(' │', 'cyan');
|
|
174
|
-
log(` │ ${settingsPath}`, 'yellow');
|
|
175
|
-
log(' │', 'cyan');
|
|
176
|
-
log(' └─────────────────────────────────────────────', 'cyan');
|
|
177
|
-
|
|
178
|
-
log('\n ┌─ 已添加的配置', 'cyan');
|
|
179
|
-
log(' │', 'cyan');
|
|
180
|
-
log(' │ "autoUpdaterStatus": "disabled"', 'yellow');
|
|
181
|
-
log(' │ "autoUpdates": false', 'yellow');
|
|
182
|
-
log(' │', 'cyan');
|
|
183
|
-
log(' └─────────────────────────────────────────────', 'cyan');
|
|
184
|
-
|
|
185
|
-
log('\n', 'reset');
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// 主函数
|
|
189
|
-
async function main() {
|
|
190
|
-
console.clear();
|
|
191
|
-
|
|
192
|
-
// ASCII Logo
|
|
193
|
-
log('\n', 'reset');
|
|
194
|
-
console.log(' \x1b[38;5;39m██████╗\x1b[38;5;75m██╗ \x1b[38;5;111m█████╗ \x1b[38;5;147m██╗ ██╗\x1b[38;5;183m██████╗ \x1b[38;5;219m███████╗\x1b[0m');
|
|
195
|
-
console.log(' \x1b[38;5;39m██╔════╝\x1b[38;5;75m██║ \x1b[38;5;111m██╔══██╗\x1b[38;5;147m██║ ██║\x1b[38;5;183m██╔══██╗\x1b[38;5;219m██╔════╝\x1b[0m');
|
|
196
|
-
console.log(' \x1b[38;5;45m██║ \x1b[38;5;81m██║ \x1b[38;5;117m███████║\x1b[38;5;153m██║ ██║\x1b[38;5;189m██║ ██║\x1b[38;5;225m█████╗ \x1b[0m');
|
|
197
|
-
console.log(' \x1b[38;5;75m██║ \x1b[38;5;111m██║ \x1b[38;5;147m██╔══██║\x1b[38;5;183m██║ ██║\x1b[38;5;219m██║ ██║\x1b[38;5;225m██╔══╝ \x1b[0m');
|
|
198
|
-
console.log(' \x1b[38;5;111m╚██████╗\x1b[38;5;147m███████╗\x1b[38;5;183m██║ ██║\x1b[38;5;219m╚██████╔╝\x1b[38;5;225m██████╔╝\x1b[38;5;231m███████╗\x1b[0m');
|
|
199
|
-
console.log(' \x1b[38;5;147m╚═════╝\x1b[38;5;183m╚══════╝\x1b[38;5;219m╚═╝ ╚═╝\x1b[38;5;225m ╚═════╝ \x1b[38;5;231m╚═════╝ ╚══════╝\x1b[0m');
|
|
200
|
-
log('\n Claude Code Auto-Update Disabler', 'magenta');
|
|
201
|
-
log(' ' + '='.repeat(50), 'cyan');
|
|
202
|
-
log('', 'reset');
|
|
203
|
-
|
|
204
|
-
try {
|
|
205
|
-
// 1. 更新 settings.json 配置
|
|
206
|
-
const configSuccess = updateClaudeSettings();
|
|
207
|
-
if (!configSuccess) {
|
|
208
|
-
log('\n[错误] 配置更新失败', 'red');
|
|
209
|
-
process.exit(1);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// 2. 安装指定版本的 claude-code
|
|
213
|
-
const installSuccess = installClaudeVersion();
|
|
214
|
-
if (!installSuccess) {
|
|
215
|
-
log('\n[警告] 安装失败,但配置已更新', 'yellow');
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// 3. 显示完成信息
|
|
219
|
-
showCompletionInfo();
|
|
220
|
-
|
|
221
|
-
} catch (error) {
|
|
222
|
-
log(`\n[错误] 执行过程中出现错误: ${error.message}`, 'red');
|
|
223
|
-
process.exit(1);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// 如果直接运行此脚本
|
|
228
|
-
if (require.main === module) {
|
|
229
|
-
main();
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// 导出函数供其他模块使用
|
|
233
|
-
module.exports = {
|
|
234
|
-
main,
|
|
235
|
-
updateClaudeSettings,
|
|
236
|
-
installClaudeVersion
|
|
237
|
-
};
|