Skip to content

Commit f590aa5

Browse files
committed
fix: stream suite start -v command
1 parent 63ecb15 commit f590aa5

File tree

1 file changed

+75
-21
lines changed

1 file changed

+75
-21
lines changed

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

Lines changed: 75 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,53 @@ const startAll = async ({ options }) => {
363363

364364
}
365365

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+
366413
/**
367414
* Starts services with nodemon in development mode by default, otherwise with PM2.
368415
* @param {Object} options - Environment settings for running the services.
@@ -375,42 +422,49 @@ const spinVanillaServices = async ({ serviceDirectories, microservicesDir, mode
375422
const spinner = ora('Starting all services in ' + mode + ' mode...').start();
376423

377424
try {
378-
// Simulate delay before starting services
379-
await delay(1);
380-
381425
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 => {
426+
const servicePath = join(microservicesDir, dir);
427+
// TODO: check if the yarn.cmd works in windows really
428+
const command = process.platform === 'win32' ? 'yarn.cmd' : 'yarn';
429+
const args = [mode];
430+
431+
const child = spawn(command, args, { cwd: servicePath, shell: true });
432+
433+
child.stdout.on('data', (data) => {
392434
const output = data.toString();
393435
// Check if the output contains the "yarn run" message
394-
if (!output.includes('yarn run')) {
436+
if (!output.includes('yarn run') && !output.includes('NODE_ENV')) {
395437
// Stop the spinner before printing the output
396-
serviceSpinner.stop();
397-
spinner.succeed(output);
438+
console.log(output.trim());
398439
// Restart the spinner after printing the output
399-
// serviceSpinner.start();
440+
}
441+
});
442+
443+
child.stderr.on('data', (data) => {
444+
const output = data.toString();
445+
// Handle stderr output
446+
spinner.fail(`Error in service ${dir}: ${output.trim()}`);
447+
});
448+
449+
child.on('close', (code) => {
450+
if (code !== 0) {
451+
spinner.fail(`Service in directory ${dir} exited with code ${code}`);
452+
} else {
453+
spinner.succeed(`Service in directory ${dir} started successfully`);
454+
400455
}
401456
});
402457
}));
403458

404-
spinner.succeed(`service${serviceDirectories.length > 0 ? 's' : ''} started successfully: ${serviceDirectories}`);
459+
spinner.succeed(`Service${serviceDirectories.length > 1 ? 's' : ''} started successfully: ${serviceDirectories.join(', ')}`);
460+
console.log('\n')
405461
} catch (error) {
406462
spinner.fail('An error occurred while starting services');
407463
console.error(error);
408-
exit(1);
464+
process.exit(1);
409465
}
410466
};
411467

412-
413-
414468
const getErrorMessage = (error, dir, microservicesDir) => {
415469
const errorMessageParts = error.message.split('\n');
416470
let errorMessage = '';

0 commit comments

Comments
 (0)