Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: reserve free ports for main and fiori (#3008)
- Loading branch information
1 parent
abcdee6
commit 55d029c
Showing
14 changed files
with
93 additions
and
59 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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
const fs = require("fs"); | ||
const packageFile = JSON.parse(fs.readFileSync(require.resolve("@ui5/webcomponents-fiori/package.json"))); | ||
module.exports = packageFile.ui5.port; | ||
const portFilePath = require.resolve("@ui5/webcomponents-fiori/.port"); | ||
const port = `${fs.readFileSync(portFilePath)}`; | ||
|
||
module.exports = 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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
const fs = require("fs"); | ||
const packageFile = JSON.parse(fs.readFileSync(require.resolve("@ui5/webcomponents/package.json"))); | ||
module.exports = packageFile.ui5.port; | ||
const portFilePath = require.resolve("@ui5/webcomponents/.port"); | ||
const port = `${fs.readFileSync(portFilePath)}`; | ||
|
||
module.exports = 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
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,46 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const commandLineArgs = require("command-line-args"); | ||
const { exec } = require("child_process"); | ||
const colors = require("colors/safe"); | ||
const isPortReachable = require("is-port-reachable"); | ||
|
||
const options = commandLineArgs([ | ||
{ name: "port", type: Number }, | ||
{ name: "portStep", type: Number }, | ||
{ name: "packageName", type: String }, | ||
{ name: "dir", type: String }, | ||
{ name: "config", type: String }, | ||
]); | ||
const serveConfig = path.join(__dirname, `serve.json`); | ||
|
||
const requestPort = async () => { | ||
const serveProcess = (await gen.next()).value; | ||
serveProcess.stdout.on('data', data => { | ||
const matches = data.match(/Accepting connections at .*?:(\d+)/); | ||
if (matches) { | ||
console.log(colors.yellow(`Reserved port ${matches[1]} for the ${options.packageName} package.`)); | ||
fs.writeFileSync(".port", matches[1]); | ||
} | ||
}); | ||
}; | ||
|
||
async function* serverGenerator(callback, port = 8080, step = 1) { | ||
while (true) { | ||
const portInUse = await isPortReachable(port, { host: "127.0.0.1" }); | ||
if (!portInUse) { | ||
const command = `serve --config "${serveConfig}" --no-port-switching --no-clipboard -l ${port} ${options.dir}`; | ||
console.log(colors.yellow(`Executing: ${command}`)); | ||
const serveProcess = exec(command, (err) => { | ||
console.log(colors.yellow(`Port ${port} already in use.`)); | ||
callback(); | ||
}); | ||
yield serveProcess; | ||
} | ||
port += step; | ||
} | ||
} | ||
|
||
const gen = serverGenerator(requestPort, options.port, options.portStep); | ||
|
||
requestPort(); |
File renamed without changes.
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