From 797104fd36cbf72df97c9431515bd963a6dda4d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 17 Jun 2024 14:47:35 +0200 Subject: [PATCH] More PR review changes --- templates/cli/lib/commands/run.js.twig | 22 ++++++++++--- templates/cli/lib/questions.js.twig | 45 +------------------------- 2 files changed, 19 insertions(+), 48 deletions(-) diff --git a/templates/cli/lib/commands/run.js.twig b/templates/cli/lib/commands/run.js.twig index 1a100c8ed..cf0981e66 100644 --- a/templates/cli/lib/commands/run.js.twig +++ b/templates/cli/lib/commands/run.js.twig @@ -49,14 +49,28 @@ const runFunction = async ({ port, functionId, noVariables, noReload, userId } = const taken = await isPortTaken(port); if(taken) { - log(`Port ${port} is already in use by another process.`); - port = null; + error(`Port ${port} is already in use by another process.`); + return; } } if(!port) { - const answers = await inquirer.prompt(questionsRunFunctions[1]); - port = answers.port; + let portFound = fale; + port = 3000; + while(port < 3100) { + const taken = await isPortTaken(port); + if(!taken) { + portFound = true; + break; + } + + port++; + } + + if(!portFound) { + error('Could not auto-suggest an available port. Please configure port with `appwrite run --port YOUR_PORT` command.'); + return; + } } // Configuration: Engine diff --git a/templates/cli/lib/questions.js.twig b/templates/cli/lib/questions.js.twig index c0843fcd7..17417a3b6 100644 --- a/templates/cli/lib/questions.js.twig +++ b/templates/cli/lib/questions.js.twig @@ -791,50 +791,7 @@ const questionsRunFunctions = [ }) return choices; } - }, - { - type: "input", - name: "port", - message: 'Which port would you like function to listen on?', - default: async () => { - let port = 3000; - while(port < 3100) { - const taken = await isPortTaken(port); - if(!taken) { - return port; - } - - port++; - } - - return 3000; - }, - validate: function(value) { - const done = this.async(); - - (async () => { - if (typeof value !== 'number' && isNaN(+value)) { - throw Error(`Port needs to be a valid integer between 1024 and 65536.`); - } - - value = +value; - - if(value < 1024 || value > 65536) { - throw Error(`Port needs to be a valid integer between 1024 and 65536.`); - } - - const taken = await isPortTaken(value); - - if(taken) { - throw Error(`Port ${value} is in use by another process. Pick a different one.`); - } - })().then(() => { - done(null, true); - }).catch((err) => { - done(err.message); - }); - }, - }, + } ]; module.exports = {