nuxt-gin-tools 0.2.16 → 0.2.17

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/.go-watch.json CHANGED
@@ -1,20 +1,20 @@
1
- {
2
- "tmpDir": ".build/.server",
3
- "testDataDir": "testdata",
4
- "includeExt": ["go", "tpl", "html"],
5
- "includeDir": [],
6
- "includeFile": [],
7
- "excludeDir": [
8
- "assets",
9
- ".build/.server",
10
- "vendor",
11
- "testdata",
12
- "node_modules",
13
- "vue",
14
- "api",
15
- ".vscode",
16
- ".git"
17
- ],
18
- "excludeFile": [],
19
- "excludeRegex": ["_test.go"]
20
- }
1
+ {
2
+ "tmpDir": ".build/.server",
3
+ "testDataDir": "testdata",
4
+ "includeExt": ["go", "tpl", "html"],
5
+ "includeDir": [],
6
+ "includeFile": [],
7
+ "excludeDir": [
8
+ "assets",
9
+ ".build/.server",
10
+ "vendor",
11
+ "testdata",
12
+ "node_modules",
13
+ "vue",
14
+ "api",
15
+ ".vscode",
16
+ ".git"
17
+ ],
18
+ "excludeFile": [],
19
+ "excludeRegex": ["_test.go"]
20
+ }
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 AlbertGao
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 AlbertGao
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,150 +1,150 @@
1
- # nuxt-gin-tools
2
-
3
- `nuxt-gin-tools` 是 `nuxt-gin-starter` 的配套开发工具包,提供 Nuxt + Gin 项目的统一命令入口。
4
-
5
- 核心目标:
6
- - 一条命令启动前后端开发环境
7
- - 自动处理 Go 侧依赖和文件监听重启
8
- - 提供 OpenAPI 代码生成与构建打包辅助
9
-
10
- ## 功能概览
11
-
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
- - 执行依赖更新流程
27
-
28
- ## 安装
29
-
30
- 在 `nuxt-gin-starter` 项目中作为依赖安装:
31
-
32
- ```bash
33
- pnpm add nuxt-gin-tools
34
- ```
35
-
36
- ## 快速开始
37
-
38
- ```bash
39
- # 初始化依赖(可选)
40
- nuxt-gin install
41
-
42
- # 启动开发
43
- nuxt-gin dev
44
- ```
45
-
46
- ## 命令说明
47
-
48
- ### `nuxt-gin dev`
49
-
50
- 开发模式下会并行运行:
51
- - Nuxt:`npx nuxt dev --port=<nuxtPort> --host`
52
- - Go:监听变更并运行 `go run main.go`
53
-
54
- Go 监听规则来自 `.go-watch.json`(见下文)。
55
-
56
- ### `nuxt-gin install`
57
-
58
- - 总是执行:`npx nuxt prepare`
59
- - 检测到 Go 时额外执行:`go mod download && go mod tidy`
60
-
61
- ### `nuxt-gin gen`
62
-
63
- 依赖 `openapi-generator-cli`,默认会:
64
- - 生成 Go Gin server 相关代码
65
- - 生成 TypeScript axios 客户端代码
66
-
67
- ### `nuxt-gin build`
68
-
69
- 执行工具链内置的构建与打包逻辑。
70
-
71
- ### `nuxt-gin cleanup`
72
-
73
- 清理由工具链生成的临时目录和产物。
74
-
75
- ### `nuxt-gin update`
76
-
77
- 执行项目约定的更新逻辑。
78
-
79
- ## 配置
80
-
81
- ### 1) `server.config.json`
82
-
83
- `dev` 命令会读取该文件,常用字段:
84
-
85
- - `ginPort`: Gin 服务端口
86
- - `nuxtPort`: Nuxt 开发端口
87
- - `baseUrl`: Nuxt baseUrl
88
- - `killPortBeforeDevelop`: 开发前是否释放端口(默认 `true`)
89
- - `cleanupBeforeDevelop`: 开发前是否执行 cleanup(默认 `false`)
90
-
91
- ### 3) 开发环境向前端暴露 `ginPort`
92
-
93
- `createDefaultConfig` 会在 Nuxt `runtimeConfig.public` 中注入 `ginPort`:
94
-
95
- - 开发环境:`useRuntimeConfig().public.ginPort` 为 `server.config.json` 的 `ginPort`
96
- - 生产环境:`useRuntimeConfig().public.ginPort` 为 `null`
97
- - 所有环境:`useRuntimeConfig().public.isDevelopment` 直接暴露当前是否开发环境
98
-
99
- 前端示例:
100
-
101
- ```ts
102
- const config = useRuntimeConfig();
103
- const ginPort = config.public.ginPort;
104
- const isDevelopment = config.public.isDevelopment;
105
- ```
106
-
107
- ### 2) `.go-watch.json`
108
-
109
- Go 监听配置文件,示例:
110
-
111
- ```json
112
- {
113
- "tmpDir": ".build/.server",
114
- "testDataDir": "testdata",
115
- "includeExt": ["go", "tpl", "html"],
116
- "includeDir": [],
117
- "includeFile": [],
118
- "excludeDir": [
119
- "assets",
120
- ".build/.server",
121
- "vendor",
122
- "testdata",
123
- "node_modules",
124
- "vue",
125
- "api",
126
- ".vscode",
127
- ".git"
128
- ],
129
- "excludeFile": [],
130
- "excludeRegex": ["_test.go"]
131
- }
132
- ```
133
-
134
- 也支持环境变量指定路径:
135
-
136
- ```bash
137
- NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
138
- ```
139
-
140
- ## 环境依赖
141
-
142
- - Node.js
143
- - pnpm
144
- - Go(需要运行 Gin 侧开发与依赖下载时)
145
- - `openapi-generator-cli`(仅 `nuxt-gin gen` 需要)
146
-
147
- ## 说明
148
-
149
- - Go 侧热更新已不再依赖 Air。
150
- - 当前方案为:`chokidar` 监听文件变化 + 重启 `go run main.go`。
1
+ # nuxt-gin-tools
2
+
3
+ `nuxt-gin-tools` 是 `nuxt-gin-starter` 的配套开发工具包,提供 Nuxt + Gin 项目的统一命令入口。
4
+
5
+ 核心目标:
6
+ - 一条命令启动前后端开发环境
7
+ - 自动处理 Go 侧依赖和文件监听重启
8
+ - 提供 OpenAPI 代码生成与构建打包辅助
9
+
10
+ ## 功能概览
11
+
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
+ - 执行依赖更新流程
27
+
28
+ ## 安装
29
+
30
+ 在 `nuxt-gin-starter` 项目中作为依赖安装:
31
+
32
+ ```bash
33
+ pnpm add nuxt-gin-tools
34
+ ```
35
+
36
+ ## 快速开始
37
+
38
+ ```bash
39
+ # 初始化依赖(可选)
40
+ nuxt-gin install
41
+
42
+ # 启动开发
43
+ nuxt-gin dev
44
+ ```
45
+
46
+ ## 命令说明
47
+
48
+ ### `nuxt-gin dev`
49
+
50
+ 开发模式下会并行运行:
51
+ - Nuxt:`npx nuxt dev --port=<nuxtPort> --host`
52
+ - Go:监听变更并运行 `go run main.go`
53
+
54
+ Go 监听规则来自 `.go-watch.json`(见下文)。
55
+
56
+ ### `nuxt-gin install`
57
+
58
+ - 总是执行:`npx nuxt prepare`
59
+ - 检测到 Go 时额外执行:`go mod download && go mod tidy`
60
+
61
+ ### `nuxt-gin gen`
62
+
63
+ 依赖 `openapi-generator-cli`,默认会:
64
+ - 生成 Go Gin server 相关代码
65
+ - 生成 TypeScript axios 客户端代码
66
+
67
+ ### `nuxt-gin build`
68
+
69
+ 执行工具链内置的构建与打包逻辑。
70
+
71
+ ### `nuxt-gin cleanup`
72
+
73
+ 清理由工具链生成的临时目录和产物。
74
+
75
+ ### `nuxt-gin update`
76
+
77
+ 执行项目约定的更新逻辑。
78
+
79
+ ## 配置
80
+
81
+ ### 1) `server.config.json`
82
+
83
+ `dev` 命令会读取该文件,常用字段:
84
+
85
+ - `ginPort`: Gin 服务端口
86
+ - `nuxtPort`: Nuxt 开发端口
87
+ - `baseUrl`: Nuxt baseUrl
88
+ - `killPortBeforeDevelop`: 开发前是否释放端口(默认 `true`)
89
+ - `cleanupBeforeDevelop`: 开发前是否执行 cleanup(默认 `false`)
90
+
91
+ ### 3) 开发环境向前端暴露 `ginPort`
92
+
93
+ `createDefaultConfig` 会在 Nuxt `runtimeConfig.public` 中注入 `ginPort`:
94
+
95
+ - 开发环境:`useRuntimeConfig().public.ginPort` 为 `server.config.json` 的 `ginPort`
96
+ - 生产环境:`useRuntimeConfig().public.ginPort` 为 `null`
97
+ - 所有环境:`useRuntimeConfig().public.isDevelopment` 直接暴露当前是否开发环境
98
+
99
+ 前端示例:
100
+
101
+ ```ts
102
+ const config = useRuntimeConfig();
103
+ const ginPort = config.public.ginPort;
104
+ const isDevelopment = config.public.isDevelopment;
105
+ ```
106
+
107
+ ### 2) `.go-watch.json`
108
+
109
+ Go 监听配置文件,示例:
110
+
111
+ ```json
112
+ {
113
+ "tmpDir": ".build/.server",
114
+ "testDataDir": "testdata",
115
+ "includeExt": ["go", "tpl", "html"],
116
+ "includeDir": [],
117
+ "includeFile": [],
118
+ "excludeDir": [
119
+ "assets",
120
+ ".build/.server",
121
+ "vendor",
122
+ "testdata",
123
+ "node_modules",
124
+ "vue",
125
+ "api",
126
+ ".vscode",
127
+ ".git"
128
+ ],
129
+ "excludeFile": [],
130
+ "excludeRegex": ["_test.go"]
131
+ }
132
+ ```
133
+
134
+ 也支持环境变量指定路径:
135
+
136
+ ```bash
137
+ NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
138
+ ```
139
+
140
+ ## 环境依赖
141
+
142
+ - Node.js
143
+ - pnpm
144
+ - Go(需要运行 Gin 侧开发与依赖下载时)
145
+ - `openapi-generator-cli`(仅 `nuxt-gin gen` 需要)
146
+
147
+ ## 说明
148
+
149
+ - Go 侧热更新已不再依赖 Air。
150
+ - 当前方案为:`chokidar` 监听文件变化 + 重启 `go run main.go`。
package/package.json CHANGED
@@ -1,30 +1,30 @@
1
- {
2
- "name": "nuxt-gin-tools",
3
- "version": "0.2.16",
4
- "description": "This project is used as a dependency for [nuxt-gin-starter](https://github.com/RapboyGao/nuxt-gin-starter.git)",
5
- "bin": {
6
- "nuxt-gin": "index.js"
7
- },
8
- "keywords": [],
9
- "author": "",
10
- "license": "MIT",
11
- "scripts": {
12
- "build": "ts-node build.ts",
13
- "publish": "npm publish --access public"
14
- },
15
- "dependencies": {
16
- "7zip-min": "^2.1.0",
17
- "chalk": "^5.4.1",
18
- "chokidar": "^3.6.0",
19
- "concurrently": "^9.2.0",
20
- "fast-glob": "^3.3.3",
21
- "fs-extra": "^11.3.0"
22
- },
23
- "devDependencies": {
24
- "@types/fs-extra": "^11.0.4",
25
- "@types/node": "^24.0.15",
26
- "nuxt": "^4.0.1",
27
- "ts-node": "^10.9.2",
28
- "typescript": "^5.8.3"
29
- }
30
- }
1
+ {
2
+ "name": "nuxt-gin-tools",
3
+ "version": "0.2.17",
4
+ "description": "This project is used as a dependency for [nuxt-gin-starter](https://github.com/RapboyGao/nuxt-gin-starter.git)",
5
+ "bin": {
6
+ "nuxt-gin": "index.js"
7
+ },
8
+ "keywords": [],
9
+ "author": "",
10
+ "license": "MIT",
11
+ "scripts": {
12
+ "build": "ts-node build.ts",
13
+ "publish": "npm publish --access public"
14
+ },
15
+ "dependencies": {
16
+ "7zip-min": "^2.1.0",
17
+ "chalk": "^5.4.1",
18
+ "chokidar": "^3.6.0",
19
+ "concurrently": "^9.2.0",
20
+ "fast-glob": "^3.3.3",
21
+ "fs-extra": "^11.3.0"
22
+ },
23
+ "devDependencies": {
24
+ "@types/fs-extra": "^11.0.4",
25
+ "@types/node": "^24.0.15",
26
+ "nuxt": "^4.0.1",
27
+ "ts-node": "^10.9.2",
28
+ "typescript": "^5.8.3"
29
+ }
30
+ }
@@ -1,5 +1,5 @@
1
- {
2
- "apiPath": "server/api",
3
- "packageName": "api",
4
- "serverPort": "8099"
1
+ {
2
+ "apiPath": "server/api",
3
+ "packageName": "api",
4
+ "serverPort": "8099"
5
5
  }
@@ -85,7 +85,7 @@ function forwardWebSocketToGin(ginPort, req, clientSocket, clientHead) {
85
85
  /**
86
86
  * 创建默认的 Nuxt 配置。
87
87
  */
88
- function createDefaultConfig({ serverConfig, }) {
88
+ function createDefaultConfig({ serverConfig }) {
89
89
  const development = isDevEnvironment();
90
90
  const baseUrl = normalizeBaseUrl(serverConfig.baseUrl);
91
91
  const publicGinPort = development ? serverConfig.ginPort : null;
@@ -127,6 +127,9 @@ function createDefaultConfig({ serverConfig, }) {
127
127
  },
128
128
  vite: {
129
129
  server: {},
130
+ optimizeDeps: {
131
+ include: ["@vue/devtools-core", "@vue/devtools-kit"],
132
+ },
130
133
  plugins: [
131
134
  {
132
135
  name: "nuxt-gin-base-url-proxy",
@@ -134,7 +137,8 @@ function createDefaultConfig({ serverConfig, }) {
134
137
  server.middlewares.use((req, res, next) => {
135
138
  var _a;
136
139
  const requestPath = ((_a = req.url) !== null && _a !== void 0 ? _a : "/").split("?")[0] || "/";
137
- const shouldForward = !isViteInternalRequest(requestPath) && !isBaseUrlRequest(baseUrl, requestPath);
140
+ const shouldForward = !isViteInternalRequest(requestPath) &&
141
+ !isBaseUrlRequest(baseUrl, requestPath);
138
142
  if (shouldForward) {
139
143
  forwardToGin(serverConfig.ginPort, req, res);
140
144
  return;
@@ -145,7 +149,8 @@ function createDefaultConfig({ serverConfig, }) {
145
149
  server.httpServer.on("upgrade", (req, socket, head) => {
146
150
  var _a;
147
151
  const requestPath = ((_a = req.url) !== null && _a !== void 0 ? _a : "/").split("?")[0] || "/";
148
- const shouldForward = !isViteInternalRequest(requestPath) && !isBaseUrlRequest(baseUrl, requestPath);
152
+ const shouldForward = !isViteInternalRequest(requestPath) &&
153
+ !isBaseUrlRequest(baseUrl, requestPath);
149
154
  if (shouldForward) {
150
155
  forwardWebSocketToGin(serverConfig.ginPort, req, socket, head);
151
156
  }
@@ -1,62 +1,62 @@
1
- {
2
- "title": "Nuxt Gin Tools Pack Config",
3
- "type": "object",
4
- "additionalProperties": false,
5
- "properties": {
6
- "extraFiles": {
7
- "type": "object",
8
- "description": "额外需要打包的文件映射(key: 源文件路径,value: 打包后对应位置)",
9
- "additionalProperties": {
10
- "type": "string"
11
- }
12
- },
13
- "extraFilesGlobs": {
14
- "type": "array",
15
- "description": "额外需要打包的文件 Glob(相对于项目根目录)",
16
- "items": {
17
- "type": "string"
18
- }
19
- },
20
- "exclude": {
21
- "type": "array",
22
- "description": "排除文件/目录 Glob(相对于项目根目录)",
23
- "items": {
24
- "type": "string"
25
- }
26
- },
27
- "zipName": {
28
- "type": "string",
29
- "description": "打包输出 zip 名称(相对于默认 zip 目录)"
30
- },
31
- "zipPath": {
32
- "type": "string",
33
- "description": "打包输出 zip 路径(相对于项目根目录或绝对路径)"
34
- },
35
- "serverPath": {
36
- "type": "string",
37
- "description": "服务器构建输出目录(相对于项目根目录或绝对路径)"
38
- },
39
- "beforePack": {
40
- "description": "打包前钩子(仅在代码调用传入时生效)"
41
- },
42
- "afterPack": {
43
- "description": "打包后钩子(仅在代码调用传入时生效)"
44
- },
45
- "cleanDist": {
46
- "type": "boolean",
47
- "description": "是否清理 dist"
48
- },
49
- "writeScripts": {
50
- "type": "boolean",
51
- "description": "是否写入启动脚本和 package.json"
52
- },
53
- "packageJson": {
54
- "type": "object",
55
- "description": "写入/覆盖 package.json 内容"
56
- },
57
- "overwrite": {
58
- "type": "boolean",
59
- "description": "复制时是否覆盖同名文件"
60
- }
61
- }
62
- }
1
+ {
2
+ "title": "Nuxt Gin Tools Pack Config",
3
+ "type": "object",
4
+ "additionalProperties": false,
5
+ "properties": {
6
+ "extraFiles": {
7
+ "type": "object",
8
+ "description": "额外需要打包的文件映射(key: 源文件路径,value: 打包后对应位置)",
9
+ "additionalProperties": {
10
+ "type": "string"
11
+ }
12
+ },
13
+ "extraFilesGlobs": {
14
+ "type": "array",
15
+ "description": "额外需要打包的文件 Glob(相对于项目根目录)",
16
+ "items": {
17
+ "type": "string"
18
+ }
19
+ },
20
+ "exclude": {
21
+ "type": "array",
22
+ "description": "排除文件/目录 Glob(相对于项目根目录)",
23
+ "items": {
24
+ "type": "string"
25
+ }
26
+ },
27
+ "zipName": {
28
+ "type": "string",
29
+ "description": "打包输出 zip 名称(相对于默认 zip 目录)"
30
+ },
31
+ "zipPath": {
32
+ "type": "string",
33
+ "description": "打包输出 zip 路径(相对于项目根目录或绝对路径)"
34
+ },
35
+ "serverPath": {
36
+ "type": "string",
37
+ "description": "服务器构建输出目录(相对于项目根目录或绝对路径)"
38
+ },
39
+ "beforePack": {
40
+ "description": "打包前钩子(仅在代码调用传入时生效)"
41
+ },
42
+ "afterPack": {
43
+ "description": "打包后钩子(仅在代码调用传入时生效)"
44
+ },
45
+ "cleanDist": {
46
+ "type": "boolean",
47
+ "description": "是否清理 dist"
48
+ },
49
+ "writeScripts": {
50
+ "type": "boolean",
51
+ "description": "是否写入启动脚本和 package.json"
52
+ },
53
+ "packageJson": {
54
+ "type": "object",
55
+ "description": "写入/覆盖 package.json 内容"
56
+ },
57
+ "overwrite": {
58
+ "type": "boolean",
59
+ "description": "复制时是否覆盖同名文件"
60
+ }
61
+ }
62
+ }