Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Effectively restarting toaster after `toaster.coffee` is edited. No m…

…ore need for CTRL+C and RERUN!
  • Loading branch information...
commit 27dbcc7002b15417c32b00599e359094768324d2 1 parent 13c76aa
@arboleya authored
View
5 build/CHANGELOG.md
@@ -1,7 +1,8 @@
# Changelog
-## 0.6.6 - 12/08/2012
- * Making toaster cross-platform (Osx, Linux, Windows)
+## 0.6.6 -
+ * Making toaster cross-platform (Osx, Linux, Win7)
+ * Effectively restarting toaster after `toaster.coffee` file is edited. \o/
## 0.6.5 - 11/27/2012
* Fixing generators [closing issue [#46](https://github.com/serpentem/coffee-toaster/issues/46)]
View
43 lib/toaster.js
@@ -30,10 +30,12 @@ var toaster = exports.toaster = {};
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
__t('toaster').Toast = (function() {
- var colors, cs, exec, fs, path;
+ var colors, cs, exec, fs, fsu, path;
fs = require("fs");
+ fsu = require("fs-util");
+
path = require("path");
exec = (require("child_process")).exec;
@@ -42,14 +44,16 @@ var toaster = exports.toaster = {};
cs = require("coffee-script");
- Toast.prototype.builders = [];
+ Toast.prototype.builders = null;
function Toast(toaster) {
- var code, config, config_file, contents, filepath, fix_scope, item, _i, _len, _ref;
+ var code, config, config_file, contents, filepath, fix_scope, item, watcher, _i, _len, _ref,
+ _this = this;
this.toaster = toaster;
this.toast = __bind(this.toast, this);
this.basepath = this.toaster.basepath;
+ this.builders = [];
if ((config = this.toaster.cli.argv["config"]) != null) {
if (!(config instanceof Object)) {
config = JSON.parse(config);
@@ -62,6 +66,14 @@ var toaster = exports.toaster = {};
} else {
config_file = this.toaster.cli.argv["config-file"];
filepath = config_file || path.join(this.basepath, "toaster.coffee");
+ watcher = fsu.watch(filepath);
+ watcher.on('change', function(f) {
+ var now;
+ now = (("" + (new Date)).match(/[0-9]{2}\:[0-9]{2}\:[0-9]{2}/))[0];
+ log(("[" + now + "] " + 'Changed'.bold + " " + filepath).cyan);
+ watcher.close();
+ return _this.toaster.reset();
+ });
if (fs.existsSync(filepath)) {
contents = fs.readFileSync(filepath, "utf-8");
try {
@@ -703,6 +715,17 @@ var toaster = exports.toaster = {};
return _results;
};
+ Builder.prototype.reset = function() {
+ var watcher, _i, _len, _ref1, _results;
+ _ref1 = this.watchers;
+ _results = [];
+ for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
+ watcher = _ref1[_i];
+ _results.push(watcher.close());
+ }
+ return _results;
+ };
+
Builder.prototype.build = function(header_code, footer_code) {
var ast, contents, f, files, i, include, namespaces, now, tmpl, vendors, _i, _len;
if (header_code == null) {
@@ -1237,10 +1260,12 @@ var toaster = exports.toaster = {};
exports.toaster = toaster;
exports.Toaster = Toaster = (function() {
- var colors;
+ var colors, fsu;
fs = require("fs");
+ fsu = require("fs-util");
+
path = require("path");
exec = (require("child_process")).exec;
@@ -1313,6 +1338,16 @@ var toaster = exports.toaster = {};
return _results;
};
+ Toaster.prototype.reset = function() {
+ var builder, _i, _len, _ref;
+ _ref = this.toast.builders;
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ builder = _ref[_i];
+ builder.reset();
+ }
+ return exports.run();
+ };
+
return Toaster;
})();
View
9 src/toaster.coffee
@@ -9,6 +9,7 @@ exports.Toaster = class Toaster
# requirements
fs = require "fs"
+ fsu = require "fs-util"
path = require "path"
exec = (require "child_process").exec
colors = require 'colors'
@@ -68,4 +69,10 @@ exports.Toaster = class Toaster
# will be compiled together the app.
build:( header_code = "", footer_code = "" )->
for builder in @toast.builders
- builder.build header_code, footer_code
+ builder.build header_code, footer_code
+
+ # resets the toaster completely - specially used when the `toaster.coffee`
+ # config file is edited :)
+ reset:()->
+ builder.reset() for builder in @toast.builders
+ exports.run()
View
4 src/toaster/core/builder.coffee
@@ -57,6 +57,10 @@ class Builder
s = new Script @, fpath, file, falias, @cli
@files.push s
+ reset:()->
+ for watcher in @watchers
+ watcher.close()
+
build:( header_code = "", footer_code = "" )=>
# namespaces
namespaces = @build_namespaces()
View
11 src/toaster/toast.coffee
@@ -2,18 +2,20 @@ class Toast
# requires
fs = require "fs"
+ fsu = require "fs-util"
path = require "path"
exec = (require "child_process").exec
colors = require 'colors'
cs = require "coffee-script"
# variables
- builders: []
+ builders: null
constructor: (@toaster) ->
# basepath
@basepath = @toaster.basepath
+ @builders = []
if (config = @toaster.cli.argv["config"])?
config = JSON.parse( config ) unless config instanceof Object
@@ -22,6 +24,13 @@ class Toast
config_file = @toaster.cli.argv["config-file"]
filepath = config_file || path.join @basepath, "toaster.coffee"
+ watcher = fsu.watch filepath
+ watcher.on 'change', (f)=>
+ now = ("#{new Date}".match /[0-9]{2}\:[0-9]{2}\:[0-9]{2}/)[0]
+ log "[#{now}] #{'Changed'.bold} #{filepath}".cyan
+ watcher.close()
+ @toaster.reset()
+
if fs.existsSync filepath
contents = fs.readFileSync filepath, "utf-8"
Please sign in to comment.
Something went wrong with that request. Please try again.