nuxt-gin-tools 0.2.17 → 0.2.19
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 +20 -20
- package/LICENSE +21 -21
- package/README.md +228 -150
- package/commands/builder.d.ts +6 -1
- package/commands/builder.js +17 -8
- package/commands/develop.d.ts +8 -3
- package/commands/develop.js +23 -9
- package/commands/pack.d.ts +6 -52
- package/commands/pack.js +124 -8
- package/commands/update.d.ts +6 -1
- package/commands/update.js +16 -9
- package/index.js +68 -37
- package/package.json +31 -30
- package/src/cli-options.d.ts +8 -0
- package/src/cli-options.js +43 -0
- package/src/go-gin-server.json +4 -4
- package/src/pack-config.schema.json +62 -62
- package/src/pack.d.ts +55 -0
- package/src/pack.js +7 -0
- package/src/server-config.json +35 -35
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,228 @@
|
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
### `nuxt-gin
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
-
|
|
65
|
-
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
### `nuxt-gin
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
- `
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
+
```bash
|
|
49
|
+
# 只跑前端
|
|
50
|
+
nuxt-gin dev --skip-go
|
|
51
|
+
|
|
52
|
+
# 只跑 Go 监听
|
|
53
|
+
nuxt-gin dev --skip-nuxt
|
|
54
|
+
|
|
55
|
+
# 跳过预清理/预安装
|
|
56
|
+
nuxt-gin dev --no-cleanup
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## 命令说明
|
|
60
|
+
|
|
61
|
+
### `nuxt-gin dev`
|
|
62
|
+
|
|
63
|
+
开发模式下会并行运行:
|
|
64
|
+
- Nuxt:`npx nuxt dev --port=<nuxtPort> --host`
|
|
65
|
+
- Go:监听变更并运行 `go run main.go`
|
|
66
|
+
|
|
67
|
+
Go 监听规则来自 `.go-watch.json`(见下文)。
|
|
68
|
+
|
|
69
|
+
可用参数:
|
|
70
|
+
|
|
71
|
+
- `--skip-go`:只启动 Nuxt
|
|
72
|
+
- `--skip-nuxt`:只启动 Go
|
|
73
|
+
- `--no-cleanup`:跳过 develop 前的 cleanup/install 检查
|
|
74
|
+
|
|
75
|
+
### `nuxt-gin install`
|
|
76
|
+
|
|
77
|
+
- 总是执行:`npx nuxt prepare`
|
|
78
|
+
- 检测到 Go 时额外执行:`go mod download && go mod tidy`
|
|
79
|
+
|
|
80
|
+
### `nuxt-gin gen`
|
|
81
|
+
|
|
82
|
+
依赖 `openapi-generator-cli`,默认会:
|
|
83
|
+
- 生成 Go Gin server 相关代码
|
|
84
|
+
- 生成 TypeScript axios 客户端代码
|
|
85
|
+
|
|
86
|
+
### `nuxt-gin build`
|
|
87
|
+
|
|
88
|
+
执行工具链内置的构建与打包逻辑。
|
|
89
|
+
|
|
90
|
+
可用参数:
|
|
91
|
+
|
|
92
|
+
- `--skip-go`:跳过 Go 构建
|
|
93
|
+
- `--skip-nuxt`:跳过 Nuxt 静态构建
|
|
94
|
+
- `--binary-name <name>`:自定义 `.build/.server` 下的 Go 二进制名称
|
|
95
|
+
|
|
96
|
+
### `pack.config.ts` / `pack.config.json`
|
|
97
|
+
|
|
98
|
+
`nuxt-gin build` 会自动读取项目根目录中的打包配置,优先级如下:
|
|
99
|
+
|
|
100
|
+
1. `pack.config.ts`
|
|
101
|
+
2. `pack.config.js`
|
|
102
|
+
3. `pack.config.cjs`
|
|
103
|
+
4. `pack.config.mjs`
|
|
104
|
+
5. `pack.config.json`
|
|
105
|
+
|
|
106
|
+
如果同时存在多个配置文件,会输出 `warn`,并按上面的优先级选择第一个。
|
|
107
|
+
|
|
108
|
+
推荐使用 `pack.config.ts`:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
import createPackConfig from 'nuxt-gin-tools/src/pack';
|
|
112
|
+
|
|
113
|
+
export default createPackConfig({
|
|
114
|
+
zipName: 'server.7z',
|
|
115
|
+
extraFilesGlobs: ['prisma/**'],
|
|
116
|
+
packageJson: {
|
|
117
|
+
private: true,
|
|
118
|
+
},
|
|
119
|
+
});
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
兼容旧的 `pack.config.json`:
|
|
123
|
+
|
|
124
|
+
```json
|
|
125
|
+
{
|
|
126
|
+
"zipName": "server.7z",
|
|
127
|
+
"extraFilesGlobs": ["prisma/**"]
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
配置校验规则:
|
|
132
|
+
|
|
133
|
+
- 明显的类型错误会直接 `error` 并终止打包
|
|
134
|
+
- 可继续执行但可能有歧义的情况会输出 `warn`
|
|
135
|
+
- 例如 `zipPath` 与 `zipName` 同时出现时,会提示 `zipPath` 优先生效
|
|
136
|
+
|
|
137
|
+
### `nuxt-gin cleanup`
|
|
138
|
+
|
|
139
|
+
清理由工具链生成的临时目录和产物。
|
|
140
|
+
|
|
141
|
+
### `nuxt-gin update`
|
|
142
|
+
|
|
143
|
+
执行项目约定的更新逻辑。
|
|
144
|
+
|
|
145
|
+
默认策略偏保守:
|
|
146
|
+
|
|
147
|
+
- Node:`pnpm update`
|
|
148
|
+
- Go:`go get -u=patch ./... && go mod tidy`
|
|
149
|
+
|
|
150
|
+
可用参数:
|
|
151
|
+
|
|
152
|
+
- `--latest`:切换为更激进的升级策略
|
|
153
|
+
- `--skip-go`:跳过 Go 依赖更新
|
|
154
|
+
- `--skip-node`:跳过 Node 依赖更新
|
|
155
|
+
|
|
156
|
+
## 配置
|
|
157
|
+
|
|
158
|
+
### 1) `server.config.json`
|
|
159
|
+
|
|
160
|
+
`dev` 命令会读取该文件,常用字段:
|
|
161
|
+
|
|
162
|
+
- `ginPort`: Gin 服务端口
|
|
163
|
+
- `nuxtPort`: Nuxt 开发端口
|
|
164
|
+
- `baseUrl`: Nuxt baseUrl
|
|
165
|
+
- `killPortBeforeDevelop`: 开发前是否释放端口(默认 `true`)
|
|
166
|
+
- `cleanupBeforeDevelop`: 开发前是否执行 cleanup(默认 `false`)
|
|
167
|
+
|
|
168
|
+
### 3) 开发环境向前端暴露 `ginPort`
|
|
169
|
+
|
|
170
|
+
`createDefaultConfig` 会在 Nuxt `runtimeConfig.public` 中注入 `ginPort`:
|
|
171
|
+
|
|
172
|
+
- 开发环境:`useRuntimeConfig().public.ginPort` 为 `server.config.json` 的 `ginPort`
|
|
173
|
+
- 生产环境:`useRuntimeConfig().public.ginPort` 为 `null`
|
|
174
|
+
- 所有环境:`useRuntimeConfig().public.isDevelopment` 直接暴露当前是否开发环境
|
|
175
|
+
|
|
176
|
+
前端示例:
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
const config = useRuntimeConfig();
|
|
180
|
+
const ginPort = config.public.ginPort;
|
|
181
|
+
const isDevelopment = config.public.isDevelopment;
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### 2) `.go-watch.json`
|
|
185
|
+
|
|
186
|
+
Go 监听配置文件,示例:
|
|
187
|
+
|
|
188
|
+
```json
|
|
189
|
+
{
|
|
190
|
+
"tmpDir": ".build/.server",
|
|
191
|
+
"testDataDir": "testdata",
|
|
192
|
+
"includeExt": ["go", "tpl", "html"],
|
|
193
|
+
"includeDir": [],
|
|
194
|
+
"includeFile": [],
|
|
195
|
+
"excludeDir": [
|
|
196
|
+
"assets",
|
|
197
|
+
".build/.server",
|
|
198
|
+
"vendor",
|
|
199
|
+
"testdata",
|
|
200
|
+
"node_modules",
|
|
201
|
+
"vue",
|
|
202
|
+
"api",
|
|
203
|
+
".vscode",
|
|
204
|
+
".git"
|
|
205
|
+
],
|
|
206
|
+
"excludeFile": [],
|
|
207
|
+
"excludeRegex": ["_test.go"]
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
也支持环境变量指定路径:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## 环境依赖
|
|
218
|
+
|
|
219
|
+
- Node.js
|
|
220
|
+
- pnpm
|
|
221
|
+
- Go(需要运行 Gin 侧开发与依赖下载时)
|
|
222
|
+
- `openapi-generator-cli`(仅 `nuxt-gin gen` 需要)
|
|
223
|
+
|
|
224
|
+
## 说明
|
|
225
|
+
|
|
226
|
+
- Go 侧热更新已不再依赖 Air。
|
|
227
|
+
- 当前方案为:`chokidar` 监听文件变化 + 重启 `go run main.go`。
|
|
228
|
+
- 打包时会按当前平台生成可执行文件名:Windows 默认 `.exe`,Linux/macOS 默认无扩展名。
|
package/commands/builder.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type BuildOptions = {
|
|
2
|
+
binaryName?: string;
|
|
3
|
+
skipGo?: boolean;
|
|
4
|
+
skipNuxt?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function build(options?: BuildOptions): Promise<void> | Promise<import("concurrently").CloseEvent[]>;
|
|
2
7
|
export default build;
|
package/commands/builder.js
CHANGED
|
@@ -7,20 +7,29 @@ exports.build = build;
|
|
|
7
7
|
const concurrently_1 = __importDefault(require("concurrently"));
|
|
8
8
|
const fs_extra_1 = require("fs-extra");
|
|
9
9
|
const path_1 = require("path");
|
|
10
|
+
const os_1 = __importDefault(require("os"));
|
|
10
11
|
const cwd = process.cwd();
|
|
11
|
-
|
|
12
|
+
const defaultBinaryName = os_1.default.platform() === "win32" ? "production.exe" : "production";
|
|
13
|
+
function build(options = {}) {
|
|
12
14
|
(0, fs_extra_1.ensureDirSync)((0, path_1.join)(cwd, "vue/.output"));
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
const commands = [];
|
|
16
|
+
if (!options.skipGo) {
|
|
17
|
+
commands.push({
|
|
18
|
+
command: `go build -o ./.build/.server/${options.binaryName || defaultBinaryName} .`,
|
|
16
19
|
name: "go",
|
|
17
20
|
prefixColor: "green",
|
|
18
|
-
}
|
|
19
|
-
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
if (!options.skipNuxt) {
|
|
24
|
+
commands.push({
|
|
20
25
|
command: "npx nuxt generate",
|
|
21
26
|
name: "nuxt",
|
|
22
27
|
prefixColor: "blue",
|
|
23
|
-
}
|
|
24
|
-
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (commands.length === 0) {
|
|
31
|
+
return Promise.resolve();
|
|
32
|
+
}
|
|
33
|
+
return (0, concurrently_1.default)(commands).result;
|
|
25
34
|
}
|
|
26
35
|
exports.default = build;
|
package/commands/develop.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
export type DevelopOptions = {
|
|
2
|
+
noCleanup?: boolean;
|
|
3
|
+
skipGo?: boolean;
|
|
4
|
+
skipNuxt?: boolean;
|
|
5
|
+
};
|
|
1
6
|
/**
|
|
2
7
|
* 启动本地开发环境。
|
|
3
8
|
*
|
|
@@ -5,17 +10,17 @@
|
|
|
5
10
|
*
|
|
6
11
|
* @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
|
|
7
12
|
*/
|
|
8
|
-
export declare function develop(): Promise<void>;
|
|
13
|
+
export declare function develop(options?: DevelopOptions): Promise<void>;
|
|
9
14
|
/**
|
|
10
15
|
* 仅启动 Nuxt 开发服务(带 nuxt 标签输出)。
|
|
11
16
|
*
|
|
12
17
|
* @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
|
|
13
18
|
*/
|
|
14
|
-
export declare function developNuxt(): Promise<void>;
|
|
19
|
+
export declare function developNuxt(options?: DevelopOptions): Promise<void>;
|
|
15
20
|
/**
|
|
16
21
|
* 仅启动 Go 开发监听流程。
|
|
17
22
|
*
|
|
18
23
|
* @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
|
|
19
24
|
*/
|
|
20
|
-
export declare function developGo(): Promise<void>;
|
|
25
|
+
export declare function developGo(options?: DevelopOptions): Promise<void>;
|
|
21
26
|
export default develop;
|
package/commands/develop.js
CHANGED
|
@@ -25,8 +25,12 @@ const utils_1 = require("../src/utils");
|
|
|
25
25
|
const cwd = process.cwd();
|
|
26
26
|
const serverConfig = (0, fs_extra_1.readJSONSync)((0, path_1.join)(cwd, "server.config.json"));
|
|
27
27
|
function prepareDevelop() {
|
|
28
|
-
return __awaiter(this,
|
|
28
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
29
29
|
const cleanupBeforeDevelop = serverConfig.cleanupBeforeDevelop === true;
|
|
30
|
+
const shouldPrepare = !options.noCleanup;
|
|
31
|
+
if (!shouldPrepare) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
30
34
|
if (cleanupBeforeDevelop) {
|
|
31
35
|
yield (0, cleanup_1.default)();
|
|
32
36
|
yield (0, postinstall_1.default)();
|
|
@@ -63,14 +67,24 @@ function runGoDev() {
|
|
|
63
67
|
* @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
|
|
64
68
|
*/
|
|
65
69
|
function develop() {
|
|
66
|
-
return __awaiter(this,
|
|
70
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
67
71
|
const killPortBeforeDevelop = serverConfig.killPortBeforeDevelop !== false;
|
|
68
|
-
yield prepareDevelop();
|
|
72
|
+
yield prepareDevelop(options);
|
|
69
73
|
// 在开发前确保占用端口被释放
|
|
70
74
|
if (killPortBeforeDevelop) {
|
|
71
|
-
(0, utils_1.killPorts)([
|
|
75
|
+
(0, utils_1.killPorts)([
|
|
76
|
+
options.skipGo ? undefined : serverConfig.ginPort,
|
|
77
|
+
options.skipNuxt ? undefined : serverConfig.nuxtPort,
|
|
78
|
+
]);
|
|
72
79
|
}
|
|
73
|
-
|
|
80
|
+
const tasks = [];
|
|
81
|
+
if (!options.skipGo) {
|
|
82
|
+
tasks.push(runGoDev());
|
|
83
|
+
}
|
|
84
|
+
if (!options.skipNuxt) {
|
|
85
|
+
tasks.push(runNuxtDev());
|
|
86
|
+
}
|
|
87
|
+
yield Promise.all(tasks);
|
|
74
88
|
});
|
|
75
89
|
}
|
|
76
90
|
/**
|
|
@@ -79,9 +93,9 @@ function develop() {
|
|
|
79
93
|
* @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
|
|
80
94
|
*/
|
|
81
95
|
function developNuxt() {
|
|
82
|
-
return __awaiter(this,
|
|
96
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
83
97
|
const killPortBeforeDevelop = serverConfig.killPortBeforeDevelop !== false;
|
|
84
|
-
yield prepareDevelop();
|
|
98
|
+
yield prepareDevelop(options);
|
|
85
99
|
if (killPortBeforeDevelop) {
|
|
86
100
|
(0, utils_1.killPorts)([serverConfig.nuxtPort]);
|
|
87
101
|
}
|
|
@@ -94,9 +108,9 @@ function developNuxt() {
|
|
|
94
108
|
* @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
|
|
95
109
|
*/
|
|
96
110
|
function developGo() {
|
|
97
|
-
return __awaiter(this,
|
|
111
|
+
return __awaiter(this, arguments, void 0, function* (options = {}) {
|
|
98
112
|
const killPortBeforeDevelop = serverConfig.killPortBeforeDevelop !== false;
|
|
99
|
-
yield prepareDevelop();
|
|
113
|
+
yield prepareDevelop(options);
|
|
100
114
|
if (killPortBeforeDevelop) {
|
|
101
115
|
(0, utils_1.killPorts)([serverConfig.ginPort]);
|
|
102
116
|
}
|
package/commands/pack.d.ts
CHANGED
|
@@ -1,55 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* 额外需要打包的文件映射
|
|
4
|
-
* key: 源文件路径(相对于项目根目录或绝对路径)
|
|
5
|
-
* value: 打包后对应位置(相对于服务器构建目录或绝对路径)
|
|
6
|
-
*/
|
|
7
|
-
extraFiles?: Record<string, string>;
|
|
8
|
-
/**
|
|
9
|
-
* 额外需要打包的文件 Glob(相对于项目根目录)
|
|
10
|
-
*/
|
|
11
|
-
extraFilesGlobs?: string[];
|
|
12
|
-
/**
|
|
13
|
-
* 排除文件/目录 Glob(相对于项目根目录)
|
|
14
|
-
*/
|
|
15
|
-
exclude?: string[];
|
|
16
|
-
/**
|
|
17
|
-
* 打包输出 zip 名称(相对于默认 zip 目录)
|
|
18
|
-
*/
|
|
19
|
-
zipName?: string;
|
|
20
|
-
/**
|
|
21
|
-
* 打包输出 zip 路径(相对于项目根目录或绝对路径)
|
|
22
|
-
*/
|
|
23
|
-
zipPath?: string;
|
|
24
|
-
/**
|
|
25
|
-
* 服务器构建输出目录(相对于项目根目录或绝对路径)
|
|
26
|
-
*/
|
|
27
|
-
serverPath?: string;
|
|
28
|
-
/**
|
|
29
|
-
* 打包前钩子
|
|
30
|
-
*/
|
|
31
|
-
beforePack?: () => Promise<void> | void;
|
|
32
|
-
/**
|
|
33
|
-
* 打包后钩子
|
|
34
|
-
*/
|
|
35
|
-
afterPack?: (zipPath: string) => Promise<void> | void;
|
|
36
|
-
/**
|
|
37
|
-
* 是否清理 dist
|
|
38
|
-
*/
|
|
39
|
-
cleanDist?: boolean;
|
|
40
|
-
/**
|
|
41
|
-
* 是否写入启动脚本和 package.json
|
|
42
|
-
*/
|
|
43
|
-
writeScripts?: boolean;
|
|
44
|
-
/**
|
|
45
|
-
* 写入/覆盖 package.json 内容
|
|
46
|
-
*/
|
|
47
|
-
packageJson?: Record<string, unknown>;
|
|
48
|
-
/**
|
|
49
|
-
* 复制时是否覆盖同名文件
|
|
50
|
-
*/
|
|
51
|
-
overwrite?: boolean;
|
|
52
|
-
}
|
|
1
|
+
import type { PackConfig } from "../src/pack";
|
|
53
2
|
/**
|
|
54
3
|
* 生成相对于服务器构建目录的绝对路径
|
|
55
4
|
* @param relativePath - 相对路径
|
|
@@ -60,6 +9,11 @@ export declare const ZIP_PATH: string;
|
|
|
60
9
|
export declare const SERVER_PATH: string;
|
|
61
10
|
export declare const ORIGINAL_DIST_PATH: string;
|
|
62
11
|
export declare const PACK_CONFIG_PATH: string;
|
|
12
|
+
export declare const PACK_CONFIG_TS_PATH: string;
|
|
13
|
+
export declare const PACK_CONFIG_JS_PATH: string;
|
|
14
|
+
export declare const PACK_CONFIG_CJS_PATH: string;
|
|
15
|
+
export declare const PACK_CONFIG_MJS_PATH: string;
|
|
16
|
+
export declare const BUILD_EXECUTABLE: string;
|
|
63
17
|
export declare const SERVER_EXECUTABLE: string;
|
|
64
18
|
export declare const PACKAGE_JSON_CONTENT: {
|
|
65
19
|
private: boolean;
|