nuxt-gin-tools 0.2.16 → 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.
Files changed (45) hide show
  1. package/commands/builder.d.ts +6 -1
  2. package/commands/builder.js +17 -8
  3. package/commands/develop.d.ts +8 -3
  4. package/commands/develop.js +23 -9
  5. package/commands/pack.d.ts +3 -1
  6. package/commands/pack.js +7 -6
  7. package/commands/update.d.ts +6 -1
  8. package/commands/update.js +16 -9
  9. package/index.js +68 -37
  10. package/package.json +1 -1
  11. package/src/cli-options.d.ts +8 -0
  12. package/src/cli-options.js +43 -0
  13. package/src/nuxt-config.js +8 -3
  14. package/src/api-generate.d.ts +0 -11
  15. package/src/api-generate.js +0 -133
  16. package/src/builder.d.ts +0 -2
  17. package/src/builder.js +0 -26
  18. package/src/cleanup.d.ts +0 -8
  19. package/src/cleanup.js +0 -97
  20. package/src/commands/api-generate.d.ts +0 -11
  21. package/src/commands/api-generate.js +0 -133
  22. package/src/commands/builder.d.ts +0 -2
  23. package/src/commands/builder.js +0 -26
  24. package/src/commands/cleanup.d.ts +0 -8
  25. package/src/commands/cleanup.js +0 -97
  26. package/src/commands/dev-go.d.ts +0 -8
  27. package/src/commands/dev-go.js +0 -306
  28. package/src/commands/develop.d.ts +0 -21
  29. package/src/commands/develop.js +0 -106
  30. package/src/commands/pack.d.ts +0 -82
  31. package/src/commands/pack.js +0 -230
  32. package/src/commands/postinstall.d.ts +0 -2
  33. package/src/commands/postinstall.js +0 -32
  34. package/src/commands/update.d.ts +0 -2
  35. package/src/commands/update.js +0 -22
  36. package/src/dev-go.d.ts +0 -8
  37. package/src/dev-go.js +0 -306
  38. package/src/develop.d.ts +0 -21
  39. package/src/develop.js +0 -106
  40. package/src/pack.d.ts +0 -82
  41. package/src/pack.js +0 -230
  42. package/src/postinstall.d.ts +0 -2
  43. package/src/postinstall.js +0 -32
  44. package/src/update.d.ts +0 -2
  45. package/src/update.js +0 -22
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-gin-tools",
3
- "version": "0.2.16",
3
+ "version": "0.2.18",
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"
@@ -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
+ }
@@ -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,11 +0,0 @@
1
- /**
2
- * 警告:本文件是API生成框架的一部分,请勿手动修改!
3
- * 任何修改可能会被自动化流程覆盖。
4
- * 如需调整生成逻辑,请修改相关配置文件或脚本。
5
- */
6
- /**
7
- * 主函数
8
- * 协调执行所有任务:生成代码、删除路径、配置Vue API
9
- */
10
- export declare function apiGenerate(): Promise<void>;
11
- export default apiGenerate;
@@ -1,133 +0,0 @@
1
- "use strict";
2
- /**
3
- * 警告:本文件是API生成框架的一部分,请勿手动修改!
4
- * 任何修改可能会被自动化流程覆盖。
5
- * 如需调整生成逻辑,请修改相关配置文件或脚本。
6
- */
7
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
- return new (P || (P = Promise))(function (resolve, reject) {
10
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
- step((generator = generator.apply(thisArg, _arguments || [])).next());
14
- });
15
- };
16
- var __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
18
- };
19
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.apiGenerate = apiGenerate;
21
- const chalk_1 = __importDefault(require("chalk"));
22
- const concurrently_1 = __importDefault(require("concurrently")); // 用于并发执行命令的工具
23
- const fs_extra_1 = __importDefault(require("fs-extra")); // 文件系统操作工具,提供更便捷的API
24
- const path_1 = __importDefault(require("path")); // 处理和转换文件路径的工具
25
- const cwd = process.cwd(); // 获取当前工作目录
26
- /**
27
- * 要执行的命令列表
28
- * 包含OpenAPI代码生成命令:
29
- * 1. 生成Go Gin服务器代码
30
- * 2. 生成TypeScript Axios客户端代码
31
- */
32
- let commands = [
33
- {
34
- command: "openapi-generator-cli generate -i openapi.yaml -g go-gin-server -c node_modules/nuxt-gin-tools/src/go-gin-server.json -o .",
35
- name: "go",
36
- prefixColor: "green",
37
- },
38
- {
39
- command: "openapi-generator-cli generate -i openapi.yaml -g typescript-axios -o vue/composables/api ",
40
- name: "vue",
41
- prefixColor: "blue",
42
- },
43
- ];
44
- /**
45
- * 执行完成后需要删除的路径列表
46
- */
47
- const pathsToDelete = ["api"];
48
- /**
49
- * 设置Vue API客户端的基础URL
50
- * 修改TypeScript axios生成的base.ts文件,将BASE_PATH设置为相对路径
51
- * @returns {Promise<string>} 返回原始文件内容的Promise
52
- */
53
- function setVueBaseUrl() {
54
- return __awaiter(this, void 0, void 0, function* () {
55
- try {
56
- // 构建Vue API运行时配置文件的完整路径
57
- const VUE_API_RUNTIME_PATH = path_1.default.join(cwd, "vue/composables/api/base.ts");
58
- // 读取原始文件内容
59
- const originalContent = yield fs_extra_1.default.readFile(VUE_API_RUNTIME_PATH, "utf-8");
60
- // 使用正则表达式替换BASE_PATH常量,移除协议和域名部分,使其成为相对路径
61
- // 匹配类似 "export const BASE_PATH = "https://example.com"" 这样的行
62
- const updatedContent = originalContent.replace(/export\s+const\s+BASE_PATH = "https?:\/\/[^/]+/, `export const BASE_PATH = "`);
63
- // 将修改后的内容写回文件
64
- yield fs_extra_1.default.outputFile(VUE_API_RUNTIME_PATH, updatedContent, "utf-8");
65
- console.log("成功更新Vue API基础URL为相对路径");
66
- return;
67
- }
68
- catch (error) {
69
- console.error("更新Vue API基础URL失败:", error);
70
- throw error; // 将错误继续抛出,以便上层处理
71
- }
72
- });
73
- }
74
- function setGoRoutes() {
75
- return __awaiter(this, void 0, void 0, function* () {
76
- const GO_API_RUNTIME_PATH = path_1.default.join(cwd, "server/api/routers.go");
77
- const originalContent = yield fs_extra_1.default.readFile(GO_API_RUNTIME_PATH, "utf-8");
78
- const updatedContent = originalContent.replace(/getRoutes/g, "GetRoutes");
79
- // overwrite
80
- yield fs_extra_1.default.outputFile(GO_API_RUNTIME_PATH, updatedContent, "utf-8");
81
- });
82
- }
83
- /**
84
- * 删除指定的路径
85
- * 用于清理生成过程中产生的临时或不需要的文件和目录
86
- */
87
- function removePaths() {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- try {
90
- // 遍历要删除的路径列表
91
- for (const path of pathsToDelete) {
92
- // 构建完整路径
93
- const fullPath = path_1.default.join(cwd, path);
94
- // 删除路径(文件或目录)
95
- yield fs_extra_1.default.remove(fullPath);
96
- console.log(`成功删除路径: ${fullPath}`);
97
- }
98
- }
99
- catch (error) {
100
- console.error("删除路径失败:", error);
101
- throw error; // 将错误继续抛出
102
- }
103
- });
104
- }
105
- /**
106
- * 主函数
107
- * 协调执行所有任务:生成代码、删除路径、配置Vue API
108
- */
109
- function apiGenerate() {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- try {
112
- // 输出开始信息
113
- console.log(chalk_1.default.bgGreen("开始生成API代码..."));
114
- // 并发执行命令列表中的所有命令,等待所有命令完成
115
- yield (0, concurrently_1.default)(commands).result;
116
- // 按顺序执行清理和配置任务
117
- let tasks = [];
118
- tasks.push(removePaths());
119
- tasks.push(setVueBaseUrl());
120
- tasks.push(setGoRoutes());
121
- yield Promise.all(tasks);
122
- console.log(chalk_1.default.bgGreen("API代码生成和配置完成!"));
123
- }
124
- catch (error) {
125
- // 捕获并处理任何阶段发生的错误
126
- console.error(chalk_1.default.red("执行过程中发生错误:"), error);
127
- // 以错误码1退出进程,表示执行失败
128
- process.exit(1);
129
- }
130
- });
131
- }
132
- // 执行主函数
133
- exports.default = apiGenerate;
package/src/builder.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare function build(): Promise<import("concurrently").CloseEvent[]>;
2
- export default build;