From 4a9ff1fe9ddaaeb24a2b391e6b8dc0d068463eed Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 27 Apr 2018 09:16:29 -0400 Subject: [PATCH] check if testrpc is installed and warn if not --- lib/cmds/simulator.js | 12 +++++++++++- lib/index.js | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/cmds/simulator.js b/lib/cmds/simulator.js index 71cc1fbd..6366290d 100644 --- a/lib/cmds/simulator.js +++ b/lib/cmds/simulator.js @@ -3,11 +3,20 @@ let shelljs = require('shelljs'); class Simulator { constructor(options) { this.blockchainConfig = options.blockchainConfig; + this.logger = options.logger; } run(options) { let cmds = []; + const testrpc = shelljs.which('testrpc'); + const ganache = shelljs.which('ganache-cli'); + if (!testrpc && !ganache) { + this.logger.warn('Ganache CLI (TestRPC) is not installed on your machine'); + this.logger.info('You can install it by running: npm -g install ganache-cli'); + process.exit(); + } + cmds.push("-p " + (this.blockchainConfig.rpcPort || options.port || 8545)); cmds.push("-h " + (this.blockchainConfig.rpcHost || options.host || 'localhost')); cmds.push("-a " + (options.numAccounts || 10)); @@ -26,7 +35,8 @@ class Simulator { cmds.push("-b \"" + (simulatorBlocktime) +"\""); } - shelljs.exec('testrpc ' + cmds.join(' '), {async : true}); + const program = ganache ? 'ganache-cli' : 'testrpc'; + shelljs.exec(`${program} ${cmds.join(' ')}`, {async : true}); } } diff --git a/lib/index.js b/lib/index.js index 1f45d1d1..3390c36b 100644 --- a/lib/index.js +++ b/lib/index.js @@ -57,7 +57,7 @@ class Embark { simulator(options) { this.context = options.context || [constants.contexts.simulator, constants.contexts.blockchain]; let Simulator = require('./cmds/simulator.js'); - let simulator = new Simulator({blockchainConfig: this.config.blockchainConfig}); + let simulator = new Simulator({blockchainConfig: this.config.blockchainConfig, logger: this.logger}); simulator.run(options); }