vg-coder-cli 1.0.10 → 1.0.12
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/README.md +273 -104
- package/package.json +5 -2
- package/src/index.js +57 -0
- package/src/server/api-server.js +320 -0
- package/src/server/views/dashboard.html +678 -0
- package/src/utils/bash-executor.js +130 -0
package/README.md
CHANGED
|
@@ -1,170 +1,260 @@
|
|
|
1
1
|
# VG Coder CLI
|
|
2
2
|
|
|
3
|
-
🚀 **CLI tool để phân tích dự án, nối file mã nguồn, đếm token
|
|
3
|
+
🚀 **Powerful CLI tool & API Server** để phân tích dự án, nối file mã nguồn, đếm token, xuất HTML và thực thi bash scripts qua REST API.
|
|
4
4
|
|
|
5
5
|
## ✨ Tính năng
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
|
|
7
|
+
### 📊 Code Analysis & Export
|
|
8
|
+
- 🔍 **Phát hiện loại dự án**: Tự động nhận diện Angular, Spring Boot, React, Vue, Node.js, Python, Java, .NET
|
|
9
|
+
- 📁 **Xử lý `.gitignore`**: Tuân thủ chuẩn Git với multi-level ignore rules
|
|
10
|
+
- 🛡️ **Hỗ trợ `.vgignore`**: Có độ ưu tiên cao hơn `.gitignore`, với cú pháp giống hệt
|
|
11
|
+
- 📜 **Bỏ qua file mặc định**: Tự động bỏ qua `node_modules`, `dist`, `.git`, `build`, `target`
|
|
12
|
+
- 📄 **Scan và nối file**: Quét toàn bộ dự án và nối các file mã nguồn
|
|
13
|
+
- 🧮 **Đếm token**: Sử dụng `tiktoken` để đếm token chính xác cho AI models
|
|
14
|
+
- ✂️ **Chia nhỏ nội dung**: Chia nội dung thông minh thành chunks nhỏ hơn
|
|
15
|
+
- 🌐 **Xuất HTML**: Tạo báo cáo HTML tương tác với syntax highlighting
|
|
16
|
+
- 📋 **Sao chép vào Clipboard**: Chế độ `-c` sao chép toàn bộ code vào clipboard
|
|
17
|
+
- 🤖 **Tối ưu cho AI**: Xuất file `combined.txt` với định dạng thân thiện cho AI
|
|
18
|
+
|
|
19
|
+
### 🚀 API Server (NEW!)
|
|
20
|
+
- 🌐 **REST API Server**: Khởi động server với `vg start`
|
|
21
|
+
- 🎨 **Beautiful Dashboard**: Tự động mở web UI để test API
|
|
22
|
+
- 📡 **5 API Endpoints**:
|
|
23
|
+
- `GET /health` - Health check
|
|
24
|
+
- `POST /api/analyze` - Phân tích dự án, download project.txt
|
|
25
|
+
- `GET /api/info` - Lấy thông tin dự án (JSON)
|
|
26
|
+
- `POST /api/execute` - **Thực thi bash scripts** với validation
|
|
27
|
+
- `DELETE /api/clean` - Xóa output directory
|
|
28
|
+
- ⚡ **Real-time Status**: Dashboard hiển thị server status live
|
|
29
|
+
- 🔒 **Syntax Validation**: Validate bash syntax trước khi execute
|
|
30
|
+
- 🧹 **Auto Cleanup**: Tự động dọn dẹp temp files
|
|
19
31
|
|
|
20
32
|
## 📦 Cài đặt
|
|
21
33
|
|
|
22
|
-
###
|
|
34
|
+
### Từ NPM (Recommended)
|
|
23
35
|
```bash
|
|
24
|
-
#
|
|
36
|
+
# Global install
|
|
25
37
|
npm install -g vg-coder-cli
|
|
26
38
|
|
|
27
|
-
#
|
|
39
|
+
# Local install
|
|
28
40
|
npm install vg-coder-cli
|
|
29
41
|
```
|
|
30
42
|
|
|
31
|
-
###
|
|
43
|
+
### Từ Source
|
|
32
44
|
```bash
|
|
33
|
-
|
|
34
|
-
git clone <repository-url>
|
|
45
|
+
git clone https://github.com/tinhthanh/vg-coder-cli.git
|
|
35
46
|
cd vg-coder-cli
|
|
36
|
-
|
|
37
|
-
# Cài đặt dependencies
|
|
38
47
|
npm install
|
|
39
|
-
|
|
40
|
-
# Cấp quyền thực thi (nếu cần)
|
|
41
|
-
chmod +x bin/vg-coder.js
|
|
42
48
|
```
|
|
43
49
|
|
|
44
50
|
## 🚀 Sử dụng
|
|
45
51
|
|
|
46
|
-
###
|
|
47
|
-
```bash
|
|
48
|
-
# Nếu cài global
|
|
49
|
-
vg-coder analyze
|
|
52
|
+
### CLI Commands
|
|
50
53
|
|
|
51
|
-
|
|
52
|
-
|
|
54
|
+
#### 1. Phân tích dự án
|
|
55
|
+
```bash
|
|
56
|
+
# Phân tích và xuất HTML
|
|
57
|
+
vg analyze
|
|
58
|
+
vg a # Alias rút gọn
|
|
53
59
|
|
|
54
|
-
#
|
|
55
|
-
vg
|
|
60
|
+
# Với options
|
|
61
|
+
vg analyze /path/to/project --max-tokens 8192 --output ./my-output
|
|
56
62
|
|
|
57
|
-
#
|
|
58
|
-
vg
|
|
63
|
+
# Copy vào clipboard (không tạo file)
|
|
64
|
+
vg analyze -c
|
|
65
|
+
vg analyze --clipboard
|
|
59
66
|
```
|
|
60
67
|
|
|
61
|
-
|
|
62
|
-
Chế độ này rất hữu ích để nhanh chóng đưa toàn bộ ngữ cảnh dự án vào các công cụ AI.
|
|
68
|
+
#### 2. Xem thông tin dự án
|
|
63
69
|
```bash
|
|
64
|
-
|
|
65
|
-
vg
|
|
70
|
+
vg info
|
|
71
|
+
vg info /path/to/project
|
|
72
|
+
```
|
|
66
73
|
|
|
67
|
-
|
|
68
|
-
|
|
74
|
+
#### 3. Xóa output
|
|
75
|
+
```bash
|
|
76
|
+
vg clean
|
|
77
|
+
vg clean --output ./my-output
|
|
69
78
|
```
|
|
70
79
|
|
|
71
|
-
|
|
80
|
+
#### 4. **Khởi động API Server** 🆕
|
|
72
81
|
```bash
|
|
73
|
-
#
|
|
74
|
-
vg
|
|
82
|
+
# Start server (mặc định port 6868)
|
|
83
|
+
vg start
|
|
84
|
+
vg s # Alias rút gọn
|
|
85
|
+
|
|
86
|
+
# Custom port
|
|
87
|
+
vg start -p 8080
|
|
75
88
|
|
|
76
|
-
#
|
|
77
|
-
vg-coder info /path/to/project
|
|
89
|
+
# Browser tự động mở dashboard tại http://localhost:6868
|
|
78
90
|
```
|
|
79
91
|
|
|
80
|
-
###
|
|
92
|
+
### API Endpoints
|
|
93
|
+
|
|
94
|
+
#### Health Check
|
|
81
95
|
```bash
|
|
82
|
-
|
|
83
|
-
|
|
96
|
+
GET http://localhost:6868/health
|
|
97
|
+
```
|
|
84
98
|
|
|
85
|
-
|
|
86
|
-
|
|
99
|
+
**Response:**
|
|
100
|
+
```json
|
|
101
|
+
{
|
|
102
|
+
"status": "ok",
|
|
103
|
+
"version": "1.0.10",
|
|
104
|
+
"timestamp": "2025-11-24T15:00:00.000Z"
|
|
105
|
+
}
|
|
87
106
|
```
|
|
88
107
|
|
|
89
|
-
|
|
108
|
+
#### Analyze Project
|
|
109
|
+
```bash
|
|
110
|
+
POST http://localhost:6868/api/analyze
|
|
111
|
+
Content-Type: application/json
|
|
112
|
+
|
|
113
|
+
{
|
|
114
|
+
"path": ".",
|
|
115
|
+
"options": {
|
|
116
|
+
"maxTokens": 8000
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
```
|
|
90
120
|
|
|
91
|
-
|
|
121
|
+
**Response:** Downloads `project.txt` file
|
|
92
122
|
|
|
93
|
-
|
|
94
|
-
Để xem danh sách các lệnh chính:
|
|
123
|
+
#### Get Project Info
|
|
95
124
|
```bash
|
|
96
|
-
|
|
125
|
+
GET http://localhost:6868/api/info?path=.
|
|
97
126
|
```
|
|
98
127
|
|
|
99
|
-
**
|
|
128
|
+
**Response:**
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"path": "/path/to/project",
|
|
132
|
+
"primaryType": "nodejs",
|
|
133
|
+
"stats": {
|
|
134
|
+
"totalFiles": 42,
|
|
135
|
+
"totalSize": 123456,
|
|
136
|
+
"totalLines": 5000
|
|
137
|
+
},
|
|
138
|
+
"tokens": {
|
|
139
|
+
"total": 15000,
|
|
140
|
+
"averagePerFile": 357
|
|
141
|
+
}
|
|
142
|
+
}
|
|
100
143
|
```
|
|
101
|
-
Usage: vg-coder [command] [options]
|
|
102
144
|
|
|
103
|
-
|
|
145
|
+
#### Execute Bash Script 🆕
|
|
146
|
+
```bash
|
|
147
|
+
POST http://localhost:6868/api/execute
|
|
148
|
+
Content-Type: application/json
|
|
104
149
|
|
|
105
|
-
|
|
106
|
-
-
|
|
107
|
-
|
|
150
|
+
{
|
|
151
|
+
"bash": "mkdir -p $(dirname \"src/test.js\")\ncat <<'EOF' > src/test.js\nconsole.log('Hello');\nEOF"
|
|
152
|
+
}
|
|
153
|
+
```
|
|
108
154
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
155
|
+
**Response:**
|
|
156
|
+
```json
|
|
157
|
+
{
|
|
158
|
+
"success": true,
|
|
159
|
+
"stdout": "",
|
|
160
|
+
"stderr": "",
|
|
161
|
+
"exitCode": 0,
|
|
162
|
+
"executionTime": 15
|
|
163
|
+
}
|
|
114
164
|
```
|
|
115
165
|
|
|
116
|
-
|
|
117
|
-
|
|
166
|
+
**Features:**
|
|
167
|
+
- ✅ Syntax validation trong `.vg/temp-execute`
|
|
168
|
+
- ✅ Execute tại working directory
|
|
169
|
+
- ✅ Auto cleanup temp files
|
|
170
|
+
- ✅ Return stdout/stderr/exitCode
|
|
171
|
+
|
|
172
|
+
#### Clean Output
|
|
118
173
|
```bash
|
|
119
|
-
|
|
174
|
+
DELETE http://localhost:6868/api/clean
|
|
175
|
+
Content-Type: application/json
|
|
176
|
+
|
|
177
|
+
{
|
|
178
|
+
"output": "./vg-output"
|
|
179
|
+
}
|
|
120
180
|
```
|
|
121
181
|
|
|
122
182
|
## ⚙️ Options
|
|
123
183
|
|
|
184
|
+
### CLI Options
|
|
185
|
+
|
|
124
186
|
| Option | Mô tả | Default |
|
|
125
187
|
|--------|-------|---------|
|
|
126
|
-
|
|
|
127
|
-
|
|
|
128
|
-
|
|
|
129
|
-
| `--extensions <list>` |
|
|
130
|
-
| `--include-hidden` | Bao gồm file ẩn
|
|
131
|
-
| `--no-structure` | Không
|
|
188
|
+
| `-o, --output <path>` | Thư mục output | ./vg-output |
|
|
189
|
+
| `-m, --max-tokens <number>` | Số token tối đa mỗi chunk | 8000 |
|
|
190
|
+
| `-t, --model <model>` | Model AI để đếm token | gpt-4 |
|
|
191
|
+
| `--extensions <list>` | Extensions (comma-separated) | Auto-detect |
|
|
192
|
+
| `--include-hidden` | Bao gồm file ẩn | false |
|
|
193
|
+
| `--no-structure` | Không giữ cấu trúc file | false |
|
|
132
194
|
| `--theme <theme>` | Theme cho syntax highlighting | github |
|
|
133
|
-
|
|
|
134
|
-
| `--
|
|
195
|
+
| `-c, --clipboard` | Copy vào clipboard | false |
|
|
196
|
+
| `--save-txt` | Lưu vào vg-projects.txt | false |
|
|
135
197
|
|
|
198
|
+
### Server Options
|
|
136
199
|
|
|
137
|
-
|
|
200
|
+
| Option | Mô tả | Default |
|
|
201
|
+
|--------|-------|---------|
|
|
202
|
+
| `-p, --port <port>` | Port cho server | 6868 |
|
|
138
203
|
|
|
139
|
-
|
|
140
|
-
Công cụ tạo ra file `combined.txt` được định dạng đặc biệt để dễ dàng đưa vào các mô hình ngôn ngữ lớn. Mỗi file được phân tách rõ ràng bằng một header duy nhất, giúp AI nhận biết và xử lý chính xác từng file.
|
|
204
|
+
## 🎨 Dashboard UI
|
|
141
205
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
206
|
+
Khi chạy `vg start`, browser tự động mở dashboard với:
|
|
207
|
+
|
|
208
|
+
- 🎯 **Interactive Forms** cho tất cả endpoints
|
|
209
|
+
- 🎨 **Beautiful Gradient UI** (purple to violet)
|
|
210
|
+
- 📊 **Real-time Server Status** (green/red indicator)
|
|
211
|
+
- 💻 **Syntax Highlighting** cho responses
|
|
212
|
+
- ⚡ **Loading States** cho async operations
|
|
213
|
+
- 📥 **Auto Download** cho analyze endpoint
|
|
214
|
+
|
|
215
|
+
## 🤖 Tích hợp AI
|
|
146
216
|
|
|
147
|
-
|
|
148
|
-
|
|
217
|
+
### System Prompt cho AI
|
|
218
|
+
|
|
219
|
+
Xem file [SYSTEM_PROMPT.md](SYSTEM_PROMPT.md) để biết cách tích hợp với AI.
|
|
220
|
+
|
|
221
|
+
**Command Prefixes:**
|
|
222
|
+
- `/ask` - Q&A mode (Markdown response)
|
|
223
|
+
- `/plan` - Planning mode (Checklist + bash)
|
|
224
|
+
- `/fix` - Bug fix mode (Analysis + solution)
|
|
225
|
+
- `/code` - Code generation (Bash script only)
|
|
226
|
+
|
|
227
|
+
### Bash Script Format
|
|
228
|
+
|
|
229
|
+
Khi AI generate code với `/code`, format chuẩn:
|
|
230
|
+
|
|
231
|
+
```bash
|
|
232
|
+
mkdir -p $(dirname "path/to/file.ext")
|
|
233
|
+
cat <<'EOF' > path/to/file.ext
|
|
234
|
+
... file content ...
|
|
235
|
+
EOF
|
|
149
236
|
```
|
|
150
237
|
|
|
151
|
-
|
|
152
|
-
|
|
238
|
+
**Quy tắc:**
|
|
239
|
+
- ✅ Luôn có `mkdir -p $(dirname "...")` trước mỗi file
|
|
240
|
+
- ✅ Sử dụng `<<'EOF'` (có quotes) để tránh expansion
|
|
241
|
+
- ✅ Chỉ include files có thay đổi
|
|
242
|
+
- ✅ Ghi đè hoàn toàn file content
|
|
153
243
|
|
|
154
244
|
## 📁 Cấu trúc Output
|
|
155
245
|
|
|
156
246
|
```
|
|
157
247
|
vg-output/
|
|
158
|
-
├── index.html # Trang chính với navigation
|
|
159
|
-
├── combined.html # Tất cả code
|
|
160
|
-
├── combined.txt #
|
|
161
|
-
├── chunks/ #
|
|
248
|
+
├── index.html # Trang chính với navigation
|
|
249
|
+
├── combined.html # Tất cả code, có search
|
|
250
|
+
├── combined.txt # Text format, tối ưu cho AI
|
|
251
|
+
├── chunks/ # Chunks riêng biệt
|
|
162
252
|
│ ├── chunk-1.html
|
|
163
253
|
│ └── ...
|
|
164
|
-
└── assets/ # CSS, JS
|
|
254
|
+
└── assets/ # CSS, JS
|
|
165
255
|
```
|
|
166
256
|
|
|
167
|
-
## 🎯
|
|
257
|
+
## 🎯 Dự án được hỗ trợ
|
|
168
258
|
|
|
169
259
|
- **Frontend**: Angular, React, Vue.js, Svelte
|
|
170
260
|
- **Backend**: Node.js, Spring Boot, Python, .NET
|
|
@@ -172,21 +262,100 @@ vg-output/
|
|
|
172
262
|
- **Languages**: JavaScript, TypeScript, Java, Python, C#, Go, Rust
|
|
173
263
|
- **Config**: JSON, YAML, XML, TOML
|
|
174
264
|
|
|
175
|
-
## 🛡️ Quy tắc bỏ qua file
|
|
265
|
+
## 🛡️ Quy tắc bỏ qua file
|
|
266
|
+
|
|
267
|
+
Thứ tự ưu tiên:
|
|
268
|
+
1. **`.vgignore`** - Cao nhất
|
|
269
|
+
2. **`.gitignore`** - Trung bình
|
|
270
|
+
3. **Default rules** - Thấp nhất (node_modules, .git, dist, build, target)
|
|
176
271
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
272
|
+
## 📝 Examples
|
|
273
|
+
|
|
274
|
+
### Example 1: Analyze và Copy
|
|
275
|
+
```bash
|
|
276
|
+
# Analyze project và copy vào clipboard
|
|
277
|
+
vg a . -c
|
|
278
|
+
|
|
279
|
+
# Paste vào AI tool (Claude, ChatGPT, etc.)
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Example 2: API Server Workflow
|
|
283
|
+
```bash
|
|
284
|
+
# 1. Start server
|
|
285
|
+
vg start
|
|
286
|
+
|
|
287
|
+
# 2. Browser mở dashboard tự động
|
|
288
|
+
# 3. Test endpoints trực tiếp trên UI
|
|
289
|
+
# 4. Hoặc dùng Postman/curl
|
|
290
|
+
|
|
291
|
+
# 5. Execute bash script từ AI
|
|
292
|
+
curl -X POST http://localhost:6868/api/execute \
|
|
293
|
+
-H "Content-Type: application/json" \
|
|
294
|
+
-d '{"bash": "mkdir -p src && echo \"test\" > src/file.js"}'
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Example 3: AI Integration
|
|
298
|
+
```bash
|
|
299
|
+
# 1. Analyze project
|
|
300
|
+
vg a . -c
|
|
301
|
+
|
|
302
|
+
# 2. Paste vào AI với prompt:
|
|
303
|
+
# "/code Thêm authentication vào project này"
|
|
304
|
+
|
|
305
|
+
# 3. AI trả về bash script
|
|
306
|
+
# 4. Copy bash script
|
|
307
|
+
|
|
308
|
+
# 5. Execute qua API
|
|
309
|
+
curl -X POST http://localhost:6868/api/execute \
|
|
310
|
+
-H "Content-Type: application/json" \
|
|
311
|
+
-d '{"bash": "..."}'
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
## 🔧 Development
|
|
315
|
+
|
|
316
|
+
```bash
|
|
317
|
+
# Install dependencies
|
|
318
|
+
npm install
|
|
319
|
+
|
|
320
|
+
# Run tests
|
|
321
|
+
npm test
|
|
322
|
+
|
|
323
|
+
# Run in dev mode
|
|
324
|
+
npm run dev
|
|
325
|
+
|
|
326
|
+
# Build and publish
|
|
327
|
+
npm run push
|
|
328
|
+
```
|
|
181
329
|
|
|
182
330
|
## 🤝 Đóng góp
|
|
183
331
|
|
|
184
|
-
1.
|
|
185
|
-
2.
|
|
186
|
-
3.
|
|
187
|
-
4.
|
|
188
|
-
5.
|
|
332
|
+
1. Fork repository
|
|
333
|
+
2. Create feature branch (`git checkout -b feature/amazing-feature`)
|
|
334
|
+
3. Commit changes (`git commit -m 'Add amazing feature'`)
|
|
335
|
+
4. Push to branch (`git push origin feature/amazing-feature`)
|
|
336
|
+
5. Create Pull Request
|
|
189
337
|
|
|
190
338
|
## 📄 License
|
|
191
339
|
|
|
192
340
|
MIT License - xem file [LICENSE](LICENSE) để biết thêm chi tiết.
|
|
341
|
+
|
|
342
|
+
## 🔗 Links
|
|
343
|
+
|
|
344
|
+
- **GitHub**: https://github.com/tinhthanh/vg-coder-cli
|
|
345
|
+
- **NPM**: https://www.npmjs.com/package/vg-coder-cli
|
|
346
|
+
- **Issues**: https://github.com/tinhthanh/vg-coder-cli/issues
|
|
347
|
+
|
|
348
|
+
## 📊 Version History
|
|
349
|
+
|
|
350
|
+
### v1.0.10 (Latest)
|
|
351
|
+
- ✨ Added API Server with REST endpoints
|
|
352
|
+
- 🎨 Beautiful dashboard UI with auto-open browser
|
|
353
|
+
- ⚡ Bash script execution with validation
|
|
354
|
+
- 🔧 Shortened commands: `vg`, `a`, `-c`, `s`
|
|
355
|
+
- 📝 System prompt documentation
|
|
356
|
+
|
|
357
|
+
### v1.0.9
|
|
358
|
+
- 🚀 Initial release
|
|
359
|
+
- 📊 Code analysis and token counting
|
|
360
|
+
- 🌐 HTML export with syntax highlighting
|
|
361
|
+
- 📋 Clipboard integration
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vg-coder-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.12",
|
|
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": {
|
|
@@ -52,7 +52,10 @@
|
|
|
52
52
|
"fs-extra": "^11.2.0",
|
|
53
53
|
"path": "^0.12.7",
|
|
54
54
|
"chalk": "^4.1.2",
|
|
55
|
-
"ora": "^5.4.1"
|
|
55
|
+
"ora": "^5.4.1",
|
|
56
|
+
"express": "^4.18.2",
|
|
57
|
+
"cors": "^2.8.5",
|
|
58
|
+
"body-parser": "^1.20.2"
|
|
56
59
|
},
|
|
57
60
|
"devDependencies": {
|
|
58
61
|
"jest": "^29.7.0",
|
package/src/index.js
CHANGED
|
@@ -10,6 +10,7 @@ const FileScanner = require('./scanner/file-scanner');
|
|
|
10
10
|
const TokenManager = require('./tokenizer/token-manager');
|
|
11
11
|
const HtmlExporter = require('./exporter/html-exporter');
|
|
12
12
|
const ClipboardManager = require('./utils/clipboard');
|
|
13
|
+
const ApiServer = require('./server/api-server');
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Main CLI Application
|
|
@@ -58,6 +59,14 @@ class VGCoderCLI {
|
|
|
58
59
|
.description('Xóa thư mục output')
|
|
59
60
|
.option('-o, --output <path>', 'Thư mục output', './vg-output')
|
|
60
61
|
.action(this.handleClean.bind(this));
|
|
62
|
+
|
|
63
|
+
// Start server command
|
|
64
|
+
this.program
|
|
65
|
+
.command('start')
|
|
66
|
+
.alias('s')
|
|
67
|
+
.description('Khởi động API server')
|
|
68
|
+
.option('-p, --port <port>', 'Port cho server', '6868')
|
|
69
|
+
.action(this.handleStart.bind(this));
|
|
61
70
|
}
|
|
62
71
|
|
|
63
72
|
/**
|
|
@@ -358,6 +367,54 @@ class VGCoderCLI {
|
|
|
358
367
|
}
|
|
359
368
|
}
|
|
360
369
|
|
|
370
|
+
/**
|
|
371
|
+
* Handle start command
|
|
372
|
+
*/
|
|
373
|
+
async handleStart(options) {
|
|
374
|
+
try {
|
|
375
|
+
const port = parseInt(options.port);
|
|
376
|
+
const server = new ApiServer(port);
|
|
377
|
+
|
|
378
|
+
await server.start();
|
|
379
|
+
|
|
380
|
+
// Auto-open browser to dashboard
|
|
381
|
+
const dashboardUrl = `http://localhost:${port}`;
|
|
382
|
+
const { exec } = require('child_process');
|
|
383
|
+
const platform = process.platform;
|
|
384
|
+
|
|
385
|
+
let openCommand;
|
|
386
|
+
if (platform === 'darwin') {
|
|
387
|
+
openCommand = `open ${dashboardUrl}`;
|
|
388
|
+
} else if (platform === 'win32') {
|
|
389
|
+
openCommand = `start ${dashboardUrl}`;
|
|
390
|
+
} else {
|
|
391
|
+
openCommand = `xdg-open ${dashboardUrl}`;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
exec(openCommand, (error) => {
|
|
395
|
+
if (error) {
|
|
396
|
+
console.log(chalk.yellow(`\n💡 Open your browser manually: ${dashboardUrl}`));
|
|
397
|
+
} else {
|
|
398
|
+
console.log(chalk.green(`\n✓ Dashboard opened in browser`));
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
|
|
402
|
+
// Handle graceful shutdown
|
|
403
|
+
const shutdown = async () => {
|
|
404
|
+
console.log(chalk.yellow('\n\nShutting down server...'));
|
|
405
|
+
await server.stop();
|
|
406
|
+
process.exit(0);
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
process.on('SIGINT', shutdown);
|
|
410
|
+
process.on('SIGTERM', shutdown);
|
|
411
|
+
|
|
412
|
+
} catch (error) {
|
|
413
|
+
console.error(chalk.red('\n❌ Failed to start server:'), error.message);
|
|
414
|
+
process.exit(1);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
361
418
|
/**
|
|
362
419
|
* Run CLI
|
|
363
420
|
*/
|