Skip to content

Commit

Permalink
feat: allow easily disabling reporters
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 4, 2018
1 parent 05cf301 commit f96ad47
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
1 change: 1 addition & 0 deletions demo/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const config = (name, color) => ({
color,
name,
reporters: ['basic', 'fancy'],
basic: false,
reporter: {
update({ state }) {
if (lastProgress !== state.progress && state.progress % 25 === 0) {
Expand Down
46 changes: 28 additions & 18 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,35 +60,45 @@ export default class WebpackBarPlugin extends ProgressPlugin {
}

// Resolve reposters
this.reporters = this.reporters.filter(Boolean).map((_reporter) => {
let reporter = _reporter;
let reporterOptions = this.options[reporter] || {};
this.reporters = this.reporters
.filter(Boolean)
.map((_reporter) => {
if (this.options[_reporter] === false) {
return false;
}

let reporter = _reporter;
let reporterOptions = this.options[reporter] || {};

if (Array.isArray(_reporter)) {
if (Array.isArray(_reporter)) {
reporter = _reporter[0]; // eslint-disable-line
if (_reporter[1]) {
if (_reporter[1] === false) {
return false;
}
if (_reporter[1]) {
reporterOptions = _reporter[1]; // eslint-disable-line
}
}
}

if (typeof reporter === 'string') {
if (reporters[reporter]) {
reporter = reporters[reporter];
} else {
if (typeof reporter === 'string') {
if (reporters[reporter]) {
reporter = reporters[reporter];
} else {
reporter = require(reporter); // eslint-disable-line
}
}
}

if (typeof reporter === 'function') {
if (typeof reporter.constructor === 'function') {
if (typeof reporter === 'function') {
if (typeof reporter.constructor === 'function') {
reporter = new reporter(reporterOptions); // eslint-disable-line
} else {
reporter = reporter(reporterOptions);
} else {
reporter = reporter(reporterOptions);
}
}
}

return reporter;
});
return reporter;
})
.filter(Boolean);
}

callReporters(fn, payload = {}) {
Expand Down

0 comments on commit f96ad47

Please sign in to comment.