diff --git a/lib/convert.js b/lib/convert.js index a4251be..8a989c7 100644 --- a/lib/convert.js +++ b/lib/convert.js @@ -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) { diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 599380f..468ce14 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -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": { "version": "6.0.0", "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", "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": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", diff --git a/package.json b/package.json index 05b24e9..e29c69b 100644 --- a/package.json +++ b/package.json @@ -24,6 +24,7 @@ }, "dependencies": { "archiver": "^4.0.1", + "cli-progress": "^3.8.2", "cpr": "^3.0.1", "jsdom": "^16.2.2", "requisition": "^1.5.0",