diff --git a/lib/blockchain.js b/lib/blockchain.js index fd07fd5d..5bb67191 100644 --- a/lib/blockchain.js +++ b/lib/blockchain.js @@ -3,6 +3,7 @@ var wrench = require('wrench'); var colors = require('colors'); var GethCommands = require('./geth_commands.js'); var utils = require('./utils.js'); +var shelljs = require('shelljs'); var Blockchain = function(blockchainConfig, Client) { this.blockchainConfig = blockchainConfig; @@ -33,7 +34,7 @@ var Blockchain = function(blockchainConfig, Client) { Blockchain.prototype.runCommand = function(cmd) { console.log(("running: " + cmd.underline).green); - return exec(cmd); + return shelljs.exec(cmd); }; Blockchain.prototype.run = function() { diff --git a/lib/cmd.js b/lib/cmd.js index e175baea..9ab1050b 100644 --- a/lib/cmd.js +++ b/lib/cmd.js @@ -1,5 +1,6 @@ var program = require('commander'); var colors = require('colors'); +var shelljs = require('shelljs'); var Cmd = function(Embark) { this.Embark = Embark; @@ -35,7 +36,7 @@ Cmd.prototype.newApp = function() { console.log("please specify your app Name".red); console.log("e.g embark new MyApp".green); console.log("e.g embark new --help for more information".green); - exit(); + process.exit(code); } self.Embark.generateTemplate('boilerplate', './', name); }); @@ -126,7 +127,7 @@ Cmd.prototype.test = function() { .command('test') .description('run tests') .action(function() { - exec('mocha test/ --no-timeouts'); + shelljs.exec('mocha test/ --no-timeouts'); }); }; diff --git a/lib/console.js b/lib/console.js index c9cd02bd..973950a3 100644 --- a/lib/console.js +++ b/lib/console.js @@ -1,4 +1,5 @@ var Web3 = require('web3'); +var utils = require('./utils.js'); var Console = function(options) { this.plugins = options.plugins; @@ -32,7 +33,7 @@ Console.prototype.executeCmd = function(cmd, callback) { ]; return callback(helpText.join('\n')); } else if (cmd === 'quit') { - exit(); + utils.exit(); } try { diff --git a/lib/index.js b/lib/index.js index a07364b4..827c112d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -216,7 +216,10 @@ var Embark = { if (!web3.isConnected()) { console.log(("Couldn't connect to " + web3Endpoint.underline + " are you sure it's on?").red); console.log("make sure you have an ethereum node or simulator running. e.g 'embark blockchain'".magenta); - exit(); + // =================================== + // TODO: should throw exception instead + // =================================== + process.exit(); } web3.eth.getAccounts(function(err, accounts) { diff --git a/lib/ipfs.js b/lib/ipfs.js index 3beecc5d..09da3cf4 100644 --- a/lib/ipfs.js +++ b/lib/ipfs.js @@ -1,5 +1,6 @@ var colors = require('colors'); var async = require('async'); +var shelljs = require('shelljs'); var IPFS = function(options) { this.options = options; @@ -13,7 +14,7 @@ IPFS.prototype.deploy = function() { var self = this; async.waterfall([ function findBinary(callback) { - var ipfs_bin = exec('which ' + self.configIpfsBin).output.split("\n")[0]; + var ipfs_bin = shelljs.exec('which ' + self.configIpfsBin).output.split("\n")[0]; if (ipfs_bin === 'ipfs not found' || ipfs_bin === ''){ console.log(('=== WARNING: ' + self.configIpfsBin + ' not found or not in the path. Guessing ~/go/bin/ipfs for path').yellow); @@ -26,7 +27,7 @@ IPFS.prototype.deploy = function() { var cmd = ipfs_bin + " add -r " + self.buildDir; console.log(("=== adding " + self.buildDir + " to ipfs").green); console.log(cmd.green); - var result = exec(cmd); + var result = shelljs.exec(cmd); return callback(null, result); }, diff --git a/lib/simulator.js b/lib/simulator.js index daf10bfc..47554c12 100644 --- a/lib/simulator.js +++ b/lib/simulator.js @@ -1,3 +1,4 @@ +var shelljs = require('shelljs'); var Simulator = function(options) { this.blockchainConfig = options.blockchainConfig; @@ -10,7 +11,7 @@ Simulator.prototype.run = function(options) { cmds.push("-h " + (this.blockchainConfig.rpcHost || options.host || 'localhost')); cmds.push("-a " + (options.num || 10)); - exec('testrpc ' + cmds.join(' ')); + shelljs.exec('testrpc ' + cmds.join(' ')); }; module.exports = Simulator; diff --git a/lib/swarm.js b/lib/swarm.js index 1ebb36bb..667e0e6c 100644 --- a/lib/swarm.js +++ b/lib/swarm.js @@ -1,5 +1,6 @@ var colors = require('colors'); var async = require('async'); +var shelljs = require('shelljs'); var Swarm = function(options) { this.options = options; @@ -10,7 +11,7 @@ Swarm.prototype.deploy = function() { var self = this; async.waterfall([ function findBinary(callback) { - var swarm_bin = exec('which swarm').output.split("\n")[0]; + var swarm_bin = shelljs.exec('which swarm').output.split("\n")[0]; if (swarm_bin==='swarm not found' || swarm_bin === ''){ console.log('=== WARNING: Swarm not in an executable path. Guessing ~/go/bin/swarm for path'.yellow); @@ -23,7 +24,7 @@ Swarm.prototype.deploy = function() { var cmd = swarm_bin + " --defaultpath " + self.buildDir + "index.html --recursive up " + self.buildDir; console.log(("=== adding " + self.buildDir + " to swarm").green); console.log(cmd.green); - var result = exec(cmd); + var result = shelljs.exec(cmd); return callback(null, result); }, diff --git a/lib/template_generator.js b/lib/template_generator.js index 3c35ddeb..8e4448ed 100644 --- a/lib/template_generator.js +++ b/lib/template_generator.js @@ -1,20 +1,7 @@ // TODO: replace with something else more native to node -require('shelljs/global'); var wrench = require('wrench'); var utils = require('./utils.js'); -var run = function(cmd) { - var result = exec(cmd, {silent: true}); - if (result.code !== 0) { - console.log("error doing.. " + cmd); - console.log(result.output); - if (result.stderr !== undefined) { - console.log(result.stderr); - } - exit(); - } -}; - var TemplateGenerator = function(templateName) { this.templateName = templateName; }; @@ -24,10 +11,10 @@ TemplateGenerator.prototype.generate = function(destinationFolder, name) { console.log('Initializing Embark Template....'.green); wrench.copyDirSyncRecursive(templatePath, destinationFolder + name); - cd(destinationFolder + name); + utils.cd(destinationFolder + name); console.log('Installing packages.. this can take a few seconds'.green); - run('npm install'); + utils.runCmd('npm install'); console.log('Init complete'.green); console.log('\nApp ready at '.green + destinationFolder + name); diff --git a/lib/test.js b/lib/test.js index 1538c4ab..9728b7b1 100644 --- a/lib/test.js +++ b/lib/test.js @@ -18,7 +18,8 @@ var Test = function(_options) { 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(); + // TODO: should throw exception instead + process.exit(); } else { console.log("=============="); console.log("Tried to load testrpc but an error occurred. This is a problem with testrpc"); diff --git a/lib/utils.js b/lib/utils.js index df0e2162..f1b032dd 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,7 +1,9 @@ +/*global exit */ var path = require('path'); var grunt = require('grunt'); var merge = require('merge'); var request = require('request'); +var shelljs = require('shelljs'); function joinPath() { return path.join.apply(path.join, arguments); @@ -25,11 +27,34 @@ function checkIsAvailable(url, callback) { }); } +function runCmd(cmd, options) { + var result = shelljs.exec(cmd, options || {silent: true}); + if (result.code !== 0) { + console.log("error doing.. " + cmd); + console.log(result.output); + if (result.stderr !== undefined) { + console.log(result.stderr); + } + exit(); + } +} + +function cd(folder) { + shelljs.cd(folder); +} + +function exit(code) { + process.exit(code); +} + module.exports = { joinPath: joinPath, filesMatchingPattern: filesMatchingPattern, fileMatchesPattern: fileMatchesPattern, recursiveMerge: recursiveMerge, - checkIsAvailable: checkIsAvailable + checkIsAvailable: checkIsAvailable, + runCmd: runCmd, + cd: cd, + exit: exit };