mirror of
https://github.com/status-im/embark-area-51.git
synced 2025-02-17 09:46:37 +00:00
move shelljs scopes to utils; require locally so it doesn't polute the global space
This commit is contained in:
parent
08ba95576d
commit
a83cc6a44a
@ -3,6 +3,7 @@ var wrench = require('wrench');
|
|||||||
var colors = require('colors');
|
var colors = require('colors');
|
||||||
var GethCommands = require('./geth_commands.js');
|
var GethCommands = require('./geth_commands.js');
|
||||||
var utils = require('./utils.js');
|
var utils = require('./utils.js');
|
||||||
|
var shelljs = require('shelljs');
|
||||||
|
|
||||||
var Blockchain = function(blockchainConfig, Client) {
|
var Blockchain = function(blockchainConfig, Client) {
|
||||||
this.blockchainConfig = blockchainConfig;
|
this.blockchainConfig = blockchainConfig;
|
||||||
@ -33,7 +34,7 @@ var Blockchain = function(blockchainConfig, Client) {
|
|||||||
|
|
||||||
Blockchain.prototype.runCommand = function(cmd) {
|
Blockchain.prototype.runCommand = function(cmd) {
|
||||||
console.log(("running: " + cmd.underline).green);
|
console.log(("running: " + cmd.underline).green);
|
||||||
return exec(cmd);
|
return shelljs.exec(cmd);
|
||||||
};
|
};
|
||||||
|
|
||||||
Blockchain.prototype.run = function() {
|
Blockchain.prototype.run = function() {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var colors = require('colors');
|
var colors = require('colors');
|
||||||
|
var shelljs = require('shelljs');
|
||||||
|
|
||||||
var Cmd = function(Embark) {
|
var Cmd = function(Embark) {
|
||||||
this.Embark = Embark;
|
this.Embark = Embark;
|
||||||
@ -35,7 +36,7 @@ Cmd.prototype.newApp = function() {
|
|||||||
console.log("please specify your app Name".red);
|
console.log("please specify your app Name".red);
|
||||||
console.log("e.g embark new MyApp".green);
|
console.log("e.g embark new MyApp".green);
|
||||||
console.log("e.g embark new --help for more information".green);
|
console.log("e.g embark new --help for more information".green);
|
||||||
exit();
|
process.exit(code);
|
||||||
}
|
}
|
||||||
self.Embark.generateTemplate('boilerplate', './', name);
|
self.Embark.generateTemplate('boilerplate', './', name);
|
||||||
});
|
});
|
||||||
@ -126,7 +127,7 @@ Cmd.prototype.test = function() {
|
|||||||
.command('test')
|
.command('test')
|
||||||
.description('run tests')
|
.description('run tests')
|
||||||
.action(function() {
|
.action(function() {
|
||||||
exec('mocha test/ --no-timeouts');
|
shelljs.exec('mocha test/ --no-timeouts');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
var Web3 = require('web3');
|
var Web3 = require('web3');
|
||||||
|
var utils = require('./utils.js');
|
||||||
|
|
||||||
var Console = function(options) {
|
var Console = function(options) {
|
||||||
this.plugins = options.plugins;
|
this.plugins = options.plugins;
|
||||||
@ -32,7 +33,7 @@ Console.prototype.executeCmd = function(cmd, callback) {
|
|||||||
];
|
];
|
||||||
return callback(helpText.join('\n'));
|
return callback(helpText.join('\n'));
|
||||||
} else if (cmd === 'quit') {
|
} else if (cmd === 'quit') {
|
||||||
exit();
|
utils.exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -216,7 +216,10 @@ var Embark = {
|
|||||||
if (!web3.isConnected()) {
|
if (!web3.isConnected()) {
|
||||||
console.log(("Couldn't connect to " + web3Endpoint.underline + " are you sure it's on?").red);
|
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);
|
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) {
|
web3.eth.getAccounts(function(err, accounts) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
var colors = require('colors');
|
var colors = require('colors');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
var shelljs = require('shelljs');
|
||||||
|
|
||||||
var IPFS = function(options) {
|
var IPFS = function(options) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
@ -13,7 +14,7 @@ IPFS.prototype.deploy = function() {
|
|||||||
var self = this;
|
var self = this;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function findBinary(callback) {
|
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 === ''){
|
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);
|
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;
|
var cmd = ipfs_bin + " add -r " + self.buildDir;
|
||||||
console.log(("=== adding " + self.buildDir + " to ipfs").green);
|
console.log(("=== adding " + self.buildDir + " to ipfs").green);
|
||||||
console.log(cmd.green);
|
console.log(cmd.green);
|
||||||
var result = exec(cmd);
|
var result = shelljs.exec(cmd);
|
||||||
|
|
||||||
return callback(null, result);
|
return callback(null, result);
|
||||||
},
|
},
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
var shelljs = require('shelljs');
|
||||||
|
|
||||||
var Simulator = function(options) {
|
var Simulator = function(options) {
|
||||||
this.blockchainConfig = options.blockchainConfig;
|
this.blockchainConfig = options.blockchainConfig;
|
||||||
@ -10,7 +11,7 @@ Simulator.prototype.run = function(options) {
|
|||||||
cmds.push("-h " + (this.blockchainConfig.rpcHost || options.host || 'localhost'));
|
cmds.push("-h " + (this.blockchainConfig.rpcHost || options.host || 'localhost'));
|
||||||
cmds.push("-a " + (options.num || 10));
|
cmds.push("-a " + (options.num || 10));
|
||||||
|
|
||||||
exec('testrpc ' + cmds.join(' '));
|
shelljs.exec('testrpc ' + cmds.join(' '));
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Simulator;
|
module.exports = Simulator;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
var colors = require('colors');
|
var colors = require('colors');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
|
var shelljs = require('shelljs');
|
||||||
|
|
||||||
var Swarm = function(options) {
|
var Swarm = function(options) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
@ -10,7 +11,7 @@ Swarm.prototype.deploy = function() {
|
|||||||
var self = this;
|
var self = this;
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function findBinary(callback) {
|
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 === ''){
|
if (swarm_bin==='swarm not found' || swarm_bin === ''){
|
||||||
console.log('=== WARNING: Swarm not in an executable path. Guessing ~/go/bin/swarm for path'.yellow);
|
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;
|
var cmd = swarm_bin + " --defaultpath " + self.buildDir + "index.html --recursive up " + self.buildDir;
|
||||||
console.log(("=== adding " + self.buildDir + " to swarm").green);
|
console.log(("=== adding " + self.buildDir + " to swarm").green);
|
||||||
console.log(cmd.green);
|
console.log(cmd.green);
|
||||||
var result = exec(cmd);
|
var result = shelljs.exec(cmd);
|
||||||
|
|
||||||
return callback(null, result);
|
return callback(null, result);
|
||||||
},
|
},
|
||||||
|
@ -1,20 +1,7 @@
|
|||||||
// TODO: replace with something else more native to node
|
// TODO: replace with something else more native to node
|
||||||
require('shelljs/global');
|
|
||||||
var wrench = require('wrench');
|
var wrench = require('wrench');
|
||||||
var utils = require('./utils.js');
|
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) {
|
var TemplateGenerator = function(templateName) {
|
||||||
this.templateName = templateName;
|
this.templateName = templateName;
|
||||||
};
|
};
|
||||||
@ -24,10 +11,10 @@ TemplateGenerator.prototype.generate = function(destinationFolder, name) {
|
|||||||
console.log('Initializing Embark Template....'.green);
|
console.log('Initializing Embark Template....'.green);
|
||||||
|
|
||||||
wrench.copyDirSyncRecursive(templatePath, destinationFolder + name);
|
wrench.copyDirSyncRecursive(templatePath, destinationFolder + name);
|
||||||
cd(destinationFolder + name);
|
utils.cd(destinationFolder + name);
|
||||||
|
|
||||||
console.log('Installing packages.. this can take a few seconds'.green);
|
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('Init complete'.green);
|
||||||
console.log('\nApp ready at '.green + destinationFolder + name);
|
console.log('\nApp ready at '.green + destinationFolder + name);
|
||||||
|
|
||||||
|
@ -18,7 +18,8 @@ var Test = function(_options) {
|
|||||||
console.log('Simulator not found; Please install it with "npm install ethereumjs-testrpc --save"');
|
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('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');
|
console.log('For more information see https://github.com/ethereumjs/testrpc');
|
||||||
exit();
|
// TODO: should throw exception instead
|
||||||
|
process.exit();
|
||||||
} else {
|
} else {
|
||||||
console.log("==============");
|
console.log("==============");
|
||||||
console.log("Tried to load testrpc but an error occurred. This is a problem with testrpc");
|
console.log("Tried to load testrpc but an error occurred. This is a problem with testrpc");
|
||||||
|
27
lib/utils.js
27
lib/utils.js
@ -1,7 +1,9 @@
|
|||||||
|
/*global exit */
|
||||||
var path = require('path');
|
var path = require('path');
|
||||||
var grunt = require('grunt');
|
var grunt = require('grunt');
|
||||||
var merge = require('merge');
|
var merge = require('merge');
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
|
var shelljs = require('shelljs');
|
||||||
|
|
||||||
function joinPath() {
|
function joinPath() {
|
||||||
return path.join.apply(path.join, arguments);
|
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 = {
|
module.exports = {
|
||||||
joinPath: joinPath,
|
joinPath: joinPath,
|
||||||
filesMatchingPattern: filesMatchingPattern,
|
filesMatchingPattern: filesMatchingPattern,
|
||||||
fileMatchesPattern: fileMatchesPattern,
|
fileMatchesPattern: fileMatchesPattern,
|
||||||
recursiveMerge: recursiveMerge,
|
recursiveMerge: recursiveMerge,
|
||||||
checkIsAvailable: checkIsAvailable
|
checkIsAvailable: checkIsAvailable,
|
||||||
|
runCmd: runCmd,
|
||||||
|
cd: cd,
|
||||||
|
exit: exit
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user