vg-coder-cli 2.0.15 → 2.0.16
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/package.json +14 -13
- package/src/server/api-server.js +45 -4
- package/vg-coder-cli-2.0.16.tgz +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vg-coder-cli",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.16",
|
|
4
4
|
"description": "🚀 CLI tool to analyze projects, concatenate source files, count tokens, and export HTML with syntax highlighting and copy functionality",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -31,26 +31,27 @@
|
|
|
31
31
|
"url": "https://github.com/tinhthanh/vg-coder-cli.git"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"body-parser": "^1.20.2",
|
|
35
|
+
"chalk": "^4.1.2",
|
|
34
36
|
"commander": "^11.1.0",
|
|
37
|
+
"cors": "^2.8.5",
|
|
35
38
|
"directory-tree": "^3.5.1",
|
|
36
|
-
"
|
|
39
|
+
"express": "^4.18.2",
|
|
40
|
+
"fs-extra": "^11.2.0",
|
|
37
41
|
"highlight.js": "^11.9.0",
|
|
38
42
|
"ignore": "^5.3.0",
|
|
39
|
-
"fs-extra": "^11.2.0",
|
|
40
|
-
"path": "^0.12.7",
|
|
41
|
-
"chalk": "^4.1.2",
|
|
42
|
-
"ora": "^5.4.1",
|
|
43
|
-
"express": "^4.18.2",
|
|
44
|
-
"cors": "^2.8.5",
|
|
45
|
-
"body-parser": "^1.20.2",
|
|
46
43
|
"node-pty": "^1.0.0",
|
|
47
|
-
"
|
|
44
|
+
"ora": "^5.4.1",
|
|
45
|
+
"path": "^0.12.7",
|
|
46
|
+
"socket.io": "^4.7.2",
|
|
47
|
+
"tiktoken": "^1.0.10",
|
|
48
|
+
"vg-coder-cli": "^2.0.15"
|
|
48
49
|
},
|
|
49
50
|
"devDependencies": {
|
|
50
|
-
"jest": "^29.7.0",
|
|
51
|
-
"nodemon": "^3.0.2",
|
|
52
51
|
"@types/jest": "^29.5.8",
|
|
53
|
-
"adm-zip": "^0.5.10"
|
|
52
|
+
"adm-zip": "^0.5.10",
|
|
53
|
+
"jest": "^29.7.0",
|
|
54
|
+
"nodemon": "^3.0.2"
|
|
54
55
|
},
|
|
55
56
|
"engines": {
|
|
56
57
|
"node": ">=16.0.0"
|
package/src/server/api-server.js
CHANGED
|
@@ -52,10 +52,8 @@ class ApiServer {
|
|
|
52
52
|
setupSocketIO() {
|
|
53
53
|
this.io.on('connection', (socket) => {
|
|
54
54
|
// Nhận event init với termId
|
|
55
|
-
// FIX: Thêm default value = {} để tránh crash khi data undefined
|
|
56
55
|
socket.on('terminal:init', (data) => {
|
|
57
56
|
if (!data || !data.termId) {
|
|
58
|
-
// console.warn('[Socket] Ignored invalid terminal:init', data);
|
|
59
57
|
return;
|
|
60
58
|
}
|
|
61
59
|
const { termId, cols, rows } = data;
|
|
@@ -101,11 +99,54 @@ class ApiServer {
|
|
|
101
99
|
|
|
102
100
|
this.app.get('/api/git/diff', async (req, res) => {
|
|
103
101
|
try {
|
|
104
|
-
|
|
102
|
+
// 1. Lấy diff của các file đã track (modified, deleted, staged)
|
|
103
|
+
const { stdout: diffStdout } = await execAsync('git diff HEAD', {
|
|
105
104
|
cwd: this.workingDir,
|
|
106
105
|
maxBuffer: 20 * 1024 * 1024
|
|
107
106
|
});
|
|
108
|
-
|
|
107
|
+
|
|
108
|
+
// 2. Lấy danh sách untracked files (files mới tạo chưa add)
|
|
109
|
+
const { stdout: untrackedStdout } = await execAsync('git ls-files --others --exclude-standard', {
|
|
110
|
+
cwd: this.workingDir,
|
|
111
|
+
maxBuffer: 20 * 1024 * 1024
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
let combinedDiff = diffStdout || '';
|
|
115
|
+
const untrackedFiles = untrackedStdout.split('\n').filter(f => f.trim());
|
|
116
|
+
|
|
117
|
+
// 3. Tạo diff giả lập cho untracked files để hiển thị trên UI
|
|
118
|
+
if (untrackedFiles.length > 0) {
|
|
119
|
+
if (combinedDiff && !combinedDiff.endsWith('\n')) combinedDiff += '\n';
|
|
120
|
+
|
|
121
|
+
for (const file of untrackedFiles) {
|
|
122
|
+
try {
|
|
123
|
+
const filePath = path.join(this.workingDir, file);
|
|
124
|
+
const stat = await fs.stat(filePath);
|
|
125
|
+
if (stat.isDirectory()) continue;
|
|
126
|
+
|
|
127
|
+
const content = await fs.readFile(filePath, 'utf8');
|
|
128
|
+
|
|
129
|
+
// Tạo header giống git diff
|
|
130
|
+
combinedDiff += `diff --git a/${file} b/${file}\n`;
|
|
131
|
+
combinedDiff += `new file mode 100644\n`;
|
|
132
|
+
combinedDiff += `--- /dev/null\n`;
|
|
133
|
+
combinedDiff += `+++ b/${file}\n`;
|
|
134
|
+
|
|
135
|
+
if (content.length > 0) {
|
|
136
|
+
const lines = content.split('\n');
|
|
137
|
+
combinedDiff += `@@ -0,0 +1,${lines.length} @@\n`;
|
|
138
|
+
lines.forEach(line => {
|
|
139
|
+
combinedDiff += `+${line}\n`;
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
combinedDiff += `\n`;
|
|
143
|
+
} catch (err) {
|
|
144
|
+
// Bỏ qua nếu lỗi đọc file (vd: binary)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
res.json({ diff: combinedDiff });
|
|
109
150
|
} catch (error) {
|
|
110
151
|
console.error(chalk.red('❌ [GIT] Error:'), error.message);
|
|
111
152
|
res.json({ diff: '', error: error.message });
|
|
Binary file
|