From 91372e53601fc2008de6a49c5c1d95fc75876dea Mon Sep 17 00:00:00 2001 From: shavyg2 Date: Sat, 12 Apr 2014 02:09:15 -0400 Subject: [PATCH] added the watch functionality --- aplication.coffee | 9 +- bin/Main.js | 224 +++++++++++++++++++++++---------------------- src/Main.coffee | 21 +++-- test/Child.coffee | 3 +- test/Person.coffee | 6 +- 5 files changed, 138 insertions(+), 125 deletions(-) diff --git a/aplication.coffee b/aplication.coffee index a14f539..0490594 100644 --- a/aplication.coffee +++ b/aplication.coffee @@ -2,10 +2,10 @@ class Person constructor:(@name)-> speak:-> - console.log "hi my name is" + console.log "hi my name is #{@name}" - walk:-> - "console.log walking" + run:-> + "console.log fast running" @@ -14,5 +14,6 @@ class Child extends Person super(name) - + cry:-> + console.log "cry" diff --git a/bin/Main.js b/bin/Main.js index 5d0b297..b4df777 100644 --- a/bin/Main.js +++ b/bin/Main.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript 1.7.1 (function() { - var FileFinder, List, added, bundle, chokidar, e, f, file, fileFinder, fs, list, output, path, program, recursive, unadded, watchMaster, watcher, _i, _len, + var FileFinder, List, added, chokidar, e, f, file, fileFinder, fs, list, output, path, program, recursive, unadded, watchMaster, watcher, _i, _len, __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; }; chokidar = require('chokidar'); @@ -35,95 +35,101 @@ unadded = []; - recursive = function(file) { - var e, f, _i, _len, _ref, _results; - if (program.verbose) { - console.log("parsing " + file); - } - try { - fileFinder.push(new FileFinder(file, program.watch)); - } catch (_error) { - e = _error; - console.log("file '" + file + "' doesn't exist"); - } - _ref = fileFinder[fileFinder.length - 1].includeStack; - _results = []; - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - f = _ref[_i]; - if (f.required !== "") { - _results.push(arguments.callee(f.required)); - } else { - _results.push(void 0); + recursive = (function(_this) { + return function(file) { + var e, f, _i, _len, _ref, _results; + if (program.verbose) { + console.log("parsing " + file); } - } - return _results; - }; - - bundle = function() { - var stack, _i, _len, _results; - _results = []; - for (_i = 0, _len = fileFinder.length; _i < _len; _i++) { - bundle = fileFinder[_i]; - _results.push((function() { - var _j, _len1, _ref, _ref1, _ref2, _results1; - _ref = bundle.includeStack; - _results1 = []; - for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { - stack = _ref[_j]; - list.append(stack); - if (program.watch) { - if (_ref1 = stack.required, __indexOf.call(added, _ref1) < 0) { - unadded.push(stack.required); - } - if (_ref2 = stack.caller, __indexOf.call(added, _ref2) < 0) { - _results1.push(unadded.push(stack.caller)); + try { + fileFinder.push(new FileFinder(file, program.watch)); + } catch (_error) { + e = _error; + console.log("file '" + file + "' doesn't exist"); + } + _ref = fileFinder[fileFinder.length - 1].includeStack; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + f = _ref[_i]; + if (f.required !== "") { + _results.push(arguments.callee(f.required)); + } else { + _results.push(void 0); + } + } + return _results; + }; + })(this); + + process.bundle = (function(_this) { + return function() { + var bundle, stack, _i, _len, _results; + _results = []; + for (_i = 0, _len = fileFinder.length; _i < _len; _i++) { + bundle = fileFinder[_i]; + _results.push((function() { + var _j, _len1, _ref, _ref1, _ref2, _results1; + _ref = bundle.includeStack; + _results1 = []; + for (_j = 0, _len1 = _ref.length; _j < _len1; _j++) { + stack = _ref[_j]; + list.append(stack); + if (program.watch) { + if (_ref1 = stack.required, __indexOf.call(added, _ref1) < 0) { + unadded.push(stack.required); + } + if (_ref2 = stack.caller, __indexOf.call(added, _ref2) < 0) { + _results1.push(unadded.push(stack.caller)); + } else { + _results1.push(void 0); + } } else { _results1.push(void 0); } - } else { - _results1.push(void 0); } - } - return _results1; - })()); - } - return _results; - }; - - output = function() { - var data, i, item, _i, _ref; - if (!list.graph) { - console.log("Nothing to output?"); - process.exit(0); - } - if (program.verbose) { - console.log("Outputing..."); - } - if (program.output) { - fs.writeFileSync(program.output, ""); - } - for (i = _i = _ref = list.graph.length - 1; _ref <= 0 ? _i <= 0 : _i >= 0; i = _ref <= 0 ? ++_i : --_i) { - item = list.graph[i]; - data = fs.readFileSync(item, { - "encoding": "utf-8" - }); - data = data.replace(/# ?include .+/g, ""); - data += "\n"; + return _results1; + })()); + } + return _results; + }; + })(this); + + output = (function(_this) { + return function() { + var data, i, item, _i, _ref; + if (!list.graph) { + console.log("Nothing to output?"); + process.exit(0); + } + if (program.verbose) { + console.log("Outputing..."); + } if (program.output) { - if (program.verbose) { - console.log("writing file " + item); + fs.writeFileSync(program.output, ""); + } + for (i = _i = _ref = list.graph.length - 1; _ref <= 0 ? _i <= 0 : _i >= 0; i = _ref <= 0 ? ++_i : --_i) { + item = list.graph[i]; + data = fs.readFileSync(item, { + "encoding": "utf-8" + }); + data = data.replace(/# ?include .+/g, ""); + data += "\n"; + if (program.output) { + if (program.verbose) { + console.log("writing file " + item); + } + fs.appendFileSync(program.output, data); + } else { + console.log(data); } - fs.appendFileSync(program.output, data); + } + if (program.output) { + return console.log("wrote to " + program.output + " complete"); } else { - console.log(data); + return console.log("write completed"); } - } - if (program.output) { - return console.log("wrote to " + program.output + " complete"); - } else { - return console.log("write completed"); - } - }; + }; + })(this); if (file.length === 0) { console.log("No Input"); @@ -131,40 +137,44 @@ watchMaster = null; - watcher = function() { - var _i, _len; - if (program.watch) { - if (program.verbose) { - console.log("watch has been added"); - } - for (_i = 0, _len = unadded.length; _i < _len; _i++) { - file = unadded[_i]; - if (typeof watcthMaster === "undefined" || watcthMaster === null) { - watchMaster = chokidar.watch(file, { - persistent: true - }); - watchMaster.on("change", (function(_this) { - return function(newfile) { - recursive(newfile); - bundle(); - return output(); - }; - })(this)); + watcher = (function(_this) { + return function() { + var _i, _len; + if (program.watch) { + if (program.verbose) { + console.log("watch has been added"); + } + console.log(unadded); + for (_i = 0, _len = unadded.length; _i < _len; _i++) { + file = unadded[_i]; + if (file !== "") { + if (typeof watcthMaster === "undefined" || watcthMaster === null) { + watchMaster = chokidar.watch(file, { + persistent: true + }); + watchMaster.on("change", function(newfile) { + recursive(newfile); + process.bundle(); + return output(); + }); + } else { + watchMaster.add(file); + added.push(file); + } + } } - watchMaster.add(file); - added.push(file); + unadded = []; + return watchMaster.close(); } - unadded = []; - return watchMaster.close(); - } - }; + }; + })(this); try { for (_i = 0, _len = file.length; _i < _len; _i++) { f = file[_i]; recursive(path.resolve(f)); } - bundle(); + process.bundle(); output(); watcher(); } catch (_error) { diff --git a/src/Main.coffee b/src/Main.coffee index 6da01ec..f7ddd31 100644 --- a/src/Main.coffee +++ b/src/Main.coffee @@ -24,7 +24,7 @@ list= new List() fileFinder=[] added=[]; unadded=[] -recursive=(file)-> +recursive=(file) => if program.verbose console.log "parsing #{file}" try @@ -36,7 +36,7 @@ recursive=(file)-> if f.required isnt "" arguments.callee(f.required) -bundle=-> +process.bundle= => for bundle in fileFinder for stack in bundle.includeStack list.append stack @@ -46,7 +46,7 @@ bundle=-> unless stack.caller in added unadded.push stack.caller -output=-> +output= => unless list.graph console.log "Nothing to output?" process.exit(0) @@ -76,28 +76,29 @@ if file.length is 0 console.log "No Input" watchMaster=null; -watcher=-> +watcher= => if program.watch if program.verbose console.log "watch has been added" - for file in unadded + console.log unadded + for file in unadded when file isnt "" unless watcthMaster? watchMaster=chokidar.watch(file,{persistent:true}) watchMaster.on("change",(newfile)=> recursive(newfile) - bundle() + process.bundle() output() ) - - watchMaster.add file - added.push file + else + watchMaster.add file + added.push file unadded=[] watchMaster.close() try for f in file recursive(path.resolve(f)) - bundle() + process.bundle() output() watcher() catch e diff --git a/test/Child.coffee b/test/Child.coffee index 33e27a1..8d77225 100644 --- a/test/Child.coffee +++ b/test/Child.coffee @@ -5,4 +5,5 @@ class Child extends Person super(name) - + cry:-> + console.log "cry" diff --git a/test/Person.coffee b/test/Person.coffee index 5d53255..af1cd43 100644 --- a/test/Person.coffee +++ b/test/Person.coffee @@ -2,7 +2,7 @@ class Person constructor:(@name)-> speak:-> - console.log "hi my name is" + console.log "hi my name is #{@name}" - walk:-> - "console.log walking" + run:-> + "console.log fast running"