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 Logger = require('./core/logger.js');
|
||||||
var Config = require('./core/config.js');
|
var Config = require('./core/config.js');
|
||||||
var ServicesMonitor = require('./core/services.js');
|
var ServicesMonitor = require('./core/services.js');
|
||||||
|
var Events = require('./core/events.js');
|
||||||
|
|
||||||
var Dashboard = require('./dashboard/dashboard.js');
|
var Dashboard = require('./dashboard/dashboard.js');
|
||||||
|
|
||||||
|
@ -37,6 +38,7 @@ var Embark = {
|
||||||
},
|
},
|
||||||
|
|
||||||
initConfig: function(env, options) {
|
initConfig: function(env, options) {
|
||||||
|
this.events = new Events();
|
||||||
this.logger = new Logger({logLevel: 'debug'});
|
this.logger = new Logger({logLevel: 'debug'});
|
||||||
|
|
||||||
this.config = new Config({env: env, logger: this.logger});
|
this.config = new Config({env: env, logger: this.logger});
|
||||||
|
@ -151,16 +153,19 @@ var Embark = {
|
||||||
},
|
},
|
||||||
function watchFilesForChanges(callback) {
|
function watchFilesForChanges(callback) {
|
||||||
self.logger.setStatus("Watching for changes");
|
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.start();
|
||||||
watch.on('redeploy', function() {
|
self.events.on('file-event', function(fileType, path) {
|
||||||
self.logger.info("received redeploy event");
|
if (fileType === 'contract' || fileType === 'config') {
|
||||||
Embark.redeploy();
|
self.logger.info("received redeploy event");
|
||||||
|
Embark.redeploy();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
watch.on('rebuildAssets', function() {
|
self.events.on('rebuildAssets', function(fileType, path) {
|
||||||
self.logger.info("received rebuildAssets event");
|
if (fileType === 'asset') {
|
||||||
// TODO: make this more efficient
|
self.logger.info("received rebuildAssets event");
|
||||||
Embark.redeploy();
|
Embark.redeploy();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
callback();
|
callback();
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,7 +7,7 @@ var fs = require('../core/fs.js');
|
||||||
// embark.json file
|
// embark.json file
|
||||||
var Watch = function(options) {
|
var Watch = function(options) {
|
||||||
this.logger = options.logger;
|
this.logger = options.logger;
|
||||||
this.events = {};
|
this.events = options.events;
|
||||||
};
|
};
|
||||||
|
|
||||||
Watch.prototype.start = function() {
|
Watch.prototype.start = function() {
|
||||||
|
@ -44,7 +44,8 @@ Watch.prototype.watchAssets = function(embarkConfig, callback) {
|
||||||
filesToWatch,
|
filesToWatch,
|
||||||
function(eventName, path) {
|
function(eventName, path) {
|
||||||
self.logger.info(`${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() {
|
function() {
|
||||||
callback();
|
callback();
|
||||||
|
@ -58,7 +59,8 @@ Watch.prototype.watchContracts = function(embarkConfig, callback) {
|
||||||
[embarkConfig.contracts],
|
[embarkConfig.contracts],
|
||||||
function(eventName, path) {
|
function(eventName, path) {
|
||||||
self.logger.info(`${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() {
|
function() {
|
||||||
callback();
|
callback();
|
||||||
|
@ -72,7 +74,8 @@ Watch.prototype.watchConfigs = function(callback) {
|
||||||
"config/**/contracts.json",
|
"config/**/contracts.json",
|
||||||
function(eventName, path) {
|
function(eventName, path) {
|
||||||
self.logger.info(`${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() {
|
function() {
|
||||||
callback();
|
callback();
|
||||||
|
@ -90,17 +93,9 @@ Watch.prototype.watchFiles = function(files, changeCallback, doneCallback) {
|
||||||
|
|
||||||
configWatcher
|
configWatcher
|
||||||
.on('add', path => changeCallback('add', path))
|
.on('add', path => changeCallback('add', path))
|
||||||
.on('change', path => changeCallback('add', path))
|
.on('change', path => changeCallback('change', path))
|
||||||
.on('unlink', path => changeCallback('add', path))
|
.on('unlink', path => changeCallback('remove', path))
|
||||||
.on('ready', doneCallback);
|
.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;
|
module.exports = Watch;
|
||||||
|
|
Loading…
Reference in New Issue