1
Fork 0

Install (and run) prettier

This commit is contained in:
Jake Howard 2019-06-29 17:43:03 +01:00
parent 2dff46d74d
commit b8b16f3ba0
Signed by: jake
GPG key ID: 57AFB45680EDD477
4 changed files with 26 additions and 13 deletions

4
.prettierrc Normal file
View file

@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "es5"
}

View file

@ -9,7 +9,7 @@ import ProgressBar from 'progress';
const BUILD_DIR = join(__dirname, 'build');
const SRC_DIR = join(__dirname, 'src');
const PROGRESS_BAR_FORMAT = "[:bar] :rate/ps :percent :current/:total";
const PROGRESS_BAR_FORMAT = '[:bar] :rate/ps :percent :current/:total';
const MAX_VALUE = process.env.MAX_VALUE ? parseInt(process.env.MAX_VALUE) : 10;
const BUNDLER_OPTIONS = {
@ -19,7 +19,7 @@ const BUNDLER_OPTIONS = {
};
function statusOutput(message: string) {
console.log("> " + message + "...");
console.log('> ' + message + '...');
}
function isPrecision(value: number, precision: number) {
@ -36,32 +36,34 @@ function renderTemplate(template: HandlebarsTemplateDelegate, value: number) {
const html = template({ value });
writeTemplate(html, value.toString());
if (isPrecision(value, 1)) {
writeTemplate(html, value.toString() + "0");
writeTemplate(html, value.toString() + '0');
}
if (isPrecision(value, 0)) {
writeTemplate(html, value.toString() + ".0");
writeTemplate(html, value.toString() + ".00");
writeTemplate(html, value.toString() + '.0');
writeTemplate(html, value.toString() + '.00');
}
}
(async function() {
rimraf.sync(BUILD_DIR);
statusOutput("Creating template");
statusOutput('Creating template');
const bundler = new Bundler(join(SRC_DIR, 'template.html'), BUNDLER_OPTIONS);
await bundler.bundle();
statusOutput("Compiling HTML template");
const template = Handlebars.compile(readFileSync(join(BUILD_DIR, 'template.html')).toString());
statusOutput('Compiling HTML template');
const template = Handlebars.compile(
readFileSync(join(BUILD_DIR, 'template.html')).toString()
);
const possibleValues = range(0, MAX_VALUE, 0.01);
const bar = new ProgressBar(PROGRESS_BAR_FORMAT, {
total: possibleValues.length,
width: 40
width: 40,
});
statusOutput("Generating pages");
possibleValues.forEach((i) => {
statusOutput('Generating pages');
possibleValues.forEach(i => {
if (i) {
renderTemplate(template, parseFloat(i.toFixed(2)));
}

5
package-lock.json generated
View file

@ -5288,6 +5288,11 @@
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz",
"integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ="
},
"prettier": {
"version": "1.18.2",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-1.18.2.tgz",
"integrity": "sha512-OeHeMc0JhFE9idD4ZdtNibzY0+TPHSpSSb9h8FqtP+YnoZZ1sl8Vc9b1sasjfymH3SonAF4QcA2+mzHPhMvIiw=="
},
"private": {
"version": "0.1.8",
"resolved": "https://registry.npmjs.org/private/-/private-0.1.8.tgz",

View file

@ -4,7 +4,8 @@
"main": "index.js",
"scripts": {
"build": "ts-node index.ts",
"lint": "tsc --noEmit --project tsconfig.json && tslint --project tsconfig.json index.ts"
"lint": "tsc --noEmit --project tsconfig.json && tslint --project tsconfig.json index.ts",
"prettier": "prettier --write index.ts"
},
"repository": {
"type": "git",
@ -28,6 +29,7 @@
"handlebars": "^4.1.2",
"mkdirp": "^0.5.1",
"parcel-bundler": "1.12.3",
"prettier": "^1.18.2",
"progress": "^2.0.3",
"rimraf": "^2.6.3",
"sass": "^1.22.1",