Keep the correct state for watching files so the appropriate one is recompiled

This commit is contained in:
Chris Hoffman 2010-02-21 18:59:27 -06:00
parent e795f41bd2
commit f582b73035
2 changed files with 26 additions and 18 deletions

View File

@ -48,14 +48,18 @@
// Compiles the source CoffeeScript, returning the desired JavaScript, tokens,
// or JSLint results.
compile_scripts = function compile_scripts() {
var source;
if (!((source = sources.shift()))) {
return null;
var _a, _b, _c, compile, source;
compile = function compile(source) {
return fs.readFile(source, function(err, code) {
return compile_script(source, code);
});
};
_a = []; _b = sources;
for (_c = 0; _c < _b.length; _c++) {
source = _b[_c];
_a.push(compile(source));
}
return fs.readFile(source, function(err, code) {
compile_script(source, code);
return compile_scripts();
});
return _a;
};
// Compile a single source script, containing the given code, according to the
// requested options. Both compile_scripts and watch_scripts share this method.
@ -93,11 +97,9 @@
// Watch a list of source CoffeeScript files, recompiling them every time the
// files are updated.
watch_scripts = function watch_scripts() {
var _a, _b, _c, source;
_a = []; _b = sources;
for (_c = 0; _c < _b.length; _c++) {
source = _b[_c];
_a.push(process.watchFile(source, {
var _a, _b, _c, source, watch;
watch = function watch(source) {
return process.watchFile(source, {
persistent: true,
interval: 500
}, function(curr, prev) {
@ -107,7 +109,12 @@
return fs.readFile(source, function(err, code) {
return compile_script(source, code);
});
}));
});
};
_a = []; _b = sources;
for (_c = 0; _c < _b.length; _c++) {
source = _b[_c];
_a.push(watch(source));
}
return _a;
};

View File

@ -58,10 +58,10 @@ version: ->
# Compiles the source CoffeeScript, returning the desired JavaScript, tokens,
# or JSLint results.
compile_scripts: ->
return unless source: sources.shift()
fs.readFile source, (err, code) ->
compile_script(source, code)
compile_scripts()
compile: (source) ->
fs.readFile source, (err, code) -> compile_script(source, code)
compile(source) for source in sources
# Compile a single source script, containing the given code, according to the
# requested options. Both compile_scripts and watch_scripts share this method.
@ -83,10 +83,11 @@ compile_script: (source, code) ->
# Watch a list of source CoffeeScript files, recompiling them every time the
# files are updated.
watch_scripts: ->
for source in sources
watch: (source) ->
process.watchFile source, {persistent: true, interval: 500}, (curr, prev) ->
return if curr.mtime.getTime() is prev.mtime.getTime()
fs.readFile source, (err, code) -> compile_script(source, code)
watch(source) for source in sources
# Write out a JavaScript source file with the compiled code.
write_js: (source, js) ->