@minus-ai/dev-vite-plugin 0.1.0-beta.1

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.
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/cleanup.ts
4
+ import { existsSync, readFileSync, writeFileSync, unlinkSync, mkdirSync } from "node:fs";
5
+ import { join, resolve } from "node:path";
6
+ var PID_FILE = ".minus/dev.pid";
7
+ function killOldProcess(pidFile) {
8
+ if (!existsSync(pidFile)) return;
9
+ let pid;
10
+ try {
11
+ pid = parseInt(readFileSync(pidFile, "utf8").trim(), 10);
12
+ } catch {
13
+ return;
14
+ }
15
+ if (!pid || pid <= 0) return;
16
+ try {
17
+ process.kill(pid, 0);
18
+ } catch {
19
+ try {
20
+ unlinkSync(pidFile);
21
+ } catch {
22
+ }
23
+ return;
24
+ }
25
+ console.log(`[minus-dev] killing residual dev server (PID ${pid})`);
26
+ try {
27
+ process.kill(-pid, "SIGTERM");
28
+ } catch {
29
+ try {
30
+ process.kill(pid, "SIGTERM");
31
+ } catch {
32
+ }
33
+ }
34
+ const deadline = Date.now() + 3e3;
35
+ while (Date.now() < deadline) {
36
+ try {
37
+ process.kill(pid, 0);
38
+ } catch {
39
+ break;
40
+ }
41
+ const wait = Date.now() + 100;
42
+ while (Date.now() < wait) {
43
+ }
44
+ }
45
+ try {
46
+ process.kill(-pid, "SIGKILL");
47
+ } catch {
48
+ try {
49
+ process.kill(pid, "SIGKILL");
50
+ } catch {
51
+ }
52
+ }
53
+ try {
54
+ unlinkSync(pidFile);
55
+ } catch {
56
+ }
57
+ console.log("[minus-dev] cleanup done");
58
+ }
59
+ function writePid(projectDir) {
60
+ const dir = join(projectDir, ".minus");
61
+ mkdirSync(dir, { recursive: true });
62
+ writeFileSync(join(projectDir, PID_FILE), String(process.pid) + "\n");
63
+ }
64
+ function cleanupDev(projectDir) {
65
+ const dir = resolve(projectDir ?? process.cwd());
66
+ killOldProcess(join(dir, PID_FILE));
67
+ }
68
+ if (process.argv[1]?.endsWith("minus-dev-cleanup") || process.argv[1]?.endsWith("cleanup.ts") || process.argv[1]?.endsWith("cleanup.js")) {
69
+ cleanupDev();
70
+ }
71
+ export {
72
+ cleanupDev,
73
+ writePid
74
+ };