Created
February 15, 2012 04:13
Nodejs Static Site Builder / Watcher - Jade/Styl -> HTML/CSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var stylus = require('stylus'), | |
jade = require('jade'), | |
fs = require('fs'); | |
function compile_jade(){ | |
console.log('compiling html index'); | |
var fn = jade.compile(fs.readFileSync('index.jade', 'utf8'), {pretty: true}); | |
if (fn){ | |
fs.writeFileSync('index.html', fn()); | |
} else { | |
console.log('Bad compile on index jade template'); | |
} | |
} | |
function compile_styl(){ | |
console.log('compiling stylsheets'); | |
stylus.render(fs.readFileSync('site.styl', 'utf8'), {filename: 'site.styl', pretty: true}, function(err, css){ | |
if (err){ | |
console.log('bad compile on stylesheet'); | |
console.log(err); | |
} else { | |
fs.writeFileSync('site.css', css); | |
} | |
}); | |
} | |
function wrap_cb(cbfn){ | |
return function(curr, prev){ | |
if (curr.mtime.getTime() != prev.mtime.getTime()){ | |
console.log('Found Change.'); | |
cbfn(); | |
} | |
} | |
} | |
fs.watchFile('index.jade', wrap_cb(compile_jade)); | |
fs.watchFile('site.styl', wrap_cb(compile_styl)); | |
compile_jade(); | |
compile_styl(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment