UNPKG

831 BJavaScriptView Raw
1"use strict";
2
3const detectPort = require(`detect-port`);
4
5const report = require(`gatsby-cli/lib/reporter`);
6
7const prompts = require(`prompts`);
8
9const 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
32module.exports = detectPortInUseAndPrompt;
33//# sourceMappingURL=detect-port-in-use-and-prompt.js.map
\No newline at end of file