forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use detect-port to check if 3000 is already used.
Based on create-react-app and specifically facebook/create-react-app#101
- Loading branch information
Showing
6 changed files
with
43 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import rl from 'readline'; | ||
|
||
export default function (question) { | ||
const rlInterface = rl.createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}); | ||
|
||
return new Promise((resolve) => { | ||
rlInterface.question(question + '\n', function(answer) { | ||
rlInterface.close(); | ||
resolve(answer); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import prompt from './prompt'; | ||
import detect from 'detect-port'; | ||
import chalk from 'chalk'; | ||
|
||
export default async function run(srv, desiredPort) { | ||
const port = await detect(desiredPort); | ||
if (port !== desiredPort) { | ||
const question = chalk.red(`Something is already running at port ${desiredPort}.\n` + | ||
`Would you like to run the app on port ${port} instead? [Y/n]`); | ||
const answer = await prompt(question); | ||
const shouldChangePort = (answer.length === 0 || answer.match(/^yes|y$/i)); | ||
if (!shouldChangePort) { | ||
console.log(chalk.red('Exiting.')); | ||
process.exit(0); | ||
} | ||
} | ||
await srv.start(port); | ||
console.log(`Ready on ${chalk.cyan(`http://localhost:${port}`)}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters