mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-04-11 03:00:13 -04:00
Keep the correct state for watching files so the appropriate one is recompiled
This commit is contained in:
@@ -48,14 +48,18 @@
|
|||||||
// Compiles the source CoffeeScript, returning the desired JavaScript, tokens,
|
// Compiles the source CoffeeScript, returning the desired JavaScript, tokens,
|
||||||
// or JSLint results.
|
// or JSLint results.
|
||||||
compile_scripts = function compile_scripts() {
|
compile_scripts = function compile_scripts() {
|
||||||
var source;
|
var _a, _b, _c, compile, source;
|
||||||
if (!((source = sources.shift()))) {
|
compile = function compile(source) {
|
||||||
return null;
|
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) {
|
return _a;
|
||||||
compile_script(source, code);
|
|
||||||
return compile_scripts();
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
// Compile a single source script, containing the given code, according to the
|
// Compile a single source script, containing the given code, according to the
|
||||||
// requested options. Both compile_scripts and watch_scripts share this method.
|
// 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
|
// Watch a list of source CoffeeScript files, recompiling them every time the
|
||||||
// files are updated.
|
// files are updated.
|
||||||
watch_scripts = function watch_scripts() {
|
watch_scripts = function watch_scripts() {
|
||||||
var _a, _b, _c, source;
|
var _a, _b, _c, source, watch;
|
||||||
_a = []; _b = sources;
|
watch = function watch(source) {
|
||||||
for (_c = 0; _c < _b.length; _c++) {
|
return process.watchFile(source, {
|
||||||
source = _b[_c];
|
|
||||||
_a.push(process.watchFile(source, {
|
|
||||||
persistent: true,
|
persistent: true,
|
||||||
interval: 500
|
interval: 500
|
||||||
}, function(curr, prev) {
|
}, function(curr, prev) {
|
||||||
@@ -107,7 +109,12 @@
|
|||||||
return fs.readFile(source, function(err, code) {
|
return fs.readFile(source, function(err, code) {
|
||||||
return compile_script(source, 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;
|
return _a;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -58,10 +58,10 @@ version: ->
|
|||||||
# Compiles the source CoffeeScript, returning the desired JavaScript, tokens,
|
# Compiles the source CoffeeScript, returning the desired JavaScript, tokens,
|
||||||
# or JSLint results.
|
# or JSLint results.
|
||||||
compile_scripts: ->
|
compile_scripts: ->
|
||||||
return unless source: sources.shift()
|
compile: (source) ->
|
||||||
fs.readFile source, (err, code) ->
|
fs.readFile source, (err, code) -> compile_script(source, code)
|
||||||
compile_script(source, code)
|
compile(source) for source in sources
|
||||||
compile_scripts()
|
|
||||||
|
|
||||||
# Compile a single source script, containing the given code, according to the
|
# Compile a single source script, containing the given code, according to the
|
||||||
# requested options. Both compile_scripts and watch_scripts share this method.
|
# 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
|
# Watch a list of source CoffeeScript files, recompiling them every time the
|
||||||
# files are updated.
|
# files are updated.
|
||||||
watch_scripts: ->
|
watch_scripts: ->
|
||||||
for source in sources
|
watch: (source) ->
|
||||||
process.watchFile source, {persistent: true, interval: 500}, (curr, prev) ->
|
process.watchFile source, {persistent: true, interval: 500}, (curr, prev) ->
|
||||||
return if curr.mtime.getTime() is prev.mtime.getTime()
|
return if curr.mtime.getTime() is prev.mtime.getTime()
|
||||||
fs.readFile source, (err, code) -> compile_script(source, code)
|
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 out a JavaScript source file with the compiled code.
|
||||||
write_js: (source, js) ->
|
write_js: (source, js) ->
|
||||||
|
|||||||
Reference in New Issue
Block a user