From b8b16f3ba06a476cb53d9bfd852882338c96ac75 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Sat, 29 Jun 2019 17:43:03 +0100 Subject: [PATCH] Install (and run) prettier --- .prettierrc | 4 ++++ index.ts | 26 ++++++++++++++------------ package-lock.json | 5 +++++ package.json | 4 +++- 4 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..d7da98a --- /dev/null +++ b/.prettierrc @@ -0,0 +1,4 @@ +{ + "singleQuote": true, + "trailingComma": "es5" +} diff --git a/index.ts b/index.ts index 69a5d6d..1b38cbf 100644 --- a/index.ts +++ b/index.ts @@ -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) { @@ -33,35 +33,37 @@ function writeTemplate(content: string, value: string) { } function renderTemplate(template: HandlebarsTemplateDelegate, value: number) { - const html = template({value}); + 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))); } diff --git a/package-lock.json b/package-lock.json index 4c59432..8ecba16 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 7efd724..8458291 100644 --- a/package.json +++ b/package.json @@ -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",