Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions packages/core/src/Site/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,7 @@ class Site {
const pagesCount = pageGenerationTasks.reduce((acc, task) => acc + task.pages.length, 0);
const progressBar = new ProgressBar(`[:bar] :current / ${pagesCount} pages built`, { total: pagesCount });
progressBar.render();
logger.setProgressBar(progressBar);

const startTime = new Date();
let isCompleted = true;
Expand All @@ -1113,6 +1114,7 @@ class Site {
isCompleted = await this.generatePagesAsyncThrottled(task.pages, progressBar);
}

logger.removeProgressBar();
this.siteLinkManager.validateAllIntralinks();
});
return isCompleted;
Expand Down
32 changes: 30 additions & 2 deletions packages/core/src/lib/progress/node-progress.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
/* eslint-disable */
/*
* Patch for node-progress to fix display issue in certain terminals.
* Patch #1 for node-progress to fix display issue in certain terminals.
* Issue related: https://github.com/MarkBind/markbind/issues/416
* The **only** changes are based on the following PR and its comments:
* https://github.com/visionmedia/node-progress/pull/168
* As the above PR is not merged since 2017, this is a temporary patch
* to fix the issue for markbind's usecase.
*/

/*
* Patch #2 for node-progress to allow logging without disturbing the progress bar.
* The changes are based on the following PR:
* https://github.com/visionmedia/node-progress/pull/155
*/

/*!
* node-progress
* Copyright(c) 2011 TJ Holowaychuk <tj@vision-media.ca>
Expand Down Expand Up @@ -57,7 +63,7 @@ exports = module.exports = ProgressBar;
function ProgressBar(fmt, options) {
this.stream = options.stream || process.stderr;

// patch
// patch #1
// options.forceTTY is undefined in git-bash on mintty Windows
if (!process.stderr.isTTY) {
var tty = require('tty').WriteStream.prototype;
Expand Down Expand Up @@ -256,3 +262,25 @@ ProgressBar.prototype.terminate = function () {
this.stream.write('\n');
}
};

// patch #2 Add interruptBegin & interruptEnd
/**
* Begin a interrupt so the user can manually write messages above the bar.
*
* @api public
*/

ProgressBar.prototype.interruptBegin = function () {
this.stream.clearLine();
this.stream.cursorTo(0);
};

/**
* End a interrupt, rendering the last draw again.
*
* @api public
*/

ProgressBar.prototype.interruptEnd = function () {
this.stream.write(this.lastDraw);
}; // end patch
61 changes: 54 additions & 7 deletions packages/core/src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import winston from 'winston';

const consoleTransport = new (winston.transports.Console)({
let progressBar: any;

const setProgressBar = (bar: any) => {
progressBar = bar;
};
const removeProgressBar = () => {
progressBar = null;
};

const consoleTransport = new winston.transports.Console({
colorize: true,
handleExceptions: true,
humanReadableUnhandledException: true,
Expand All @@ -13,10 +22,48 @@ winston.configure({
transports: [consoleTransport],
});

export = {
error: winston.error,
warn: winston.warn,
info: winston.info,
verbose: winston.verbose,
debug: winston.debug,
// create a wrapper for error messages
const errorWrap = (input: any) => {
if (progressBar) {
progressBar.interruptBegin();
winston.error(input);
progressBar.interruptEnd();
} else {
winston.error(input);
}
};

// create a wrapper for warning messages
const warnWarp = (input: any) => {
if (progressBar) {
progressBar.interruptBegin();
winston.warn(input);
progressBar.interruptEnd();
} else {
winston.warn(input);
}
};

// create a wrapper for info messages
const infoWarp = (input: any) => {
if (progressBar) {
progressBar.interruptBegin();
winston.info(input);
progressBar.interruptEnd();
} else {
winston.info(input);
}
};

const { debug } = winston;
const { verbose } = winston;

export {
errorWrap as error,
warnWarp as warn,
infoWarp as info,
verbose,
debug,
setProgressBar,
removeProgressBar,
};