Add progress bar when outputting pages
This commit is contained in:
parent
41277bbcb0
commit
f9f4ae3460
3 changed files with 32 additions and 3 deletions
20
index.ts
20
index.ts
|
@ -5,9 +5,11 @@ import { readFileSync, writeFileSync } from 'fs';
|
||||||
import Handlebars from 'handlebars';
|
import Handlebars from 'handlebars';
|
||||||
import mkdirp from 'mkdirp';
|
import mkdirp from 'mkdirp';
|
||||||
import { range } from 'underscore';
|
import { range } from 'underscore';
|
||||||
|
import ProgressBar from 'progress';
|
||||||
|
|
||||||
const BUILD_DIR = join(__dirname, 'build');
|
const BUILD_DIR = join(__dirname, 'build');
|
||||||
const SRC_DIR = join(__dirname, 'src');
|
const SRC_DIR = join(__dirname, 'src');
|
||||||
|
const PROGRESS_BAR_FORMAT = "[:bar] :rate/ps :percent";
|
||||||
|
|
||||||
const BUNDLER_OPTIONS = {
|
const BUNDLER_OPTIONS = {
|
||||||
outDir: BUILD_DIR,
|
outDir: BUILD_DIR,
|
||||||
|
@ -15,6 +17,10 @@ const BUNDLER_OPTIONS = {
|
||||||
minify: true,
|
minify: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function statusOutput(message: string) {
|
||||||
|
console.log("> " + message + "...");
|
||||||
|
}
|
||||||
|
|
||||||
function writeTemplate(content: string, value: string) {
|
function writeTemplate(content: string, value: string) {
|
||||||
const outputFile = join(BUILD_DIR, value, 'index.html');
|
const outputFile = join(BUILD_DIR, value, 'index.html');
|
||||||
mkdirp.sync(dirname(outputFile));
|
mkdirp.sync(dirname(outputFile));
|
||||||
|
@ -29,14 +35,22 @@ function renderTemplate(template: HandlebarsTemplateDelegate, value: number) {
|
||||||
(async function() {
|
(async function() {
|
||||||
rimraf.sync(BUILD_DIR);
|
rimraf.sync(BUILD_DIR);
|
||||||
|
|
||||||
|
statusOutput("Creating template");
|
||||||
const bundler = new Bundler(join(SRC_DIR, 'template.html'), BUNDLER_OPTIONS);
|
const bundler = new Bundler(join(SRC_DIR, 'template.html'), BUNDLER_OPTIONS);
|
||||||
|
|
||||||
await bundler.bundle();
|
await bundler.bundle();
|
||||||
|
|
||||||
|
statusOutput("Compiling HTML template");
|
||||||
const template = Handlebars.compile(readFileSync(join(BUILD_DIR, 'template.html')).toString());
|
const template = Handlebars.compile(readFileSync(join(BUILD_DIR, 'template.html')).toString());
|
||||||
|
|
||||||
range(0, 10, 0.5).forEach((i) => {
|
const possibleValues = range(0, 10, 0.5);
|
||||||
console.log(i);
|
const bar = new ProgressBar(PROGRESS_BAR_FORMAT, {
|
||||||
|
total: possibleValues.length,
|
||||||
|
width: 40
|
||||||
|
});
|
||||||
|
|
||||||
|
statusOutput("Generating pages");
|
||||||
|
possibleValues.forEach((i) => {
|
||||||
renderTemplate(template, i);
|
renderTemplate(template, i);
|
||||||
|
bar.tick();
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
|
13
package-lock.json
generated
13
package-lock.json
generated
|
@ -1074,6 +1074,14 @@
|
||||||
"@types/express-serve-static-core": "*"
|
"@types/express-serve-static-core": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@types/progress": {
|
||||||
|
"version": "2.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/progress/-/progress-2.0.3.tgz",
|
||||||
|
"integrity": "sha512-bPOsfCZ4tsTlKiBjBhKnM8jpY5nmIll166IPD58D92hR7G7kZDfx5iB9wGF4NfZrdKolebjeAr3GouYkSGoJ/A==",
|
||||||
|
"requires": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@types/q": {
|
"@types/q": {
|
||||||
"version": "1.5.2",
|
"version": "1.5.2",
|
||||||
"resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.2.tgz",
|
"resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.2.tgz",
|
||||||
|
@ -5295,6 +5303,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz",
|
||||||
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
|
"integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag=="
|
||||||
},
|
},
|
||||||
|
"progress": {
|
||||||
|
"version": "2.0.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz",
|
||||||
|
"integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA=="
|
||||||
|
},
|
||||||
"proto-list": {
|
"proto-list": {
|
||||||
"version": "1.2.4",
|
"version": "1.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/proto-list/-/proto-list-1.2.4.tgz",
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
"@types/mkdirp": "^0.5.2",
|
"@types/mkdirp": "^0.5.2",
|
||||||
"@types/node": "^12.0.10",
|
"@types/node": "^12.0.10",
|
||||||
"@types/parcel-bundler": "^1.12.0",
|
"@types/parcel-bundler": "^1.12.0",
|
||||||
|
"@types/progress": "^2.0.3",
|
||||||
"@types/rimraf": "^2.0.2",
|
"@types/rimraf": "^2.0.2",
|
||||||
"@types/underscore": "^1.9.1",
|
"@types/underscore": "^1.9.1",
|
||||||
"animate.css": "3.7.0",
|
"animate.css": "3.7.0",
|
||||||
|
@ -27,6 +28,7 @@
|
||||||
"handlebars": "^4.1.2",
|
"handlebars": "^4.1.2",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
"parcel-bundler": "1.12.3",
|
"parcel-bundler": "1.12.3",
|
||||||
|
"progress": "^2.0.3",
|
||||||
"rimraf": "^2.6.3",
|
"rimraf": "^2.6.3",
|
||||||
"sass": "^1.22.1",
|
"sass": "^1.22.1",
|
||||||
"ts-node": "8.3.0",
|
"ts-node": "8.3.0",
|
||||||
|
|
Reference in a new issue