Skip to content

Commit

Permalink
💄 Add chalk for some colors in logging
Browse files Browse the repository at this point in the history
  • Loading branch information
segersniels committed May 27, 2019
1 parent 310e294 commit c72d4e2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
30 changes: 27 additions & 3 deletions src/helpers/logger.ts
Original file line number Diff line number Diff line change
@@ -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);
};
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -136,7 +137,7 @@ export default class Supdock {
this.spawn('docker', [command, ...flags, id]);
}
} else {
info(error);
warn(error);
}
}

Expand Down

0 comments on commit c72d4e2

Please sign in to comment.