@tamara027/lerna-terminal
Version:
Powerful cli ui for monorepos
66 lines (55 loc) • 1.72 kB
JavaScript
/* eslint no-console: 0*/
;
var chalk = require('chalk');
var _require = require('../store'),
getUiState = _require.getUiState;
var _require2 = require('../getTerminalPanel'),
getBox = _require2.getBox;
var _require3 = require('../getDimensions'),
getDimensions = _require3.getDimensions;
/**
* @description clears the terminal
* @param {Function} render - the render function
* @param {Object} di - dependency injection
* @returns {void}
**/
function renderNotification(render) {
var uiState = getUiState();
var dimensions = getDimensions();
var _uiState$notification = uiState.notifications[0],
_uiState$notification2 = _uiState$notification.type,
type = _uiState$notification2 === undefined ? 'info' : _uiState$notification2,
message = _uiState$notification.message,
_uiState$notification3 = _uiState$notification.delay,
delay = _uiState$notification3 === undefined ? 2000 : _uiState$notification3;
var msg = void 0;
var colored = function colored(color, value) {
/* istanbul ignore next */
if (process.env.NODE_ENV === 'test') {
return value;
}
/* istanbul ignore next */
return chalk[color].bold(value);
};
switch (type) {
case 'error':
msg = colored('red', message);
break;
case 'warning':
msg = colored('yellow', message);
break;
case 'success':
msg = colored('green', message);
break;
default:
msg = message;
break;
}
uiState.print(getBox(type, [msg], dimensions.width));
setTimeout(function () {
var notifications = uiState.notifications.slice(1, uiState.notifications.length - 1);
uiState.notifications = notifications;
render();
}, delay);
}
module.exports = renderNotification;