@shareai-lab/kode 1.1.3 → 1.1.6
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/cli.js +50 -63
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -1,78 +1,65 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const { spawn
|
|
3
|
+
const { spawn } = require('child_process');
|
|
4
4
|
const path = require('path');
|
|
5
5
|
|
|
6
|
-
//
|
|
6
|
+
// Prefer bun if available, otherwise use node with loader
|
|
7
7
|
const args = process.argv.slice(2);
|
|
8
8
|
const cliPath = path.join(__dirname, 'src', 'entrypoints', 'cli.tsx');
|
|
9
9
|
|
|
10
|
-
//
|
|
10
|
+
// Try bun first
|
|
11
11
|
try {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
} catch {}
|
|
19
|
-
|
|
20
|
-
function startWithBun() {
|
|
12
|
+
const { execSync } = require('child_process');
|
|
13
|
+
execSync('bun --version', { stdio: 'ignore' });
|
|
14
|
+
|
|
15
|
+
// Bun is available
|
|
21
16
|
const child = spawn('bun', ['run', cliPath, ...args], {
|
|
22
17
|
stdio: 'inherit',
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
18
|
+
env: {
|
|
19
|
+
...process.env,
|
|
20
|
+
YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm')
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
child.on('exit', (code) => process.exit(code || 0));
|
|
25
|
+
child.on('error', () => {
|
|
26
|
+
// Fallback to node if bun fails
|
|
27
|
+
runWithNode();
|
|
28
|
+
});
|
|
29
|
+
} catch {
|
|
30
|
+
// Bun not available, use node
|
|
31
|
+
runWithNode();
|
|
28
32
|
}
|
|
29
33
|
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
console.error('macOS:')
|
|
50
|
-
console.error(' brew tap oven-sh/bun && brew install bun')
|
|
51
|
-
console.error(' # 或者')
|
|
52
|
-
console.error(' curl -fsSL https://bun.sh/install | bash')
|
|
53
|
-
console.error(' # zsh: echo "export PATH=\"$HOME/.bun/bin:$PATH\"" >> ~/.zshrc && source ~/.zshrc')
|
|
54
|
-
console.error('')
|
|
55
|
-
console.error('安装完成后:')
|
|
56
|
-
console.error(' bun --version')
|
|
57
|
-
console.error(' bun add -g @shareai-lab/kode@latest')
|
|
58
|
-
console.error(' kode')
|
|
59
|
-
} else {
|
|
60
|
-
console.error('Linux:')
|
|
61
|
-
console.error(' curl -fsSL https://bun.sh/install | bash')
|
|
62
|
-
console.error(' echo "export PATH=\"$HOME/.bun/bin:$PATH\"" >> ~/.bashrc && source ~/.bashrc')
|
|
63
|
-
console.error('')
|
|
64
|
-
console.error('安装完成后:')
|
|
65
|
-
console.error(' bun --version')
|
|
66
|
-
console.error(' bun add -g @shareai-lab/kode@latest')
|
|
67
|
-
console.error(' kode')
|
|
34
|
+
function runWithNode() {
|
|
35
|
+
// Use local tsx installation; if missing, try PATH-resolved tsx
|
|
36
|
+
const binDir = path.join(__dirname, 'node_modules', '.bin')
|
|
37
|
+
const tsxPath = process.platform === 'win32'
|
|
38
|
+
? path.join(binDir, 'tsx.cmd')
|
|
39
|
+
: path.join(binDir, 'tsx')
|
|
40
|
+
|
|
41
|
+
const runPathTsx = () => {
|
|
42
|
+
const child2 = spawn('tsx', [cliPath, ...args], {
|
|
43
|
+
stdio: 'inherit',
|
|
44
|
+
shell: process.platform === 'win32',
|
|
45
|
+
env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
|
|
46
|
+
})
|
|
47
|
+
child2.on('error', () => {
|
|
48
|
+
console.error('\nError: tsx is required but not found.')
|
|
49
|
+
console.error('Please install tsx globally: npm install -g tsx')
|
|
50
|
+
process.exit(1)
|
|
51
|
+
})
|
|
52
|
+
child2.on('exit', (code2) => process.exit(code2 || 0))
|
|
68
53
|
}
|
|
69
|
-
console.error('')
|
|
70
|
-
process.exit(1)
|
|
71
|
-
}
|
|
72
54
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
55
|
+
const child = spawn(tsxPath, [cliPath, ...args], {
|
|
56
|
+
stdio: 'inherit',
|
|
57
|
+
env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
child.on('error', () => runPathTsx())
|
|
61
|
+
child.on('exit', (code) => {
|
|
62
|
+
if (code && code !== 0) return runPathTsx()
|
|
63
|
+
process.exit(code || 0)
|
|
64
|
+
})
|
|
78
65
|
}
|