diff --git a/lib/index.js b/lib/index.js index 765653eba..f95079fc4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -15,6 +15,7 @@ var TemplateGenerator = require('./template_generator.js'); var Blockchain = require('./blockchain.js'); var Server = require('./server.js'); var Watch = require('./watch.js'); +var Pipeline = require('./pipeline.js'); var Embark = { @@ -35,19 +36,45 @@ var Embark = { }, run: function(env) { - Embark.deploy(function(abi) { - Embark.buildAssets(abi); - var server = new Server({}); - server.start(function() { + async.waterfall([ + function deployAndGenerateABI(callback) { + Embark.deploy(function(abi) { + callback(null, abi); + }); + }, + function buildPipeline(abi, callback) { + var pipeline = new Pipeline({}); + pipeline.build(abi); + callback(); + }, + function startAssetServer(callback) { + var server = new Server({}); + server.start(callback); + }, + function watchFilesForChanges(callback) { var watch = new Watch(); watch.start(); - }); + callback(); + } + ], function(err, result) { + console.log("finished".underline); }); }, build: function(env) { - Embark.deploy(function(abi) { - Embark.buildAssets(abi); + async.waterfall([ + function deployAndGenerateABI(callback) { + Embark.deploy(function(abi) { + callback(null, abi); + }); + }, + function buildPipeline(abi, callback) { + var pipeline = new Pipeline({}); + pipeline.build(abi); + callback(); + } + ], function(err, result) { + console.log("finished".underline); }); }, @@ -56,67 +83,31 @@ var Embark = { blockchain.run({env: env}); }, - - - - - - deploy: function(done) { async.waterfall([ function loadConfig(callback) { - var contractsManager = Embark.initConfig('config/', 'app/contracts/**/*.sol', 'development'); - callback(null, contractsManager); - }, - function buildContracts(contractsManager, callback) { - contractsManager.build(); - callback(null, contractsManager); - }, - function deployContracts(contractsManager, callback) { - var web3 = new Web3(); - web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')); - var deploy = new Deploy(web3, contractsManager); - deploy.deployAll(function() { + var contractsManager = Embark.initConfig('config/', 'app/contracts/**/*.sol', 'development'); callback(null, contractsManager); - }); - }, - function generateABI(contractsManager, callback) { - var abiGenerator = new ABIGenerator(contractsManager); - callback(null, abiGenerator.generateABI()); - }, + }, + function buildContracts(contractsManager, callback) { + contractsManager.build(); + callback(null, contractsManager); + }, + function deployContracts(contractsManager, callback) { + var web3 = new Web3(); + web3.setProvider(new web3.providers.HttpProvider('http://localhost:8545')); + var deploy = new Deploy(web3, contractsManager); + deploy.deployAll(function() { + callback(null, contractsManager); + }); + }, + function generateABI(contractsManager, callback) { + var abiGenerator = new ABIGenerator(contractsManager); + callback(null, abiGenerator.generateABI()); + }, ], function(err, result) { done(result); }); - }, - - buildAssets: function(abi) { - var embarkConfig = JSON.parse(fs.readFileSync("embark.json")); - - var appConfig = embarkConfig.app; - - for(var targetFile in appConfig) { - var originalFiles = grunt.file.expand({nonull: true}, appConfig[targetFile]); - console.log(originalFiles); - // remove duplicates - - var content = originalFiles.filter(function(file) { - return file.indexOf('.') >= 0; - }).map(function(file) { - console.log("reading " + file); - if (file === 'embark.js') { - return fs.readFileSync("../js/bluebird.js") + fs.readFileSync("../js/web3.js") + fs.readFileSync("../js/embark.js") + "\n" + abi; - } else { - return fs.readFileSync(file); - } - }).join("\n"); - - var dir = targetFile.split('/').slice(0, -1).join('/'); - console.log("creating dir " + "dist/" + dir); - mkdirp.sync("dist/" + dir); - - //console.log(content); - fs.writeFileSync("dist/" + targetFile, content); - } } }; diff --git a/lib/pipeline.js b/lib/pipeline.js new file mode 100644 index 000000000..68371bb24 --- /dev/null +++ b/lib/pipeline.js @@ -0,0 +1,40 @@ +var fs = require('fs'); +var grunt = require('grunt'); +var mkdirp = require('mkdirp'); + +var Pipeline = function(options) { + this.options = options; +}; + +Pipeline.prototype.build = function(abi) { + var embarkConfig = JSON.parse(fs.readFileSync("embark.json")); + + var appConfig = embarkConfig.app; + + for(var targetFile in appConfig) { + var originalFiles = grunt.file.expand({nonull: true}, appConfig[targetFile]); + console.log(originalFiles); + // remove duplicates + + var content = originalFiles.filter(function(file) { + return file.indexOf('.') >= 0; + }).map(function(file) { + console.log("reading " + file); + if (file === 'embark.js') { + return fs.readFileSync("../js/bluebird.js") + fs.readFileSync("../js/web3.js") + fs.readFileSync("../js/embark.js") + "\n" + abi; + } else { + return fs.readFileSync(file); + } + }).join("\n"); + + var dir = targetFile.split('/').slice(0, -1).join('/'); + console.log("creating dir " + "dist/" + dir); + mkdirp.sync("dist/" + dir); + + //console.log(content); + fs.writeFileSync("dist/" + targetFile, content); + } +}; + +module.exports = Pipeline; + diff --git a/lib/watch.js b/lib/watch.js index 3bb3877e9..764c83fdb 100644 --- a/lib/watch.js +++ b/lib/watch.js @@ -1,3 +1,4 @@ +/*jshint esversion: 6 */ var fs = require('fs'); var chokidar = require('chokidar');