Skip to content

Commit b6922a6

Browse files
committed
feat: keep suite.json sorted and return next port from sorted json
1 parent 02a0e98 commit b6922a6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

.suite-cli/cli/scripts/scripts.module.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,12 +1318,9 @@ const addProjectConfigs = ({ project_root, answers }) => {
13181318

13191319
// Function to get the next available port
13201320
const getNextAvailablePort = ({ services }) => {
1321-
const usedPorts = services.map(service => service.port);
1322-
let port = 9001;
1323-
while (usedPorts.includes(port)) {
1324-
port++;
1325-
}
1326-
return port;
1321+
const usedPorts = services.map(service => service.port).sort((a, b) => a - b);
1322+
let last_port = usedPorts[usedPorts.length - 1] || 9000
1323+
return last_port + 1;
13271324
};
13281325

13291326
const getExistingServices = ({ currentDir }) => {
@@ -1342,6 +1339,9 @@ const registerServiceWithSuiteJson = ({ root_dir, name, port }) => {
13421339
config.services = [];
13431340
}
13441341
config.services.push({ name, port });
1342+
1343+
// keep the services ordered by port
1344+
config.services.sort((a, b) => a.port - b.port);
13451345
writeFile(configPath, JSON.stringify(config, null, 2), 'utf8');
13461346
}
13471347

0 commit comments

Comments
 (0)