UNPKG

pages

Version:

AngularJS / Node.js sidekick.

111 lines (75 loc) 2.74 kB
async = require 'async' gaze = require 'gaze' utils = require '../../lib/utils' log = require '../../lib/log' notify = require '../../lib/notify' refresh = require '../../lib/refresh' cleanup = require './cleanup' deps = require './deps' jsCompiler = require './js' cssCompiler = require './css' jadeCompiler = require './jade' compiling = false watcherCleanup = (cb) -> commands = [ "rm -r #{process.cwd()}/_app/compiled" "rm -r #{process.cwd()}/_app/views" "rm #{process.cwd()}/_app/index.html" ] async.each commands, utils.runWithCb, () -> cb() The cost of this `watch` being faster than than `node-watch` is that a backoff algorithm needed to be implemented. watcherBake = () -> return log.info compiler: 'Already compiling, ignoring change.' if compiling Remove the cached config file if we updated any references, etc. delete require.cache["#{process.cwd()}/pages.litcoffee"] compiling = true Reset asset definitions. global.pages.opts.watch = false global.pages = opts: global.pages.opts assets: js: [] css: [] async.series [ watcherCleanup jsCompiler.build cssCompiler.build jadeCompiler.build ], () -> refresh global.pages.opts.browser compiling = false log.info compiler: 'Pages re-compiled application.' watch = (cb) -> return cb() if process.env.NODE_ENV is 'production' or global.pages.opts.watch is false Now, add to resources. createMonitor = (obj) -> Current issue - only relative paths work. obj.dir = obj.dir.replace "#{process.cwd()}/", '' log.info compiler: "Watching #{obj.dir} for changes..." gaze obj.dir, (err, watcher) -> @on 'all', (event, filepath) => log.warn compiler: "#{filepath} was #{event}" obj.cb filepath dirs = [ dir: "#{process.cwd()}/pages.litcoffee" cb: () -> log.warn 'Please re-start Pages for changes to take affect.' , dir: "#{process.cwd()}/index.jade" cb: watcherBake , dir: "#{process.cwd()}/views/**/*.jade" cb: watcherBake , dir: "#{process.cwd()}/angular_modules/**/*.litcoffee" cb: watcherBake , dir: "#{process.cwd()}/pages/**/*.litcoffee" cb: watcherBake , dir: "#{process.cwd()}/css/**/*.css" cb: watcherBake ] createMonitor dir for dir in dirs if global.pages.opts.watch cb() ## Public API ## module.exports = exports = (cb) -> watch () -> cb()