nuxt-gin-tools 0.2.5 → 0.2.6
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/dev-go.js +7 -6
package/package.json
CHANGED
package/src/dev-go.js
CHANGED
|
@@ -23,6 +23,7 @@ const cwd = process.cwd();
|
|
|
23
23
|
const RESTART_DEBOUNCE_MS = 150;
|
|
24
24
|
const SHUTDOWN_TIMEOUT_MS = 2000;
|
|
25
25
|
const LOG_TAG = "go-watch";
|
|
26
|
+
const GO_WATCH_PREFIX = chalk_1.default.bgMagenta.white(`[${LOG_TAG}]`);
|
|
26
27
|
const serverConfigPath = (0, path_1.join)(cwd, "server.config.json");
|
|
27
28
|
const ginPort = getGinPort();
|
|
28
29
|
function getGinPort() {
|
|
@@ -96,7 +97,7 @@ function loadWatchConfig() {
|
|
|
96
97
|
parsedConfig = JSON.parse((0, fs_extra_1.readFileSync)(configPath, "utf-8"));
|
|
97
98
|
}
|
|
98
99
|
catch (_j) {
|
|
99
|
-
console.warn(
|
|
100
|
+
console.warn(`${GO_WATCH_PREFIX} invalid watch config JSON, fallback to defaults: ${configPath}`);
|
|
100
101
|
return defaultConfig;
|
|
101
102
|
}
|
|
102
103
|
const includeExt = toStringArray((_a = parsedConfig.includeExt) !== null && _a !== void 0 ? _a : parsedConfig.include_ext)
|
|
@@ -183,7 +184,7 @@ function quote(arg) {
|
|
|
183
184
|
function runGoProcess() {
|
|
184
185
|
const command = `go run ${quote("main.go")}`;
|
|
185
186
|
killGinPortIfNeeded();
|
|
186
|
-
console.log(
|
|
187
|
+
console.log(`${GO_WATCH_PREFIX} start: ${command}`);
|
|
187
188
|
return (0, child_process_1.spawn)(command, {
|
|
188
189
|
cwd,
|
|
189
190
|
shell: true,
|
|
@@ -240,7 +241,7 @@ function startGoDev() {
|
|
|
240
241
|
const watchRoots = watchConfig.includeDir.length
|
|
241
242
|
? watchConfig.includeDir.map((dir) => (0, path_1.join)(cwd, dir))
|
|
242
243
|
: [cwd];
|
|
243
|
-
console.log(
|
|
244
|
+
console.log(`${GO_WATCH_PREFIX} watching: ${watchRoots.map((item) => toProjectRelative(item)).join(", ")}`);
|
|
244
245
|
let restarting = false;
|
|
245
246
|
let goProc = runGoProcess();
|
|
246
247
|
let restartTimer = null;
|
|
@@ -265,7 +266,7 @@ function startGoDev() {
|
|
|
265
266
|
return;
|
|
266
267
|
}
|
|
267
268
|
restarting = true;
|
|
268
|
-
console.log(
|
|
269
|
+
console.log(`${GO_WATCH_PREFIX} ${eventName}: ${relPath}, restarting...`);
|
|
269
270
|
yield stopGoProcess(goProc);
|
|
270
271
|
goProc = runGoProcess();
|
|
271
272
|
restarting = false;
|
|
@@ -276,7 +277,7 @@ function startGoDev() {
|
|
|
276
277
|
.on("change", (filePath) => triggerRestart("change", filePath))
|
|
277
278
|
.on("unlink", (filePath) => triggerRestart("unlink", filePath))
|
|
278
279
|
.on("error", (error) => {
|
|
279
|
-
console.error(
|
|
280
|
+
console.error(`${GO_WATCH_PREFIX} watcher error: ${String(error)}`);
|
|
280
281
|
});
|
|
281
282
|
const shutdown = () => __awaiter(this, void 0, void 0, function* () {
|
|
282
283
|
if (restartTimer) {
|
|
@@ -299,7 +300,7 @@ function startGoDev() {
|
|
|
299
300
|
if (require.main === module) {
|
|
300
301
|
// 兼容直接执行该文件(例如 node src/dev-go.js)。
|
|
301
302
|
startGoDev().catch((error) => {
|
|
302
|
-
console.error(
|
|
303
|
+
console.error(`${GO_WATCH_PREFIX} failed to start: ${String(error)}`);
|
|
303
304
|
process.exit(1);
|
|
304
305
|
});
|
|
305
306
|
}
|