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 throat = require("throat");
const { JSDOM } = require("jsdom");
const cliProgress = require("cli-progress");
const substitutions = require("./substitutions.json");
module.exports = async (cachePath, manifestPath, contentPath, concurrentJobs) => {
const manifestContents = await fs.readFile(manifestPath, { encoding: "utf-8" });
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));
console.log("All chapters converted");
@ -32,7 +42,6 @@ async function convertChapter(chapter, cachePath, contentPath) {
const destFilePath = path.resolve(contentPath, destFileName);
await fs.writeFile(destFilePath, output);
console.log(`- Finished converting ${filename}`);
}
function getChapterString(chapter, rawChapterDoc) {