Skip to content

Instantly share code, notes, and snippets.

@StevePotter
Created November 8, 2012 20:17
Show Gist options
  • Save StevePotter/4041281 to your computer and use it in GitHub Desktop.
Save StevePotter/4041281 to your computer and use it in GitHub Desktop.
cake task for precompiling jade templates using clientjade
{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