nuxt-gin-tools 0.1.21 → 0.1.22
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 +1 -1
- package/src/develop.js +111 -3
- package/src/server-config.json +11 -1
package/package.json
CHANGED
package/src/develop.js
CHANGED
|
@@ -17,6 +17,8 @@ const concurrently_1 = __importDefault(require("concurrently"));
|
|
|
17
17
|
const fs_extra_1 = require("fs-extra");
|
|
18
18
|
const os_1 = __importDefault(require("os"));
|
|
19
19
|
const path_1 = require("path");
|
|
20
|
+
const child_process_1 = require("child_process");
|
|
21
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
20
22
|
const cleanup_1 = __importDefault(require("./cleanup"));
|
|
21
23
|
const postinstall_1 = __importDefault(require("./postinstall"));
|
|
22
24
|
const cwd = process.cwd();
|
|
@@ -36,14 +38,120 @@ function getAirCommand() {
|
|
|
36
38
|
return "air -c node_modules/nuxt-gin-tools/.air.toml";
|
|
37
39
|
}
|
|
38
40
|
}
|
|
41
|
+
function killPort(port) {
|
|
42
|
+
if (!Number.isInteger(port)) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
try {
|
|
46
|
+
const output = (0, child_process_1.execSync)(`lsof -ti tcp:${port}`, {
|
|
47
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
48
|
+
})
|
|
49
|
+
.toString()
|
|
50
|
+
.trim();
|
|
51
|
+
if (!output) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const pids = output
|
|
55
|
+
.split("\n")
|
|
56
|
+
.map((pid) => Number(pid.trim()))
|
|
57
|
+
.filter((pid) => Number.isInteger(pid) && pid > 0);
|
|
58
|
+
for (const pid of pids) {
|
|
59
|
+
try {
|
|
60
|
+
process.kill(pid, "SIGKILL");
|
|
61
|
+
console.log(chalk_1.default.yellow(`Killed process ${pid} on port ${port} (unix)`));
|
|
62
|
+
}
|
|
63
|
+
catch (_a) {
|
|
64
|
+
// Best-effort: if the process is already gone, ignore.
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (_b) {
|
|
69
|
+
// Best-effort: lsof might be missing or no process is listening on the port.
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function killPortWindows(port) {
|
|
73
|
+
if (!Number.isInteger(port)) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const output = (0, child_process_1.execSync)(`netstat -ano -p tcp`, {
|
|
78
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
79
|
+
})
|
|
80
|
+
.toString()
|
|
81
|
+
.trim();
|
|
82
|
+
if (!output) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const pids = new Set();
|
|
86
|
+
for (const line of output.split("\n")) {
|
|
87
|
+
const trimmed = line.trim();
|
|
88
|
+
if (!trimmed || !trimmed.startsWith("TCP")) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const parts = trimmed.split(/\s+/);
|
|
92
|
+
if (parts.length < 5) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const localAddress = parts[1];
|
|
96
|
+
const pid = Number(parts[parts.length - 1]);
|
|
97
|
+
const match = localAddress.match(/:(\d+)$/);
|
|
98
|
+
if (!match) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const localPort = Number(match[1]);
|
|
102
|
+
if (localPort === port && Number.isInteger(pid) && pid > 0) {
|
|
103
|
+
pids.add(pid);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
for (const pid of pids) {
|
|
107
|
+
try {
|
|
108
|
+
(0, child_process_1.execSync)(`taskkill /PID ${pid} /F`, {
|
|
109
|
+
stdio: ["ignore", "ignore", "ignore"],
|
|
110
|
+
});
|
|
111
|
+
console.log(chalk_1.default.yellow(`Killed process ${pid} on port ${port} (win32)`));
|
|
112
|
+
}
|
|
113
|
+
catch (_a) {
|
|
114
|
+
// Best-effort: if the process is already gone, ignore.
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch (_b) {
|
|
119
|
+
// Best-effort: netstat might be missing or no process is listening on the port.
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
function killPortsFromConfig() {
|
|
123
|
+
const ports = [serverConfig.ginPort, serverConfig.nuxtPort]
|
|
124
|
+
.filter((port) => Number.isInteger(port) && port > 0)
|
|
125
|
+
.filter((port, index, list) => list.indexOf(port) === index);
|
|
126
|
+
for (const port of ports) {
|
|
127
|
+
if (os_1.default.platform() === "win32") {
|
|
128
|
+
killPortWindows(port);
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
killPort(port);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
39
135
|
function develop() {
|
|
40
136
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
137
|
+
const cleanupBeforeDevelop = serverConfig.cleanupBeforeDevelop === true;
|
|
138
|
+
const killPortBeforeDevelop = serverConfig.killPortBeforeDevelop !== false;
|
|
139
|
+
// 如果配置为开发前清理,则直接执行清理和安装后处理
|
|
140
|
+
if (cleanupBeforeDevelop) {
|
|
44
141
|
yield (0, cleanup_1.default)();
|
|
45
142
|
yield (0, postinstall_1.default)();
|
|
46
143
|
}
|
|
144
|
+
else {
|
|
145
|
+
// 否则仅在关键依赖缺失时执行
|
|
146
|
+
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"))) {
|
|
147
|
+
yield (0, cleanup_1.default)();
|
|
148
|
+
yield (0, postinstall_1.default)();
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// 在开发前确保占用端口被释放
|
|
152
|
+
if (killPortBeforeDevelop) {
|
|
153
|
+
killPortsFromConfig();
|
|
154
|
+
}
|
|
47
155
|
(0, fs_extra_1.ensureDirSync)((0, path_1.join)(cwd, ".build/.server"));
|
|
48
156
|
yield (0, concurrently_1.default)([
|
|
49
157
|
{
|
package/src/server-config.json
CHANGED
|
@@ -15,6 +15,16 @@
|
|
|
15
15
|
"title": "The base url for nuxt. / Nuxt的BaseUrl",
|
|
16
16
|
"type": "string",
|
|
17
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
|
|
18
28
|
}
|
|
19
29
|
},
|
|
20
30
|
"required": [
|
|
@@ -22,4 +32,4 @@
|
|
|
22
32
|
"nuxtPort",
|
|
23
33
|
"baseUrl"
|
|
24
34
|
]
|
|
25
|
-
}
|
|
35
|
+
}
|