@mapbox/batfish
Version:
The React-powered static-site generator you didn't know you wanted
35 lines (28 loc) • 906 B
JavaScript
//
;
const path = require('path');
const chokidar = require('chokidar');
const writeContextModule = require('./write-context-module');
const constants = require('./constants');
// Rebuild the context module when there are changes that would require that.
function watchContext(
batfishConfig ,
options
) {
const pageGlob = path.join(
batfishConfig.pagesDirectory,
`./**/*.${constants.PAGE_EXT_GLOB}`
);
const pageWatcher = chokidar.watch(pageGlob);
const rebuildPages = () => {
writeContextModule(batfishConfig)
.then(() => {
options.afterCompilation();
})
.catch(options.onError);
};
pageWatcher.on('change', rebuildPages);
pageWatcher.on('unlink', rebuildPages);
pageWatcher.on('error', options.onError);
}
module.exports = watchContext;