deep-code-xl 0.34.0

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.
Files changed (3) hide show
  1. package/cli.js +26 -0
  2. package/install.js +101 -0
  3. package/package.json +38 -0
package/cli.js ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env node
2
+ // Deep Code launcher — spawns deep-code.exe with all arguments forwarded.
3
+ const { spawn } = require("child_process");
4
+ const path = require("path");
5
+ const fs = require("fs");
6
+
7
+ const exe = path.join(__dirname, "deep-code.exe");
8
+
9
+ if (!fs.existsSync(exe)) {
10
+ console.error("deep-code.exe 未找到。");
11
+ console.error("请尝试: npm install -g deep-code-xl");
12
+ console.error("或从 GitHub 手动下载: https://github.com/Violet1314/deep-code-xl/releases");
13
+ process.exit(1);
14
+ }
15
+
16
+ const child = spawn(exe, process.argv.slice(2), {
17
+ stdio: "inherit",
18
+ windowsHide: true,
19
+ });
20
+
21
+ child.on("exit", (code, signal) => {
22
+ if (signal) {
23
+ process.exit(1);
24
+ }
25
+ process.exit(code || 0);
26
+ });
package/install.js ADDED
@@ -0,0 +1,101 @@
1
+ // Deep Code postinstall — downloads the latest deep-code.exe from GitHub Releases.
2
+ const https = require("https");
3
+ const fs = require("fs");
4
+ const path = require("path");
5
+
6
+ const version = require("./package.json").version; // "0.34.0"
7
+ const binaryName = "deep-code.exe";
8
+ const downloadURL = `https://github.com/Violet1314/deep-code-xl/releases/download/v${version}/${binaryName}`;
9
+ const dest = path.join(__dirname, binaryName);
10
+
11
+ console.log(`\n ⬇ Deep Code v${version}`);
12
+ console.log(` ${downloadURL}\n`);
13
+
14
+ const file = fs.createWriteStream(dest);
15
+
16
+ https
17
+ .get(downloadURL, { timeout: 300000 }, (res) => {
18
+ // GitHub Releases redirect to Amazon S3 (302)
19
+ if (res.statusCode === 302 || res.statusCode === 301) {
20
+ https
21
+ .get(res.headers.location, { timeout: 300000 }, (res2) => {
22
+ if (res2.statusCode !== 200) {
23
+ cleanup(`下载失败: HTTP ${res2.statusCode}`);
24
+ return;
25
+ }
26
+ pipeWithProgress(res2);
27
+ })
28
+ .on("error", (e) => cleanup(`下载失败: ${e.message}`));
29
+ return;
30
+ }
31
+
32
+ if (res.statusCode !== 200) {
33
+ cleanup(`下载失败: HTTP ${res.statusCode}`);
34
+ return;
35
+ }
36
+
37
+ pipeWithProgress(res);
38
+ })
39
+ .on("error", (e) => cleanup(`下载失败: ${e.message}`));
40
+
41
+ function pipeWithProgress(res) {
42
+ const total = parseInt(res.headers["content-length"], 10) || 0;
43
+ let downloaded = 0;
44
+ const startTime = Date.now();
45
+
46
+ res.on("data", (chunk) => {
47
+ downloaded += chunk.length;
48
+ file.write(chunk);
49
+
50
+ // Progress every 200ms
51
+ const now = Date.now();
52
+ if (!pipeWithProgress._last || now - pipeWithProgress._last > 200) {
53
+ pipeWithProgress._last = now;
54
+ renderBar(downloaded, total, startTime);
55
+ }
56
+ });
57
+
58
+ res.on("end", () => {
59
+ file.end();
60
+ renderBar(downloaded, total, startTime);
61
+ console.log("\n ✓ Deep Code 安装完成 — 输入 deep-code 启动\n");
62
+ });
63
+
64
+ res.on("error", (e) => cleanup(`下载中断: ${e.message}`));
65
+ }
66
+
67
+ function renderBar(downloaded, total, started) {
68
+ if (total <= 0) {
69
+ const mb = (downloaded / (1 << 20)).toFixed(1);
70
+ process.stdout.write(`\r ${mb} MB 已下载...`);
71
+ return;
72
+ }
73
+ const pct = Math.min(100, Math.round((downloaded / total) * 100));
74
+ const width = 30;
75
+ const filled = Math.round((pct / 100) * width);
76
+ const bar = "█".repeat(filled) + "░".repeat(width - filled);
77
+ const elapsed = Math.max(0.1, (Date.now() - started) / 1000);
78
+ const speed = formatBytes(downloaded / elapsed);
79
+ process.stdout.write(
80
+ `\r ${bar} ${pct}% (${formatBytes(downloaded)} / ${formatBytes(total)}) ${speed}/s`
81
+ );
82
+ }
83
+
84
+ function formatBytes(bytes) {
85
+ if (bytes >= 1 << 30) return (bytes / (1 << 30)).toFixed(1) + " GB";
86
+ if (bytes >= 1 << 20) return (bytes / (1 << 20)).toFixed(1) + " MB";
87
+ if (bytes >= 1 << 10) return (bytes / (1 << 10)).toFixed(1) + " KB";
88
+ return Math.round(bytes) + " B";
89
+ }
90
+
91
+ function cleanup(msg) {
92
+ console.error(`\n ✗ ${msg}`);
93
+ console.error(" 可尝试手动下载: ", downloadURL);
94
+ console.error(" 安装 deep-code.exe 后放到本目录即可使用。\n");
95
+ try {
96
+ fs.unlinkSync(dest);
97
+ } catch (_) {
98
+ /* best effort */
99
+ }
100
+ // Do not exit with error — allow npm install to succeed for retry
101
+ }
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "deep-code-xl",
3
+ "version": "0.34.0",
4
+ "description": "Deep Code — AI-powered CLI coding assistant. One command to install, one command to start.",
5
+ "main": "cli.js",
6
+ "bin": {
7
+ "deep-code": "cli.js"
8
+ },
9
+ "scripts": {
10
+ "postinstall": "node install.js"
11
+ },
12
+ "files": [
13
+ "install.js",
14
+ "cli.js"
15
+ ],
16
+ "keywords": [
17
+ "ai",
18
+ "cli",
19
+ "coding-assistant",
20
+ "deep-code",
21
+ "developer-tools"
22
+ ],
23
+ "author": {
24
+ "name": "xielong",
25
+ "email": "1596761421@qq.com"
26
+ },
27
+ "license": "MIT",
28
+ "repository": {
29
+ "type": "git",
30
+ "url": "https://github.com/Violet1314/deep-code-xl"
31
+ },
32
+ "homepage": "https://github.com/Violet1314/deep-code-xl#readme",
33
+ "engines": {
34
+ "node": ">=14.0.0"
35
+ },
36
+ "os": ["win32"],
37
+ "preferGlobal": true
38
+ }