@gengjiawen/os-init 1.1.0 → 1.1.1
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/build/index.d.ts +2 -0
- package/build/index.js +63 -0
- package/package.json +1 -1
package/build/index.d.ts
ADDED
package/build/index.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeConfig = writeConfig;
|
|
4
|
+
exports.installDeps = installDeps;
|
|
5
|
+
const fs = require("fs");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const os = require("os");
|
|
8
|
+
const execa_1 = require("execa");
|
|
9
|
+
function getDefaultConfigDir() {
|
|
10
|
+
return path.join(os.homedir(), '.claude-code-router');
|
|
11
|
+
}
|
|
12
|
+
function ensureDir(dirPath) {
|
|
13
|
+
fs.mkdirSync(dirPath, { recursive: true });
|
|
14
|
+
}
|
|
15
|
+
const DEFAULT_TEMPLATE = `{
|
|
16
|
+
"Providers": [
|
|
17
|
+
{
|
|
18
|
+
"name": "jw",
|
|
19
|
+
"api_base_url": "https://ai.gengjiawen.com/api/openai/v1/chat/completions",
|
|
20
|
+
"api_key": "API_KEY_PLACEHOLDER",
|
|
21
|
+
"models": ["code", "free", "free-thinking"],
|
|
22
|
+
"transformer": {
|
|
23
|
+
"use": ["openrouter"]
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"Router": {
|
|
28
|
+
"default": "jw,code",
|
|
29
|
+
"background": "jw,code",
|
|
30
|
+
"think": "jw,code",
|
|
31
|
+
"longContext": "jw,code"
|
|
32
|
+
}
|
|
33
|
+
}`;
|
|
34
|
+
function writeConfig(apiKey) {
|
|
35
|
+
const configDir = getDefaultConfigDir();
|
|
36
|
+
const configPath = path.join(configDir, 'config.json');
|
|
37
|
+
ensureDir(configDir);
|
|
38
|
+
const content = DEFAULT_TEMPLATE.replace('API_KEY_PLACEHOLDER', apiKey);
|
|
39
|
+
fs.writeFileSync(configPath, content);
|
|
40
|
+
return configPath;
|
|
41
|
+
}
|
|
42
|
+
async function commandExists(command) {
|
|
43
|
+
try {
|
|
44
|
+
const { failed } = await (0, execa_1.execa)(command, ['--version'], { stdio: 'ignore', reject: false });
|
|
45
|
+
return !failed;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async function installDeps() {
|
|
52
|
+
const packages = ['@anthropic-ai/claude-code', '@musistudio/claude-code-router'];
|
|
53
|
+
const usePnpm = await commandExists('pnpm');
|
|
54
|
+
if (usePnpm) {
|
|
55
|
+
console.log('pnpm detected. Installing dependencies with pnpm...');
|
|
56
|
+
await (0, execa_1.execa)('pnpm', ['add', '-g', ...packages], { stdio: 'inherit' });
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
console.log('pnpm not found. Falling back to npm...');
|
|
60
|
+
await (0, execa_1.execa)('npm', ['install', '-g', ...packages], { stdio: 'inherit' });
|
|
61
|
+
}
|
|
62
|
+
console.log('Dependencies installed successfully.');
|
|
63
|
+
}
|