From 8138f9030991d52715105c7e4ddbd2e5e8fe45a5 Mon Sep 17 00:00:00 2001 From: skrinits <110100reg@gmail.com> Date: Fri, 22 May 2020 10:55:36 +0300 Subject: [PATCH] added output option --- lib/cli.js | 10 ++++++++-- lib/reporters/console.js | 8 ++++++-- lib/reporters/inline.js | 8 ++++++-- package.json | 2 +- 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index 72ae9d6..c7a9fbe 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -10,6 +10,7 @@ function run(args) { .description(packageDetails.description) .usage('[options] ') .option('-c, --config ', 'configuration file path') + .option('-o, --output ', 'configuration of output; stderr - default, stdout', 'stderr') .option('-r, --reporter ', 'error reporter; console - default, inline', 'console') .parse(args); @@ -37,8 +38,13 @@ function run(args) { }); if (errors.length) { - reporter.writer(errors); - process.exit(2); + if (program.output == 'stderr') { + reporter.writer(errors); + process.exit(2); + } else { + reporter.writer(errors, program.output); + process.exit(0); + } } else { process.exit(0); } diff --git a/lib/reporters/console.js b/lib/reporters/console.js index 19efc72..59ff8ec 100644 --- a/lib/reporters/console.js +++ b/lib/reporters/console.js @@ -1,4 +1,4 @@ -module.exports = function (errors) { +module.exports = function (errors, output = 'stderr') { if (errors.length) { var messages = []; @@ -10,6 +10,10 @@ module.exports = function (errors) { messages.push(error.message); }); - console.error(messages.join('\n')); + if (output == 'stderr') { + console.error(messages.join('\n')); + } else { + console.log(messages.join('\n')); + } } }; diff --git a/lib/reporters/inline.js b/lib/reporters/inline.js index a42afb8..7cb719a 100644 --- a/lib/reporters/inline.js +++ b/lib/reporters/inline.js @@ -1,4 +1,4 @@ -module.exports = function (errors) { +module.exports = function (errors, output = 'stderr') { if (errors.length) { errors.forEach(function (error) { var message = [ @@ -8,7 +8,11 @@ module.exports = function (errors) { ' ' + error.msg ]; - console.error(message.join('')); + if (output == 'stderr') { + console.error(message.join('')); + } else { + console.log(message.join('')); + } }); } }; diff --git a/package.json b/package.json index fc93c0c..5dd0e11 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "pug-lint", - "version": "2.6.0", + "version": "2.7.0", "description": "An unopinionated and configurable linter and style checker for Pug (formerly Jade)", "author": "Ben Edwards ", "license": "ISC",