Skip to content

Commit

Permalink
feat: consola integration with bars
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 2, 2018
1 parent 8db1118 commit 1c22321
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module.exports = {
{ singleQuote: true, trailingComma: 'es5', arrowParens: 'always' },
],
'class-methods-use-this': 0,
'prefer-template': 0
'prefer-template': 0,
'no-underscore-dangle': 0
},
};
15 changes: 14 additions & 1 deletion kitchen-sync/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
const path = require('path');

const consola = require('consola');

const requireESM = require('esm')(module);

const Self = requireESM('../src/index').default;

consola.wrapConsole();

let lastProgress;

module.exports = {
mode: 'production',
context: __dirname,
Expand All @@ -21,8 +27,15 @@ module.exports = {
plugins: [
new Self({
color: 'orange',
// profile: true,
name: 'kitchen-sync',
reporter: {
update({ state }) {
if (lastProgress !== state.progress && state.progress % 25 === 0) {
consola.log(state.progress + '%');
lastProgress = state.progress;
}
},
},
}),
],
};
14 changes: 13 additions & 1 deletion src/reporters/bars.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ import { throttle } from '../utils';
import { formatRequest } from '../utils/request';
import { BULLET, TICK } from '../utils/consts';

const globalConsole = console;
// Convention: Original values are kept with two underscores

const globalConsole = {
log: console.__log || console.log, // eslint-disable-line no-console
_stdout: console._stdout, // eslint-disable-line no-console
};

const renderT = throttle((fn, ...args) => fn(...args), 1, 50);

Expand All @@ -21,6 +26,8 @@ export default class BarsReporter {
compiling() {
if (!globalConsole.draft) {
draftLog(globalConsole);
console.__stdout = console._stdout; // eslint-disable-line no-console
console._stdout = globalConsole._stdout; // eslint-disable-line no-console
}

Consola.pause();
Expand All @@ -29,6 +36,11 @@ export default class BarsReporter {
}

done() {
// eslint-disable-next-line no-console
// if (console.__stdout) {
// console._stdout = console.__stdout; // eslint-disable-line no-console
// delete console.__stdout; // eslint-disable-line no-console
// }
Consola.resume();
}

Expand Down

0 comments on commit 1c22321

Please sign in to comment.