UNPKG

coffee-watcher

Version:

A script that can watch a directory and recompile your .coffee scripts if they change

47 lines (31 loc) 1.71 kB
// Generated by CoffeeScript 1.6.2 (function() { var WATCHED_FILES, compileCoffeeScript, compileIfNeeded, findCoffeeFiles, program, usage, watcher_lib; usage = "Watch a directory and recompile .coffee scripts if they change.\nUsage: coffee-watcher -p [prefix] -d [directory]."; program = require('commander'); program.version('1.6.0').usage(usage).option('-d, --directory <path>', 'Specify which directory to scan. [Default: .]').option('-p, --prefix <type>', 'Which prefix should the compiled files have? Default is script.coffee will be compiled to .coffee.script.js.').option('-n, --noprefix', "Don't use a prefix. script.coffee will be compiled to script.js. Not the default option!").parse(process.argv); program.directory = program.directory || '.'; if (program.prefix === void 0 || program.prefix === true) { program.prefix = '.coffee.'; } if (program.noprefix) { program.prefix = ''; } require('util').puts("Compiling files in `" + program.directory + "`. The prefix is `" + program.prefix + "`..."); watcher_lib = require('watcher_lib'); findCoffeeFiles = function(dir) { return watcher_lib.findFiles('*.coffee', dir, compileIfNeeded); }; WATCHED_FILES = {}; compileIfNeeded = function(file) { return watcher_lib.compileIfNeeded(WATCHED_FILES, file, compileCoffeeScript); }; compileCoffeeScript = function(file) { var fnGetOutputFile; fnGetOutputFile = function(file) { return file.replace(/([^\/\\]+)\.coffee/, "" + program.prefix + "$1.js"); }; return watcher_lib.compileFile("coffee -bp " + file, file, fnGetOutputFile); }; watcher_lib.startDirectoryPoll(program.directory, findCoffeeFiles); }).call(this);