Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Watch more files

  • Loading branch information...
commit ca04075a9e722e436cd99dc35ca6b89c49b98a16 1 parent 2a5d05a
@3rd-Eden 3rd-Eden authored
Showing with 67 additions and 2 deletions.
  1. +1 −1  bin/square
  2. +66 −1 lib/watch.js
View
2  bin/square
@@ -152,7 +152,7 @@ program.on('--watch', function watching (live) {
});
// start watching for file changes in the given directory
- watch(files, extensions, function update (err, files) {
+ watch.call(square, files, extensions, function update (err, files) {
if (err) return square.logger.error(
'Watcher error %s, canceling watch operations on %s'
, err.message, files
View
67 lib/watch.js
@@ -16,6 +16,7 @@ var canihaz = require('canihaz')('square')
function watching(files, extensions, fn) {
var processors = require('./pre-process')
+ , square = this
, changes = []
, limited;
@@ -81,6 +82,70 @@ function watching(files, extensions, fn) {
notifier.on('change', filter);
notifier.on('error', fn);
+
+ // now that we have started watching our default files we can start searching
+ // for other files that might trigger a change for these build
+ var finder = require('findit').find(square.package.path)
+ , extras = [];
+
+ /**
+ * We have found a new file in the directory that matches our extension, watch
+ * it for changes.
+ *
+ * @param {String} file
+ * @api private
+ */
+
+ finder.on('file', function found(file) {
+ var trimmed = file.slice(1)
+ , extension = path.extname(trimmed).slice(1);
+
+ // make sure we are not watching file already
+ if (~files.indexOf(file) || ~files.indexOf(trimmed)) return;
+
+ // don't watch node_module folders.. ever.. we might want to look at the
+ // possible gitignore or .npmignore files to see what other files need to be
+ // black listen, but that is more a @TODO item
+ if (~file.indexOf('node_modules/')) return;
+
+ // make sure the file isn't in a dot directory as well..
+ var paths = trimmed.split('/');
+ if (paths.some(function some(path) { return path[0] === '.'; })) return;
+
+ // in addition to that, it shouldn't really be one of our output files.. or
+ // we will be creating a watching loop as we will be changing that file
+ // during the write
+ var distributions = []
+ , possibles = extensions.length ? extensions : [extension];
+
+ possibles.forEach(function forEach(ext) {
+ var dummy = { content: '', group: 'squared', extension: ext }
+ , dist = square.package.configuration.dist
+ , dev = square.template(dist.dev, square.tag(dummy, 'dev'))
+ , min = square.template(dist.min, square.tag(dummy, 'min'));
+
+ distributions.push(dev, min);
+ });
+
+ if (~distributions.indexOf(file)) return;
+
+ // now the last check is that we actually support this file ;D
+ if (!extensions.length || ~extensions.indexOf(path.extname(file).slice(1))) {
+ extras.push(file);
+ }
+ });
+
+ /**
+ * We are done scanning the directory, see if we need to push out more files.
+ *
+ * @api private
+ */
+
+ finder.on('end', function end() {
+ if (!extras.length) return;
+
+ notifier.add(extras);
+ });
}
/**
@@ -105,7 +170,7 @@ watching.live = function live (port) {
io = io.listen(port, {
'log level': 0 // socket.io spams like whore, silence it
, 'browser client etag': true // cache, but with etags for quick refresh
- , 'browser client gzip': true // minimal overhead for requests
+ , 'browser client gzip': false // minimal overhead for requests
, 'resource': '/live' // fancy pancy resources
});
Please sign in to comment.
Something went wrong with that request. Please try again.