nuxt-gin-tools 0.2.6 → 0.2.7
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/index.js +42 -1
- package/package.json +1 -1
- package/src/develop.d.ts +12 -0
- package/src/develop.js +65 -24
- package/src/nuxt-config.js +16 -2
package/index.js
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
3
36
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
38
|
};
|
|
@@ -8,7 +41,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
8
41
|
// 导入构建和打包功能
|
|
9
42
|
const pack_1 = __importDefault(require("./src/pack"));
|
|
10
43
|
// 导入开发模式功能
|
|
11
|
-
const develop_1 =
|
|
44
|
+
const develop_1 = __importStar(require("./src/develop"));
|
|
12
45
|
// 导入API生成功能
|
|
13
46
|
const api_generate_1 = __importDefault(require("./src/api-generate"));
|
|
14
47
|
// 导入安装后处理功能
|
|
@@ -30,6 +63,14 @@ switch (args[0]) {
|
|
|
30
63
|
// 启动开发模式
|
|
31
64
|
(0, develop_1.default)();
|
|
32
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;
|
|
33
74
|
case "build":
|
|
34
75
|
// 执行构建和打包操作
|
|
35
76
|
(0, pack_1.default)();
|
package/package.json
CHANGED
package/src/develop.d.ts
CHANGED
|
@@ -6,4 +6,16 @@
|
|
|
6
6
|
* @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
|
|
7
7
|
*/
|
|
8
8
|
export declare function develop(): Promise<void>;
|
|
9
|
+
/**
|
|
10
|
+
* 仅启动 Nuxt 开发服务(带 nuxt 标签输出)。
|
|
11
|
+
*
|
|
12
|
+
* @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
|
|
13
|
+
*/
|
|
14
|
+
export declare function developNuxt(): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* 仅启动 Go 开发监听流程。
|
|
17
|
+
*
|
|
18
|
+
* @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
|
|
19
|
+
*/
|
|
20
|
+
export declare function developGo(): Promise<void>;
|
|
9
21
|
export default develop;
|
package/src/develop.js
CHANGED
|
@@ -13,6 +13,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.develop = develop;
|
|
16
|
+
exports.developNuxt = developNuxt;
|
|
17
|
+
exports.developGo = developGo;
|
|
16
18
|
const concurrently_1 = __importDefault(require("concurrently"));
|
|
17
19
|
const fs_extra_1 = require("fs-extra");
|
|
18
20
|
const path_1 = require("path");
|
|
@@ -22,6 +24,37 @@ const dev_go_1 = require("./dev-go");
|
|
|
22
24
|
const utils_1 = require("./utils");
|
|
23
25
|
const cwd = process.cwd();
|
|
24
26
|
const serverConfig = (0, fs_extra_1.readJSONSync)((0, path_1.join)(cwd, "server.config.json"));
|
|
27
|
+
function prepareDevelop() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const cleanupBeforeDevelop = serverConfig.cleanupBeforeDevelop === true;
|
|
30
|
+
if (cleanupBeforeDevelop) {
|
|
31
|
+
yield (0, cleanup_1.default)();
|
|
32
|
+
yield (0, postinstall_1.default)();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (!(0, fs_extra_1.existsSync)((0, path_1.join)(cwd, "vue/.nuxt")) || !(0, fs_extra_1.existsSync)((0, path_1.join)(cwd, "go.sum"))) {
|
|
36
|
+
yield (0, cleanup_1.default)();
|
|
37
|
+
yield (0, postinstall_1.default)();
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function runNuxtDev() {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
yield (0, concurrently_1.default)([
|
|
44
|
+
{
|
|
45
|
+
command: `npx nuxt dev --port=${serverConfig.nuxtPort} --host`,
|
|
46
|
+
name: "nuxt",
|
|
47
|
+
prefixColor: "blue",
|
|
48
|
+
},
|
|
49
|
+
]).result;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
function runGoDev() {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
(0, fs_extra_1.ensureDirSync)((0, path_1.join)(cwd, ".build/.server"));
|
|
55
|
+
yield (0, dev_go_1.startGoDev)();
|
|
56
|
+
});
|
|
57
|
+
}
|
|
25
58
|
/**
|
|
26
59
|
* 启动本地开发环境。
|
|
27
60
|
*
|
|
@@ -31,35 +64,43 @@ const serverConfig = (0, fs_extra_1.readJSONSync)((0, path_1.join)(cwd, "server.
|
|
|
31
64
|
*/
|
|
32
65
|
function develop() {
|
|
33
66
|
return __awaiter(this, void 0, void 0, function* () {
|
|
34
|
-
const cleanupBeforeDevelop = serverConfig.cleanupBeforeDevelop === true;
|
|
35
67
|
const killPortBeforeDevelop = serverConfig.killPortBeforeDevelop !== false;
|
|
36
|
-
|
|
37
|
-
if (cleanupBeforeDevelop) {
|
|
38
|
-
yield (0, cleanup_1.default)();
|
|
39
|
-
yield (0, postinstall_1.default)();
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
// 否则仅在关键依赖缺失时执行
|
|
43
|
-
if (!(0, fs_extra_1.existsSync)((0, path_1.join)(cwd, "vue/.nuxt")) || !(0, fs_extra_1.existsSync)((0, path_1.join)(cwd, "go.sum"))) {
|
|
44
|
-
yield (0, cleanup_1.default)();
|
|
45
|
-
yield (0, postinstall_1.default)();
|
|
46
|
-
}
|
|
47
|
-
}
|
|
68
|
+
yield prepareDevelop();
|
|
48
69
|
// 在开发前确保占用端口被释放
|
|
49
70
|
if (killPortBeforeDevelop) {
|
|
50
71
|
(0, utils_1.killPorts)([serverConfig.ginPort, serverConfig.nuxtPort]);
|
|
51
72
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
73
|
+
yield Promise.all([runGoDev(), runNuxtDev()]);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 仅启动 Nuxt 开发服务(带 nuxt 标签输出)。
|
|
78
|
+
*
|
|
79
|
+
* @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
|
|
80
|
+
*/
|
|
81
|
+
function developNuxt() {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const killPortBeforeDevelop = serverConfig.killPortBeforeDevelop !== false;
|
|
84
|
+
yield prepareDevelop();
|
|
85
|
+
if (killPortBeforeDevelop) {
|
|
86
|
+
(0, utils_1.killPorts)([serverConfig.nuxtPort]);
|
|
87
|
+
}
|
|
88
|
+
yield runNuxtDev();
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 仅启动 Go 开发监听流程。
|
|
93
|
+
*
|
|
94
|
+
* @returns {Promise<void>} 仅在开发进程退出或出现异常时返回。
|
|
95
|
+
*/
|
|
96
|
+
function developGo() {
|
|
97
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
+
const killPortBeforeDevelop = serverConfig.killPortBeforeDevelop !== false;
|
|
99
|
+
yield prepareDevelop();
|
|
100
|
+
if (killPortBeforeDevelop) {
|
|
101
|
+
(0, utils_1.killPorts)([serverConfig.ginPort]);
|
|
102
|
+
}
|
|
103
|
+
yield runGoDev();
|
|
63
104
|
});
|
|
64
105
|
}
|
|
65
106
|
exports.default = develop;
|
package/src/nuxt-config.js
CHANGED
|
@@ -30,13 +30,16 @@ function createDefaultConfig({ serverConfig, apiBasePath }) {
|
|
|
30
30
|
* 例如,将 "https://example.com/api-go" 转换为 "/api-go"
|
|
31
31
|
*/
|
|
32
32
|
const thisBasePath = apiBasePath.replace(/^https?:[/]{2}[^/]+/, "");
|
|
33
|
+
const normalizedProxyBasePath = thisBasePath.endsWith("/")
|
|
34
|
+
? thisBasePath.slice(0, -1)
|
|
35
|
+
: thisBasePath;
|
|
33
36
|
/**
|
|
34
37
|
* 目标服务器的 URL
|
|
35
38
|
* 格式为:http://localhost:ginPort/serverBasePath
|
|
36
39
|
* 其中,ginPort 是从 serverConfig 中获取的 Gin 服务器的端口号
|
|
37
40
|
* serverBasePath 是从 MyNuxtConfig 中获取的服务器基础路径
|
|
38
41
|
*/
|
|
39
|
-
const target = `http://localhost:${serverConfig.ginPort}${
|
|
42
|
+
const target = `http://localhost:${serverConfig.ginPort}${normalizedProxyBasePath}`;
|
|
40
43
|
return {
|
|
41
44
|
buildDir: "vue/.nuxt", // 设置构建目录为 "vue/.nuxt",表示 Nuxt 项目的构建输出将存放在该目录下
|
|
42
45
|
srcDir: "vue", // 设置源代码目录为 "vue",表示 Nuxt 项目的源代码将存放在该目录下
|
|
@@ -85,15 +88,26 @@ function createDefaultConfig({ serverConfig, apiBasePath }) {
|
|
|
85
88
|
},
|
|
86
89
|
devProxy: {
|
|
87
90
|
// 定义代理规则,将匹配 thisBasePath 的请求代理到目标服务器
|
|
88
|
-
[
|
|
91
|
+
[normalizedProxyBasePath]: {
|
|
89
92
|
// 目标服务器的 URL
|
|
90
93
|
target: target,
|
|
91
94
|
// 是否改变请求的源,设置为 true 可以避免跨域问题
|
|
92
95
|
changeOrigin: true,
|
|
96
|
+
// 启用 WebSocket 代理
|
|
97
|
+
ws: true,
|
|
93
98
|
},
|
|
94
99
|
},
|
|
95
100
|
},
|
|
96
101
|
vite: {
|
|
102
|
+
server: {
|
|
103
|
+
proxy: {
|
|
104
|
+
[normalizedProxyBasePath]: {
|
|
105
|
+
target,
|
|
106
|
+
changeOrigin: true,
|
|
107
|
+
ws: true,
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
97
111
|
// 配置 Vite 插件
|
|
98
112
|
plugins: [],
|
|
99
113
|
// 配置 esbuild 编译器的选项
|