Filipe Silva d2bef98bb9 feat(@angular/cli): ng e2e defaults to random port (#4753)
BREAKING CHANGE: `ng e2e` will use a random port for serving by default
instead of using 4200.
2017-02-17 19:53:22 +00:00

25 lines
685 B
TypeScript

import * as denodeify from 'denodeify';
const SilentError = require('silent-error');
const PortFinder = require('portfinder');
const getPort = <any>denodeify(PortFinder.getPort);
PortFinder.basePort = 49152;
export function checkPort(port: number, host: string) {
return getPort({ port, host })
.then((foundPort: number) => {
// 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;
});
}