istarshine 1.2.4 → 1.2.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/bin/cli.js +1 -1
- package/lib/config.js +68 -0
- package/package.json +1 -1
package/bin/cli.js
CHANGED
package/lib/config.js
CHANGED
|
@@ -129,6 +129,8 @@ export async function config_action(options) {
|
|
|
129
129
|
write_config({ api_key: options.apiKey });
|
|
130
130
|
const masked = mask_api_key(options.apiKey);
|
|
131
131
|
console.log(chalk.green(`✔ API Key 已保存: ${masked}`));
|
|
132
|
+
// 同步写入 shell 配置文件,确保全局环境变量可用(Kiro 等 IDE 环境)
|
|
133
|
+
setup_shell_env(options.apiKey, chalk);
|
|
132
134
|
// 同步配置 OpenClaw SecretRef
|
|
133
135
|
setup_openclaw_secretref(options.apiKey, chalk);
|
|
134
136
|
} catch (err) {
|
|
@@ -239,3 +241,69 @@ function setup_openclaw_secretref(api_key, chalk) {
|
|
|
239
241
|
console.log(chalk.yellow(`⚠ OpenClaw SecretRef 自动配置失败: ${err.message}`));
|
|
240
242
|
}
|
|
241
243
|
}
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* 将 ISTARSHINE_API_KEY 写入用户 shell 配置文件(~/.bashrc、~/.zshrc)
|
|
248
|
+
* 实现全局环境变量,确保 Kiro 等 IDE 执行 shell 命令时能读到
|
|
249
|
+
*
|
|
250
|
+
* 逻辑:
|
|
251
|
+
* - 如果文件中已有 export ISTARSHINE_API_KEY=... 行,替换为新值
|
|
252
|
+
* - 如果没有,追加到文件末尾
|
|
253
|
+
* - 同时处理 ~/.bashrc 和 ~/.zshrc,覆盖 bash 和 zsh 两种 shell
|
|
254
|
+
*
|
|
255
|
+
* @param {string} api_key - API Key 明文
|
|
256
|
+
* @param {object} chalk - chalk 实例
|
|
257
|
+
*/
|
|
258
|
+
function setup_shell_env(api_key, chalk) {
|
|
259
|
+
const env_line = `export ISTARSHINE_API_KEY="${api_key}"`;
|
|
260
|
+
const marker = 'export ISTARSHINE_API_KEY=';
|
|
261
|
+
|
|
262
|
+
// 需要写入的 shell 配置文件列表
|
|
263
|
+
const rc_files = [
|
|
264
|
+
join(homedir(), '.bashrc'),
|
|
265
|
+
join(homedir(), '.zshrc'),
|
|
266
|
+
];
|
|
267
|
+
|
|
268
|
+
let updated_count = 0;
|
|
269
|
+
|
|
270
|
+
for (const rc_path of rc_files) {
|
|
271
|
+
try {
|
|
272
|
+
if (!existsSync(rc_path)) {
|
|
273
|
+
// 文件不存在,跳过(不主动创建用户没有的 shell 配置文件)
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
let content = readFileSync(rc_path, 'utf8');
|
|
278
|
+
const lines = content.split('\n');
|
|
279
|
+
let found = false;
|
|
280
|
+
|
|
281
|
+
// 查找并替换已有的 export ISTARSHINE_API_KEY=... 行
|
|
282
|
+
for (let i = 0; i < lines.length; i++) {
|
|
283
|
+
if (lines[i].trimStart().startsWith(marker)) {
|
|
284
|
+
lines[i] = env_line;
|
|
285
|
+
found = true;
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (found) {
|
|
291
|
+
// 替换已有行
|
|
292
|
+
writeFileSync(rc_path, lines.join('\n'), 'utf8');
|
|
293
|
+
} else {
|
|
294
|
+
// 追加到文件末尾
|
|
295
|
+
const suffix = content.endsWith('\n') ? '' : '\n';
|
|
296
|
+
writeFileSync(rc_path, content + suffix + '\n# iStarshine API Key\n' + env_line + '\n', 'utf8');
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
updated_count++;
|
|
300
|
+
} catch {
|
|
301
|
+
// 单个文件写入失败不阻断流程
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (updated_count > 0) {
|
|
306
|
+
console.log(chalk.green(`✔ 环境变量 ISTARSHINE_API_KEY 已写入 shell 配置文件 (${updated_count} 个)`));
|
|
307
|
+
console.log(chalk.gray(' 重新打开终端或执行 source ~/.bashrc 后生效'));
|
|
308
|
+
}
|
|
309
|
+
}
|