pumpkinai-config 1.0.3 → 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 +3 -2
- package/templates/config.toml +1 -1
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
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pumpkinai-config",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "PumpkinAI 一键安装配置工具 - 支持 Codex 和 Claude Code",
|
|
5
5
|
"main": "codex-setup.js",
|
|
6
6
|
"bin": {
|
|
7
7
|
"codex-config": "./codex-setup.js",
|
|
8
|
-
"claude-config": "./claude-setup.js"
|
|
8
|
+
"claude-config": "./claude-setup.js",
|
|
9
|
+
"claude-au": "./claude-au.js"
|
|
9
10
|
},
|
|
10
11
|
"scripts": {
|
|
11
12
|
"test": "node codex-setup.js",
|
package/templates/config.toml
CHANGED