feat: use configly/TOML for configuration
Alan Pearce alan@alanpearce.eu
Sun, 18 Jun 2017 20:07:14 +0200
6 files changed, 62 insertions(+), 6 deletions(-)
M package.json → package.json
@@ -29,10 +29,12 @@ "standard": "^10.0.2", "supertest": "^3.0.0" }, "dependencies": { + "configly": "^4.1.0", "gray-matter": "^2.1.1", "koa": "^2.2.0", "koa-nunjucks-next": "^1.1.3", "koa-router": "^7.2.1", - "markdown-it": "^8.3.1" + "markdown-it": "^8.3.1", + "toml": "^2.3.2" } }
M src/index.js → src/index.js
@@ -1,9 +1,11 @@ 'use strict' -const PORT = process.env.PORT || 3000 - const Koa = require('koa') const app = new Koa() + +const config = require('./modules/config.js') + +const PORT = process.env.PORT || config.server.port const Router = require('koa-router') const router = new Router() @@ -11,7 +13,7 @@ const view = require('koa-nunjucks-next') const Posts = require('./modules/posts.js') -const posts = Posts.getFolder(process.env.POST_DIR) +const posts = Posts.getFolder(config.posts.folder) app.use( view(`${__dirname}/views`, {
A src/modules/config.js
@@ -0,0 +1,10 @@+'use strict' + +const TOML = require('toml') +const config = require('configly') + +module.exports = config({ + parsers: { + toml: TOML.parse + } +})
M test/index.test.js → test/index.test.js
@@ -2,7 +2,9 @@ const test = require('ava') const path = require('path') const request = require('supertest') -process.env.POST_DIR = path.resolve(__dirname, '../test/data/') +const config = require('../src/modules/config.js') +config.posts.folder = path.resolve(__dirname, './data/') + const app = require('../src/index.js') test('homepage', t => {
M yarn.lock → yarn.lock
@@ -941,6 +941,10 @@ commondir@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" +compare-property@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/compare-property/-/compare-property-2.0.0.tgz#e535ae960832a16ab01c5e6af2e96bc845134700" + component-emitter@^1.2.0: version "1.2.1" resolved "https://registry.yarnpkg.com/component-emitter/-/component-emitter-1.2.1.tgz#137918d6d78283f7df7a6b7c5a63e140e69425e6" @@ -956,6 +960,16 @@ dependencies: inherits "^2.0.3" readable-stream "^2.2.2" typedarray "^0.0.6" + +configly@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/configly/-/configly-4.1.0.tgz#48a6af73cddd1e4d98d44fe264b78db2b0880bce" + dependencies: + compare-property "^2.0.0" + deeply "^2.0.3" + fulcon "^1.0.2" + precise-typeof "^1.0.2" + stripbom "^3.0.0" configstore@^3.0.0: version "3.1.0" @@ -1127,6 +1141,13 @@ deep-is@~0.1.3: version "0.1.3" resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" +deeply@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/deeply/-/deeply-2.0.3.tgz#613b1fe7380c00e36df896872f0efaecb1642342" + dependencies: + fulcon "^1.0.1" + precise-typeof "^1.0.2" + define-properties@^1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/define-properties/-/define-properties-1.1.2.tgz#83a73f2fea569898fb737193c8f873caf6d45c94" @@ -1756,6 +1777,10 @@ inherits "~2.0.0" mkdirp ">=0.5 0" rimraf "2" +fulcon@^1.0.1, fulcon@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/fulcon/-/fulcon-1.0.2.tgz#8a4dfda4c73fcd9cc62a79d5045c392b45547320" + function-bind@^1.0.2, function-bind@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.0.tgz#16176714c801798e4e8f2cf7f7529467bb4a5771" @@ -2156,7 +2181,7 @@ resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-1.0.1.tgz#75f16642b480f187a711c814161fd3a4a7655898" dependencies: binary-extensions "^1.0.0" -is-buffer@^1.1.5: +is-buffer@^1.1.1, is-buffer@^1.1.5: version "1.1.5" resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.5.tgz#1f3b26ef613b214b88cbca23cc6c01d87961eecc" @@ -3393,6 +3418,12 @@ pluralize@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/pluralize/-/pluralize-1.2.1.tgz#d1a21483fd22bb41e58a12fa3421823140897c45" +precise-typeof@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/precise-typeof/-/precise-typeof-1.0.2.tgz#db8ed470fd08470f5ef7c9b08ee70d6dd5232f0b" + dependencies: + is-buffer "^1.1.1" + prelude-ls@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" @@ -4048,6 +4079,10 @@ strip-json-comments@~2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" + +stripbom@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/stripbom/-/stripbom-3.0.0.tgz#0159d615b4ebcdfa78aae57c87d4f81e96ed979b" superagent@^3.0.0: version "3.5.2"