nuxt-gin-tools 0.2.17 → 0.2.18

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`。
@@ -1,2 +1,7 @@
1
- export declare function build(): Promise<import("concurrently").CloseEvent[]>;
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;
@@ -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
- function build() {
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
- return (0, concurrently_1.default)([
14
- {
15
- command: "go build -o ./.build/.server/production.exe .",
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
- ]).result;
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;
@@ -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;
@@ -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, void 0, void 0, function* () {
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, void 0, void 0, function* () {
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)([serverConfig.ginPort, serverConfig.nuxtPort]);
75
+ (0, utils_1.killPorts)([
76
+ options.skipGo ? undefined : serverConfig.ginPort,
77
+ options.skipNuxt ? undefined : serverConfig.nuxtPort,
78
+ ]);
72
79
  }
73
- yield Promise.all([runGoDev(), runNuxtDev()]);
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, void 0, void 0, function* () {
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, void 0, void 0, function* () {
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
  }
@@ -1,4 +1,5 @@
1
- export interface PackConfig {
1
+ import type { BuildOptions } from "./builder";
2
+ export interface PackConfig extends BuildOptions {
2
3
  /**
3
4
  * 额外需要打包的文件映射
4
5
  * key: 源文件路径(相对于项目根目录或绝对路径)
@@ -60,6 +61,7 @@ export declare const ZIP_PATH: string;
60
61
  export declare const SERVER_PATH: string;
61
62
  export declare const ORIGINAL_DIST_PATH: string;
62
63
  export declare const PACK_CONFIG_PATH: string;
64
+ export declare const BUILD_EXECUTABLE: string;
63
65
  export declare const SERVER_EXECUTABLE: string;
64
66
  export declare const PACKAGE_JSON_CONTENT: {
65
67
  private: boolean;
package/commands/pack.js CHANGED
@@ -45,7 +45,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
45
45
  return (mod && mod.__esModule) ? mod : { "default": mod };
46
46
  };
47
47
  Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.FILES_TO_COPY = exports.PACKAGE_JSON_CONTENT = exports.SERVER_EXECUTABLE = exports.PACK_CONFIG_PATH = exports.ORIGINAL_DIST_PATH = exports.SERVER_PATH = exports.ZIP_PATH = void 0;
48
+ exports.FILES_TO_COPY = exports.PACKAGE_JSON_CONTENT = exports.SERVER_EXECUTABLE = exports.BUILD_EXECUTABLE = exports.PACK_CONFIG_PATH = exports.ORIGINAL_DIST_PATH = exports.SERVER_PATH = exports.ZIP_PATH = void 0;
49
49
  exports.builtPath = builtPath;
50
50
  exports.buildAndPack = buildAndPack;
51
51
  // 导入项目构建工具,用于执行 Nuxt 项目的构建流程
@@ -73,18 +73,19 @@ exports.SERVER_PATH = Path.resolve(process.cwd(), ".build/production/server");
73
73
  // 定义原始 dist 目录路径,用于清理操作
74
74
  exports.ORIGINAL_DIST_PATH = Path.resolve(process.cwd(), "dist");
75
75
  exports.PACK_CONFIG_PATH = Path.resolve(process.cwd(), "pack.config.json");
76
+ exports.BUILD_EXECUTABLE = os.platform() === "win32" ? "production.exe" : "production";
76
77
  exports.SERVER_EXECUTABLE = os.platform() === "win32" ? "server-production.exe" : "server-production"; // 根据操作系统选择可执行文件名
77
78
  // 定义打包后项目的 package.json 内容
78
79
  exports.PACKAGE_JSON_CONTENT = {
79
80
  private: true,
80
81
  scripts: {
81
- start: "./server-production.exe", // 定义启动命令
82
+ start: `./${exports.SERVER_EXECUTABLE}`, // 定义启动命令
82
83
  },
83
84
  };
84
85
  // 定义需要复制到构建目录的文件映射关系(目标为构建目录下的相对路径)
85
86
  const DEFAULT_FILES_TO_COPY = {
86
87
  "vue/.output": "vue/.output", // Vue 应用构建输出
87
- [`.build/.server/production.exe`]: "server-production.exe", // 生产环境可执行文件
88
+ [`.build/.server/${exports.BUILD_EXECUTABLE}`]: exports.SERVER_EXECUTABLE, // 生产环境可执行文件
88
89
  "server.config.json": "server.config.json", // 服务器配置文件
89
90
  };
90
91
  // 兼容旧导出:默认构建目录下的绝对目标路径
@@ -96,9 +97,9 @@ function writeScriptFiles(serverPath, config) {
96
97
  // 写入 Windows 批处理启动脚本
97
98
  FS.outputFileSync(Path.resolve(serverPath, "start.bat"), `powershell -ExecutionPolicy ByPass -File ./start.ps1`);
98
99
  // 写入 PowerShell 启动脚本
99
- FS.outputFileSync(Path.resolve(serverPath, "start.ps1"), `./server-production.exe`);
100
+ FS.outputFileSync(Path.resolve(serverPath, "start.ps1"), `./${exports.SERVER_EXECUTABLE}`);
100
101
  // 写入 Linux/macOS 启动脚本
101
- FS.outputFileSync(Path.resolve(serverPath, "start.sh"), `./server-production.exe`);
102
+ FS.outputFileSync(Path.resolve(serverPath, "start.sh"), `./${exports.SERVER_EXECUTABLE}`);
102
103
  // 写入 package.json 文件,使用 2 个空格缩进
103
104
  const mergedPackageJson = mergePackageJson(exports.PACKAGE_JSON_CONTENT, config === null || config === void 0 ? void 0 : config.packageJson);
104
105
  FS.outputJSONSync(Path.resolve(serverPath, "package.json"), mergedPackageJson, { spaces: 2 });
@@ -212,7 +213,7 @@ function buildAndPack(config) {
212
213
  const resolvedConfig = config !== null && config !== void 0 ? config : readPackConfigFromCwd();
213
214
  const serverPath = resolveServerPath(resolvedConfig);
214
215
  const zipPath = resolveZipPath(resolvedConfig);
215
- yield (0, builder_1.default)(); // 执行项目构建
216
+ yield (0, builder_1.default)(resolvedConfig); // 执行项目构建
216
217
  if (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : resolvedConfig.beforePack) {
217
218
  yield resolvedConfig.beforePack();
218
219
  }
@@ -1,2 +1,7 @@
1
- export declare function update(): void;
1
+ export type UpdateOptions = {
2
+ latest?: boolean;
3
+ skipGo?: boolean;
4
+ skipNode?: boolean;
5
+ };
6
+ export declare function update(options?: UpdateOptions): Promise<void> | Promise<import("concurrently").CloseEvent[]>;
2
7
  export default update;
@@ -5,18 +5,25 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.update = update;
7
7
  const concurrently_1 = __importDefault(require("concurrently"));
8
- function update() {
9
- (0, concurrently_1.default)([
10
- {
11
- command: "pnpm update --latest",
8
+ function update(options = {}) {
9
+ const commands = [];
10
+ if (!options.skipNode) {
11
+ commands.push({
12
+ command: options.latest ? "pnpm update --latest" : "pnpm update",
12
13
  name: "pnpm",
13
14
  prefixColor: "magenta",
14
- },
15
- {
16
- command: "go get -u && go mod tidy",
15
+ });
16
+ }
17
+ if (!options.skipGo) {
18
+ commands.push({
19
+ command: options.latest ? "go get -u ./... && go mod tidy" : "go get -u=patch ./... && go mod tidy",
17
20
  name: "go",
18
21
  prefixColor: "green",
19
- },
20
- ]);
22
+ });
23
+ }
24
+ if (commands.length === 0) {
25
+ return Promise.resolve();
26
+ }
27
+ return (0, concurrently_1.default)(commands).result;
21
28
  }
22
29
  exports.default = update;
package/index.js CHANGED
@@ -33,6 +33,15 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  return result;
34
34
  };
35
35
  })();
36
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
37
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
+ return new (P || (P = Promise))(function (resolve, reject) {
39
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
43
+ });
44
+ };
36
45
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
46
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
47
  };
@@ -50,6 +59,7 @@ const postinstall_1 = __importDefault(require("./commands/postinstall"));
50
59
  const cleanup_1 = __importDefault(require("./commands/cleanup"));
51
60
  // 导入更新功能
52
61
  const update_1 = __importDefault(require("./commands/update"));
62
+ const cli_options_1 = require("./src/cli-options");
53
63
  // 获取命令行参数(去除前两个默认参数)
54
64
  const args = process.argv.slice(2);
55
65
  // 检查是否提供了命令
@@ -57,41 +67,62 @@ if (args.length === 0) {
57
67
  console.error("未提供命令。请指定要运行的命令。");
58
68
  process.exit(1);
59
69
  }
60
- // 根据第一个参数执行对应的命令
61
- switch (args[0]) {
62
- case "dev":
63
- // 启动开发模式
64
- (0, develop_1.default)();
65
- break;
66
- case "dev:nuxt":
67
- // 仅启动 Nuxt 开发模式
68
- (0, develop_1.developNuxt)();
69
- break;
70
- case "dev:go":
71
- // 仅启动 Go 开发模式
72
- (0, develop_1.developGo)();
73
- break;
74
- case "build":
75
- // 执行构建和打包操作
76
- (0, pack_1.default)();
77
- break;
78
- case "gen":
79
- // 生成API代码(注:此处命令可能拼写错误,应为generate)
80
- (0, api_generate_1.default)();
81
- break;
82
- case "install":
83
- // 执行安装后的初始化操作
84
- (0, postinstall_1.default)();
85
- break;
86
- case "cleanup":
87
- // 执行清理操作
88
- (0, cleanup_1.default)();
89
- break;
90
- case "update":
91
- // 更新依赖
92
- (0, update_1.default)();
93
- break;
94
- default:
95
- console.error(`未知命令: ${args[0]}`);
96
- process.exit(1);
70
+ function main() {
71
+ return __awaiter(this, void 0, void 0, function* () {
72
+ const command = args[0];
73
+ const options = (0, cli_options_1.parseCLIOptions)(args.slice(1));
74
+ switch (command) {
75
+ case "dev":
76
+ yield (0, develop_1.default)({
77
+ noCleanup: (0, cli_options_1.hasFlag)(options, "no-cleanup"),
78
+ skipGo: (0, cli_options_1.hasFlag)(options, "skip-go"),
79
+ skipNuxt: (0, cli_options_1.hasFlag)(options, "skip-nuxt"),
80
+ });
81
+ break;
82
+ case "dev:nuxt":
83
+ yield (0, develop_1.developNuxt)({
84
+ noCleanup: (0, cli_options_1.hasFlag)(options, "no-cleanup"),
85
+ });
86
+ break;
87
+ case "dev:go":
88
+ yield (0, develop_1.developGo)({
89
+ noCleanup: (0, cli_options_1.hasFlag)(options, "no-cleanup"),
90
+ });
91
+ break;
92
+ case "build":
93
+ yield (0, pack_1.default)({
94
+ binaryName: (0, cli_options_1.getOption)(options, "binary-name"),
95
+ skipGo: (0, cli_options_1.hasFlag)(options, "skip-go"),
96
+ skipNuxt: (0, cli_options_1.hasFlag)(options, "skip-nuxt"),
97
+ });
98
+ break;
99
+ case "gen":
100
+ // 生成API代码(注:此处命令可能拼写错误,应为generate)
101
+ yield (0, api_generate_1.default)();
102
+ break;
103
+ case "install":
104
+ // 执行安装后的初始化操作
105
+ yield (0, postinstall_1.default)();
106
+ break;
107
+ case "cleanup":
108
+ // 执行清理操作
109
+ yield (0, cleanup_1.default)();
110
+ break;
111
+ case "update":
112
+ // 更新依赖
113
+ yield (0, update_1.default)({
114
+ latest: (0, cli_options_1.hasFlag)(options, "latest"),
115
+ skipGo: (0, cli_options_1.hasFlag)(options, "skip-go"),
116
+ skipNode: (0, cli_options_1.hasFlag)(options, "skip-node"),
117
+ });
118
+ break;
119
+ default:
120
+ console.error(`未知命令: ${command}`);
121
+ process.exit(1);
122
+ }
123
+ });
97
124
  }
125
+ void main().catch((error) => {
126
+ console.error(error);
127
+ process.exit(1);
128
+ });
package/package.json CHANGED
@@ -1,30 +1,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
+ {
2
+ "name": "nuxt-gin-tools",
3
+ "version": "0.2.18",
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
+ }
@@ -0,0 +1,8 @@
1
+ export type CLIOptions = {
2
+ flags: Set<string>;
3
+ values: Map<string, string>;
4
+ positionals: string[];
5
+ };
6
+ export declare function parseCLIOptions(args: string[]): CLIOptions;
7
+ export declare function hasFlag(options: CLIOptions, key: string): boolean;
8
+ export declare function getOption(options: CLIOptions, key: string): string | undefined;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseCLIOptions = parseCLIOptions;
4
+ exports.hasFlag = hasFlag;
5
+ exports.getOption = getOption;
6
+ function normalizeKey(key) {
7
+ return key.replace(/^-+/, "").trim();
8
+ }
9
+ function parseCLIOptions(args) {
10
+ var _a, _b, _c, _d;
11
+ const flags = new Set();
12
+ const values = new Map();
13
+ const positionals = [];
14
+ for (let i = 0; i < args.length; i += 1) {
15
+ const current = (_b = (_a = args[i]) === null || _a === void 0 ? void 0 : _a.trim()) !== null && _b !== void 0 ? _b : "";
16
+ if (!current)
17
+ continue;
18
+ if (!current.startsWith("-")) {
19
+ positionals.push(current);
20
+ continue;
21
+ }
22
+ const eqIndex = current.indexOf("=");
23
+ if (eqIndex >= 0) {
24
+ values.set(normalizeKey(current.slice(0, eqIndex)), current.slice(eqIndex + 1));
25
+ continue;
26
+ }
27
+ const key = normalizeKey(current);
28
+ const next = (_d = (_c = args[i + 1]) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : "";
29
+ if (next && !next.startsWith("-")) {
30
+ values.set(key, next);
31
+ i += 1;
32
+ continue;
33
+ }
34
+ flags.add(key);
35
+ }
36
+ return { flags, values, positionals };
37
+ }
38
+ function hasFlag(options, key) {
39
+ return options.flags.has(normalizeKey(key));
40
+ }
41
+ function getOption(options, key) {
42
+ return options.values.get(normalizeKey(key));
43
+ }
@@ -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
  }
@@ -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
+ }
@@ -1,35 +1,35 @@
1
- {
2
- "title": "API configuration schema",
3
- "description": "API configuration schema. For more info see http://json-schema.org/ and https://frontaid.io/blog/json-schema-vscode/",
4
- "type": "object",
5
- "properties": {
6
- "ginPort": {
7
- "title": "The port for Gin / Gin框架端口",
8
- "type": "integer"
9
- },
10
- "nuxtPort": {
11
- "title": "The port for Nuxt / Nuxt框架devServer端口",
12
- "type": "integer"
13
- },
14
- "baseUrl": {
15
- "title": "The base url for nuxt. / Nuxt的BaseUrl",
16
- "type": "string",
17
- "pattern": "^\\/\\w.+"
18
- },
19
- "killPortBeforeDevelop": {
20
- "title": "Kill port before develop / 开发前释放端口",
21
- "type": "boolean",
22
- "default": true
23
- },
24
- "cleanupBeforeDevelop": {
25
- "title": "Cleanup before develop / 开发前清理",
26
- "type": "boolean",
27
- "default": false
28
- }
29
- },
30
- "required": [
31
- "ginPort",
32
- "nuxtPort",
33
- "baseUrl"
34
- ]
35
- }
1
+ {
2
+ "title": "API configuration schema",
3
+ "description": "API configuration schema. For more info see http://json-schema.org/ and https://frontaid.io/blog/json-schema-vscode/",
4
+ "type": "object",
5
+ "properties": {
6
+ "ginPort": {
7
+ "title": "The port for Gin / Gin框架端口",
8
+ "type": "integer"
9
+ },
10
+ "nuxtPort": {
11
+ "title": "The port for Nuxt / Nuxt框架devServer端口",
12
+ "type": "integer"
13
+ },
14
+ "baseUrl": {
15
+ "title": "The base url for nuxt. / Nuxt的BaseUrl",
16
+ "type": "string",
17
+ "pattern": "^\\/\\w.+"
18
+ },
19
+ "killPortBeforeDevelop": {
20
+ "title": "Kill port before develop / 开发前释放端口",
21
+ "type": "boolean",
22
+ "default": true
23
+ },
24
+ "cleanupBeforeDevelop": {
25
+ "title": "Cleanup before develop / 开发前清理",
26
+ "type": "boolean",
27
+ "default": false
28
+ }
29
+ },
30
+ "required": [
31
+ "ginPort",
32
+ "nuxtPort",
33
+ "baseUrl"
34
+ ]
35
+ }