diff options
author | Dimitri Staessens <[email protected]> | 2019-10-06 21:37:45 +0200 |
---|---|---|
committer | Dimitri Staessens <[email protected]> | 2019-10-06 21:37:45 +0200 |
commit | 3c51c3be85bb0d1bdb87ea0d6632f1c256912f27 (patch) | |
tree | c7ccc8279b12c4f7bdbbb4270d617e48f51722e4 /node_modules/postcss-reporter/lib/formatter.js | |
parent | 412c104bebc507bea9c94fd53b5bdc4b64cbfe31 (diff) | |
download | website-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.tar.gz website-3c51c3be85bb0d1bdb87ea0d6632f1c256912f27.zip |
build: Add some required modules for node
Diffstat (limited to 'node_modules/postcss-reporter/lib/formatter.js')
-rw-r--r-- | node_modules/postcss-reporter/lib/formatter.js | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/node_modules/postcss-reporter/lib/formatter.js b/node_modules/postcss-reporter/lib/formatter.js new file mode 100644 index 0000000..b5719b8 --- /dev/null +++ b/node_modules/postcss-reporter/lib/formatter.js @@ -0,0 +1,80 @@ +var chalk = require('chalk'); +var path = require('path'); +var symbols = require('log-symbols'); +var _ = require('lodash'); +var util = require('./util'); + +module.exports = function(opts) { + var options = opts || {}; + var sortByPosition = (typeof options.sortByPosition !== 'undefined') ? options.sortByPosition : true; + var positionless = options.positionless || 'first'; + + return function(input) { + var messages = input.messages; + var source = input.source; + + if (!messages.length) return ''; + + var orderedMessages = _.sortBy( + messages, + function(m) { + if (!m.line) return 1; + if (positionless === 'any') return 1; + if (positionless === 'first') return 2; + if (positionless === 'last') return 0; + }, + function(m) { + if (!sortByPosition) return 1; + return m.line; + }, + function(m) { + if (!sortByPosition) return 1; + return m.column; + } + ); + + var output = '\n'; + + if (source) { + output += chalk.bold.underline(logFrom(source)) + '\n'; + } + + orderedMessages.forEach(function(w) { + output += messageToString(w) + '\n'; + }); + + return output; + + function messageToString(message) { + var location = util.getLocation(message); + var str = ''; + + if (location.line) { + str += chalk.bold(location.line); + } + + if (location.column) { + str += chalk.bold(':' + location.column) + } + + if (location.line || location.column) { + str += '\t'; + } + + if (!options.noIcon && message.type === 'warning') { + str += chalk.yellow(symbols.warning + ' '); + } + + str += message.text; + if (!options.noPlugin) { + str += chalk.yellow(' [' + message.plugin + ']'); + } + return str; + } + + function logFrom(fromValue) { + if (fromValue.charAt(0) === '<') return fromValue; + return path.relative(process.cwd(), fromValue).split(path.sep).join('/'); + } + }; +}; |