Skip to content

Commit 02a0e98

Browse files
committed
refactor: clean up code
1 parent 6aed995 commit 02a0e98

File tree

2 files changed

+18
-74
lines changed

2 files changed

+18
-74
lines changed

.suite-cli/cli/cli.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,14 @@ program
173173
// find out if this separater works on windows
174174
// const project_base = `@${answers.repo_name}-${Date.now()}`
175175
const project_base = `@${answers.repo_name}`
176-
actionHandlers.scaffoldNewRepo({ answers: { ...answers, project_base, private: true } });
176+
actionHandlers.scaffoldNewRepo({
177+
answers: {
178+
...answers,
179+
project_base,
180+
private: true,
181+
port: parseFloat(answers.port)
182+
}
183+
});
177184
});
178185
break;
179186
case 'service':
@@ -192,7 +199,13 @@ program
192199
default: getNextAvailablePort({ services: existing_services }),
193200
validate: input => input === '' || !isNaN(input) ? true : 'Port must be a number.'
194201
}
195-
]).then((answers) => actionHandlers.scaffoldNewService({ answers: { ...answers, private: true } }))
202+
]).then((answers) => actionHandlers.scaffoldNewService({
203+
answers: {
204+
...answers,
205+
private: true,
206+
port: parseFloat(answers.port)
207+
}
208+
}))
196209
break;
197210
case 'library':
198211
prompt([

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

Lines changed: 3 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -360,56 +360,8 @@ const startAll = async ({ options }) => {
360360
// case -v(--vanilla)
361361
// TODO: run services with nodemon in dev mode otherwise PM2
362362
// runVanillaServices({ services: [], mode: options.mode })
363-
364363
}
365364

366-
// /**
367-
// * Starts services with nodemon in development mode by default, otherwise with PM2.
368-
// * @param {Object} options - Environment settings for running the services.
369-
// * @param {string[]} options.serviceDirectories - List of service directories under `options.microservicesDir`.
370-
// * @param {string} options.microservicesDir - The root directory of the services.
371-
// * @param {string} [options.mode='dev'] - The environment mode for running the services. Defaults to 'dev'.
372-
// * @returns {void} Starts the services and logs their startup status.
373-
// */
374-
// const spinVanillaServices = async ({ serviceDirectories, microservicesDir, mode = 'dev' }) => {
375-
// const spinner = ora('Starting all services in ' + mode + ' mode...').start();
376-
377-
// try {
378-
// // Simulate delay before starting services
379-
// await delay(1);
380-
381-
// await Promise.all(serviceDirectories.map(async (dir) => {
382-
// const serviceSpinner = ora('Starting service concurrently in: ' + dir).start();
383-
// const processes = await exec(`yarn ${mode}`, { cwd: join(microservicesDir, dir) }, async (error, stdout, stderr) => {
384-
// if (error) {
385-
// const errorMessage = getErrorMessage(error, dir, microservicesDir);
386-
// serviceSpinner.fail(errorMessage);
387-
// } else {
388-
// serviceSpinner.succeed(`Service in directory ${dir} started successfully`);
389-
// }
390-
// });
391-
// processes.stdout.on('data', data => {
392-
// const output = data.toString();
393-
// // Check if the output contains the "yarn run" message
394-
// if (!output.includes('yarn run')) {
395-
// // Stop the spinner before printing the output
396-
// serviceSpinner.stop();
397-
// spinner.succeed(output);
398-
// // Restart the spinner after printing the output
399-
// // serviceSpinner.start();
400-
// }
401-
// });
402-
// }));
403-
404-
// spinner.succeed(`service${serviceDirectories.length > 0 ? 's' : ''} started successfully: ${serviceDirectories}`);
405-
// } catch (error) {
406-
// spinner.fail('An error occurred while starting services');
407-
// console.error(error);
408-
// exit(1);
409-
// }
410-
// };
411-
412-
413365
/**
414366
* Starts services with nodemon in development mode by default, otherwise with PM2.
415367
* @param {Object} options - Environment settings for running the services.
@@ -441,9 +393,10 @@ const spinVanillaServices = async ({ serviceDirectories, microservicesDir, mode
441393
});
442394

443395
child.stderr.on('data', (data) => {
444-
const output = data.toString();
396+
let output = data.toString();
397+
output = output.split(':')
445398
// Handle stderr output
446-
spinner.fail(`Error in service ${dir}: ${output.trim()}`);
399+
console.log(`${output[0]}: ${dir}: ${output[1]}`);
447400
});
448401

449402
child.on('close', (code) => {
@@ -465,28 +418,6 @@ const spinVanillaServices = async ({ serviceDirectories, microservicesDir, mode
465418
}
466419
};
467420

468-
const getErrorMessage = (error, dir, microservicesDir) => {
469-
const errorMessageParts = error.message.split('\n');
470-
let errorMessage = '';
471-
if (errorMessageParts[1]) {
472-
if (errorMessageParts[1].startsWith('error Command') && errorMessageParts[1].endsWith('not found.')) {
473-
errorMessage = `Missing script at ${dir}${sep}package.json: ${errorMessageParts[1].match(/"(.*?)"/)[1]}`;
474-
} else if (errorMessageParts[1].startsWith('error There are more than one workspace')) {
475-
errorMessage = errorMessageParts[1].replace('error ', '');
476-
} else if (errorMessageParts[1].includes('Unknown workspace')) {
477-
if (existsSync(`${microservicesDir}/${dir}/package.json`)) {
478-
errorMessage = 'Wrong workspace naming';
479-
} else {
480-
errorMessage = `Missing package.json @microservices-suite${sep}${dir}`;
481-
}
482-
} else {
483-
errorMessage = error.message;
484-
}
485-
}
486-
return errorMessage;
487-
};
488-
489-
490421
/**
491422
*
492423
* @param {Object} options Environment to run the

0 commit comments

Comments
 (0)