Skip to content
This repository has been archived by the owner on Apr 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #35 from ipfs/feature/watch-serve
Browse files Browse the repository at this point in the history
Add serve option to Make
  • Loading branch information
RichardLitt committed Mar 10, 2016
2 parents 49c49cb + cae036a commit 2b17181
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 5 deletions.
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ record="_dnslink.blog"

build: $(shell find src tmpl) build.js package.json
node build.js
# FIXME: this watches + serves. ideally it would be an option --watch.

serve: $(shell find src tmpl) build.js package.json
node build.js --watch

node_modules: package.json
npm install
Expand Down
29 changes: 25 additions & 4 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,34 @@ var feed = require('metalsmith-feed')
var msstatic = require('metalsmith-static')
var drafts = require('metalsmith-drafts')
var headingsidentifier = require('metalsmith-headings-identifier')
var msIf = require('metalsmith-if')

var nunjucks = require('nunjucks')
var njmd = require('nunjucks-markdown')
var njdate = require('nunjucks-date')
var marked = require('marked')

var meow = require('meow')

var cli = meow(`
Usage
$ node build.js
Options
-w, --watch Watch the files
Examples
$ node build.js --watch
`)

marked.setOptions({
gfm: true,
tables: true,
smartLists: true
})

var njenv = nunjucks.configure()
var njenv = nunjucks.configure({watch: cli.flags.watch})
njmd.register(njenv, marked)

njdate.setDefaultFormat('YYYY-MM-DD, h:mm:ss a')
Expand Down Expand Up @@ -52,11 +67,17 @@ Metalsmith(__dirname)
.use(permalinks())
.use(feed({'collection': 'posts'}))
.use(msstatic({'src': 'tmpl/static', 'dest': 'static'}))
.use(serve({
.use(msIf(
cli.flags.watch,
serve({
'port': 8081,
'verbose': true
}))
.use(watch())
})
))
.use(msIf(
cli.flags.watch,
watch()
))
.destination('./build')
.build(function (err) {
if (err) {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
"main": "index.js",
"dependencies": {
"marked": "^0.3.3",
"meow": "^3.7.0",
"metalsmith": "^1.7.0",
"metalsmith-collections": "^0.7.0",
"metalsmith-debug": "0.0.2",
"metalsmith-drafts": "0.0.1",
"metalsmith-feed": "0.0.6",
"metalsmith-headings-identifier": "0.0.4",
"metalsmith-if": "^0.1.1",
"metalsmith-markdown": "^0.2.1",
"metalsmith-partial": "^0.1.0",
"metalsmith-permalinks": "^0.4.0",
Expand Down

0 comments on commit 2b17181

Please sign in to comment.