Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add progress bar for progress flag #1238

Merged
merged 4 commits into from
Feb 18, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions packages/webpack-cli/lib/utils/Compiler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const webpack = require('webpack');
const logger = require('./logger');
const readline = require('readline');
rishabh3112 marked this conversation as resolved.
Show resolved Hide resolved
const { cyanBright, greenBright } = require('chalk');
const { CompilerOutput } = require('./CompilerOutput');

class Compiler {
Expand All @@ -15,17 +17,24 @@ class Compiler {

compilation.hooks.beforeRun.tap('webpackProgress', () => {
if (outputOptions.progress) {
let tmpMsg;
process.stdout.write("\n");
const defaultProgressPluginHandler = (percent, msg) => {
percent = Math.floor(percent * 100);
if (percent === 100) {
msg = 'Compilation completed';
process.stdout.clearLine();
process.stdout.cursorTo(0);
if (percent !== undefined) {
rishabh3112 marked this conversation as resolved.
Show resolved Hide resolved
process.stdout.write(' (')
for(let i = 0; i <= 100; i+=10) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for(let i = 0; i <= 100; i+=10) {
for (let i = 0; i <= 100; i+=10) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is prettier not running for this file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup I think so, let me check.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably you did a commit and skipped the git hooks?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to run eslint with --no-ignore for it to lint.

if (i <= percent) {
process.stdout.write(greenBright("#"));
} else {
process.stdout.write("#");
}
}
process.stdout.write(`) ${percent}% : `)
process.stdout.write(`${cyanBright(msg)}`);
if (percent === 100) process.stdout.write(`${cyanBright("Complilation completed\n")}`);
}

if (msg && tmpMsg != msg) {
logger.info(percent + '% ' + msg);
}
tmpMsg = msg;
};
if (!progressPluginExists) {
new ProgressPlugin(defaultProgressPluginHandler).apply(compilation);
Expand Down