move shelljs scopes to utils; require locally so it doesn't polute the global space

This commit is contained in:
Iuri Matias 2017-02-18 16:06:39 -05:00
parent 08ba95576d
commit a83cc6a44a
10 changed files with 49 additions and 27 deletions

View File

@ -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() {

View File

@ -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');
});
};

View File

@ -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 {

View File

@ -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) {

View File

@ -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);
},

View File

@ -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;

View File

@ -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);
},

View File

@ -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);

View File

@ -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");

View File

@ -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
};