wayfarer-to-fs
v1.0.2
Published
Save wayfarer-to-server routes to disk
Downloads
5
Maintainers
Readme
wayfarer-to-fs
Save wayfarer-to-server routes to disk. Spiritual successor to brick-router.
Installation
$ npm install wayfarer-to-fs
Usage
const toServer = require('wayfarer-to-server')
const toFs = require('wayfarer-to-fs')
const wayfarer = require('wayfarer')
const filed = require('filed')
const router = toServer(wayfarer())
router.on('/', {
get: (req, res) => filed(__dirname + '/index.html').pipe(res))
})
toFs(router, __dirname + '/dist', (err) => {
if (err) throw err
})
API
toFs(router, [dir,] [overrides,] [cb(err)])
Call all paths on a wayfarer-to-fs
router and write them to a directory.
dir
defaults to ./
. An optional overrides
argument can be passed in to
rename files:
// Write the `/` path as `dist/index.html`
const overrides = { '/': '/index.html' }
toFs(router, __dirname + '/dist', overrides, (err) => {
if (err) throw err
})
Why?
In development an application usually goes through 3 stages:
- experiment - some html, css, js to toy around locally
- static - static files, usually hosted on GitHub pages
- server - application with a working backend
When switching stages it's common to throw out your build process, and start
from scratch. wayfarer-to-fs
allows you to keep the same build process by
serving files both in-memory (for experimentation and servers) and being able
to write to the filesystem (for static pages).
TODO
- browserify example
- html composition example
- bump coverage to 100%