@shareai-lab/kode 1.1.3 → 1.1.8
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 -62
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -1,78 +1,66 @@
|
|
|
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
|
-
|
|
12
|
+
const { execSync } = require('child_process');
|
|
13
|
+
execSync('bun --version', { stdio: 'ignore' });
|
|
14
|
+
|
|
15
|
+
// Bun is available
|
|
16
|
+
const child = spawn('bun', ['run', cliPath, ...args], {
|
|
17
|
+
stdio: 'inherit',
|
|
18
|
+
env: {
|
|
19
|
+
...process.env,
|
|
20
|
+
YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm')
|
|
16
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();
|
|
32
|
+
}
|
|
33
|
+
|
|
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))
|
|
17
53
|
}
|
|
18
|
-
} catch {}
|
|
19
54
|
|
|
20
|
-
|
|
21
|
-
const child = spawn('bun', ['run', cliPath, ...args], {
|
|
55
|
+
const child = spawn(tsxPath, [cliPath, ...args], {
|
|
22
56
|
stdio: 'inherit',
|
|
23
57
|
shell: process.platform === 'win32',
|
|
24
58
|
env: { ...process.env, YOGA_WASM_PATH: path.join(__dirname, 'yoga.wasm') },
|
|
25
59
|
})
|
|
26
|
-
|
|
27
|
-
child.on('error', () =>
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
console.error('Kode requires Bun for optimal startup and compatibility.')
|
|
33
|
-
console.error('Install Bun, then install Kode with Bun, and run Kode:')
|
|
34
|
-
console.error('')
|
|
35
|
-
if (process.platform === 'win32') {
|
|
36
|
-
console.error('Windows (PowerShell, recommended):')
|
|
37
|
-
console.error(' winget install --id=Oven-sh.Bun -e')
|
|
38
|
-
console.error(' # 如果未安装 winget,可用 PowerShell 安装脚本:')
|
|
39
|
-
console.error(' powershell -ExecutionPolicy Bypass -NoLogo -NoProfile -Command "iwr https://bun.sh/install.ps1 -UseBasicParsing | iex"')
|
|
40
|
-
console.error(' # 若脚本受限:Set-ExecutionPolicy RemoteSigned -Scope CurrentUser')
|
|
41
|
-
console.error(' # 若 bun 未自动加入 PATH,可执行:')
|
|
42
|
-
console.error(' setx PATH "%USERPROFILE%\\.bun\\bin;%PATH%"')
|
|
43
|
-
console.error('')
|
|
44
|
-
console.error('安装完成后:')
|
|
45
|
-
console.error(' bun --version')
|
|
46
|
-
console.error(' bun add -g @shareai-lab/kode@latest')
|
|
47
|
-
console.error(' kode')
|
|
48
|
-
} else if (process.platform === 'darwin') {
|
|
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')
|
|
68
|
-
}
|
|
69
|
-
console.error('')
|
|
70
|
-
process.exit(1)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
try {
|
|
74
|
-
execSync('bun --version', { stdio: 'ignore' })
|
|
75
|
-
startWithBun()
|
|
76
|
-
} catch {
|
|
77
|
-
showBunInstructionsAndExit()
|
|
60
|
+
|
|
61
|
+
child.on('error', () => runPathTsx())
|
|
62
|
+
child.on('exit', (code) => {
|
|
63
|
+
if (code && code !== 0) return runPathTsx()
|
|
64
|
+
process.exit(code || 0)
|
|
65
|
+
})
|
|
78
66
|
}
|