nuxt-gin-tools 0.2.19 → 0.2.21

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 (2) hide show
  1. package/README.md +342 -95
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,101 +1,118 @@
1
- # nuxt-gin-tools
1
+ # nuxt-gin-tools 🧰
2
2
 
3
- `nuxt-gin-tools` 是 `nuxt-gin-starter` 的配套开发工具包,提供 Nuxt + Gin 项目的统一命令入口。
3
+ [![npm version](https://img.shields.io/npm/v/nuxt-gin-tools?style=flat-square)](https://www.npmjs.com/package/nuxt-gin-tools)
4
+ [![npm downloads](https://img.shields.io/npm/dm/nuxt-gin-tools?style=flat-square)](https://www.npmjs.com/package/nuxt-gin-tools)
5
+ [![Node](https://img.shields.io/badge/Node-18%2B-339933?logo=node.js&logoColor=white&style=flat-square)](https://nodejs.org)
6
+ [![Nuxt](https://img.shields.io/badge/Nuxt-4.x-00DC82?logo=nuxt&logoColor=white&style=flat-square)](https://nuxt.com)
7
+ [![Go](https://img.shields.io/badge/Go-supported-00ADD8?logo=go&logoColor=white&style=flat-square)](https://go.dev)
8
+ [![License](https://img.shields.io/badge/license-MIT-0b5fff?style=flat-square)](./LICENSE)
4
9
 
5
- 核心目标:
6
- - 一条命令启动前后端开发环境
7
- - 自动处理 Go 侧依赖和文件监听重启
8
- - 提供 OpenAPI 代码生成与构建打包辅助
10
+ `nuxt-gin-tools` is the companion CLI for [`nuxt-gin-starter`](https://github.com/RapboyGao/nuxt-gin-starter.git), built to make **Nuxt + Gin** development feel like one coherent workflow instead of two separate toolchains.
9
11
 
10
- ## 功能概览
12
+ Quick Jump:
11
13
 
12
- - `nuxt-gin dev`
13
- - 启动 Nuxt 开发服务
14
- - 启动 Go 文件监听(基于 `chokidar`)
15
- - Go 文件变化后自动重启 `go run main.go`
16
- - `nuxt-gin install`
17
- - 执行 Nuxt prepare
18
- - 如果检测到 Go,则执行 `go mod download && go mod tidy`
19
- - `nuxt-gin gen`
20
- - 基于 `openapi.yaml` 生成 Go / TS API 代码
21
- - `nuxt-gin build`
22
- - 执行项目构建与打包流程
23
- - `nuxt-gin cleanup`
24
- - 清理开发产物
25
- - `nuxt-gin update`
26
- - 执行依赖更新流程
14
+ - [English](#english)
15
+ - [中文](#中文)
27
16
 
28
- ## 安装
17
+ ## English
29
18
 
30
- `nuxt-gin-starter` 项目中作为依赖安装:
19
+ ### Highlights
20
+
21
+ - 🚀 One command to run Nuxt dev + Go watcher together
22
+ - 🔁 Automatic Go restart on file changes with `chokidar`
23
+ - 📦 Build-and-pack workflow for deployment artifacts
24
+ - 🧩 `pack.config.ts` support with typed config helper
25
+ - 🛡️ Config validation with `warn` and `error` feedback
26
+ - 🔧 Useful CLI switches for partial workflows like `--skip-go`
27
+
28
+ ### 📦 Install
31
29
 
32
30
  ```bash
33
- pnpm add nuxt-gin-tools
31
+ pnpm add -D nuxt-gin-tools
34
32
  ```
35
33
 
36
- ## 快速开始
34
+ ### ⚡ Quick Start
37
35
 
38
36
  ```bash
39
- # 初始化依赖(可选)
37
+ # optional bootstrap
40
38
  nuxt-gin install
41
39
 
42
- # 启动开发
40
+ # start Nuxt + Go together
43
41
  nuxt-gin dev
44
42
  ```
45
43
 
46
- 常用变体:
44
+ Common variants:
47
45
 
48
46
  ```bash
49
- # 只跑前端
47
+ # frontend only
50
48
  nuxt-gin dev --skip-go
51
49
 
52
- # 只跑 Go 监听
50
+ # go watcher only
53
51
  nuxt-gin dev --skip-nuxt
54
52
 
55
- # 跳过预清理/预安装
53
+ # skip cleanup / bootstrap checks
56
54
  nuxt-gin dev --no-cleanup
57
55
  ```
58
56
 
59
- ## 命令说明
57
+ ### 🗂️ Commands
60
58
 
61
- ### `nuxt-gin dev`
59
+ #### `nuxt-gin dev`
62
60
 
63
- 开发模式下会并行运行:
64
- - Nuxt:`npx nuxt dev --port=<nuxtPort> --host`
65
- - Go:监听变更并运行 `go run main.go`
61
+ Runs the local development stack:
66
62
 
67
- Go 监听规则来自 `.go-watch.json`(见下文)。
63
+ - Nuxt: `npx nuxt dev --port=<nuxtPort> --host`
64
+ - Go: watches files and restarts `go run main.go`
68
65
 
69
- 可用参数:
66
+ Flags:
70
67
 
71
- - `--skip-go`:只启动 Nuxt
72
- - `--skip-nuxt`:只启动 Go
73
- - `--no-cleanup`:跳过 develop 前的 cleanup/install 检查
68
+ - `--skip-go`: start Nuxt only
69
+ - `--skip-nuxt`: start Go only
70
+ - `--no-cleanup`: skip pre-cleanup and bootstrap checks
74
71
 
75
- ### `nuxt-gin install`
72
+ #### `nuxt-gin install`
76
73
 
77
- - 总是执行:`npx nuxt prepare`
78
- - 检测到 Go 时额外执行:`go mod download && go mod tidy`
74
+ Bootstraps the project:
79
75
 
80
- ### `nuxt-gin gen`
76
+ - always runs `npx nuxt prepare`
77
+ - if Go is available, also runs `go mod download && go mod tidy`
81
78
 
82
- 依赖 `openapi-generator-cli`,默认会:
83
- - 生成 Go Gin server 相关代码
84
- - 生成 TypeScript axios 客户端代码
79
+ #### `nuxt-gin gen`
85
80
 
86
- ### `nuxt-gin build`
81
+ Generates API code from `openapi.yaml`:
87
82
 
88
- 执行工具链内置的构建与打包逻辑。
83
+ - Go Gin server code
84
+ - TypeScript axios client code
89
85
 
90
- 可用参数:
86
+ #### `nuxt-gin build`
91
87
 
92
- - `--skip-go`:跳过 Go 构建
93
- - `--skip-nuxt`:跳过 Nuxt 静态构建
94
- - `--binary-name <name>`:自定义 `.build/.server` 下的 Go 二进制名称
88
+ Runs the build-and-pack flow.
95
89
 
96
- ### `pack.config.ts` / `pack.config.json`
90
+ Flags:
97
91
 
98
- `nuxt-gin build` 会自动读取项目根目录中的打包配置,优先级如下:
92
+ - `--skip-go`: skip Go build
93
+ - `--skip-nuxt`: skip Nuxt static build
94
+ - `--binary-name <name>`: override the Go binary name under `.build/.server`
95
+
96
+ #### `nuxt-gin cleanup`
97
+
98
+ Removes generated temp files and build output.
99
+
100
+ #### `nuxt-gin update`
101
+
102
+ Updates project dependencies with a conservative default strategy:
103
+
104
+ - Node: `pnpm update`
105
+ - Go: `go get -u=patch ./... && go mod tidy`
106
+
107
+ Flags:
108
+
109
+ - `--latest`: switch to a more aggressive upgrade strategy
110
+ - `--skip-go`: skip Go dependency updates
111
+ - `--skip-node`: skip Node dependency updates
112
+
113
+ ### 🧩 `pack.config.ts` / `pack.config.json`
114
+
115
+ `nuxt-gin build` can auto-load pack config from the project root with this priority:
99
116
 
100
117
  1. `pack.config.ts`
101
118
  2. `pack.config.js`
@@ -103,9 +120,9 @@ Go 监听规则来自 `.go-watch.json`(见下文)。
103
120
  4. `pack.config.mjs`
104
121
  5. `pack.config.json`
105
122
 
106
- 如果同时存在多个配置文件,会输出 `warn`,并按上面的优先级选择第一个。
123
+ If multiple config files exist, the CLI prints a `warn` and uses the first one by priority.
107
124
 
108
- 推荐使用 `pack.config.ts`:
125
+ Recommended TypeScript form:
109
126
 
110
127
  ```ts
111
128
  import createPackConfig from 'nuxt-gin-tools/src/pack';
@@ -119,7 +136,7 @@ export default createPackConfig({
119
136
  });
120
137
  ```
121
138
 
122
- 兼容旧的 `pack.config.json`:
139
+ Legacy JSON is still supported:
123
140
 
124
141
  ```json
125
142
  {
@@ -128,52 +145,282 @@ export default createPackConfig({
128
145
  }
129
146
  ```
130
147
 
131
- 配置校验规则:
148
+ Validation behavior:
149
+
150
+ - ❌ obvious type problems produce an `error` and stop packing
151
+ - ⚠️ ambiguous but survivable cases produce a `warn`
152
+ - 📝 example: if both `zipPath` and `zipName` are present, `zipPath` wins and a warning is shown
153
+
154
+ ### 🧱 `pack.config.ts` Helper
155
+
156
+ Use the helper from [`src/pack.ts`](./src/pack.ts):
157
+
158
+ ```ts
159
+ import createPackConfig from 'nuxt-gin-tools/src/pack';
160
+
161
+ export default createPackConfig({
162
+ serverPath: '.build/production/server',
163
+ zipName: 'release.7z',
164
+ });
165
+ ```
166
+
167
+ It provides:
168
+
169
+ - `PackConfig` type
170
+ - `createPackConfig(config)` helper
171
+ - default export as `createPackConfig`
172
+
173
+ ### ⚙️ Runtime Config
174
+
175
+ #### `server.config.json`
176
+
177
+ `dev` reads this file for the main runtime wiring:
178
+
179
+ - `ginPort`: Gin server port
180
+ - `nuxtPort`: Nuxt dev port
181
+ - `baseUrl`: Nuxt base URL
182
+ - `killPortBeforeDevelop`: whether to free ports before dev, default `true`
183
+ - `cleanupBeforeDevelop`: whether to cleanup before dev, default `false`
184
+
185
+ #### Frontend Runtime Exposure
186
+
187
+ `createDefaultConfig` injects values into Nuxt `runtimeConfig.public`:
188
+
189
+ - `public.ginPort`: available in development, `null` in production
190
+ - `public.isDevelopment`: direct development flag
191
+
192
+ Example:
193
+
194
+ ```ts
195
+ const config = useRuntimeConfig();
196
+ const ginPort = config.public.ginPort;
197
+ const isDevelopment = config.public.isDevelopment;
198
+ ```
199
+
200
+ #### `.go-watch.json`
201
+
202
+ Go watcher rules come from `.go-watch.json`:
203
+
204
+ ```json
205
+ {
206
+ "tmpDir": ".build/.server",
207
+ "testDataDir": "testdata",
208
+ "includeExt": ["go", "tpl", "html"],
209
+ "includeDir": [],
210
+ "includeFile": [],
211
+ "excludeDir": [
212
+ "assets",
213
+ ".build/.server",
214
+ "vendor",
215
+ "testdata",
216
+ "node_modules",
217
+ "vue",
218
+ "api",
219
+ ".vscode",
220
+ ".git"
221
+ ],
222
+ "excludeFile": [],
223
+ "excludeRegex": ["_test.go"]
224
+ }
225
+ ```
226
+
227
+ You can also point to a custom watcher config:
228
+
229
+ ```bash
230
+ NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
231
+ ```
232
+
233
+ ### 🖥️ Environment
234
+
235
+ - Node.js
236
+ - pnpm
237
+ - Go, if you need the Gin side to run
238
+ - `openapi-generator-cli`, only for `nuxt-gin gen`
239
+
240
+ ### 📝 Notes
241
+
242
+ - 💨 Go hot reload no longer depends on Air
243
+ - 👀 The current watcher model is `chokidar` + restart `go run main.go`
244
+ - 🪟 Packaging uses platform-aware executable naming: Windows defaults to `.exe`, Linux/macOS defaults to no extension
245
+
246
+ ---
247
+
248
+ ## 中文
249
+
250
+ ### ✨ 功能亮点
251
+
252
+ - 🚀 一条命令同时启动 Nuxt 与 Go 开发环境
253
+ - 🔁 基于 `chokidar` 的 Go 文件监听与自动重启
254
+ - 📦 内置构建与打包流程,适合产物发布
255
+ - 🧩 支持 `pack.config.ts`,并提供类型化 helper
256
+ - 🛡️ 对打包配置做校验,区分 `warn` 和 `error`
257
+ - 🔧 支持 `--skip-go` 等局部开发参数
258
+
259
+ ### 📦 安装
260
+
261
+ ```bash
262
+ pnpm add -D nuxt-gin-tools
263
+ ```
264
+
265
+ ### ⚡ 快速开始
266
+
267
+ ```bash
268
+ # 可选:初始化依赖
269
+ nuxt-gin install
270
+
271
+ # 同时启动前后端开发环境
272
+ nuxt-gin dev
273
+ ```
274
+
275
+ 常见变体:
276
+
277
+ ```bash
278
+ # 仅启动前端
279
+ nuxt-gin dev --skip-go
280
+
281
+ # 仅启动 Go 监听
282
+ nuxt-gin dev --skip-nuxt
283
+
284
+ # 跳过预清理 / 预安装检查
285
+ nuxt-gin dev --no-cleanup
286
+ ```
287
+
288
+ ### 🗂️ 命令说明
132
289
 
133
- - 明显的类型错误会直接 `error` 并终止打包
134
- - 可继续执行但可能有歧义的情况会输出 `warn`
135
- - 例如 `zipPath` 与 `zipName` 同时出现时,会提示 `zipPath` 优先生效
290
+ #### `nuxt-gin dev`
136
291
 
137
- ### `nuxt-gin cleanup`
292
+ 启动本地开发环境:
138
293
 
139
- 清理由工具链生成的临时目录和产物。
294
+ - Nuxt:`npx nuxt dev --port=<nuxtPort> --host`
295
+ - Go:监听文件变化并重启 `go run main.go`
296
+
297
+ 参数:
298
+
299
+ - `--skip-go`:只启动 Nuxt
300
+ - `--skip-nuxt`:只启动 Go
301
+ - `--no-cleanup`:跳过 develop 前的 cleanup / bootstrap 检查
302
+
303
+ #### `nuxt-gin install`
304
+
305
+ 用于初始化项目:
306
+
307
+ - 总是执行 `npx nuxt prepare`
308
+ - 检测到 Go 后,额外执行 `go mod download && go mod tidy`
309
+
310
+ #### `nuxt-gin gen`
311
+
312
+ 基于 `openapi.yaml` 生成 API 代码:
313
+
314
+ - Go Gin server 代码
315
+ - TypeScript axios 客户端代码
140
316
 
141
- ### `nuxt-gin update`
317
+ #### `nuxt-gin build`
142
318
 
143
- 执行项目约定的更新逻辑。
319
+ 执行构建与打包流程。
144
320
 
145
- 默认策略偏保守:
321
+ 参数:
322
+
323
+ - `--skip-go`:跳过 Go 构建
324
+ - `--skip-nuxt`:跳过 Nuxt 静态构建
325
+ - `--binary-name <name>`:覆盖 `.build/.server` 下的 Go 二进制名称
326
+
327
+ #### `nuxt-gin cleanup`
328
+
329
+ 清理临时文件与构建产物。
330
+
331
+ #### `nuxt-gin update`
332
+
333
+ 按偏保守的默认策略更新依赖:
146
334
 
147
335
  - Node:`pnpm update`
148
336
  - Go:`go get -u=patch ./... && go mod tidy`
149
337
 
150
- 可用参数:
338
+ 参数:
151
339
 
152
- - `--latest`:切换为更激进的升级策略
340
+ - `--latest`:切换成更激进的升级策略
153
341
  - `--skip-go`:跳过 Go 依赖更新
154
342
  - `--skip-node`:跳过 Node 依赖更新
155
343
 
156
- ## 配置
344
+ ### 🧩 `pack.config.ts` / `pack.config.json`
345
+
346
+ `nuxt-gin build` 会自动读取项目根目录中的打包配置,优先级如下:
347
+
348
+ 1. `pack.config.ts`
349
+ 2. `pack.config.js`
350
+ 3. `pack.config.cjs`
351
+ 4. `pack.config.mjs`
352
+ 5. `pack.config.json`
353
+
354
+ 如果同时存在多个配置文件,CLI 会输出 `warn`,并按优先级选择第一个。
355
+
356
+ 推荐使用 TypeScript 写法:
357
+
358
+ ```ts
359
+ import createPackConfig from 'nuxt-gin-tools/src/pack';
360
+
361
+ export default createPackConfig({
362
+ zipName: 'server.7z',
363
+ extraFilesGlobs: ['prisma/**'],
364
+ packageJson: {
365
+ private: true,
366
+ },
367
+ });
368
+ ```
369
+
370
+ 旧的 JSON 配置仍然兼容:
371
+
372
+ ```json
373
+ {
374
+ "zipName": "server.7z",
375
+ "extraFilesGlobs": ["prisma/**"]
376
+ }
377
+ ```
378
+
379
+ 校验规则:
380
+
381
+ - ❌ 明显类型错误会直接 `error` 并终止打包
382
+ - ⚠️ 可继续执行但存在歧义的情况会输出 `warn`
383
+ - 📝 例如同时设置 `zipPath` 和 `zipName` 时,会提示 `zipPath` 优先生效
384
+
385
+ ### 🧱 `pack.config.ts` Helper
386
+
387
+ 可通过 [`src/pack.ts`](./src/pack.ts) 使用 helper:
388
+
389
+ ```ts
390
+ import createPackConfig from 'nuxt-gin-tools/src/pack';
391
+
392
+ export default createPackConfig({
393
+ serverPath: '.build/production/server',
394
+ zipName: 'release.7z',
395
+ });
396
+ ```
397
+
398
+ 它提供:
399
+
400
+ - `PackConfig` 类型
401
+ - `createPackConfig(config)` 函数
402
+ - 默认导出即 `createPackConfig`
403
+
404
+ ### ⚙️ 运行时配置
157
405
 
158
- ### 1) `server.config.json`
406
+ #### `server.config.json`
159
407
 
160
- `dev` 命令会读取该文件,常用字段:
408
+ `dev` 命令会读取这个文件来确定运行方式:
161
409
 
162
- - `ginPort`: Gin 服务端口
163
- - `nuxtPort`: Nuxt 开发端口
164
- - `baseUrl`: Nuxt baseUrl
165
- - `killPortBeforeDevelop`: 开发前是否释放端口(默认 `true`)
166
- - `cleanupBeforeDevelop`: 开发前是否执行 cleanup(默认 `false`)
410
+ - `ginPort`:Gin 服务端口
411
+ - `nuxtPort`:Nuxt 开发端口
412
+ - `baseUrl`:Nuxt 的 base URL
413
+ - `killPortBeforeDevelop`:开发前是否释放端口,默认 `true`
414
+ - `cleanupBeforeDevelop`:开发前是否执行 cleanup,默认 `false`
167
415
 
168
- ### 3) 开发环境向前端暴露 `ginPort`
416
+ #### 前端运行时暴露
169
417
 
170
- `createDefaultConfig` 会在 Nuxt `runtimeConfig.public` 中注入 `ginPort`:
418
+ `createDefaultConfig` 会把以下值注入 Nuxt `runtimeConfig.public`:
171
419
 
172
- - 开发环境:`useRuntimeConfig().public.ginPort` `server.config.json` 的 `ginPort`
173
- - 生产环境:`useRuntimeConfig().public.ginPort` 为 `null`
174
- - 所有环境:`useRuntimeConfig().public.isDevelopment` 直接暴露当前是否开发环境
420
+ - `public.ginPort`:开发环境可读,生产环境为 `null`
421
+ - `public.isDevelopment`:当前是否为开发环境
175
422
 
176
- 前端示例:
423
+ 示例:
177
424
 
178
425
  ```ts
179
426
  const config = useRuntimeConfig();
@@ -181,9 +428,9 @@ const ginPort = config.public.ginPort;
181
428
  const isDevelopment = config.public.isDevelopment;
182
429
  ```
183
430
 
184
- ### 2) `.go-watch.json`
431
+ #### `.go-watch.json`
185
432
 
186
- Go 监听配置文件,示例:
433
+ Go 监听规则来自 `.go-watch.json`:
187
434
 
188
435
  ```json
189
436
  {
@@ -208,21 +455,21 @@ Go 监听配置文件,示例:
208
455
  }
209
456
  ```
210
457
 
211
- 也支持环境变量指定路径:
458
+ 也支持通过环境变量指定:
212
459
 
213
460
  ```bash
214
461
  NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
215
462
  ```
216
463
 
217
- ## 环境依赖
464
+ ### 🖥️ 环境依赖
218
465
 
219
466
  - Node.js
220
467
  - pnpm
221
- - Go(需要运行 Gin 侧开发与依赖下载时)
222
- - `openapi-generator-cli`(仅 `nuxt-gin gen` 需要)
468
+ - Go,若需要运行 Gin 侧开发流程
469
+ - `openapi-generator-cli`,仅 `nuxt-gin gen` 需要
223
470
 
224
- ## 说明
471
+ ### 📝 说明
225
472
 
226
- - Go 侧热更新已不再依赖 Air
227
- - 当前方案为:`chokidar` 监听文件变化 + 重启 `go run main.go`。
228
- - 打包时会按当前平台生成可执行文件名:Windows 默认 `.exe`,Linux/macOS 默认无扩展名。
473
+ - 💨 Go 热更新不再依赖 Air
474
+ - 👀 当前 Go 开发监听方案为 `chokidar` + 重启 `go run main.go`
475
+ - 🪟 打包时会按平台生成可执行文件名:Windows 默认 `.exe`,Linux/macOS 默认无扩展名
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-gin-tools",
3
- "version": "0.2.19",
3
+ "version": "0.2.21",
4
4
  "description": "This project is used as a dependency for [nuxt-gin-starter](https://github.com/RapboyGao/nuxt-gin-starter.git)",
5
5
  "bin": {
6
6
  "nuxt-gin": "index.js"