check if testrpc is installed and warn if not

This commit is contained in:
Jonathan Rainville 2018-04-27 09:16:29 -04:00
parent 7ebaa7aaca
commit 4a9ff1fe9d
2 changed files with 12 additions and 2 deletions

View File

@ -3,11 +3,20 @@ let shelljs = require('shelljs');
class Simulator { class Simulator {
constructor(options) { constructor(options) {
this.blockchainConfig = options.blockchainConfig; this.blockchainConfig = options.blockchainConfig;
this.logger = options.logger;
} }
run(options) { run(options) {
let cmds = []; 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("-p " + (this.blockchainConfig.rpcPort || options.port || 8545));
cmds.push("-h " + (this.blockchainConfig.rpcHost || options.host || 'localhost')); cmds.push("-h " + (this.blockchainConfig.rpcHost || options.host || 'localhost'));
cmds.push("-a " + (options.numAccounts || 10)); cmds.push("-a " + (options.numAccounts || 10));
@ -26,7 +35,8 @@ class Simulator {
cmds.push("-b \"" + (simulatorBlocktime) +"\""); cmds.push("-b \"" + (simulatorBlocktime) +"\"");
} }
shelljs.exec('testrpc ' + cmds.join(' '), {async : true}); const program = ganache ? 'ganache-cli' : 'testrpc';
shelljs.exec(`${program} ${cmds.join(' ')}`, {async : true});
} }
} }

View File

@ -57,7 +57,7 @@ class Embark {
simulator(options) { simulator(options) {
this.context = options.context || [constants.contexts.simulator, constants.contexts.blockchain]; this.context = options.context || [constants.contexts.simulator, constants.contexts.blockchain];
let Simulator = require('./cmds/simulator.js'); 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); simulator.run(options);
} }