@liuzijian625/code-cli 1.0.3 → 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/lib/config.js +36 -23
- package/package.json +1 -1
package/lib/config.js
CHANGED
|
@@ -48,25 +48,32 @@ async function applyCodex(preset) {
|
|
|
48
48
|
fs.writeFileSync(authFile, JSON.stringify(auth, null, 2));
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
// Claude Code
|
|
51
|
+
// Claude Code 配置
|
|
52
52
|
async function applyClaude(preset) {
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
if (isWindows) {
|
|
54
|
+
// Windows: 使用 setx 命令设置环境变量
|
|
55
|
+
await execAsync(`setx ANTHROPIC_BASE_URL "${preset.url}"`);
|
|
56
|
+
await execAsync(`setx ANTHROPIC_AUTH_TOKEN "${preset.key}"`);
|
|
57
|
+
} else {
|
|
58
|
+
// Linux/macOS: 修改 settings.json
|
|
59
|
+
const claudeDir = path.join(os.homedir(), '.claude');
|
|
60
|
+
const settingsFile = path.join(claudeDir, 'settings.json');
|
|
55
61
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
if (!fs.existsSync(claudeDir)) {
|
|
63
|
+
fs.mkdirSync(claudeDir, { recursive: true });
|
|
64
|
+
}
|
|
59
65
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
66
|
+
let settings = {};
|
|
67
|
+
if (fs.existsSync(settingsFile)) {
|
|
68
|
+
settings = JSON.parse(fs.readFileSync(settingsFile, 'utf-8'));
|
|
69
|
+
}
|
|
64
70
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
71
|
+
if (!settings.env) settings.env = {};
|
|
72
|
+
settings.env.ANTHROPIC_BASE_URL = preset.url;
|
|
73
|
+
settings.env.ANTHROPIC_AUTH_TOKEN = preset.key;
|
|
68
74
|
|
|
69
|
-
|
|
75
|
+
fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2));
|
|
76
|
+
}
|
|
70
77
|
}
|
|
71
78
|
|
|
72
79
|
// Gemini CLI 配置
|
|
@@ -116,16 +123,22 @@ async function clearCodex() {
|
|
|
116
123
|
}
|
|
117
124
|
|
|
118
125
|
async function clearClaude() {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
126
|
+
if (isWindows) {
|
|
127
|
+
// Windows: 使用 reg delete 删除环境变量
|
|
128
|
+
await execAsync(`reg delete "HKCU\\Environment" /v ANTHROPIC_BASE_URL /f`).catch(() => {});
|
|
129
|
+
await execAsync(`reg delete "HKCU\\Environment" /v ANTHROPIC_AUTH_TOKEN /f`).catch(() => {});
|
|
130
|
+
} else {
|
|
131
|
+
const claudeDir = path.join(os.homedir(), '.claude');
|
|
132
|
+
const settingsFile = path.join(claudeDir, 'settings.json');
|
|
133
|
+
|
|
134
|
+
if (fs.existsSync(settingsFile)) {
|
|
135
|
+
let settings = JSON.parse(fs.readFileSync(settingsFile, 'utf-8'));
|
|
136
|
+
if (settings.env) {
|
|
137
|
+
delete settings.env.ANTHROPIC_BASE_URL;
|
|
138
|
+
delete settings.env.ANTHROPIC_AUTH_TOKEN;
|
|
139
|
+
}
|
|
140
|
+
fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2));
|
|
127
141
|
}
|
|
128
|
-
fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2));
|
|
129
142
|
}
|
|
130
143
|
}
|
|
131
144
|
|