Skip to content
Browse files

Keep the correct state for watching files so the appropriate one is r…

…ecompiled
  • Loading branch information...
1 parent e795f41 commit f582b73035161abe458c265581b5dd7e8fdbff20 @cehoffman cehoffman committed
Showing with 26 additions and 18 deletions.
  1. +20 −13 lib/command_line.js
  2. +6 −5 src/command_line.coffee
View
33 lib/command_line.js
@@ -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
11 src/command_line.coffee
@@ -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) ->

0 comments on commit f582b73

Please sign in to comment.
Something went wrong with that request. Please try again.