nuxt-gin-tools 0.2.0 → 0.2.2

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 CHANGED
@@ -1,23 +1,135 @@
1
1
  # nuxt-gin-tools
2
2
 
3
- This project is used as a dependency for [nuxt-gin-starter](https://github.com/RapboyGao/nuxt-gin-starter.git)
3
+ `nuxt-gin-tools` 是 `nuxt-gin-starter` 的配套开发工具包,提供 Nuxt + Gin 项目的统一命令入口。
4
4
 
5
- ## Command: nuxt-gin dev
5
+ 核心目标:
6
+ - 一条命令启动前后端开发环境
7
+ - 自动处理 Go 侧依赖和文件监听重启
8
+ - 提供 OpenAPI 代码生成与构建打包辅助
6
9
 
7
- - Starting the develop server.
10
+ ## 功能概览
8
11
 
9
- ## Command: nuxt-gin build
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
+ - 执行依赖更新流程
10
27
 
11
- - Build script
28
+ ## 安装
12
29
 
13
- ## Command: nuxt-gin gen
30
+ `nuxt-gin-starter` 项目中作为依赖安装:
14
31
 
15
- - Generate API based on openapi.yaml
32
+ ```bash
33
+ pnpm add nuxt-gin-tools
34
+ ```
16
35
 
17
- ## Command: nuxt-gin install
36
+ ## 快速开始
18
37
 
19
- - Postinstall script.
38
+ ```bash
39
+ # 初始化依赖(可选)
40
+ nuxt-gin install
20
41
 
21
- ## Command: nuxt-gin cleanup
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
+ ### 2) `.go-watch.json`
92
+
93
+ Go 监听配置文件,示例:
94
+
95
+ ```json
96
+ {
97
+ "tmpDir": ".build/.server",
98
+ "testDataDir": "testdata",
99
+ "includeExt": ["go", "tpl", "html"],
100
+ "includeDir": [],
101
+ "includeFile": [],
102
+ "excludeDir": [
103
+ "assets",
104
+ ".build/.server",
105
+ "vendor",
106
+ "testdata",
107
+ "node_modules",
108
+ "vue",
109
+ "api",
110
+ ".vscode",
111
+ ".git"
112
+ ],
113
+ "excludeFile": [],
114
+ "excludeRegex": ["_test.go"]
115
+ }
116
+ ```
117
+
118
+ 也支持环境变量指定路径:
119
+
120
+ ```bash
121
+ NUXT_GIN_WATCH_CONFIG=/path/to/.go-watch.json
122
+ ```
123
+
124
+ ## 环境依赖
125
+
126
+ - Node.js
127
+ - pnpm
128
+ - Go(需要运行 Gin 侧开发与依赖下载时)
129
+ - `openapi-generator-cli`(仅 `nuxt-gin gen` 需要)
130
+
131
+ ## 说明
132
+
133
+ - Go 侧热更新已不再依赖 Air。
134
+ - 当前方案为:`chokidar` 监听文件变化 + 重启 `go run main.go`。
22
135
 
23
- - Cleanup script.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-gin-tools",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
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"
package/src/dev-go.d.ts CHANGED
@@ -1 +1,8 @@
1
- export {};
1
+ /**
2
+ * 启动 Go 开发监听流程:执行 `go run main.go`,并在文件变更后自动重启。
3
+ *
4
+ * 该函数通常由 `develop()` 调用;执行后会持续监听,直到收到退出信号。
5
+ *
6
+ * @returns {Promise<void>} 仅在监听流程被中断并完成清理后返回。
7
+ */
8
+ export declare function startGoDev(): Promise<void>;
package/src/dev-go.js CHANGED
@@ -12,6 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.startGoDev = startGoDev;
15
16
  const child_process_1 = require("child_process");
16
17
  const child_process_2 = require("child_process");
17
18
  const chokidar_1 = __importDefault(require("chokidar"));
@@ -306,7 +307,14 @@ function stopGoProcess(proc) {
306
307
  });
307
308
  });
308
309
  }
309
- function start() {
310
+ /**
311
+ * 启动 Go 开发监听流程:执行 `go run main.go`,并在文件变更后自动重启。
312
+ *
313
+ * 该函数通常由 `develop()` 调用;执行后会持续监听,直到收到退出信号。
314
+ *
315
+ * @returns {Promise<void>} 仅在监听流程被中断并完成清理后返回。
316
+ */
317
+ function startGoDev() {
310
318
  return __awaiter(this, void 0, void 0, function* () {
311
319
  const watchConfig = loadWatchConfig();
312
320
  const watchRoots = watchConfig.includeDir.length
@@ -368,7 +376,10 @@ function start() {
368
376
  }));
369
377
  });
370
378
  }
371
- start().catch((error) => {
372
- console.error(chalk_1.default.red(`[${LOG_TAG}] failed to start: ${String(error)}`));
373
- process.exit(1);
374
- });
379
+ if (require.main === module) {
380
+ // 兼容直接执行该文件(例如 node src/dev-go.js)。
381
+ startGoDev().catch((error) => {
382
+ console.error(chalk_1.default.red(`[${LOG_TAG}] failed to start: ${String(error)}`));
383
+ process.exit(1);
384
+ });
385
+ }
package/src/develop.d.ts CHANGED
@@ -1,2 +1,9 @@
1
+ /**
2
+ * 启动本地开发环境。
3
+ *
4
+ * 行为包括:按配置执行预清理、释放开发端口、并行启动 Nuxt 与 Go 监听流程。
5
+ *
6
+ * @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
7
+ */
1
8
  export declare function develop(): Promise<void>;
2
9
  export default develop;
package/src/develop.js CHANGED
@@ -21,12 +21,9 @@ const child_process_1 = require("child_process");
21
21
  const chalk_1 = __importDefault(require("chalk"));
22
22
  const cleanup_1 = __importDefault(require("./cleanup"));
23
23
  const postinstall_1 = __importDefault(require("./postinstall"));
24
+ const dev_go_1 = require("./dev-go");
24
25
  const cwd = process.cwd();
25
26
  const serverConfig = (0, fs_extra_1.readJSONSync)((0, path_1.join)(cwd, "server.config.json"));
26
- function getGoDevCommand() {
27
- const scriptPath = (0, path_1.join)(__dirname, "dev-go.js");
28
- return `"${process.execPath}" "${scriptPath}"`;
29
- }
30
27
  function killPort(port) {
31
28
  if (!Number.isInteger(port)) {
32
29
  return;
@@ -121,6 +118,13 @@ function killPortsFromConfig() {
121
118
  }
122
119
  }
123
120
  }
121
+ /**
122
+ * 启动本地开发环境。
123
+ *
124
+ * 行为包括:按配置执行预清理、释放开发端口、并行启动 Nuxt 与 Go 监听流程。
125
+ *
126
+ * @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
127
+ */
124
128
  function develop() {
125
129
  return __awaiter(this, void 0, void 0, function* () {
126
130
  const cleanupBeforeDevelop = serverConfig.cleanupBeforeDevelop === true;
@@ -142,18 +146,16 @@ function develop() {
142
146
  killPortsFromConfig();
143
147
  }
144
148
  (0, fs_extra_1.ensureDirSync)((0, path_1.join)(cwd, ".build/.server"));
145
- yield (0, concurrently_1.default)([
146
- {
147
- command: getGoDevCommand(),
148
- name: "go",
149
- prefixColor: "green",
150
- },
149
+ // Nuxt 保持在 concurrently 中运行,统一复用 nuxt 标签输出。
150
+ const nuxtTask = (0, concurrently_1.default)([
151
151
  {
152
152
  command: `npx nuxt dev --port=${serverConfig.nuxtPort} --host`,
153
153
  name: "nuxt",
154
154
  prefixColor: "blue",
155
155
  },
156
156
  ]).result;
157
+ // Go 侧直接调用本地 dev-go 逻辑,避免额外 shell 路径和引号问题。
158
+ yield Promise.all([(0, dev_go_1.startGoDev)(), nuxtTask]);
157
159
  });
158
160
  }
159
161
  exports.default = develop;