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 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 :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 MAX_VALUE = process.env.MAX_VALUE ? parseInt(process.env.MAX_VALUE) : 10;
const BUNDLER_OPTIONS = { const BUNDLER_OPTIONS = {
@ -19,7 +19,7 @@ const BUNDLER_OPTIONS = {
}; };
function statusOutput(message: string) { function statusOutput(message: string) {
console.log("> " + message + "..."); console.log('> ' + message + '...');
} }
function isPrecision(value: number, precision: number) { function isPrecision(value: number, precision: number) {
@ -33,35 +33,37 @@ function writeTemplate(content: string, value: string) {
} }
function renderTemplate(template: HandlebarsTemplateDelegate, value: number) { function renderTemplate(template: HandlebarsTemplateDelegate, value: number) {
const html = template({value}); const html = template({ value });
writeTemplate(html, value.toString()); writeTemplate(html, value.toString());
if (isPrecision(value, 1)) { if (isPrecision(value, 1)) {
writeTemplate(html, value.toString() + "0"); writeTemplate(html, value.toString() + '0');
} }
if (isPrecision(value, 0)) { if (isPrecision(value, 0)) {
writeTemplate(html, value.toString() + ".0"); writeTemplate(html, value.toString() + '.0');
writeTemplate(html, value.toString() + ".00"); writeTemplate(html, value.toString() + '.00');
} }
} }
(async function() { (async function() {
rimraf.sync(BUILD_DIR); rimraf.sync(BUILD_DIR);
statusOutput("Creating template"); 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"); 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()
);
const possibleValues = range(0, MAX_VALUE, 0.01); const possibleValues = range(0, MAX_VALUE, 0.01);
const bar = new ProgressBar(PROGRESS_BAR_FORMAT, { const bar = new ProgressBar(PROGRESS_BAR_FORMAT, {
total: possibleValues.length, total: possibleValues.length,
width: 40 width: 40,
}); });
statusOutput("Generating pages"); statusOutput('Generating pages');
possibleValues.forEach((i) => { possibleValues.forEach(i => {
if (i) { if (i) {
renderTemplate(template, parseFloat(i.toFixed(2))); 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", "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.1.2.tgz",
"integrity": "sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=" "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": { "private": {
"version": "0.1.8", "version": "0.1.8",
"resolved": "https://registry.npmjs.org/private/-/private-0.1.8.tgz", "resolved": "https://registry.npmjs.org/private/-/private-0.1.8.tgz",

View file

@ -4,7 +4,8 @@
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"build": "ts-node index.ts", "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": { "repository": {
"type": "git", "type": "git",
@ -28,6 +29,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",
"prettier": "^1.18.2",
"progress": "^2.0.3", "progress": "^2.0.3",
"rimraf": "^2.6.3", "rimraf": "^2.6.3",
"sass": "^1.22.1", "sass": "^1.22.1",