nuxt-gin-tools 0.2.22 → 0.3.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.
- package/README.md +287 -79
- package/commands/cleanup.d.ts +7 -4
- package/commands/cleanup.js +32 -21
- package/commands/dev-go.js +8 -8
- package/commands/develop.js +19 -0
- package/commands/pack.js +47 -6
- package/commands/postinstall.d.ts +5 -1
- package/commands/postinstall.js +25 -8
- package/commands/update.d.ts +4 -2
- package/commands/update.js +16 -3
- package/index.js +40 -24
- package/package.json +2 -2
- package/src/assets/go-gin-server.json +5 -0
- package/src/assets/pack-config.schema.json +62 -0
- package/src/assets/server-config.schema.json +35 -0
- package/src/cli/commands/build.d.ts +1 -0
- package/src/cli/commands/build.js +22 -0
- package/src/cli/commands/cleanup.d.ts +11 -0
- package/src/cli/commands/cleanup.js +115 -0
- package/src/cli/commands/develop.d.ts +26 -0
- package/src/cli/commands/develop.js +168 -0
- package/src/cli/commands/install.d.ts +6 -0
- package/src/cli/commands/install.js +59 -0
- package/src/cli/commands/update.d.ts +9 -0
- package/src/cli/commands/update.js +55 -0
- package/src/cli/options.d.ts +10 -0
- package/src/cli/options.js +66 -0
- package/src/cli/terminal-ui.d.ts +7 -0
- package/src/cli/terminal-ui.js +118 -0
- package/src/cli-options.d.ts +1 -0
- package/src/cli-options.js +15 -0
- package/src/config/package-manager.d.ts +7 -0
- package/src/config/package-manager.js +39 -0
- package/src/nuxt-gin.d.ts +103 -0
- package/src/nuxt-gin.js +178 -0
- package/src/pack.d.ts +9 -1
- package/src/package-manager.d.ts +7 -0
- package/src/package-manager.js +39 -0
- package/src/services/build-service.d.ts +7 -0
- package/src/services/build-service.js +35 -0
- package/src/services/go-dev-service.d.ts +8 -0
- package/src/services/go-dev-service.js +356 -0
- package/src/services/pack-service.d.ts +23 -0
- package/src/services/pack-service.js +372 -0
- package/src/system/ports.d.ts +7 -0
- package/src/system/ports.js +112 -0
- package/src/terminal-ui.d.ts +3 -0
- package/src/terminal-ui.js +99 -14
- package/src/utils.js +3 -3
package/README.md
CHANGED
|
@@ -21,9 +21,11 @@ Quick Jump:
|
|
|
21
21
|
- 🚀 One command to run Nuxt dev + Go watcher together
|
|
22
22
|
- 🔁 Automatic Go restart on file changes with `chokidar`
|
|
23
23
|
- 📦 Build-and-pack workflow for deployment artifacts
|
|
24
|
-
- 🧩 `
|
|
24
|
+
- 🧩 `nuxt-gin.config.ts` support with typed config helper
|
|
25
25
|
- 🛡️ Config validation with `warn` and `error` feedback
|
|
26
26
|
- 🔧 Useful CLI switches for partial workflows like `--skip-go`
|
|
27
|
+
- 🎨 Colorful command banners and clearer terminal feedback
|
|
28
|
+
- 📋 Fancy end-of-command summaries that show what just changed
|
|
27
29
|
|
|
28
30
|
### 📦 Install
|
|
29
31
|
|
|
@@ -31,6 +33,12 @@ Quick Jump:
|
|
|
31
33
|
pnpm add -D nuxt-gin-tools
|
|
32
34
|
```
|
|
33
35
|
|
|
36
|
+
or
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
bun add -d nuxt-gin-tools
|
|
40
|
+
```
|
|
41
|
+
|
|
34
42
|
### ⚡ Quick Start
|
|
35
43
|
|
|
36
44
|
```bash
|
|
@@ -54,6 +62,45 @@ nuxt-gin dev --skip-nuxt
|
|
|
54
62
|
nuxt-gin dev --no-cleanup
|
|
55
63
|
```
|
|
56
64
|
|
|
65
|
+
### 🧱 Source Layout
|
|
66
|
+
|
|
67
|
+
```text
|
|
68
|
+
src/
|
|
69
|
+
├── assets/
|
|
70
|
+
│ ├── go-gin-server.json
|
|
71
|
+
│ ├── pack-config.schema.json
|
|
72
|
+
│ └── server-config.schema.json
|
|
73
|
+
├── cli/
|
|
74
|
+
│ ├── commands/
|
|
75
|
+
│ │ ├── build.ts
|
|
76
|
+
│ │ ├── cleanup.ts
|
|
77
|
+
│ │ ├── develop.ts
|
|
78
|
+
│ │ ├── install.ts
|
|
79
|
+
│ │ └── update.ts
|
|
80
|
+
│ ├── options.ts
|
|
81
|
+
│ └── terminal-ui.ts
|
|
82
|
+
├── config/
|
|
83
|
+
│ └── package-manager.ts
|
|
84
|
+
├── services/
|
|
85
|
+
│ ├── build-service.ts
|
|
86
|
+
│ ├── go-dev-service.ts
|
|
87
|
+
│ └── pack-service.ts
|
|
88
|
+
├── system/
|
|
89
|
+
│ └── ports.ts
|
|
90
|
+
├── nuxt-config.ts
|
|
91
|
+
├── nuxt-gin.ts
|
|
92
|
+
└── pack.ts
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Responsibility split:
|
|
96
|
+
|
|
97
|
+
- `src/cli`: command entrypoints, option parsing, terminal output
|
|
98
|
+
- `src/config`: CLI configuration helpers
|
|
99
|
+
- `src/services`: build, pack, and Go watcher implementation
|
|
100
|
+
- `src/system`: low-level system helpers such as port cleanup
|
|
101
|
+
- `src/assets`: JSON resources and schemas shipped in the package
|
|
102
|
+
- `src/nuxt-config.ts`, `src/nuxt-gin.ts`, `src/pack.ts`: public helper modules for consumers
|
|
103
|
+
|
|
57
104
|
### 🗂️ Commands
|
|
58
105
|
|
|
59
106
|
#### `nuxt-gin dev`
|
|
@@ -62,6 +109,7 @@ Runs the local development stack:
|
|
|
62
109
|
|
|
63
110
|
- Nuxt: `npx nuxt dev --port=<nuxtPort> --host`
|
|
64
111
|
- Go: watches files and restarts `go run main.go`
|
|
112
|
+
- prints a styled command banner before startup
|
|
65
113
|
|
|
66
114
|
Flags:
|
|
67
115
|
|
|
@@ -75,68 +123,99 @@ Bootstraps the project:
|
|
|
75
123
|
|
|
76
124
|
- always runs `npx nuxt prepare`
|
|
77
125
|
- if Go is available, also runs `go mod download && go mod tidy`
|
|
126
|
+
- prints a styled command banner before execution
|
|
127
|
+
|
|
128
|
+
Options:
|
|
129
|
+
|
|
130
|
+
- `--skip-go`: skip Go dependency bootstrap
|
|
131
|
+
- `--skip-nuxt`: skip Nuxt prepare
|
|
78
132
|
|
|
79
133
|
#### `nuxt-gin build`
|
|
80
134
|
|
|
81
135
|
Runs the build-and-pack flow.
|
|
82
136
|
|
|
137
|
+
Terminal output includes:
|
|
138
|
+
|
|
139
|
+
- a styled command banner at startup
|
|
140
|
+
- the final `.7z` archive path after packing
|
|
141
|
+
- the bundle directory path used to assemble the release
|
|
142
|
+
|
|
83
143
|
Flags:
|
|
84
144
|
|
|
85
145
|
- `--skip-go`: skip Go build
|
|
86
146
|
- `--skip-nuxt`: skip Nuxt static build
|
|
147
|
+
- `--skip-build`: skip the build step and only assemble/package existing artifacts
|
|
148
|
+
- `--skip-zip`: skip `.7z` creation and only prepare the bundle directory
|
|
87
149
|
- `--binary-name <name>`: override the Go binary name under `.build/.server`
|
|
88
150
|
|
|
89
151
|
#### `nuxt-gin cleanup`
|
|
90
152
|
|
|
91
153
|
Removes generated temp files and build output.
|
|
92
154
|
|
|
155
|
+
Also prints a styled command banner before cleanup starts.
|
|
156
|
+
|
|
157
|
+
Options:
|
|
158
|
+
|
|
159
|
+
- `--dry-run`: print what would be removed without deleting anything
|
|
160
|
+
|
|
93
161
|
#### `nuxt-gin update`
|
|
94
162
|
|
|
95
163
|
Updates project dependencies with a conservative default strategy:
|
|
96
164
|
|
|
97
|
-
- Node:
|
|
165
|
+
- Node: package manager is controlled by `--package-manager`, default `auto`
|
|
98
166
|
- Go: `go get -u=patch ./... && go mod tidy`
|
|
99
167
|
|
|
100
|
-
|
|
168
|
+
Options:
|
|
101
169
|
|
|
102
|
-
- `--
|
|
170
|
+
- `--package-manager <auto|bun|pnpm|npm>`: package manager selection, default `auto`
|
|
171
|
+
- `--latest <true|false>`: whether to use the aggressive update strategy, default `false`
|
|
103
172
|
- `--skip-go`: skip Go dependency updates
|
|
104
173
|
- `--skip-node`: skip Node dependency updates
|
|
105
174
|
|
|
106
|
-
|
|
175
|
+
Examples:
|
|
176
|
+
|
|
177
|
+
```bash
|
|
178
|
+
nuxt-gin update
|
|
179
|
+
nuxt-gin update --package-manager bun --latest true
|
|
180
|
+
nuxt-gin update --package-manager pnpm --latest false
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
Also prints a styled command banner before execution.
|
|
184
|
+
|
|
185
|
+
### 🧩 `nuxt-gin.config.ts`
|
|
107
186
|
|
|
108
|
-
`nuxt-gin
|
|
187
|
+
`nuxt-gin` commands can auto-load project config from the root with this priority:
|
|
109
188
|
|
|
110
|
-
1. `
|
|
111
|
-
2. `
|
|
112
|
-
3. `
|
|
113
|
-
4. `
|
|
114
|
-
5. `
|
|
189
|
+
1. `nuxt-gin.config.ts`
|
|
190
|
+
2. `nuxt-gin.config.js`
|
|
191
|
+
3. `nuxt-gin.config.cjs`
|
|
192
|
+
4. `nuxt-gin.config.mjs`
|
|
193
|
+
5. `nuxt-gin.config.json`
|
|
115
194
|
|
|
116
195
|
If multiple config files exist, the CLI prints a `warn` and uses the first one by priority.
|
|
117
196
|
|
|
118
197
|
Recommended TypeScript form:
|
|
119
198
|
|
|
120
199
|
```ts
|
|
121
|
-
import
|
|
200
|
+
import createNuxtGinConfig from 'nuxt-gin-tools/src/nuxt-gin';
|
|
122
201
|
|
|
123
|
-
export default
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
202
|
+
export default createNuxtGinConfig({
|
|
203
|
+
dev: {
|
|
204
|
+
killPortBeforeDevelop: true,
|
|
205
|
+
},
|
|
206
|
+
goWatch: {
|
|
207
|
+
include: {
|
|
208
|
+
ext: ['go', 'tpl', 'html'],
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
pack: {
|
|
212
|
+
zipName: 'server.7z',
|
|
213
|
+
extraFilesGlobs: ['prisma/**'],
|
|
128
214
|
},
|
|
129
215
|
});
|
|
130
216
|
```
|
|
131
217
|
|
|
132
|
-
Legacy
|
|
133
|
-
|
|
134
|
-
```json
|
|
135
|
-
{
|
|
136
|
-
"zipName": "server.7z",
|
|
137
|
-
"extraFilesGlobs": ["prisma/**"]
|
|
138
|
-
}
|
|
139
|
-
```
|
|
218
|
+
Legacy `pack.config.*` is still supported as a fallback for `build`, but `nuxt-gin.config.*` is now the primary entry.
|
|
140
219
|
|
|
141
220
|
Validation behavior:
|
|
142
221
|
|
|
@@ -144,36 +223,57 @@ Validation behavior:
|
|
|
144
223
|
- ⚠️ ambiguous but survivable cases produce a `warn`
|
|
145
224
|
- 📝 example: if both `zipPath` and `zipName` are present, `zipPath` wins and a warning is shown
|
|
146
225
|
|
|
147
|
-
### 🧱 `
|
|
226
|
+
### 🧱 `nuxt-gin.config.ts` Helper
|
|
148
227
|
|
|
149
|
-
Use the helper from [`src/
|
|
228
|
+
Use the helper from [`src/nuxt-gin.ts`](./src/nuxt-gin.ts):
|
|
150
229
|
|
|
151
230
|
```ts
|
|
152
|
-
import
|
|
231
|
+
import createNuxtGinConfig from 'nuxt-gin-tools/src/nuxt-gin';
|
|
153
232
|
|
|
154
|
-
export default
|
|
155
|
-
|
|
156
|
-
|
|
233
|
+
export default createNuxtGinConfig({
|
|
234
|
+
dev: {
|
|
235
|
+
killPortBeforeDevelop: true,
|
|
236
|
+
},
|
|
237
|
+
goWatch: {
|
|
238
|
+
exclude: {
|
|
239
|
+
dir: ['vendor', 'testdata'],
|
|
240
|
+
},
|
|
241
|
+
},
|
|
242
|
+
pack: {
|
|
243
|
+
serverPath: '.build/production/server',
|
|
244
|
+
zipName: 'release.7z',
|
|
245
|
+
},
|
|
157
246
|
});
|
|
158
247
|
```
|
|
159
248
|
|
|
160
249
|
It provides:
|
|
161
250
|
|
|
162
|
-
- `
|
|
163
|
-
- `
|
|
164
|
-
- default export as `
|
|
251
|
+
- `NuxtGinConfig` type
|
|
252
|
+
- `createNuxtGinConfig(config)` helper
|
|
253
|
+
- default export as `createNuxtGinConfig`
|
|
165
254
|
|
|
166
255
|
### ⚙️ Runtime Config
|
|
167
256
|
|
|
257
|
+
#### `nuxt-gin.config.ts`
|
|
258
|
+
|
|
259
|
+
`dev`, `install`, `cleanup`, `update`, and `build` can all read defaults from this file:
|
|
260
|
+
|
|
261
|
+
- `dev`: development command defaults
|
|
262
|
+
- `goWatch`: built-in Go watcher defaults
|
|
263
|
+
- `install`: bootstrap command defaults
|
|
264
|
+
- `cleanup`: cleanup command defaults
|
|
265
|
+
- `update`: dependency update defaults
|
|
266
|
+
- `pack`: build-and-pack defaults
|
|
267
|
+
|
|
168
268
|
#### `server.config.json`
|
|
169
269
|
|
|
170
|
-
`
|
|
270
|
+
`server.config.json` is still kept for Go runtime and packaged output:
|
|
171
271
|
|
|
172
272
|
- `ginPort`: Gin server port
|
|
173
273
|
- `nuxtPort`: Nuxt dev port
|
|
174
274
|
- `baseUrl`: Nuxt base URL
|
|
175
|
-
|
|
176
|
-
- `
|
|
275
|
+
|
|
276
|
+
`nuxt-gin build` requires this file to exist in the project root.
|
|
177
277
|
|
|
178
278
|
#### Frontend Runtime Exposure
|
|
179
279
|
|
|
@@ -192,7 +292,8 @@ const isDevelopment = config.public.isDevelopment;
|
|
|
192
292
|
|
|
193
293
|
#### `.go-watch.json`
|
|
194
294
|
|
|
195
|
-
Go watcher
|
|
295
|
+
Go watcher defaults are built into `src/services/go-dev-service.ts`.
|
|
296
|
+
You can set project-level defaults in `nuxt-gin.config.ts` with `goWatch`, and then optionally override them with `.go-watch.json`:
|
|
196
297
|
|
|
197
298
|
```json
|
|
198
299
|
{
|
|
@@ -217,7 +318,7 @@ Go watcher rules come from `.go-watch.json`:
|
|
|
217
318
|
}
|
|
218
319
|
```
|
|
219
320
|
|
|
220
|
-
You can also point to a custom watcher config:
|
|
321
|
+
You can also point to a custom watcher config file:
|
|
221
322
|
|
|
222
323
|
```bash
|
|
223
324
|
NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
|
|
@@ -226,7 +327,7 @@ NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
|
|
|
226
327
|
### 🖥️ Environment
|
|
227
328
|
|
|
228
329
|
- Node.js
|
|
229
|
-
- pnpm
|
|
330
|
+
- pnpm or bun
|
|
230
331
|
- Go, if you need the Gin side to run
|
|
231
332
|
- no extra generator dependency is required for the current command set
|
|
232
333
|
|
|
@@ -235,6 +336,9 @@ NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
|
|
|
235
336
|
- 💨 Go hot reload no longer depends on Air
|
|
236
337
|
- 👀 The current watcher model is `chokidar` + restart `go run main.go`
|
|
237
338
|
- 🪟 Packaging uses platform-aware executable naming: Windows defaults to `.exe`, Linux/macOS defaults to no extension
|
|
339
|
+
- 🌈 Main commands print a consistent banner and clearer success/info output in the terminal
|
|
340
|
+
- 📋 Commands also print a styled summary of the actions they performed; long-running dev commands print the startup summary before entering watch mode
|
|
341
|
+
- 📦 Both `pnpm` and `bun` are supported, but one working tree should stick to one package manager at a time
|
|
238
342
|
|
|
239
343
|
---
|
|
240
344
|
|
|
@@ -245,9 +349,11 @@ NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
|
|
|
245
349
|
- 🚀 一条命令同时启动 Nuxt 与 Go 开发环境
|
|
246
350
|
- 🔁 基于 `chokidar` 的 Go 文件监听与自动重启
|
|
247
351
|
- 📦 内置构建与打包流程,适合产物发布
|
|
248
|
-
- 🧩 支持 `
|
|
352
|
+
- 🧩 支持 `nuxt-gin.config.ts`,并提供类型化 helper
|
|
249
353
|
- 🛡️ 对打包配置做校验,区分 `warn` 和 `error`
|
|
250
354
|
- 🔧 支持 `--skip-go` 等局部开发参数
|
|
355
|
+
- 🎨 提供更醒目的彩色命令行 banner 与输出提示
|
|
356
|
+
- 📋 命令结束时会打印更清晰的结果摘要
|
|
251
357
|
|
|
252
358
|
### 📦 安装
|
|
253
359
|
|
|
@@ -255,6 +361,12 @@ NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
|
|
|
255
361
|
pnpm add -D nuxt-gin-tools
|
|
256
362
|
```
|
|
257
363
|
|
|
364
|
+
或
|
|
365
|
+
|
|
366
|
+
```bash
|
|
367
|
+
bun add -d nuxt-gin-tools
|
|
368
|
+
```
|
|
369
|
+
|
|
258
370
|
### ⚡ 快速开始
|
|
259
371
|
|
|
260
372
|
```bash
|
|
@@ -278,6 +390,45 @@ nuxt-gin dev --skip-nuxt
|
|
|
278
390
|
nuxt-gin dev --no-cleanup
|
|
279
391
|
```
|
|
280
392
|
|
|
393
|
+
### 🧱 源码结构
|
|
394
|
+
|
|
395
|
+
```text
|
|
396
|
+
src/
|
|
397
|
+
├── assets/
|
|
398
|
+
│ ├── go-gin-server.json
|
|
399
|
+
│ ├── pack-config.schema.json
|
|
400
|
+
│ └── server-config.schema.json
|
|
401
|
+
├── cli/
|
|
402
|
+
│ ├── commands/
|
|
403
|
+
│ │ ├── build.ts
|
|
404
|
+
│ │ ├── cleanup.ts
|
|
405
|
+
│ │ ├── develop.ts
|
|
406
|
+
│ │ ├── install.ts
|
|
407
|
+
│ │ └── update.ts
|
|
408
|
+
│ ├── options.ts
|
|
409
|
+
│ └── terminal-ui.ts
|
|
410
|
+
├── config/
|
|
411
|
+
│ └── package-manager.ts
|
|
412
|
+
├── services/
|
|
413
|
+
│ ├── build-service.ts
|
|
414
|
+
│ ├── go-dev-service.ts
|
|
415
|
+
│ └── pack-service.ts
|
|
416
|
+
├── system/
|
|
417
|
+
│ └── ports.ts
|
|
418
|
+
├── nuxt-config.ts
|
|
419
|
+
├── nuxt-gin.ts
|
|
420
|
+
└── pack.ts
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
职责划分:
|
|
424
|
+
|
|
425
|
+
- `src/cli`:命令入口、参数解析、终端输出
|
|
426
|
+
- `src/config`:CLI 配置解析
|
|
427
|
+
- `src/services`:构建、打包、Go watcher 执行逻辑
|
|
428
|
+
- `src/system`:端口清理等底层系统辅助能力
|
|
429
|
+
- `src/assets`:随 npm 包一起分发的 JSON 资源与 schema
|
|
430
|
+
- `src/nuxt-config.ts`、`src/nuxt-gin.ts`、`src/pack.ts`:给使用方直接 import 的 helper 模块
|
|
431
|
+
|
|
281
432
|
### 🗂️ 命令说明
|
|
282
433
|
|
|
283
434
|
#### `nuxt-gin dev`
|
|
@@ -286,6 +437,7 @@ nuxt-gin dev --no-cleanup
|
|
|
286
437
|
|
|
287
438
|
- Nuxt:`npx nuxt dev --port=<nuxtPort> --host`
|
|
288
439
|
- Go:监听文件变化并重启 `go run main.go`
|
|
440
|
+
- 启动前会输出一段样式化 banner
|
|
289
441
|
|
|
290
442
|
参数:
|
|
291
443
|
|
|
@@ -299,68 +451,99 @@ nuxt-gin dev --no-cleanup
|
|
|
299
451
|
|
|
300
452
|
- 总是执行 `npx nuxt prepare`
|
|
301
453
|
- 检测到 Go 后,额外执行 `go mod download && go mod tidy`
|
|
454
|
+
- 执行前会输出一段样式化 banner
|
|
455
|
+
|
|
456
|
+
参数:
|
|
457
|
+
|
|
458
|
+
- `--skip-go`:跳过 Go 依赖初始化
|
|
459
|
+
- `--skip-nuxt`:跳过 Nuxt prepare
|
|
302
460
|
|
|
303
461
|
#### `nuxt-gin build`
|
|
304
462
|
|
|
305
463
|
执行构建与打包流程。
|
|
306
464
|
|
|
465
|
+
命令行输出会额外包含:
|
|
466
|
+
|
|
467
|
+
- 启动时的样式化 banner
|
|
468
|
+
- 打包完成后的 `.7z` 文件绝对路径
|
|
469
|
+
- 组装发布产物时使用的 bundle 目录路径
|
|
470
|
+
|
|
307
471
|
参数:
|
|
308
472
|
|
|
309
473
|
- `--skip-go`:跳过 Go 构建
|
|
310
474
|
- `--skip-nuxt`:跳过 Nuxt 静态构建
|
|
475
|
+
- `--skip-build`:跳过构建阶段,仅组装或打包现有产物
|
|
476
|
+
- `--skip-zip`:跳过 `.7z` 生成,仅准备 bundle 目录
|
|
311
477
|
- `--binary-name <name>`:覆盖 `.build/.server` 下的 Go 二进制名称
|
|
312
478
|
|
|
313
479
|
#### `nuxt-gin cleanup`
|
|
314
480
|
|
|
315
481
|
清理临时文件与构建产物。
|
|
316
482
|
|
|
483
|
+
执行前也会输出一段样式化 banner。
|
|
484
|
+
|
|
485
|
+
参数:
|
|
486
|
+
|
|
487
|
+
- `--dry-run`:只打印将要删除的内容,不真正删除
|
|
488
|
+
|
|
317
489
|
#### `nuxt-gin update`
|
|
318
490
|
|
|
319
491
|
按偏保守的默认策略更新依赖:
|
|
320
492
|
|
|
321
|
-
- Node
|
|
493
|
+
- Node:通过 `--package-manager` 控制,默认值为 `auto`
|
|
322
494
|
- Go:`go get -u=patch ./... && go mod tidy`
|
|
323
495
|
|
|
324
496
|
参数:
|
|
325
497
|
|
|
326
|
-
- `--
|
|
498
|
+
- `--package-manager <auto|bun|pnpm|npm>`:指定包管理器,默认 `auto`
|
|
499
|
+
- `--latest <true|false>`:是否使用更激进的升级策略,默认 `false`
|
|
327
500
|
- `--skip-go`:跳过 Go 依赖更新
|
|
328
501
|
- `--skip-node`:跳过 Node 依赖更新
|
|
329
502
|
|
|
330
|
-
|
|
503
|
+
示例:
|
|
504
|
+
|
|
505
|
+
```bash
|
|
506
|
+
nuxt-gin update
|
|
507
|
+
nuxt-gin update --package-manager bun --latest true
|
|
508
|
+
nuxt-gin update --package-manager pnpm --latest false
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
执行前也会输出一段样式化 banner。
|
|
331
512
|
|
|
332
|
-
`nuxt-gin
|
|
513
|
+
### 🧩 `nuxt-gin.config.ts`
|
|
333
514
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
515
|
+
`nuxt-gin` 会自动读取项目根目录中的统一配置,优先级如下:
|
|
516
|
+
|
|
517
|
+
1. `nuxt-gin.config.ts`
|
|
518
|
+
2. `nuxt-gin.config.js`
|
|
519
|
+
3. `nuxt-gin.config.cjs`
|
|
520
|
+
4. `nuxt-gin.config.mjs`
|
|
521
|
+
5. `nuxt-gin.config.json`
|
|
339
522
|
|
|
340
523
|
如果同时存在多个配置文件,CLI 会输出 `warn`,并按优先级选择第一个。
|
|
341
524
|
|
|
342
525
|
推荐使用 TypeScript 写法:
|
|
343
526
|
|
|
344
527
|
```ts
|
|
345
|
-
import
|
|
528
|
+
import createNuxtGinConfig from 'nuxt-gin-tools/src/nuxt-gin';
|
|
346
529
|
|
|
347
|
-
export default
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
530
|
+
export default createNuxtGinConfig({
|
|
531
|
+
dev: {
|
|
532
|
+
killPortBeforeDevelop: true,
|
|
533
|
+
},
|
|
534
|
+
goWatch: {
|
|
535
|
+
include: {
|
|
536
|
+
ext: ['go', 'tpl', 'html'],
|
|
537
|
+
},
|
|
538
|
+
},
|
|
539
|
+
pack: {
|
|
540
|
+
zipName: 'server.7z',
|
|
541
|
+
extraFilesGlobs: ['prisma/**'],
|
|
352
542
|
},
|
|
353
543
|
});
|
|
354
544
|
```
|
|
355
545
|
|
|
356
|
-
旧的
|
|
357
|
-
|
|
358
|
-
```json
|
|
359
|
-
{
|
|
360
|
-
"zipName": "server.7z",
|
|
361
|
-
"extraFilesGlobs": ["prisma/**"]
|
|
362
|
-
}
|
|
363
|
-
```
|
|
546
|
+
旧的 `pack.config.*` 仍可作为 `build` 的兼容兜底,但 `nuxt-gin.config.*` 已经成为主入口。
|
|
364
547
|
|
|
365
548
|
校验规则:
|
|
366
549
|
|
|
@@ -368,36 +551,57 @@ export default createPackConfig({
|
|
|
368
551
|
- ⚠️ 可继续执行但存在歧义的情况会输出 `warn`
|
|
369
552
|
- 📝 例如同时设置 `zipPath` 和 `zipName` 时,会提示 `zipPath` 优先生效
|
|
370
553
|
|
|
371
|
-
### 🧱 `
|
|
554
|
+
### 🧱 `nuxt-gin.config.ts` Helper
|
|
372
555
|
|
|
373
|
-
可通过 [`src/
|
|
556
|
+
可通过 [`src/nuxt-gin.ts`](./src/nuxt-gin.ts) 使用 helper:
|
|
374
557
|
|
|
375
558
|
```ts
|
|
376
|
-
import
|
|
559
|
+
import createNuxtGinConfig from 'nuxt-gin-tools/src/nuxt-gin';
|
|
377
560
|
|
|
378
|
-
export default
|
|
379
|
-
|
|
380
|
-
|
|
561
|
+
export default createNuxtGinConfig({
|
|
562
|
+
dev: {
|
|
563
|
+
killPortBeforeDevelop: true,
|
|
564
|
+
},
|
|
565
|
+
goWatch: {
|
|
566
|
+
exclude: {
|
|
567
|
+
dir: ['vendor', 'testdata'],
|
|
568
|
+
},
|
|
569
|
+
},
|
|
570
|
+
pack: {
|
|
571
|
+
serverPath: '.build/production/server',
|
|
572
|
+
zipName: 'release.7z',
|
|
573
|
+
},
|
|
381
574
|
});
|
|
382
575
|
```
|
|
383
576
|
|
|
384
577
|
它提供:
|
|
385
578
|
|
|
386
|
-
- `
|
|
387
|
-
- `
|
|
388
|
-
- 默认导出即 `
|
|
579
|
+
- `NuxtGinConfig` 类型
|
|
580
|
+
- `createNuxtGinConfig(config)` 函数
|
|
581
|
+
- 默认导出即 `createNuxtGinConfig`
|
|
389
582
|
|
|
390
583
|
### ⚙️ 运行时配置
|
|
391
584
|
|
|
585
|
+
#### `nuxt-gin.config.ts`
|
|
586
|
+
|
|
587
|
+
`dev`、`install`、`cleanup`、`update`、`build` 都可以从这个文件读取默认值:
|
|
588
|
+
|
|
589
|
+
- `dev`:开发命令默认行为
|
|
590
|
+
- `goWatch`:Go watcher 的默认规则
|
|
591
|
+
- `install`:初始化命令默认行为
|
|
592
|
+
- `cleanup`:清理命令默认行为
|
|
593
|
+
- `update`:包管理器与更新策略默认值
|
|
594
|
+
- `pack`:打包默认值
|
|
595
|
+
|
|
392
596
|
#### `server.config.json`
|
|
393
597
|
|
|
394
|
-
`
|
|
598
|
+
`server.config.json` 仍然保留,用于 Go 运行时与打包产物:
|
|
395
599
|
|
|
396
600
|
- `ginPort`:Gin 服务端口
|
|
397
601
|
- `nuxtPort`:Nuxt 开发端口
|
|
398
602
|
- `baseUrl`:Nuxt 的 base URL
|
|
399
|
-
|
|
400
|
-
- `
|
|
603
|
+
|
|
604
|
+
`nuxt-gin build` 要求项目根目录中存在这个文件。
|
|
401
605
|
|
|
402
606
|
#### 前端运行时暴露
|
|
403
607
|
|
|
@@ -416,7 +620,8 @@ const isDevelopment = config.public.isDevelopment;
|
|
|
416
620
|
|
|
417
621
|
#### `.go-watch.json`
|
|
418
622
|
|
|
419
|
-
Go
|
|
623
|
+
Go watcher 的默认规则已经内置在 `src/services/go-dev-service.ts`。
|
|
624
|
+
你可以先在 `nuxt-gin.config.ts` 里通过 `goWatch` 设置项目级默认值,再用项目根目录的 `.go-watch.json` 做覆盖:
|
|
420
625
|
|
|
421
626
|
```json
|
|
422
627
|
{
|
|
@@ -441,7 +646,7 @@ Go 监听规则来自 `.go-watch.json`:
|
|
|
441
646
|
}
|
|
442
647
|
```
|
|
443
648
|
|
|
444
|
-
|
|
649
|
+
也支持通过环境变量指定自定义配置文件:
|
|
445
650
|
|
|
446
651
|
```bash
|
|
447
652
|
NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
|
|
@@ -450,7 +655,7 @@ NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
|
|
|
450
655
|
### 🖥️ 环境依赖
|
|
451
656
|
|
|
452
657
|
- Node.js
|
|
453
|
-
- pnpm
|
|
658
|
+
- pnpm 或 bun
|
|
454
659
|
- Go,若需要运行 Gin 侧开发流程
|
|
455
660
|
- 当前命令集不再依赖额外的代码生成器
|
|
456
661
|
|
|
@@ -459,3 +664,6 @@ NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
|
|
|
459
664
|
- 💨 Go 热更新不再依赖 Air
|
|
460
665
|
- 👀 当前 Go 开发监听方案为 `chokidar` + 重启 `go run main.go`
|
|
461
666
|
- 🪟 打包时会按平台生成可执行文件名:Windows 默认 `.exe`,Linux/macOS 默认无扩展名
|
|
667
|
+
- 🌈 主要命令会输出统一风格的 banner,并提供更清晰的成功 / 信息提示
|
|
668
|
+
- 📋 命令结束后会打印本次实际执行内容的摘要;`dev` 这类常驻命令会在进入监听前先打印启动摘要
|
|
669
|
+
- 📦 同一个工作副本建议固定使用一种包管理器,不要在同一套依赖目录里反复混用 `pnpm` 与 `bun`
|
package/commands/cleanup.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export type CleanupOptions = {
|
|
2
|
+
dryRun?: boolean;
|
|
3
|
+
};
|
|
4
|
+
export declare function ifExistsRemove(relativePath: string, options?: CleanupOptions, actions?: string[]): void;
|
|
5
|
+
export declare function cleanUpNuxt(options?: CleanupOptions, actions?: string[]): Promise<void> | Promise<import("concurrently").CloseEvent[]>;
|
|
6
|
+
export declare function cleanUpBuild(options?: CleanupOptions, actions?: string[]): void;
|
|
4
7
|
/**
|
|
5
8
|
* 清理构建目录和临时文件
|
|
6
9
|
*/
|
|
7
|
-
export declare function cleanUp(): Promise<void>;
|
|
10
|
+
export declare function cleanUp(options?: CleanupOptions): Promise<void>;
|
|
8
11
|
export default cleanUp;
|