返回 DeepSeek-TUI-2026
run.js
1 const { spawnSync } = require("child_process");
2 const { getBinaryPath } = require("./install");
3
4 const pkg = require("../package.json");
5
6 function isVersionFlag() {
7 const args = process.argv.slice(2);
8 return args.includes("--version") || args.includes("-v") || args.includes("-V");
9 }
10
11 function handleVersionFallback(binaryName) {
12 if (isVersionFlag()) {
13 const binVersion = pkg.deepseekBinaryVersion || pkg.version;
14 console.log(`${binaryName} (npm wrapper) v${pkg.version}`);
15 console.log(`binary version: v${binVersion}`);
16 console.log(`repo: ${pkg.repository?.url || "N/A"}`);
17 process.exit(0);
18 }
19 }
20
21 async function run(binaryName) {
22 // Intercept --version before attempting binary download/launch
23 handleVersionFallback(binaryName);
24
25 const binaryPath = await getBinaryPath(binaryName);
26 const result = spawnSync(binaryPath, process.argv.slice(2), {
27 stdio: "inherit",
28 });
29 if (result.error) {
30 // If binary fails and user asked for --version, show npm version instead
31 handleVersionFallback(binaryName);
32 throw result.error;
33 }
34 process.exit(result.status ?? 1);
35 }
36
37 async function runDeepseek() {
38 await run("deepseek");
39 }
40
41 async function runDeepseekTui() {
42 await run("deepseek-tui");
43 }
44
45 module.exports = {
46 run,
47 runDeepseek,
48 runDeepseekTui,
49 };
50
51 if (require.main === module) {
52 const command = process.argv[1] || "";
53 if (command.includes("tui")) {
54 runDeepseekTui();
55 } else {
56 runDeepseek();
57 }
58 }
59
59 lines JAVASCRIPT