Skip to content

Commit 28604a3

Browse files
committed
chore: format code
1 parent c56b206 commit 28604a3

1 file changed

Lines changed: 28 additions & 28 deletions

File tree

index.js

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ if (ports.length === 0) {
1717
}
1818

1919
const findPidCommand = port => process.platform === 'win32'
20-
? `netstat -ano | findstr :${port}`
21-
: `lsof -i:${port} -t`;
20+
? `netstat -ano | findstr :${port}`
21+
: `lsof -i:${port} -t`;
2222

2323
const killCommand = pid => process.platform === 'win32'
24-
? `taskkill /PID ${pid} /F`
25-
: `kill -9 ${pid}`;
24+
? `taskkill /PID ${pid} /F`
25+
: `kill -9 ${pid}`;
2626

2727
const findAndKillProcess = (port) => {
2828
return new Promise((resolve, reject) => {
@@ -34,11 +34,11 @@ const findAndKillProcess = (port) => {
3434
}
3535

3636
const pids = process.platform === 'win32'
37-
? stdout
38-
.split('\n')
39-
.filter(line => line.includes('LISTEN'))
40-
.map(line => line.trim().split(/\s+/))
41-
: stdout.split('\n').map(line => line.trim()).filter(line => line);
37+
? stdout
38+
.split('\n')
39+
.filter(line => line.includes('LISTEN'))
40+
.map(line => line.trim().split(/\s+/))
41+
: stdout.split('\n').map(line => line.trim()).filter(line => line);
4242

4343
if (pids.length === 0) {
4444
resolve(`No process found on port ${port}`);
@@ -48,30 +48,30 @@ const findAndKillProcess = (port) => {
4848
console.log(`Processes on port ${port} have PIDs: ${pids.join(', ')}`);
4949

5050
Promise.all(
51-
pids.map(pid =>
52-
new Promise((killResolve, killReject) => {
53-
exec(killCommand(pid), (killErr, killStdout, killStderr) => {
54-
if (killErr || killStderr) {
55-
killReject(`Error killing process ${pid}: ${killErr || killStderr}`);
56-
return;
57-
}
58-
killResolve(`Process ${pid} killed successfully on port ${port}.`);
59-
});
60-
})
61-
)
51+
pids.map(pid =>
52+
new Promise((killResolve, killReject) => {
53+
exec(killCommand(pid), (killErr, killStdout, killStderr) => {
54+
if (killErr || killStderr) {
55+
killReject(`Error killing process ${pid}: ${killErr || killStderr}`);
56+
return;
57+
}
58+
killResolve(`Process ${pid} killed successfully on port ${port}.`);
59+
});
60+
})
61+
)
6262
)
63-
.then(killResults => resolve(killResults.join('\n')))
64-
.catch(killErr => reject(killErr));
63+
.then(killResults => resolve(killResults.join('\n')))
64+
.catch(killErr => reject(killErr));
6565
});
6666
});
6767
};
6868

6969

7070
// 并行处理所有端口
7171
Promise.all(ports.map(findAndKillProcess))
72-
.then(results => {
73-
results.forEach(result => console.log(result));
74-
})
75-
.catch(err => {
76-
console.error(err);
77-
});
72+
.then(results => {
73+
results.forEach(result => console.log(result));
74+
})
75+
.catch(err => {
76+
console.error(err);
77+
});

0 commit comments

Comments
 (0)