requisite
Version:
A cosmic javascript bundler.
52 lines (45 loc) • 1.23 kB
JavaScript
// Generated by CoffeeScript 1.7.1
var bundle, fs, path, vigil;
fs = require('fs');
path = require('path');
vigil = require('vigil');
bundle = require('./bundle');
module.exports = function(options, cb) {
return bundle(options, function(err, _bundle) {
var dir, rebuildBundle, watch, watched;
if (err != null) {
return cb(err);
}
cb(null, _bundle);
dir = path.dirname(_bundle.absolutePath);
watched = {};
rebuildBundle = function(filename, stats) {
var mod, requireAs;
requireAs = filename.replace(/\.\w+$/, '');
if (!(((mod = _bundle.find(requireAs)) != null) && mod.absolutePath === path.join(dir, filename))) {
return;
}
return _bundle.parse({
deep: true
}, function(err) {
if (err != null) {
return cb(err);
}
return cb(null, _bundle, filename);
});
};
watch = function(dir) {
if (watched[dir]) {
return;
}
return vigil.watch(dir, {
recurse: false
}, rebuildBundle);
};
watch(dir);
return _bundle.walkDependencies(function(mod) {
return watch(path.dirname(mod.absolutePath));
});
});
};
//# sourceMappingURL=watch.map