Add a nice progress bar for the convert step

This commit is contained in:
Domenic Denicola 2020-10-22 19:31:28 -04:00
commit ae5b179d7c
3 changed files with 27 additions and 3 deletions

View file

@ -3,14 +3,24 @@ const path = require("path");
const fs = require("fs").promises; const fs = require("fs").promises;
const throat = require("throat"); const throat = require("throat");
const { JSDOM } = require("jsdom"); const { JSDOM } = require("jsdom");
const cliProgress = require("cli-progress");
const substitutions = require("./substitutions.json"); const substitutions = require("./substitutions.json");
module.exports = async (cachePath, manifestPath, contentPath, concurrentJobs) => { module.exports = async (cachePath, manifestPath, contentPath, concurrentJobs) => {
const manifestContents = await fs.readFile(manifestPath, { encoding: "utf-8" }); const manifestContents = await fs.readFile(manifestPath, { encoding: "utf-8" });
const chapters = JSON.parse(manifestContents); const chapters = JSON.parse(manifestContents);
console.log("All chapters downloaded; beginning conversion to EPUB chapters");
const mapper = throat(concurrentJobs, chapter => convertChapter(chapter, cachePath, contentPath)); console.log("Converting raw downloaded HTML to EPUB chapters");
const progress = new cliProgress.SingleBar({
stopOnComplete: true,
clearOnComplete: true
}, cliProgress.Presets.shades_classic);
progress.start(chapters.length, 0);
const mapper = throat(concurrentJobs, async chapter => {
await convertChapter(chapter, cachePath, contentPath);
progress.increment();
});
await Promise.all(chapters.map(mapper)); await Promise.all(chapters.map(mapper));
console.log("All chapters converted"); console.log("All chapters converted");
@ -32,7 +42,6 @@ async function convertChapter(chapter, cachePath, contentPath) {
const destFilePath = path.resolve(contentPath, destFileName); const destFilePath = path.resolve(contentPath, destFileName);
await fs.writeFile(destFilePath, output); await fs.writeFile(destFilePath, output);
console.log(`- Finished converting ${filename}`);
} }
function getChapterString(chapter, rawChapterDoc) { function getChapterString(chapter, rawChapterDoc) {

14
npm-shrinkwrap.json generated
View file

@ -335,6 +335,15 @@
} }
} }
}, },
"cli-progress": {
"version": "3.8.2",
"resolved": "https://registry.npmjs.org/cli-progress/-/cli-progress-3.8.2.tgz",
"integrity": "sha512-qRwBxLldMSfxB+YGFgNRaj5vyyHe1yMpVeDL79c+7puGujdKJHQHydgqXDcrkvQgJ5U/d3lpf6vffSoVVUftVQ==",
"requires": {
"colors": "^1.1.2",
"string-width": "^4.2.0"
}
},
"cliui": { "cliui": {
"version": "6.0.0", "version": "6.0.0",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz", "resolved": "https://registry.npmjs.org/cliui/-/cliui-6.0.0.tgz",
@ -358,6 +367,11 @@
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
}, },
"colors": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
"integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA=="
},
"combined-stream": { "combined-stream": {
"version": "1.0.8", "version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",

View file

@ -24,6 +24,7 @@
}, },
"dependencies": { "dependencies": {
"archiver": "^4.0.1", "archiver": "^4.0.1",
"cli-progress": "^3.8.2",
"cpr": "^3.0.1", "cpr": "^3.0.1",
"jsdom": "^16.2.2", "jsdom": "^16.2.2",
"requisition": "^1.5.0", "requisition": "^1.5.0",