mirror of
https://github.com/snachodog/just-the-docs.git
synced 2025-09-13 05:13:33 -06:00
Initial commit
This commit is contained in:
80
node_modules/postcss-reporter/lib/formatter.js
generated
vendored
Normal file
80
node_modules/postcss-reporter/lib/formatter.js
generated
vendored
Normal file
@@ -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('/');
|
||||
}
|
||||
};
|
||||
};
|
81
node_modules/postcss-reporter/lib/reporter.js
generated
vendored
Normal file
81
node_modules/postcss-reporter/lib/reporter.js
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
var chalk = require('chalk');
|
||||
var _ = require('lodash');
|
||||
var defaultFormatter = require('./formatter');
|
||||
var util = require('./util');
|
||||
|
||||
module.exports = function(opts) {
|
||||
var options = opts || {};
|
||||
|
||||
var formatter = options.formatter || defaultFormatter({
|
||||
sortByPosition: (typeof options.sortByPosition !== 'undefined') ? options.sortByPosition : true,
|
||||
positionless: options.positionless || 'first',
|
||||
noIcon: options.noIcon,
|
||||
noPlugin: options.noPlugin,
|
||||
});
|
||||
|
||||
var pluginFilter;
|
||||
if (!options.plugins) {
|
||||
// Every plugin
|
||||
pluginFilter = function() { return true; };
|
||||
} else if (options.plugins.every(function(plugin) { return plugin[0] === '!'; })) {
|
||||
// Blacklist
|
||||
pluginFilter = function(message) {
|
||||
return options.plugins.indexOf('!' + message.plugin) === -1;
|
||||
};
|
||||
} else {
|
||||
// Whitelist
|
||||
pluginFilter = function(message) {
|
||||
return options.plugins.indexOf(message.plugin) !== -1;
|
||||
};
|
||||
}
|
||||
|
||||
var messageFilter = options.filter || function(message) { return (message.type === 'warning'); };
|
||||
|
||||
return function(css, result) {
|
||||
var messagesToLog = result.messages
|
||||
.filter(pluginFilter)
|
||||
.filter(messageFilter);
|
||||
|
||||
var resultSource = (!result.root.source) ? ''
|
||||
: result.root.source.input.file || result.root.source.input.id
|
||||
|
||||
var sourceGroupedMessages = _.groupBy(messagesToLog, function(message) {
|
||||
return util.getLocation(message).file || resultSource;
|
||||
});
|
||||
|
||||
var report = '';
|
||||
_.forOwn(sourceGroupedMessages, function(messages, source) {
|
||||
report += formatter({
|
||||
messages: messages,
|
||||
source: source,
|
||||
});
|
||||
});
|
||||
|
||||
if (options.clearReportedMessages) {
|
||||
result.messages = _.difference(result.messages, messagesToLog);
|
||||
}
|
||||
|
||||
if (options.clearAllMessages) {
|
||||
var messagesToClear = result.messages.filter(pluginFilter);
|
||||
result.messages = _.difference(result.messages, messagesToClear);
|
||||
}
|
||||
|
||||
|
||||
if (!report) return;
|
||||
|
||||
console.log(report);
|
||||
|
||||
if (options.throwError && shouldThrowError()) {
|
||||
throw new Error(chalk.red.bold('\n** postcss-reporter: warnings or errors were found **'));
|
||||
}
|
||||
|
||||
function shouldThrowError() {
|
||||
return (
|
||||
messagesToLog.length
|
||||
&& messagesToLog.some(function(message) {
|
||||
return message.type === 'warning' || message.type === 'error';
|
||||
})
|
||||
);
|
||||
}
|
||||
};
|
||||
};
|
20
node_modules/postcss-reporter/lib/util.js
generated
vendored
Normal file
20
node_modules/postcss-reporter/lib/util.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
var _ = require('lodash');
|
||||
|
||||
exports.getLocation = function(message) {
|
||||
var messageNode = message.node;
|
||||
|
||||
var location = {
|
||||
line: message.line,
|
||||
column: message.column,
|
||||
};
|
||||
|
||||
var messageInput = _.get(messageNode, 'source.input');
|
||||
|
||||
if (!messageInput) return location;
|
||||
|
||||
var originLocation = messageInput.origin && messageInput.origin(message.line, message.column)
|
||||
if (originLocation) return originLocation
|
||||
|
||||
location.file = messageInput.file || messageInput.id;
|
||||
return location;
|
||||
};
|
Reference in New Issue
Block a user