prjct-cli 0.11.2 → 0.11.3
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/bin/serve.js +46 -0
- package/package.json +1 -1
package/bin/serve.js
CHANGED
|
@@ -93,6 +93,52 @@ if (needsSharedInstall || needsWebInstall) {
|
|
|
93
93
|
console.log('✅ Dependencies installed!\n')
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
+
// Kill any process using the port
|
|
97
|
+
function killPort(portToKill) {
|
|
98
|
+
try {
|
|
99
|
+
if (process.platform === 'win32') {
|
|
100
|
+
// Windows
|
|
101
|
+
const result = spawnSync('netstat', ['-ano'], { shell: true, encoding: 'utf8' })
|
|
102
|
+
const lines = result.stdout.split('\n')
|
|
103
|
+
for (const line of lines) {
|
|
104
|
+
if (line.includes(`:${portToKill}`) && line.includes('LISTENING')) {
|
|
105
|
+
const parts = line.trim().split(/\s+/)
|
|
106
|
+
const pid = parts[parts.length - 1]
|
|
107
|
+
if (pid && pid !== '0') {
|
|
108
|
+
spawnSync('taskkill', ['/F', '/PID', pid], { shell: true })
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
// macOS / Linux
|
|
114
|
+
const result = spawnSync('lsof', ['-ti', `:${portToKill}`], {
|
|
115
|
+
shell: true,
|
|
116
|
+
encoding: 'utf8',
|
|
117
|
+
})
|
|
118
|
+
const pids = result.stdout.trim().split('\n').filter(Boolean)
|
|
119
|
+
for (const pid of pids) {
|
|
120
|
+
spawnSync('kill', ['-9', pid], { shell: true })
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} catch {
|
|
124
|
+
// Ignore errors - port might not be in use
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Kill port if occupied
|
|
129
|
+
const checkPort = spawnSync('lsof', ['-ti', `:${port}`], {
|
|
130
|
+
shell: true,
|
|
131
|
+
encoding: 'utf8',
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
if (checkPort.stdout.trim()) {
|
|
135
|
+
console.log(`⚠️ Port ${port} is in use. Killing existing process...`)
|
|
136
|
+
killPort(port)
|
|
137
|
+
// Small delay to ensure port is released
|
|
138
|
+
spawnSync('sleep', ['1'], { shell: true })
|
|
139
|
+
console.log(`✅ Port ${port} freed\n`)
|
|
140
|
+
}
|
|
141
|
+
|
|
96
142
|
console.log(`
|
|
97
143
|
╔═══════════════════════════════════════════════════════════╗
|
|
98
144
|
║ ║
|