fix pipeline and watching of contracts and assets

This commit is contained in:
Iuri Matias 2016-09-23 01:37:15 -07:00
parent 432bc5a5b1
commit f004a1a7e1
5 changed files with 88 additions and 13 deletions

View File

@ -20,3 +20,4 @@ $(document).ready(function() {
}); });
}); });
window.abc = 5;

View File

@ -19,6 +19,12 @@ Config.prototype.loadConfigFiles = function(options) {
this.loadContractsConfigFile(); this.loadContractsConfigFile();
}; };
Config.prototype.reloadConfig = function() {
this.loadPipelineConfigFile();
this.loadBlockchainConfigFile();
this.loadContractsConfigFile();
};
Config.prototype.loadBlockchainConfigFile = function() { Config.prototype.loadBlockchainConfigFile = function() {
var defaultBlockchainConfig = JSON.parse(fs.readFileSync(this.configDir + this.env + "/blockchain.json"))[this.env]; var defaultBlockchainConfig = JSON.parse(fs.readFileSync(this.configDir + this.env + "/blockchain.json"))[this.env];
this.blockchainConfig = defaultBlockchainConfig; this.blockchainConfig = defaultBlockchainConfig;

View File

@ -45,6 +45,46 @@ var Embark = {
//return this.contractsManager; //return this.contractsManager;
}, },
redeploy: function(env) {
var self = this;
async.waterfall([
function reloadFiles(callback) {
self.config.reloadConfig();
callback();
},
function deployAndBuildContractsManager(callback) {
Embark.monitor.setStatus("Redeploying changed Contracts");
Embark.buildAndDeploy(function(contractsManager) {
callback(null, contractsManager);
});
},
function generateConsoleABI(contractsManager, callback) {
var abiGenerator = new ABIGenerator(self.config.blockchainConfig, contractsManager);
var consoleABI = abiGenerator.generateABI({useEmbarkJS: false});
Embark.console.runCode(consoleABI);
callback(null, contractsManager);
},
function generateABI(contractsManager, callback) {
var abiGenerator = new ABIGenerator(self.config.blockchainConfig, contractsManager);
callback(null, abiGenerator.generateABI({useEmbarkJS: true}));
},
function buildPipeline(abi, callback) {
Embark.monitor.setStatus("Building Assets");
var pipeline = new Pipeline({
buildDir: self.config.buildDir,
contractsFiles: self.config.contractsFiles,
assetFiles: self.config.assetFiles,
logger: self.logger
});
pipeline.build(abi);
callback();
}
], function(err, result) {
Embark.monitor.setStatus("Ready");
self.logger.trace("finished".underline);
});
},
run: function(env) { run: function(env) {
var self = this; var self = this;
async.waterfall([ async.waterfall([
@ -104,6 +144,15 @@ var Embark = {
Embark.monitor.setStatus("Watching for changes"); Embark.monitor.setStatus("Watching for changes");
var watch = new Watch({logger: self.logger}); var watch = new Watch({logger: self.logger});
watch.start(); watch.start();
watch.on('redeploy', function() {
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();
});
callback(); callback();
} }
], function(err, result) { ], function(err, result) {

View File

@ -26,6 +26,7 @@ Pipeline.prototype.build = function(abi) {
self.logger.info("creating dir " + this.buildDir + dir); self.logger.info("creating dir " + this.buildDir + dir);
mkdirp.sync(this.buildDir + dir); mkdirp.sync(this.buildDir + dir);
self.logger.info("writing file " + this.buildDir + targetFile);
fs.writeFileSync(this.buildDir + targetFile, content); fs.writeFileSync(this.buildDir + targetFile, content);
} }
}; };

View File

@ -4,6 +4,7 @@ var chokidar = require('chokidar');
var Watch = function(options) { var Watch = function(options) {
this.logger = options.logger; this.logger = options.logger;
this.events = {};
}; };
Watch.prototype.start = function() { Watch.prototype.start = function() {
@ -19,33 +20,50 @@ Watch.prototype.start = function() {
// TODO: add callback to ready // TODO: add callback to ready
this.logger.trace(filesToWatch); this.logger.trace(filesToWatch);
var assetWatcher = chokidar.watch(filesToWatch, { var assetWatcher = chokidar.watch(filesToWatch, {
ignored: /[\/\\]\./, ignored: /[\/\\]\./, persistent: true, ignoreInitial: true, followSymlinks: true
persistent: true,
ignoreInitial: true,
followSymlinks: true
}); });
assetWatcher assetWatcher
.on('add', path => this.logger.info(`File ${path} has been added`)) .on('add', path => {
.on('change', path => this.logger.info(`File ${path} has been changed`)) this.logger.info(`File ${path} has been added`)
.on('unlink', path => this.logger.info(`File ${path} has been removed`)) this.trigger('rebuildAssets', path);
})
.on('change', path => {
this.logger.info(`File ${path} has been changed`)
this.trigger('rebuildAssets', path);
})
.on('unlink', path => {
this.logger.info(`File ${path} has been removed`)
this.trigger('rebuildAssets', path);
})
.on('ready', () => this.logger.info('ready to watch changes')); .on('ready', () => this.logger.info('ready to watch changes'));
var contractsToWatch = []; var contractsToWatch = [];
contractsToWatch.push(embarkConfig.contracts); contractsToWatch.push(embarkConfig.contracts);
this.logger.trace(contractsToWatch); this.logger.trace(contractsToWatch);
var contractWatcher = chokidar.watch(contractsToWatch, { var contractWatcher = chokidar.watch(contractsToWatch, {
ignored: /[\/\\]\./, ignored: /[\/\\]\./, persistent: true, ignoreInitial: true, followSymlinks: true
persistent: true,
ignoreInitial: true,
followSymlinks: true
}); });
contractWatcher contractWatcher
.on('add', path => this.logger.info(`File ${path} has been added`)) .on('add', path => {
.on('change', path => this.logger.info(`File ${path} has been changed`)) this.logger.info(`File ${path} has been added`)
this.trigger('redeploy', path);
})
.on('change', path => {
this.logger.info(`File ${path} has been changed`);
this.trigger('redeploy', path);
})
.on('unlink', path => this.logger.info(`File ${path} has been removed`)) .on('unlink', path => this.logger.info(`File ${path} has been removed`))
.on('ready', () => this.logger.info('ready to watch changes')); .on('ready', () => this.logger.info('ready to watch changes'));
this.logger.info("done!"); this.logger.info("done!");
}; };
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;