@liuzijian625/code-cli 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/lib/config.js +47 -23
- package/package.json +1 -1
package/lib/config.js
CHANGED
|
@@ -48,25 +48,38 @@ 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: 修改 ~/.claude.json
|
|
55
|
+
const claudeFile = path.join(os.homedir(), '.claude.json');
|
|
56
|
+
let config = {};
|
|
57
|
+
if (fs.existsSync(claudeFile)) {
|
|
58
|
+
config = JSON.parse(fs.readFileSync(claudeFile, 'utf-8'));
|
|
59
|
+
}
|
|
60
|
+
config.apiKey = preset.key;
|
|
61
|
+
config.baseUrl = preset.url;
|
|
62
|
+
fs.writeFileSync(claudeFile, JSON.stringify(config, null, 2));
|
|
63
|
+
} else {
|
|
64
|
+
// Linux/macOS: 修改 ~/.claude/settings.json
|
|
65
|
+
const claudeDir = path.join(os.homedir(), '.claude');
|
|
66
|
+
const settingsFile = path.join(claudeDir, 'settings.json');
|
|
55
67
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
68
|
+
if (!fs.existsSync(claudeDir)) {
|
|
69
|
+
fs.mkdirSync(claudeDir, { recursive: true });
|
|
70
|
+
}
|
|
59
71
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
72
|
+
let settings = {};
|
|
73
|
+
if (fs.existsSync(settingsFile)) {
|
|
74
|
+
settings = JSON.parse(fs.readFileSync(settingsFile, 'utf-8'));
|
|
75
|
+
}
|
|
64
76
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
77
|
+
if (!settings.env) settings.env = {};
|
|
78
|
+
settings.env.ANTHROPIC_BASE_URL = preset.url;
|
|
79
|
+
settings.env.ANTHROPIC_AUTH_TOKEN = preset.key;
|
|
68
80
|
|
|
69
|
-
|
|
81
|
+
fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2));
|
|
82
|
+
}
|
|
70
83
|
}
|
|
71
84
|
|
|
72
85
|
// Gemini CLI 配置
|
|
@@ -116,16 +129,27 @@ async function clearCodex() {
|
|
|
116
129
|
}
|
|
117
130
|
|
|
118
131
|
async function clearClaude() {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
delete
|
|
126
|
-
|
|
132
|
+
if (isWindows) {
|
|
133
|
+
// Windows: 修改 ~/.claude.json
|
|
134
|
+
const claudeFile = path.join(os.homedir(), '.claude.json');
|
|
135
|
+
if (fs.existsSync(claudeFile)) {
|
|
136
|
+
let config = JSON.parse(fs.readFileSync(claudeFile, 'utf-8'));
|
|
137
|
+
delete config.apiKey;
|
|
138
|
+
delete config.baseUrl;
|
|
139
|
+
fs.writeFileSync(claudeFile, JSON.stringify(config, null, 2));
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
const claudeDir = path.join(os.homedir(), '.claude');
|
|
143
|
+
const settingsFile = path.join(claudeDir, 'settings.json');
|
|
144
|
+
|
|
145
|
+
if (fs.existsSync(settingsFile)) {
|
|
146
|
+
let settings = JSON.parse(fs.readFileSync(settingsFile, 'utf-8'));
|
|
147
|
+
if (settings.env) {
|
|
148
|
+
delete settings.env.ANTHROPIC_BASE_URL;
|
|
149
|
+
delete settings.env.ANTHROPIC_AUTH_TOKEN;
|
|
150
|
+
}
|
|
151
|
+
fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2));
|
|
127
152
|
}
|
|
128
|
-
fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2));
|
|
129
153
|
}
|
|
130
154
|
}
|
|
131
155
|
|