-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(dcellar-web-ui): unavailable sp not placed last, dev startup port…
… auto-increment issue
- Loading branch information
Showing
4 changed files
with
46 additions
and
6 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,40 @@ | ||
#!/usr/bin/env node | ||
|
||
const { execSync } = require('child_process'); | ||
|
||
const args = process.argv.slice(2); | ||
|
||
let port = 3200; // Default port is 3200 | ||
|
||
// Parsing command line arguments | ||
for (let i = 0; i < args.length; i++) { | ||
const arg = args[i]; | ||
if (arg === '-p' || arg === '--port') { | ||
const nextArg = args[i + 1]; | ||
if (nextArg && !isNaN(nextArg)) { | ||
port = parseInt(nextArg, 10); | ||
} else { | ||
console.error('Invalid port number. Please provide a valid port number.'); | ||
process.exit(1); | ||
} | ||
} | ||
} | ||
|
||
function getNextAvailablePort(port) { | ||
const command = `lsof -ti:${port}`; | ||
try { | ||
execSync(command); | ||
return getNextAvailablePort(port + 1); | ||
} catch (error) { | ||
return port; | ||
} | ||
} | ||
|
||
function startNextServer(port) { | ||
const command = `next dev -p ${port}`; | ||
console.log(`Starting Next.js server on port ${port}`); | ||
execSync(command, { stdio: 'inherit' }); | ||
} | ||
|
||
const availablePort = getNextAvailablePort(port); | ||
startNextServer(availablePort); |
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