-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathpre-start.cjs
More file actions
87 lines (75 loc) · 2.83 KB
/
pre-start.cjs
File metadata and controls
87 lines (75 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const { execSync } = require('child_process');
// Get git hash with fallback
const getGitHash = () => {
try {
return execSync('git rev-parse --short HEAD').toString().trim();
} catch {
return 'no-git-info';
}
};
// ---------------------------------------------------------------------------
// Kill any stale process occupying the dev port so restarts are clean.
// ---------------------------------------------------------------------------
const DEV_PORT = Number(process.env.PORT) || 5173;
function killStalePortProcess(port) {
const isWin = process.platform === 'win32';
try {
if (isWin) {
// netstat output: " TCP 0.0.0.0:5173 0.0.0.0:0 LISTENING 12345"
const out = execSync(`netstat -ano | findstr :${port} | findstr LISTENING`, {
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'pipe'],
});
const pids = new Set();
for (const line of out.trim().split('\n')) {
const parts = line.trim().split(/\s+/);
const pid = parseInt(parts[parts.length - 1], 10);
if (pid && pid !== process.pid) {
pids.add(pid);
}
}
for (const pid of pids) {
try {
execSync(`taskkill /PID ${pid} /F`, { stdio: 'pipe' });
console.log(`🧹 Killed stale process on port ${port} (PID ${pid})`);
} catch {
// Process may have already exited — ignore
}
}
} else {
// Unix: lsof gives clean PID output
const out = execSync(`lsof -ti tcp:${port}`, {
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'pipe'],
});
for (const pidStr of out.trim().split('\n')) {
const pid = parseInt(pidStr, 10);
if (pid && pid !== process.pid) {
try {
process.kill(pid, 'SIGTERM');
console.log(`🧹 Killed stale process on port ${port} (PID ${pid})`);
} catch {
// Process may have already exited — ignore
}
}
}
}
} catch {
// No process found on port — nothing to clean up (this is the happy path)
}
}
killStalePortProcess(DEV_PORT);
let commitJson = {
hash: JSON.stringify(getGitHash()),
version: JSON.stringify(process.env.npm_package_version),
};
console.log(`
★═══════════════════════════════════════★
D E V O N Z
⚡️ Welcome ⚡️
★═══════════════════════════════════════★
`);
console.log('📍 Current Version Tag:', `v${commitJson.version}`);
console.log('📍 Current Commit Version:', commitJson.hash);
console.log(' Please wait until the URL appears here');
console.log('★═══════════════════════════════════════★');