forked from angular/angular-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-port.ts
More file actions
22 lines (18 loc) · 746 Bytes
/
Copy pathcheck-port.ts
File metadata and controls
22 lines (18 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import * as denodeify from 'denodeify';
const SilentError = require('silent-error');
const PortFinder = require('portfinder');
const getPort = denodeify<{host: string, port: number}, number>(PortFinder.getPort);
export function checkPort(port: number, host: string, basePort = 49152): Promise<number> {
PortFinder.basePort = basePort;
return getPort({ port, host })
.then(foundPort => {
// If the port isn't available and we weren't looking for any port, throw error.
if (port !== foundPort && port !== 0) {
throw new SilentError(
`Port ${port} is already in use. Use '--port' to specify a different port.`
);
}
// Otherwise, our found port is good.
return foundPort;
});
}