nuxt-gin-tools 0.0.4 → 0.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-gin-tools",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "bin": {
6
6
  "nuxt-gin": "index.js"
@@ -19,11 +19,18 @@
19
19
  "fs-extra": "^11.3.0"
20
20
  },
21
21
  "devDependencies": {
22
+ "@nuxt/schema": "^4.0.0",
22
23
  "@types/fs-extra": "^11.0.4",
23
24
  "@types/node": "^24.0.14",
25
+ "@vue/language-core": "^3.0.3",
26
+ "css-minimizer-webpack-plugin": "^7.0.2",
27
+ "esbuild-loader": "^4.3.0",
28
+ "mini-css-extract-plugin": "^2.9.2",
24
29
  "nitro": "^0.0.0",
25
30
  "nuxt": "^3.17.7",
26
31
  "ts-node": "^10.9.2",
27
- "typescript": "^5.8.3"
32
+ "typescript": "^5.8.3",
33
+ "vue-loader": "^17.4.2",
34
+ "webpack-dev-middleware": "^7.4.2"
28
35
  }
29
36
  }
package/src/generate.js CHANGED
@@ -4,15 +4,6 @@
4
4
  * 任何修改可能会被自动化流程覆盖。
5
5
  * 如需调整生成逻辑,请修改相关配置文件或脚本。
6
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
7
  var __importDefault = (this && this.__importDefault) || function (mod) {
17
8
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
9
  };
@@ -50,72 +41,66 @@ const pathsToDelete = ["api"];
50
41
  * 修改TypeScript axios生成的base.ts文件,将BASE_PATH设置为相对路径
51
42
  * @returns {Promise<string>} 返回原始文件内容的Promise
52
43
  */
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 originalContent;
67
- }
68
- catch (error) {
69
- console.error("更新Vue API基础URL失败:", error);
70
- throw error; // 将错误继续抛出,以便上层处理
71
- }
72
- });
44
+ async function setVueBaseUrl() {
45
+ try {
46
+ // 构建Vue API运行时配置文件的完整路径
47
+ const VUE_API_RUNTIME_PATH = path_1.default.join(cwd, "vue/composables/api/base.ts");
48
+ // 读取原始文件内容
49
+ const originalContent = await fs_extra_1.default.readFile(VUE_API_RUNTIME_PATH, "utf-8");
50
+ // 使用正则表达式替换BASE_PATH常量,移除协议和域名部分,使其成为相对路径
51
+ // 匹配类似 "export const BASE_PATH = "https://example.com"" 这样的行
52
+ const updatedContent = originalContent.replace(/export\s+const\s+BASE_PATH = "https?:\/\/[^/]+/, `export const BASE_PATH = "`);
53
+ // 将修改后的内容写回文件
54
+ await fs_extra_1.default.outputFile(VUE_API_RUNTIME_PATH, updatedContent, "utf-8");
55
+ console.log("成功更新Vue API基础URL为相对路径");
56
+ return originalContent;
57
+ }
58
+ catch (error) {
59
+ console.error("更新Vue API基础URL失败:", error);
60
+ throw error; // 将错误继续抛出,以便上层处理
61
+ }
73
62
  }
74
63
  /**
75
64
  * 删除指定的路径
76
65
  * 用于清理生成过程中产生的临时或不需要的文件和目录
77
66
  */
78
- function removePaths() {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- try {
81
- // 遍历要删除的路径列表
82
- for (const path of pathsToDelete) {
83
- // 构建完整路径
84
- const fullPath = path_1.default.join(cwd, path);
85
- // 删除路径(文件或目录)
86
- yield fs_extra_1.default.remove(fullPath);
87
- console.log(`成功删除路径: ${fullPath}`);
88
- }
67
+ async function removePaths() {
68
+ try {
69
+ // 遍历要删除的路径列表
70
+ for (const path of pathsToDelete) {
71
+ // 构建完整路径
72
+ const fullPath = path_1.default.join(cwd, path);
73
+ // 删除路径(文件或目录)
74
+ await fs_extra_1.default.remove(fullPath);
75
+ console.log(`成功删除路径: ${fullPath}`);
89
76
  }
90
- catch (error) {
91
- console.error("删除路径失败:", error);
92
- throw error; // 将错误继续抛出
93
- }
94
- });
77
+ }
78
+ catch (error) {
79
+ console.error("删除路径失败:", error);
80
+ throw error; // 将错误继续抛出
81
+ }
95
82
  }
96
83
  /**
97
84
  * 主函数
98
85
  * 协调执行所有任务:生成代码、删除路径、配置Vue API
99
86
  */
100
- function apiGenerate() {
101
- return __awaiter(this, void 0, void 0, function* () {
102
- try {
103
- // 输出开始信息
104
- console.log(chalk_1.default.bgGreen("开始生成API代码..."));
105
- // 并发执行命令列表中的所有命令,等待所有命令完成
106
- yield (0, concurrently_1.default)(commands).result;
107
- // 按顺序执行清理和配置任务
108
- yield removePaths();
109
- yield setVueBaseUrl();
110
- console.log(chalk_1.default.bgGreen("API代码生成和配置完成!"));
111
- }
112
- catch (error) {
113
- // 捕获并处理任何阶段发生的错误
114
- console.error(chalk_1.default.red("执行过程中发生错误:"), error);
115
- // 以错误码1退出进程,表示执行失败
116
- process.exit(1);
117
- }
118
- });
87
+ async function apiGenerate() {
88
+ try {
89
+ // 输出开始信息
90
+ console.log(chalk_1.default.bgGreen("开始生成API代码..."));
91
+ // 并发执行命令列表中的所有命令,等待所有命令完成
92
+ await (0, concurrently_1.default)(commands).result;
93
+ // 按顺序执行清理和配置任务
94
+ await removePaths();
95
+ await setVueBaseUrl();
96
+ console.log(chalk_1.default.bgGreen("API代码生成和配置完成!"));
97
+ }
98
+ catch (error) {
99
+ // 捕获并处理任何阶段发生的错误
100
+ console.error(chalk_1.default.red("执行过程中发生错误:"), error);
101
+ // 以错误码1退出进程,表示执行失败
102
+ process.exit(1);
103
+ }
119
104
  }
120
105
  // 执行主函数
121
106
  exports.default = apiGenerate;
@@ -1,3 +1,4 @@
1
+ import type { NuxtConfig } from "nuxt/config";
1
2
  /** API配置模式接口 */
2
3
  export interface ServerConfig {
3
4
  /** Gin框架端口 */
@@ -7,42 +8,6 @@ export interface ServerConfig {
7
8
  /** Nuxt的BaseUrl,必须以/开头并包含至少一个单词字符 */
8
9
  baseUrl: string;
9
10
  }
10
- /**
11
- * 处理基础路径,去除协议和域名部分,只保留路径部分
12
- * 例如,将 "https://example.com/api-go" 转换为 "/api-go"
13
- *
14
- */
15
- declare const thisBasePath: any;
16
- export declare const config: {
17
- ssr: boolean;
18
- app: {
19
- baseURL: string;
20
- };
21
- devServer: {
22
- port: number;
23
- };
24
- experimental: {
25
- payloadExtraction: boolean;
26
- };
27
- nitro: {
28
- devProxy: {
29
- [thisBasePath]: {
30
- target: string;
31
- changeOrigin: boolean;
32
- };
33
- };
34
- };
35
- vite: {
36
- esbuild: {
37
- jsxFactory: string;
38
- jsxFragment: string;
39
- };
40
- };
41
- rootDir: string;
42
- devtools: {
43
- timeline: {
44
- enabled: boolean;
45
- };
46
- };
47
- };
48
- export default config;
11
+ export declare const config: NuxtConfig;
12
+ export declare function getServerConfig(nitro: NuxtConfig["nitro"]): NuxtConfig;
13
+ export default getServerConfig;
@@ -1,34 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.config = void 0;
4
+ exports.getServerConfig = getServerConfig;
4
5
  const fs_extra_1 = require("fs-extra");
5
6
  const path_1 = require("path");
6
- // @ts-ignore
7
- const api_1 = require("../../../vue/composables/api/api");
8
7
  const cwd = process.cwd();
9
8
  const serverConfig = (0, fs_extra_1.readJSONSync)((0, path_1.resolve)(cwd, `server.config.json`));
10
- /**
11
- * 处理基础路径,去除协议和域名部分,只保留路径部分
12
- * 例如,将 "https://example.com/api-go" 转换为 "/api-go"
13
- *
14
- */
15
- const thisBasePath = api_1.BASE_PATH.replace(/^https?:[/]{2}[^/]+/, "");
16
- /**
17
- * 定义代理目标 URL
18
- * 拼接本地服务器的地址和处理后的基础路径,用于开发环境的代理
19
- * 例如,当 Gin 服务器端口为 8099 时,目标 URL 可能为 "http://localhost:8099/api-go"
20
- */
21
- const target = `http://localhost:${serverConfig.ginPort}${thisBasePath}`;
22
9
  exports.config = {
23
10
  ssr: false,
24
11
  app: { baseURL: serverConfig.baseUrl },
25
12
  devServer: { port: serverConfig.nuxtPort },
26
13
  experimental: { payloadExtraction: false },
27
- nitro: {
28
- devProxy: {
29
- [thisBasePath]: { target, changeOrigin: true },
30
- },
31
- },
32
14
  vite: {
33
15
  esbuild: { jsxFactory: "h", jsxFragment: "Fragment" },
34
16
  },
@@ -39,4 +21,10 @@ exports.config = {
39
21
  },
40
22
  },
41
23
  };
42
- exports.default = exports.config;
24
+ function getServerConfig(nitro) {
25
+ return {
26
+ ...exports.config,
27
+ nitro,
28
+ };
29
+ }
30
+ exports.default = getServerConfig;
package/src/pack.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -57,26 +48,22 @@ function writeScriptFiles() {
57
48
  /**
58
49
  * 打包文件为7z格式
59
50
  */
60
- function pack() {
61
- return __awaiter(this, void 0, void 0, function* () {
51
+ async function pack() {
52
+ fs_extra_1.default.removeSync(p(DIST_PACKAGE));
53
+ fs_extra_1.default.removeSync(p(_7Z_PATH));
54
+ copyFiles();
55
+ writeScriptFiles();
56
+ fs_extra_1.default.outputJSONSync(p(PACKAGE_JSON), PACKAGE_JSON_CONTENT, { spaces: 2 });
57
+ _7zip_min_1.default.pack(p(DIST_PACKAGE), p(_7Z_PATH), () => {
62
58
  fs_extra_1.default.removeSync(p(DIST_PACKAGE));
63
- fs_extra_1.default.removeSync(p(_7Z_PATH));
64
- copyFiles();
65
- writeScriptFiles();
66
- fs_extra_1.default.outputJSONSync(p(PACKAGE_JSON), PACKAGE_JSON_CONTENT, { spaces: 2 });
67
- _7zip_min_1.default.pack(p(DIST_PACKAGE), p(_7Z_PATH), () => {
68
- fs_extra_1.default.removeSync(p(DIST_PACKAGE));
69
- });
70
59
  });
71
60
  }
72
61
  /**
73
62
  * 先generate,让后打包
74
63
  */
75
- function buildAndPack() {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- yield (0, builder_1.default)();
78
- yield pack();
79
- console.log(chalk_1.default.bgGreen("打包完成!", _7Z_PATH));
80
- });
64
+ async function buildAndPack() {
65
+ await (0, builder_1.default)();
66
+ await pack();
67
+ console.log(chalk_1.default.bgGreen("打包完成!", _7Z_PATH));
81
68
  }
82
69
  exports.default = buildAndPack;