From c5a8acc12db01ab75884229bac2e914cc62e7bb5 Mon Sep 17 00:00:00 2001 From: joshbuddy Date: Mon, 12 Jun 2017 18:39:14 -0700 Subject: [PATCH] Linting with "test" --- circle.yml | 11 ++ js/constants/colors.js | 20 ++-- js/fox.js | 78 +++++++------ js/render-fox.js | 243 ++++++++++++++++++++--------------------- run.js | 18 +-- server.js | 60 +++++----- 6 files changed, 219 insertions(+), 211 deletions(-) create mode 100644 circle.yml diff --git a/circle.yml b/circle.yml new file mode 100644 index 0000000..9cf2b94 --- /dev/null +++ b/circle.yml @@ -0,0 +1,11 @@ +dependencies: + pre: + - sudo apt-get install libgif-dev + +machine: + node: + version: 6.7.0 + +test: + override: + - npm run lint diff --git a/js/constants/colors.js b/js/constants/colors.js index 53b6da1..1c22588 100644 --- a/js/constants/colors.js +++ b/js/constants/colors.js @@ -1,16 +1,16 @@ const head = { - brick: [0, 62, 53], - yellow: [48, 100, 64] + brick: [0, 62, 53], + yellow: [48, 100, 64] } const bg = { - forest: '#006375', - green: '#63D6A3', - blue: '#358EFF', - salmon: '#FF9B7A', - coral: '#F96854', + forest: '#006375', + green: '#63D6A3', + blue: '#358EFF', + salmon: '#FF9B7A', + coral: '#F96854' } module.exports = { - head: head, - bg: bg -}; + head: head, + bg: bg +} diff --git a/js/fox.js b/js/fox.js index a249124..e0d63b5 100644 --- a/js/fox.js +++ b/js/fox.js @@ -1,95 +1,91 @@ -const Chance = require('chance'); -const colors = require('./constants/colors.js'); +const Chance = require('chance') +const colors = require('./constants/colors.js') const hsl = function (h, s, l) { - return "hsl(" + h + "," + s + "%, " + l + "%)"; + return 'hsl(' + h + ',' + s + '%, ' + l + '%)' } const Fox = function (IMG_WIDTH, IMG_HEIGHT, seed) { - if (seed) { - chance = new Chance(seed); - } else { - chance = new Chance(); - } + const chance = seed ? new Chance(seed) : new Chance() // origin: head top left corner const kappa = chance.floating({min: 0.2, max: 0.45}) const headColor = (function () { - const level = chance.floating({min: 0, max: 1}); - const result = []; - const min = colors.head.brick; - const max = colors.head.yellow; - for (let i=0; i { - app.listen(activePort, () => { - console.log('worker ' + worker.id + ' is listening on port ' + activePort); - }); + app.listen(activePort, () => { + console.log('worker ' + worker.id + ' is listening on port ' + activePort) + }) }, { - 'respawn': true, // workers will restart on failure - 'verbose': true, // logs what happens to console -}); + 'respawn': true, // workers will restart on failure + 'verbose': true // logs what happens to console +}) diff --git a/server.js b/server.js index 912edb4..53bed90 100644 --- a/server.js +++ b/server.js @@ -1,42 +1,44 @@ +/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "newrelic" }] */ + try { - const newrelic = require('newrelic'); + const newrelic = require('newrelic') } catch (e) { - console.error("WARNING unable to load newrelic") + console.error('WARNING unable to load newrelic') } -const express = require('express'); -const uuid = require('uuid/v4'); -const sanitize = require('sanitize-filename'); -const Canvas = require('canvas'); +const express = require('express') +const uuid = require('uuid/v4') +const sanitize = require('sanitize-filename') +const Canvas = require('canvas') -const Fox = require('./js/fox.js'); -const renderFox = require('./js/render-fox.js'); +const Fox = require('./js/fox.js') +const renderFox = require('./js/render-fox.js') -function composeImage(width, height, seed) { - seed = seed || uuid(); - const fox = Fox(width, height, seed); - const canvas = new Canvas(width, height); - renderFox(canvas, fox); - return canvas; +function composeImage (width, height, seed) { + seed = seed || uuid() + const fox = Fox(width, height, seed) + const canvas = new Canvas(width, height) + renderFox(canvas, fox) + return canvas }; -const cacheTimeout = 60 * 60 * 24 * 30; -const app = express(); +const cacheTimeout = 60 * 60 * 24 * 30 +const app = express() app.get('/healthcheck', (req, res) => { - res.status(200).end(); -}); + res.status(200).end() +}) app.get('/:width/:seed', (req, res) => { - let width = parseInt(req.params.width) || 400; - if (width > 400) width = 400; - const seed = sanitize(req.params.seed) || uuid(); - const canvas = composeImage(width, width, seed); - const buffer = canvas.toBuffer(); - res.set('Cache-Control', 'max-age=' + cacheTimeout); - res.set('Content-length', buffer.length); - res.type('png'); - res.end(buffer, 'binary'); -}); + let width = parseInt(req.params.width) || 400 + if (width > 400) width = 400 + const seed = sanitize(req.params.seed) || uuid() + const canvas = composeImage(width, width, seed) + const buffer = canvas.toBuffer() + res.set('Cache-Control', 'max-age=' + cacheTimeout) + res.set('Content-length', buffer.length) + res.type('png') + res.end(buffer, 'binary') +}) -module.exports = app; +module.exports = app