mirror of
https://github.com/status-im/react-native.git
synced 2025-02-04 21:53:30 +00:00
packager: slightly more complete progress message.
Reviewed By: cpojer Differential Revision: D4326391 fbshipit-source-id: 134e09f1db6e21165c4af78a9e1266d7f9d046c8
This commit is contained in:
parent
1f07e89538
commit
db63537eb5
51
packager/react-packager/src/Server/index.js
vendored
51
packager/react-packager/src/Server/index.js
vendored
@ -696,22 +696,14 @@ class Server {
|
|||||||
entry_point: options.entryFile,
|
entry_point: options.entryFile,
|
||||||
})), ['bundle_url']);
|
})), ['bundle_url']);
|
||||||
|
|
||||||
let consoleProgress = () => {};
|
let updateTTYProgressMessage = () => {};
|
||||||
if (process.stdout.isTTY && !this._opts.silent) {
|
if (process.stdout.isTTY && !this._opts.silent) {
|
||||||
const onProgress = (doneCount, totalCount) => {
|
updateTTYProgressMessage = startTTYProgressMessage();
|
||||||
const format = 'transformed %s/%s (%s%)';
|
|
||||||
const percent = Math.floor(100 * doneCount / totalCount);
|
|
||||||
terminal.status(format, doneCount, totalCount, percent);
|
|
||||||
if (doneCount === totalCount) {
|
|
||||||
terminal.persistStatus();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
consoleProgress = throttle(onProgress, 200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const mres = MultipartResponse.wrap(req, res);
|
const mres = MultipartResponse.wrap(req, res);
|
||||||
options.onProgress = (done, total) => {
|
options.onProgress = (done, total) => {
|
||||||
consoleProgress(done, total);
|
updateTTYProgressMessage(done, total);
|
||||||
mres.writeChunk({'Content-Type': 'application/json'}, JSON.stringify({done, total}));
|
mres.writeChunk({'Content-Type': 'application/json'}, JSON.stringify({done, total}));
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -893,7 +885,7 @@ class Server {
|
|||||||
entryModuleOnly: boolean,
|
entryModuleOnly: boolean,
|
||||||
generateSourceMaps: boolean,
|
generateSourceMaps: boolean,
|
||||||
assetPlugins: Array<string>,
|
assetPlugins: Array<string>,
|
||||||
onProgress?: () => mixed,
|
onProgress?: (doneCont: number, totalCount: number) => mixed,
|
||||||
} {
|
} {
|
||||||
// `true` to parse the query param as an object.
|
// `true` to parse the query param as an object.
|
||||||
const urlObj = url.parse(reqUrl, true);
|
const urlObj = url.parse(reqUrl, true);
|
||||||
@ -958,6 +950,41 @@ class Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getProgressBar(ratio: number, length: number) {
|
||||||
|
const blockCount = Math.floor(ratio * length);
|
||||||
|
return (
|
||||||
|
'\u2593'.repeat(blockCount) +
|
||||||
|
'\u2591'.repeat(length - blockCount)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We use Math.pow(ratio, 2) to as a conservative measure of progress because we
|
||||||
|
* know the `totalCount` is going to progressively increase as well. We also
|
||||||
|
* prevent the ratio from going backwards.
|
||||||
|
*/
|
||||||
|
function startTTYProgressMessage(
|
||||||
|
): (doneCount: number, totalCount: number) => void {
|
||||||
|
let currentRatio = 0;
|
||||||
|
const updateMessage = (doneCount, totalCount) => {
|
||||||
|
const isDone = doneCount === totalCount;
|
||||||
|
const conservativeRatio = Math.pow(doneCount / totalCount, 2);
|
||||||
|
currentRatio = Math.max(conservativeRatio, currentRatio);
|
||||||
|
terminal.status(
|
||||||
|
'Transforming files %s%s% (%s/%s)%s',
|
||||||
|
isDone ? '' : getProgressBar(currentRatio, 20) + ' ',
|
||||||
|
(100 * currentRatio).toFixed(1),
|
||||||
|
doneCount,
|
||||||
|
totalCount,
|
||||||
|
isDone ? ', done.' : '...',
|
||||||
|
);
|
||||||
|
if (isDone) {
|
||||||
|
terminal.persistStatus();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return throttle(updateMessage, 200);
|
||||||
|
}
|
||||||
|
|
||||||
function contentsEqual(array: Array<mixed>, set: Set<mixed>): boolean {
|
function contentsEqual(array: Array<mixed>, set: Set<mixed>): boolean {
|
||||||
return array.length === set.size && array.every(set.has, set);
|
return array.length === set.size && array.every(set.has, set);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user