mirror of https://github.com/embarklabs/embark.git
refactor pipeline to use events instead
This commit is contained in:
parent
3d240c9d84
commit
3433c75554
|
@ -0,0 +1,3 @@
|
|||
var EventEmitter = require('events');
|
||||
|
||||
module.exports = EventEmitter;
|
21
lib/index.js
21
lib/index.js
|
@ -15,6 +15,7 @@ var Test = require('./core/test.js');
|
|||
var Logger = require('./core/logger.js');
|
||||
var Config = require('./core/config.js');
|
||||
var ServicesMonitor = require('./core/services.js');
|
||||
var Events = require('./core/events.js');
|
||||
|
||||
var Dashboard = require('./dashboard/dashboard.js');
|
||||
|
||||
|
@ -37,6 +38,7 @@ var Embark = {
|
|||
},
|
||||
|
||||
initConfig: function(env, options) {
|
||||
this.events = new Events();
|
||||
this.logger = new Logger({logLevel: 'debug'});
|
||||
|
||||
this.config = new Config({env: env, logger: this.logger});
|
||||
|
@ -151,16 +153,19 @@ var Embark = {
|
|||
},
|
||||
function watchFilesForChanges(callback) {
|
||||
self.logger.setStatus("Watching for changes");
|
||||
var watch = new Watch({logger: self.logger});
|
||||
var watch = new Watch({logger: self.logger, events: self.events});
|
||||
watch.start();
|
||||
watch.on('redeploy', function() {
|
||||
self.logger.info("received redeploy event");
|
||||
Embark.redeploy();
|
||||
self.events.on('file-event', function(fileType, path) {
|
||||
if (fileType === 'contract' || fileType === 'config') {
|
||||
self.logger.info("received redeploy event");
|
||||
Embark.redeploy();
|
||||
}
|
||||
});
|
||||
watch.on('rebuildAssets', function() {
|
||||
self.logger.info("received rebuildAssets event");
|
||||
// TODO: make this more efficient
|
||||
Embark.redeploy();
|
||||
self.events.on('rebuildAssets', function(fileType, path) {
|
||||
if (fileType === 'asset') {
|
||||
self.logger.info("received rebuildAssets event");
|
||||
Embark.redeploy();
|
||||
}
|
||||
});
|
||||
callback();
|
||||
},
|
||||
|
|
|
@ -7,7 +7,7 @@ var fs = require('../core/fs.js');
|
|||
// embark.json file
|
||||
var Watch = function(options) {
|
||||
this.logger = options.logger;
|
||||
this.events = {};
|
||||
this.events = options.events;
|
||||
};
|
||||
|
||||
Watch.prototype.start = function() {
|
||||
|
@ -44,7 +44,8 @@ Watch.prototype.watchAssets = function(embarkConfig, callback) {
|
|||
filesToWatch,
|
||||
function(eventName, path) {
|
||||
self.logger.info(`${eventName}: ${path}`);
|
||||
self.trigger('rebuildAssets', path);
|
||||
self.events.emit('file-' + eventName, 'asset', path);
|
||||
self.events.emit('file-event', 'asset', path);
|
||||
},
|
||||
function() {
|
||||
callback();
|
||||
|
@ -58,7 +59,8 @@ Watch.prototype.watchContracts = function(embarkConfig, callback) {
|
|||
[embarkConfig.contracts],
|
||||
function(eventName, path) {
|
||||
self.logger.info(`${eventName}: ${path}`);
|
||||
self.trigger('redeploy', path);
|
||||
self.events.emit('file-' + eventName, 'contract', path);
|
||||
self.events.emit('file-event', 'contract', path);
|
||||
},
|
||||
function() {
|
||||
callback();
|
||||
|
@ -72,7 +74,8 @@ Watch.prototype.watchConfigs = function(callback) {
|
|||
"config/**/contracts.json",
|
||||
function(eventName, path) {
|
||||
self.logger.info(`${eventName}: ${path}`);
|
||||
self.trigger('redeploy', path);
|
||||
self.events.emit('file-' + eventName, 'config', path);
|
||||
self.events.emit('file-event', 'config', path);
|
||||
},
|
||||
function() {
|
||||
callback();
|
||||
|
@ -90,17 +93,9 @@ Watch.prototype.watchFiles = function(files, changeCallback, doneCallback) {
|
|||
|
||||
configWatcher
|
||||
.on('add', path => changeCallback('add', path))
|
||||
.on('change', path => changeCallback('add', path))
|
||||
.on('unlink', path => changeCallback('add', path))
|
||||
.on('change', path => changeCallback('change', path))
|
||||
.on('unlink', path => changeCallback('remove', path))
|
||||
.on('ready', doneCallback);
|
||||
};
|
||||
|
||||
Watch.prototype.on = function(eventName, callback) {
|
||||
this.events[eventName] = callback;
|
||||
};
|
||||
|
||||
Watch.prototype.trigger = function(eventName, values) {
|
||||
this.events[eventName](values);
|
||||
};
|
||||
|
||||
module.exports = Watch;
|
||||
|
|
Loading…
Reference in New Issue