diff --git a/Makefile b/Makefile index fb3fef3ff..6c549f278 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/build.js b/build.js index 4863bf1a2..57257d736 100644 --- a/build.js +++ b/build.js @@ -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') @@ -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) { diff --git a/package.json b/package.json index 5fdd1b511..a3b6a24df 100644 --- a/package.json +++ b/package.json @@ -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",