diff --git a/.suite-cli/cli/scripts/assets/serverContent.asset.js b/.suite-cli/cli/scripts/assets/serverContent.asset.js index 666616b..e5d634b 100644 --- a/.suite-cli/cli/scripts/assets/serverContent.asset.js +++ b/.suite-cli/cli/scripts/assets/serverContent.asset.js @@ -10,10 +10,10 @@ const { router } = require('./src/routes'); // const app = require('./src/app'); mongoose.connect(config.db).then(() => { -logger.info(\`📀 successfully connected to db: \${config.db}\`); + logger.info(\`📀 successfully connected to db: \${config.db}\`); }).catch(err => { -logger.error(\`failed to connect to db.exiting...\${err.message}\`); -process.exit(0); + logger.error(\`failed to connect to db. Exiting... \${err.message}\`); + process.exit(0); }); const app = express(); @@ -21,22 +21,22 @@ const app = express(); app.use(express.json()); app.get('/', (req, res) => { -res.json({ message: 'hello from ${answers.project_base}/${answers.service_name}' }); + res.json({ message: 'hello from ${answers.project_base}/${answers.service_name}' }); }); const server = http.createServer(app); server.on('error', (err) => { -logger.error(err); -if (err.code === 'EADDRINUSE') { - logger.error('Address already in use, retrying...'); - setTimeout(() => { - server.close(); - server.listen(config.port, 'localhost'); - }, 1000); - errorHandler(err); -} -}) + logger.error(err); + if (err.code === 'EADDRINUSE') { + logger.error('Address already in use, retrying...'); + setTimeout(() => { + server.close(); + server.listen(config.port, 'localhost'); + }, 1000); + errorHandler(err); + } +}); server.listen(config.port, () => { logger.info(\`🚀 ${answers.project_base}/${answers.service_name} listening at: http://localhost:\${config.port}\`); @@ -48,11 +48,11 @@ app.use(morgan.successHandler); app.use('/api/v1', router); -// global error handler should come after all other middlewares +// Global error handler should come after all other middlewares app.all('*', (req, res, next) => { -const err = new APIError(404, \`requested resource not found on server: \${req.originalUrl}\`); -next(err); + const err = new APIError(404, \`requested resource not found on server: \${req.originalUrl}\`); + next(err); }); app.use(errorHandler); -`; \ No newline at end of file +`; diff --git a/.suite-cli/cli/scripts/scripts.module.js b/.suite-cli/cli/scripts/scripts.module.js index ee26ebc..c25002c 100644 --- a/.suite-cli/cli/scripts/scripts.module.js +++ b/.suite-cli/cli/scripts/scripts.module.js @@ -383,20 +383,27 @@ const spinVanillaServices = async ({ serviceDirectories, microservicesDir, mode const child = spawn(command, args, { cwd: servicePath, shell: true }); child.stdout.on('data', (data) => { - const output = data.toString(); + let output = data.toString(); // Check if the output contains the "yarn run" message if (!output.includes('yarn run') && !output.includes('NODE_ENV')) { // Stop the spinner before printing the output - console.log(output.trim()); + if (output.includes('info')) { + const parts = output.trim().split(':'); + const formattedOutput = formatLog(parts[0], dir, parts.slice(1).join(':').trim()); + console.log(formattedOutput); + } else { + console.log(output.trim()); + } // Restart the spinner after printing the output } }); child.stderr.on('data', (data) => { let output = data.toString(); - output = output.split(':') + const parts = output.trim().split(':'); + const formattedOutput = formatLog(parts[0], dir, parts.slice(1).join(':').trim()); // Handle stderr output - console.log(`${output[0]}: ${dir}: ${output[1]}`); + console.log(formattedOutput); }); child.on('close', (code) => { @@ -418,6 +425,15 @@ const spinVanillaServices = async ({ serviceDirectories, microservicesDir, mode } }; +const padString = (str, length) => str.padEnd(length, ' '); + +// Function to format the log messages +const formatLog = (level, dir, message) => { + const paddedLevel = padString(level, 5); + const paddedDir = padString(dir, 8); + return `${paddedLevel}: ${paddedDir}: ${message}`; +}; + /** * * @param {Object} options Environment to run the