requisite
Version:
A cosmic javascript bundler.
58 lines (51 loc) • 1.33 kB
JavaScript
// Generated by CoffeeScript 1.12.4
var bundle, fs, path, vigil;
fs = require('fs');
path = require('path');
vigil = require('vigil');
bundle = require('./bundle');
module.exports = function(options, cb) {
var watched;
watched = {};
return bundle(options, function(err, _bundle) {
var dir, rebuildBundle, watch;
if (err != null) {
return cb(err);
}
cb(null, _bundle);
dir = path.dirname(_bundle.absolutePath);
rebuildBundle = function(filename, stats) {
var absPath, mod;
absPath = path.resolve(path.join(dir, filename));
mod = _bundle.find(function(mod) {
return absPath === mod.absolutePath;
});
if (mod == null) {
console.warn(filename, 'not found in bundle');
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;
}
watched[dir] = true;
return vigil.watch(dir, {
recurse: true
}, rebuildBundle);
};
watch(dir);
return _bundle.walkDependencies(function(mod) {
return watch(path.dirname(mod.absolutePath));
});
});
};
//# sourceMappingURL=watch.js.map