1 | "use strict";
|
2 |
|
3 | const detectPort = require(`detect-port`);
|
4 |
|
5 | const report = require(`gatsby-cli/lib/reporter`);
|
6 |
|
7 | const prompts = require(`prompts`);
|
8 |
|
9 | const detectPortInUseAndPrompt = async port => {
|
10 | let foundPort = port;
|
11 | const detectedPort = await detectPort(port).catch(err => report.panic(err));
|
12 |
|
13 | if (port !== detectedPort) {
|
14 | report.log(`\nSomething is already running at port ${port}`);
|
15 | const response = await prompts({
|
16 | type: `confirm`,
|
17 | name: `newPort`,
|
18 | message: `Would you like to run the app at another port instead?`,
|
19 | initial: true
|
20 | });
|
21 |
|
22 | if (response.newPort) {
|
23 | foundPort = detectedPort;
|
24 | } else {
|
25 | throw new Error(`USER_REJECTED`);
|
26 | }
|
27 | }
|
28 |
|
29 | return foundPort;
|
30 | };
|
31 |
|
32 | module.exports = detectPortInUseAndPrompt;
|
33 |
|
\ | No newline at end of file |