diff --git a/package.json b/package.json index 9f18ae08..c720cd47 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,7 @@ "dependencies": { "@types/inquirer": "0.0.43", "@types/node": "^11.9.4", + "chalk": "^2.4.2", "inquirer": "^5.1.0", "minimist": "^1.2.0" }, diff --git a/src/helpers/logger.ts b/src/helpers/logger.ts index 6ebb4bb7..1f2c8911 100644 --- a/src/helpers/logger.ts +++ b/src/helpers/logger.ts @@ -1,8 +1,32 @@ +import chalk from 'chalk'; +const log = console.log; + export const logAndForget = (msg: string) => { - console.log(msg); + log(msg); process.exit(0); }; -export const info = (msg: string) => { - console.log(msg); +export const info = (msg: string, highlighted: boolean | string[] = []) => { + let message = msg; + + if (typeof highlighted === 'boolean') { + message = chalk.underline.blue(message); + } else { + for (const word of msg.replace(/[^\w\s]/gi, '').split(' ')) { + if (highlighted.includes(word)) { + message = message.replace(word, chalk.blue(word)); + } + } + } + + log(message); +}; + +export const warn = (msg: string) => { + log(chalk.yellow(msg)); +}; + +export const error = (msg: string) => { + log(chalk.red(msg)); + process.exit(1); }; diff --git a/src/index.ts b/src/index.ts index 7d893234..284323fb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,7 +2,7 @@ import { execSync, spawn, spawnSync } from 'child_process'; import * as inquirer from 'inquirer'; import { version } from '../package.json'; import { IdCommands, NameCommands } from './enums'; -import { info, logAndForget } from './helpers/logger'; +import { info, logAndForget, warn } from './helpers/logger'; import metadata from './metadata'; import Type from './types/type'; @@ -94,8 +94,9 @@ export default class Supdock { } private executeInParallel(command: string, type: Type) { - info('Asynchronous execution of command is happening in the background...'); - info(`Some containers might take longer than others to ${command}...`); + info('Asynchronous execution of command is happening in the background'); + info(`Some containers might take longer than others to ${command}`, true); + spawn; const { ids } = this.getDockerInfo(type); ids.forEach(id => { @@ -136,7 +137,7 @@ export default class Supdock { this.spawn('docker', [command, ...flags, id]); } } else { - info(error); + warn(error); } }