diff --git a/demo/app/images/.gitkeep b/demo/app/images/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/demo/embark.json b/demo/embark.json index c210eada5..4fb81d319 100644 --- a/demo/embark.json +++ b/demo/embark.json @@ -2,15 +2,12 @@ "contracts": ["app/contracts/**"], "app": { "css/app.css": ["app/css/**"], + "images/": ["app/images/**"], "js/app.js": ["embark.js", "app/js/_vendor/jquery.min.js", "app/js/_vendor/bootstrap.min.js", "app/js/**"], "index.html": "app/index.html" }, "buildDir": "dist/", "config": "config/", "plugins": { - "embark-pipelinefiles": {}, - "embark-pipelinefiles2": {}, - "embark-babel": {}, - "embark-contracts": {} } } diff --git a/demo/package.json b/demo/package.json index 13eed53be..d478305a5 100644 --- a/demo/package.json +++ b/demo/package.json @@ -11,6 +11,6 @@ "homepage": "", "devDependencies": { "embark": "^2.2.1", - "mocha": "^3.2.0" + "mocha": "^2.2.5" } } diff --git a/lib/abi.js b/lib/abi.js index 0c7dcf2a4..a339c896a 100644 --- a/lib/abi.js +++ b/lib/abi.js @@ -3,8 +3,8 @@ var Plugins = require('./plugins.js'); var ABIGenerator = function(options) { this.blockchainConfig = options.blockchainConfig || {}; this.contractsManager = options.contractsManager; - this.rpcHost = options.blockchainConfig.rpcHost; - this.rpcPort = options.blockchainConfig.rpcPort; + this.rpcHost = options.blockchainConfig && options.blockchainConfig.rpcHost; + this.rpcPort = options.blockchainConfig && options.blockchainConfig.rpcPort; this.plugins = options.plugins || new Plugins({}); }; diff --git a/lib/compiler.js b/lib/compiler.js index 9d2c5a945..156fbbd4d 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -49,7 +49,6 @@ Compiler.prototype.compile_solidity = function(contractFiles) { for (var i = 0; i < contractFiles.length; i++){ // TODO: this depends on the config var filename = contractFiles[i].filename.replace('app/contracts/',''); - console.log("normal compile " + filename); input[filename] = contractFiles[i].content.toString(); } diff --git a/lib/config.js b/lib/config.js index 60daa9baf..791097cf4 100644 --- a/lib/config.js +++ b/lib/config.js @@ -21,10 +21,14 @@ var Config = function(options) { }; Config.prototype.loadConfigFiles = function(options) { + var interceptLogs = options.interceptLogs; + if (options.interceptLogs === undefined) { + interceptLogs = true; + } this.embarkConfig = JSON.parse(fs.readFileSync(options.embarkConfig)); this.embarkConfig.plugins = this.embarkConfig.plugins || {}; - this.plugins = new Plugins({plugins: this.embarkConfig.plugins, logger: this.logger}); + this.plugins = new Plugins({plugins: this.embarkConfig.plugins, logger: this.logger, interceptLogs: interceptLogs}); this.plugins.loadPlugins(); this.loadPipelineConfigFile(); @@ -66,7 +70,6 @@ Config.prototype.loadContractsConfigFile = function() { var envContractsConfig = configObject[this.env]; var mergedConfig = merge.recursive(defaultContractsConfig, envContractsConfig); - console.log(JSON.stringify(mergedConfig)); this.contractsConfig = mergedConfig; }; diff --git a/lib/contracts.js b/lib/contracts.js index cd45e77b5..5fd10a78c 100644 --- a/lib/contracts.js +++ b/lib/contracts.js @@ -78,7 +78,7 @@ ContractsManager.prototype.build = function(done) { contract.functionHashes = compiledContract.functionHashes; contract.abiDefinition = compiledContract.abiDefinition; - contract.gas = (contractConfig && contractConfig.gas) || self.contractsConfig.gas; + contract.gas = (contractConfig && contractConfig.gas) || self.contractsConfig.gas || 'auto'; adjustGas(contract); contract.gasPrice = contract.gasPrice || self.contractsConfig.gasPrice; diff --git a/lib/pipeline.js b/lib/pipeline.js index a193d4d72..fb56ac0ea 100644 --- a/lib/pipeline.js +++ b/lib/pipeline.js @@ -33,7 +33,6 @@ Pipeline.prototype.build = function(abi) { pipelinePlugins.forEach(function(plugin) { try { if (file.options && file.options.skipPipeline) { - console.log("skipping"); return; } file.content = plugin.runPipeline({targetFile: file.filename, source: file.content}); diff --git a/lib/plugin.js b/lib/plugin.js index 0d706abe8..79c3a24b3 100644 --- a/lib/plugin.js +++ b/lib/plugin.js @@ -9,6 +9,7 @@ var Plugin = function(options) { this.pluginModule = options.pluginModule; this.pluginPath = options.pluginPath; this.pluginConfig = options.pluginConfig; + this.shouldInterceptLogs = options.interceptLogs; this.clientWeb3Providers = []; this.contractsGenerators = []; this.pipeline = []; @@ -22,8 +23,10 @@ var Plugin = function(options) { }; Plugin.prototype.loadPlugin = function() { - this.interceptLogs(this.pluginModule); - (this.pluginModule.call(this, this)); + if (this.shouldInterceptLogs) { + this.interceptLogs(this.pluginModule); + } + (this.pluginModule.call(this, this)); }; Plugin.prototype.loadPluginFile = function(filename) { @@ -36,7 +39,8 @@ Plugin.prototype.pathToFile = function(filename) { Plugin.prototype.interceptLogs = function(context) { var self = this; - context.console = console; + // TODO: this is a bit nasty, figure out a better way + context.console = context.console || console; context.console.error = function(txt) { // TODO: logger should support an array instead of a single argument //self.logger.error.apply(self.logger, arguments); diff --git a/lib/plugins.js b/lib/plugins.js index f4f29b587..352b773f1 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -3,6 +3,7 @@ var path = require('path'); var Plugins = function(options) { this.pluginList = options.plugins || []; + this.interceptLogs = options.interceptLogs; this.plugins = []; // TODO: need backup 'NullLogger' this.logger = options.logger; @@ -28,7 +29,7 @@ Plugins.prototype.loadPlugin = function(pluginName, pluginConfig) { var pluginPath = path.join(process.env.PWD, 'node_modules', pluginName); var plugin = require(pluginPath); - var pluginWrapper = new Plugin({name: pluginName, pluginModule: plugin, pluginConfig: pluginConfig, logger: this.logger, pluginPath: pluginPath}); + var pluginWrapper = new Plugin({name: pluginName, pluginModule: plugin, pluginConfig: pluginConfig, logger: this.logger, pluginPath: pluginPath, interceptLogs: this.interceptLogs}); pluginWrapper.loadPlugin(); this.plugins.push(pluginWrapper); }; diff --git a/lib/test.js b/lib/test.js index 74fadb568..c5cb1d622 100644 --- a/lib/test.js +++ b/lib/test.js @@ -7,23 +7,27 @@ var TestLogger = require('./test_logger.js'); var Config = require('./config.js'); var ABIGenerator = require('./abi.js'); -// TODO: load config file -// TODO: include plugins var Test = function(options) { - //try { - this.sim = require('ethereumjs-testrpc'); - //} catch(e) { - // this.sim = false; - //} - //if (this.sim === false) { - // console.log('Simulator not found; Please install it with "npm install -g ethereumjs-testrpc'); - // console.log('For more information see https://github.com/ethereumjs/testrpc'); - // exit(); - //} - + try { + this.sim = require('ethereumjs-testrpc'); + } catch (e) { + if (e.code === 'MODULE_NOT_FOUND') { + console.log('Simulator not found; Please install it with "npm install ethereumjs-testrpc --save"'); + console.log('IMPORTANT: if you using a NodeJS version older than 6.9.1 then you need to install an older version of testrpc "npm install ethereumjs-testrpc@2.0 --save"'); + console.log('For more information see https://github.com/ethereumjs/testrpc'); + exit(); + } else { + console.log("=============="); + console.log("Tried to load testrpc but an error occurred. This is a problem with testrpc"); + console.log('IMPORTANT: if you using a NodeJS version older than 6.9.1 then you need to install an older version of testrpc "npm install ethereumjs-testrpc@2.0 --save". Alternatively install node 6.9.1 and the testrpc 3.0'); + console.log("=============="); + throw e; + } + } + this.web3 = new Web3(); - this.web3.setProvider(this.sim.provider(options)); + this.web3.setProvider(this.sim.provider()); }; Test.prototype.deployAll = function(contractsConfig, cb) { @@ -33,21 +37,20 @@ Test.prototype.deployAll = function(contractsConfig, cb) { async.waterfall([ function getConfig(callback) { var config = new Config({env: 'test', logger: logger}); - config.loadConfigFiles({embarkConfig: 'embark.json'}); + config.loadConfigFiles({embarkConfig: 'embark.json', interceptLogs: false}); + config.contractsConfig = {contracts: contractsConfig}; callback(null, config); }, - function buildContracts(callback) { - //var config = new Config({env: 'test'}); - //config.contractsFiles = config.loadFiles(["app/contracts/**"]); - config.contractsConfig = {contracts: contractsConfig} ; - + function buildContracts(config, callback) { var contractsManager = new ContractsManager({ contractFiles: config.contractsFiles, contractsConfig: config.contractsConfig, logger: logger, plugins: config.plugins }); - contractsManager.build(callback); + contractsManager.build(function() { + callback(null, contractsManager); + }); }, function deployContracts(contractsManager, callback) { var deploy = new Deploy({ @@ -76,10 +79,9 @@ Test.prototype.deployAll = function(contractsConfig, cb) { } var web3 = self.web3; web3.eth.defaultAccount = accounts[0]; - console.log("hello!"); // TODO: replace evals with separate process so it's isolated and with // a callback - //eval(result); // jshint ignore:line + eval(result); // jshint ignore:line cb(); }); });