Skip to content

Commit

Permalink
Merge pull request #6 from SparkartGroupInc/add-prefix-option
Browse files Browse the repository at this point in the history
Add prefix option
  • Loading branch information
nebez committed Jan 27, 2016
2 parents c32e240 + 159df1f commit b607763
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,11 @@ Default: `false`

Emit gulp error on reported warning

##### prefixLogs

Type: `boolean`
Default: `false`

Prefix log messages with the plugin name

## LICENSE [MIT](LICENSE)
12 changes: 9 additions & 3 deletions reporters/stylish.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ function Stylish (options) {
// Default options
var opts = {
breakOnError: false,
breakOnWarning: false
breakOnWarning: false,
prefixLogs: false
};
var totalErrorCount = 0;
var totalWarningCount = 0;

// Extend and override default options with the ones user has set
for (var attr in options) { opts[attr] = options[attr]; }

var logPrefix = options.prefixLogs ? colors.cyan('[' + PLUGIN_NAME + ']\t') : '';

// File specific reporter
function reportFile (filepath, data) {
var lines = [];
Expand All @@ -40,6 +43,9 @@ function Stylish (options) {
lines.push(' ' + logSymbols.error + ' ' + colors.red(data.errorCount + ' error' + (data.errorCount !== 1 ? 's' : '')));
lines.push(' ' + logSymbols.warning + ' ' + colors.yellow(data.warningCount + ' warning' + (data.warningCount !== 1 ? 's' : '')));

// Prefix lines with plugin name for clearer logs
lines = lines.map(function (line) { return logPrefix + line; });

return lines.join('\n') + '\n';
}

Expand All @@ -48,8 +54,8 @@ function Stylish (options) {
if (totalErrorCount === 0 && totalWarningCount === 0) {
// Success!
} else {
console.log(logSymbols.error + colors.red(' ' + totalErrorCount + ' errors'));
console.log(logSymbols.warning + colors.yellow(' ' + totalWarningCount + ' warnings') + '\n');
console.log(logPrefix + logSymbols.error + colors.red(' ' + totalErrorCount + ' errors'));
console.log(logPrefix + logSymbols.warning + colors.yellow(' ' + totalWarningCount + ' warnings') + '\n');
}
}

Expand Down

0 comments on commit b607763

Please sign in to comment.