mirror of https://github.com/status-im/metro.git
Update http progress output in cli; add platform, shorten rest
Reviewed By: rafeca, davidaurelio Differential Revision: D6395717 fbshipit-source-id: 0fed7f29539bb59bc300d88b09a99be13bbb42ba
This commit is contained in:
parent
6557272f8c
commit
a766a4a499
|
@ -17,7 +17,6 @@ const formatBanner = require('./formatBanner');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const reporting = require('./reporting');
|
const reporting = require('./reporting');
|
||||||
const throttle = require('lodash/throttle');
|
const throttle = require('lodash/throttle');
|
||||||
const util = require('util');
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
AmbiguousModuleResolutionError,
|
AmbiguousModuleResolutionError,
|
||||||
|
@ -40,14 +39,7 @@ type BundleProgress = {
|
||||||
|
|
||||||
const DARK_BLOCK_CHAR = '\u2593';
|
const DARK_BLOCK_CHAR = '\u2593';
|
||||||
const LIGHT_BLOCK_CHAR = '\u2591';
|
const LIGHT_BLOCK_CHAR = '\u2591';
|
||||||
|
const MAX_PROGRESS_BAR_CHAR_WIDTH = 16;
|
||||||
function getProgressBar(ratio: number, length: number) {
|
|
||||||
const blockCount = Math.floor(ratio * length);
|
|
||||||
return (
|
|
||||||
DARK_BLOCK_CHAR.repeat(blockCount) +
|
|
||||||
LIGHT_BLOCK_CHAR.repeat(length - blockCount)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export type TerminalReportableEvent =
|
export type TerminalReportableEvent =
|
||||||
| ReportableEvent
|
| ReportableEvent
|
||||||
|
@ -94,7 +86,7 @@ class TerminalReporter {
|
||||||
* Construct a message that represents the progress of a
|
* Construct a message that represents the progress of a
|
||||||
* single bundle build, for example:
|
* single bundle build, for example:
|
||||||
*
|
*
|
||||||
* Bunding `foo.js` |#### | 34.2% (324/945)
|
* Bunding `foo.js` [ios, dev, minified] |#### | 34.2% (324/945)
|
||||||
*/
|
*/
|
||||||
_getBundleStatusMessage(
|
_getBundleStatusMessage(
|
||||||
{
|
{
|
||||||
|
@ -106,16 +98,33 @@ class TerminalReporter {
|
||||||
phase: BuildPhase,
|
phase: BuildPhase,
|
||||||
): string {
|
): string {
|
||||||
const localPath = path.relative('.', bundleOptions.entryFile);
|
const localPath = path.relative('.', bundleOptions.entryFile);
|
||||||
return util.format(
|
const fileName = path.basename(localPath);
|
||||||
'Bundling `%s` [%s, %s] %s%s%% (%s/%s)%s',
|
const dirName = path.dirname(localPath);
|
||||||
localPath,
|
|
||||||
bundleOptions.dev ? 'development' : 'production',
|
const platform = bundleOptions.platform
|
||||||
bundleOptions.minify ? 'minified' : 'non-minified',
|
? bundleOptions.platform + ', '
|
||||||
phase === 'in_progress' ? getProgressBar(ratio, 16) + ' ' : '',
|
: '';
|
||||||
(100 * ratio).toFixed(1),
|
const devOrProd = bundleOptions.dev ? 'dev' : 'prod';
|
||||||
transformedFileCount,
|
const min = bundleOptions.minify ? ', minified' : '';
|
||||||
totalFileCount,
|
const progress = (100 * ratio).toFixed(1);
|
||||||
phase === 'done' ? ', done.' : phase === 'failed' ? ', failed.' : '',
|
const currentPhase =
|
||||||
|
phase === 'done' ? ', done.' : phase === 'failed' ? ', failed.' : '';
|
||||||
|
|
||||||
|
const filledBar = Math.floor(ratio * MAX_PROGRESS_BAR_CHAR_WIDTH);
|
||||||
|
|
||||||
|
return (
|
||||||
|
chalk.inverse.green.bold(' BUNDLE ') +
|
||||||
|
chalk.dim(` [${platform}${devOrProd}${min}] ${dirName}/`) +
|
||||||
|
chalk.bold(fileName) +
|
||||||
|
' ' +
|
||||||
|
chalk.green.bgGreen(DARK_BLOCK_CHAR.repeat(filledBar)) +
|
||||||
|
chalk.bgWhite.white(
|
||||||
|
LIGHT_BLOCK_CHAR.repeat(MAX_PROGRESS_BAR_CHAR_WIDTH - filledBar),
|
||||||
|
) +
|
||||||
|
chalk.bold(` ${progress}% `) +
|
||||||
|
chalk.dim(`(${transformedFileCount}/${totalFileCount})`) +
|
||||||
|
currentPhase +
|
||||||
|
'\n'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue