2016-08-21 16:02:02 +00:00
|
|
|
/*jshint esversion: 6 */
|
2016-08-21 15:24:57 +00:00
|
|
|
var fs = require('fs');
|
|
|
|
var chokidar = require('chokidar');
|
|
|
|
|
|
|
|
var Watch = function(options) {
|
2016-09-17 03:56:25 +00:00
|
|
|
this.logger = options.logger;
|
2016-08-21 15:24:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Watch.prototype.start = function() {
|
|
|
|
var embarkConfig = JSON.parse(fs.readFileSync("embark.json"));
|
|
|
|
|
|
|
|
var appConfig = embarkConfig.app;
|
|
|
|
var filesToWatch = [];
|
|
|
|
|
|
|
|
for(var targetFile in appConfig) {
|
|
|
|
filesToWatch.push(appConfig[targetFile]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: add callback to ready
|
2016-09-17 03:56:25 +00:00
|
|
|
this.logger.trace(filesToWatch);
|
2016-08-21 15:24:57 +00:00
|
|
|
var watcher = chokidar.watch(filesToWatch, {
|
|
|
|
ignored: /[\/\\]\./,
|
|
|
|
persistent: true,
|
|
|
|
ignoreInitial: true,
|
|
|
|
followSymlinks: true
|
|
|
|
});
|
|
|
|
watcher
|
2016-09-17 03:56:25 +00:00
|
|
|
.on('add', path => this.logger.info(`File ${path} has been added`))
|
|
|
|
.on('change', path => this.logger.info(`File ${path} has been changed`))
|
|
|
|
.on('unlink', path => this.logger.info(`File ${path} has been removed`))
|
|
|
|
.on('ready', () => this.logger.info('ready to watch changes'));
|
|
|
|
this.logger.info("done!");
|
2016-08-21 15:24:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Watch;
|