Created
November 8, 2012 20:17
-
-
Save StevePotter/4041281 to your computer and use it in GitHub Desktop.
cake task for precompiling jade templates using clientjade
This file contains 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
{exec} = require 'child_process' | |
chokidar = require('chokidar') | |
fs = require 'fs' | |
task 'build:templates:watch', 'in /templates continually precompile jade templates into public/templates.js', (options) -> | |
console.log options | |
watcher = chokidar.watch "templates", | |
ignored: (name) -> false | |
persistent: true | |
compile = -> | |
command = 'clientjade templates/*.jade > public/js/templates.js' | |
console.log "Executing " + command | |
exec command, (err, stdout, stderr) -> | |
throw err if err | |
console.log stdout + stderr | |
updateIfNecessary = (path) -> | |
if path.indexOf('.jade') > 0 | |
console.log 'Compiling templates due to ' + path | |
compile() | |
#initial adds get the event emitted, so this avoids that. just a workaround | |
setTimeout -> | |
watcher.on 'add', updateIfNecessary | |
, 4000 | |
watcher.on 'change', updateIfNecessary | |
console.log "Initial compilation" | |
compile() | |
task 'build:templates', 'Build jade templates from templates/*.jade to public/js/templates.js', -> | |
exec 'clientjade templates/*.jade > templates/templates.js', (err, stdout, stderr) -> | |
throw err if err | |
console.log stdout + stderr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment