refactor watch module
This commit is contained in:
parent
656ac157d3
commit
4c1f3fb8f6
92
lib/watch.js
92
lib/watch.js
|
@ -37,70 +37,58 @@ Watch.prototype.watchAssets = function(embarkConfig, callback) {
|
||||||
filesToWatch.push(appConfig[targetFile]);
|
filesToWatch.push(appConfig[targetFile]);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.trace(filesToWatch);
|
this.watchFiles(
|
||||||
|
filesToWatch,
|
||||||
var assetWatcher = chokidar.watch(filesToWatch, {
|
function(eventName, path) {
|
||||||
ignored: /[\/\\]\./, persistent: true, ignoreInitial: true, followSymlinks: true
|
self.logger.info(`${eventName}: ${path}`);
|
||||||
});
|
|
||||||
|
|
||||||
assetWatcher
|
|
||||||
.on('add', path => {
|
|
||||||
self.logger.info(`File ${path} has been added`);
|
|
||||||
self.trigger('rebuildAssets', path);
|
self.trigger('rebuildAssets', path);
|
||||||
})
|
},
|
||||||
.on('change', path => {
|
function() {
|
||||||
self.logger.info(`File ${path} has been changed`);
|
callback();
|
||||||
self.trigger('rebuildAssets', path);
|
}
|
||||||
})
|
);
|
||||||
.on('unlink', path => {
|
|
||||||
self.logger.info(`File ${path} has been removed`);
|
|
||||||
self.trigger('rebuildAssets', path);
|
|
||||||
})
|
|
||||||
.on('ready', () => callback());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Watch.prototype.watchContracts = function(embarkConfig, callback) {
|
Watch.prototype.watchContracts = function(embarkConfig, callback) {
|
||||||
var contractsToWatch = [];
|
var self = this;
|
||||||
contractsToWatch.push(embarkConfig.contracts);
|
this.watchFiles(
|
||||||
|
[embarkConfig.contracts],
|
||||||
this.logger.trace(contractsToWatch);
|
function(eventName, path) {
|
||||||
|
self.logger.info(`${eventName}: ${path}`);
|
||||||
var contractWatcher = chokidar.watch(contractsToWatch, {
|
|
||||||
ignored: /[\/\\]\./, persistent: true, ignoreInitial: true, followSymlinks: true
|
|
||||||
});
|
|
||||||
|
|
||||||
contractWatcher
|
|
||||||
.on('add', path => {
|
|
||||||
self.logger.info(`File ${path} has been added`);
|
|
||||||
self.trigger('redeploy', path);
|
self.trigger('redeploy', path);
|
||||||
})
|
},
|
||||||
.on('change', path => {
|
function() {
|
||||||
self.logger.info(`File ${path} has been changed`);
|
callback();
|
||||||
self.trigger('redeploy', path);
|
}
|
||||||
})
|
);
|
||||||
.on('unlink', path => this.logger.info(`File ${path} has been removed`))
|
|
||||||
.on('ready', () => callback());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Watch.prototype.watchConfigs = function(callback) {
|
Watch.prototype.watchConfigs = function(callback) {
|
||||||
var configWatcher = chokidar.watch("config/**/contracts.json", {
|
var self = this;
|
||||||
|
this.watchFiles(
|
||||||
|
"config/**/contracts.json",
|
||||||
|
function(eventName, path) {
|
||||||
|
self.logger.info(`${eventName}: ${path}`);
|
||||||
|
self.trigger('redeploy', path);
|
||||||
|
},
|
||||||
|
function() {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
Watch.prototype.watchFiles = function(files, changeCallback, doneCallback) {
|
||||||
|
this.logger.trace(files);
|
||||||
|
|
||||||
|
var configWatcher = chokidar.watch(files, {
|
||||||
ignored: /[\/\\]\./, persistent: true, ignoreInitial: true, followSymlinks: true
|
ignored: /[\/\\]\./, persistent: true, ignoreInitial: true, followSymlinks: true
|
||||||
});
|
});
|
||||||
|
|
||||||
configWatcher
|
configWatcher
|
||||||
.on('add', path => {
|
.on('add', path => changeCallback('add', path))
|
||||||
self.logger.info(`File ${path} has been added`);
|
.on('change', path => changeCallback('add', path))
|
||||||
self.trigger('redeploy', path);
|
.on('unlink', path => changeCallback('add', path))
|
||||||
})
|
.on('ready', doneCallback);
|
||||||
.on('change', path => {
|
|
||||||
self.logger.info(`File ${path} has been changed`);
|
|
||||||
self.trigger('redeploy', path);
|
|
||||||
})
|
|
||||||
.on('unlink', path => {
|
|
||||||
self.logger.info(`File ${path} has been removed`);
|
|
||||||
self.trigger('redeploy', path);
|
|
||||||
})
|
|
||||||
.on('ready', () => callback());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Watch.prototype.on = function(eventName, callback) {
|
Watch.prototype.on = function(eventName, callback) {
|
||||||
|
|
Loading…
Reference in New Issue