1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | const program = require('commander');
|
9 | const chalk = require('chalk');
|
10 | const find = require('find-process');
|
11 |
|
12 | const { version } = require('../package.json');
|
13 |
|
14 | const terminal = chalk.cyan('athena:');
|
15 |
|
16 | function kill(pid, milliseconds) {
|
17 |
|
18 | process.kill(pid);
|
19 |
|
20 |
|
21 | return new Promise((resolve) => setTimeout(resolve, milliseconds));
|
22 | }
|
23 |
|
24 | async function pipeline(port) {
|
25 | try {
|
26 | const matches = await find('port', port);
|
27 | const success = await chalk.magenta(`Machine ${port} free success....`);
|
28 |
|
29 | await Promise.all(matches.map((match) => kill(match.pid, 2500)));
|
30 |
|
31 |
|
32 | console.log(`${terminal} ${success}`);
|
33 |
|
34 | } catch (err) {
|
35 |
|
36 | console.error(err.stack);
|
37 |
|
38 | process.exit(1);
|
39 | }
|
40 | }
|
41 |
|
42 | program
|
43 | .version(version)
|
44 | .usage('<port>')
|
45 | .action(pipeline)
|
46 | .parse(process.argv);
|