embark-area-51/lib/cmd.js

157 lines
4.1 KiB
JavaScript
Raw Normal View History

2016-08-18 00:29:41 +00:00
var program = require('commander');
var colors = require('colors');
var Cmd = function(Embark) {
this.Embark = Embark;
2016-10-29 15:16:43 +00:00
program.version('2.1.2');
2016-08-18 00:29:41 +00:00
};
Cmd.prototype.process = function(args) {
this.newApp();
this.demo();
this.build();
2016-08-18 00:29:41 +00:00
this.run();
this.blockchain();
2016-08-18 00:29:41 +00:00
this.simulator();
2016-10-02 21:26:57 +00:00
this.test();
this.ipfs();
2016-08-18 00:29:41 +00:00
this.otherCommands();
program.parse(args);
};
Cmd.prototype.newApp = function() {
var self = this;
program
.command('new [name]')
.description('new application')
.action(function(name, options) {
if (name === undefined) {
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();
}
self.Embark.generateTemplate('boilerplate', './', name);
});
};
Cmd.prototype.demo = function() {
var self = this;
program
.command('demo')
.description('create a working dapp with a SimpleStorage contract')
.action(function() {
self.Embark.generateTemplate('demo', './', 'embark_demo');
});
};
Cmd.prototype.build = function() {
var self = this;
program
.command('build [environment]')
.description('deploy and build dapp at dist/ (default: development)')
.action(function(env, options) {
2016-08-22 03:40:05 +00:00
self.Embark.initConfig(env || 'development', {
embarkConfig: 'embark.json'
});
self.Embark.build(env || 'development');
});
};
2016-08-18 00:29:41 +00:00
Cmd.prototype.run = function() {
var self = this;
program
.command('run [environment]')
.option('-p, --port [port]', 'port to run the dev webserver (default: 8000)')
.option('-b, --host [host]', 'host to run the dev webserver (default: localhost)')
2016-10-30 02:00:54 +00:00
.option('--noserver', 'disable the development webserver')
2016-10-30 02:30:41 +00:00
.option('--nodashboard', 'simple mode, disables the dashboard')
2016-08-18 00:29:41 +00:00
.description('run dapp (default: development)')
.action(function(env, options) {
2016-08-22 03:40:05 +00:00
self.Embark.initConfig(env || 'development', {
embarkConfig: 'embark.json'
});
self.Embark.run({
env: env || 'development',
serverPort: options.port,
2016-10-30 02:00:54 +00:00
serverHost: options.host,
2016-10-30 02:30:41 +00:00
runWebserver: !options.noserver,
useDashboard: !options.nodashboard
});
2016-08-18 00:29:41 +00:00
});
};
Cmd.prototype.blockchain = function() {
var self = this;
program
.command('blockchain [environment]')
.option('-c, --client [client]', 'Use a specific ethereum client or simulator (supported: geth, parity, ethersim, testrpc')
.description('run blockchain server (default: development)')
.action(function(env ,options) {
2016-08-22 03:40:05 +00:00
self.Embark.initConfig(env || 'development', {
embarkConfig: 'embark.json'
});
self.Embark.blockchain(env || 'development', options.client || 'geth');
});
};
2016-08-18 00:29:41 +00:00
Cmd.prototype.simulator = function() {
program
.command('simulator')
.description('run a fast ethereum rpc simulator')
2016-10-02 22:45:55 +00:00
.option('--testrpc', 'use testrpc as the rpc simulator [default]')
.option('--ethersim', 'use ethersim as the rpc simulator')
.action(function(options) {
var Sim;
if (options.ethersim) {
try {
Sim = require('ethersim');
} catch(e) {
console.log('EtherSim not found; Please install it with "npm install ethersim --save"');
console.log('For more information see https://github.com/iurimatias/ethersim');
process.exit(1);
}
Sim.startServer();
}
else {
try {
Sim = require('ethereumjs-testrpc');
} catch(e) {
console.log('TestRPC not found; Please install it with "npm install -g ethereumjs-testrpc');
console.log('For more information see https://github.com/ethereumjs/testrpc');
process.exit(1);
}
exec('testrpc');
2016-08-18 00:29:41 +00:00
}
});
};
2016-10-02 21:26:57 +00:00
Cmd.prototype.test = function() {
program
.command('test')
.description('run tests')
.action(function() {
exec('mocha test/ --no-timeouts');
});
};
Cmd.prototype.ipfs = function() {
var self = this;
program
.command('ipfs')
.description('deploy to IPFS')
.action(function() {
self.Embark.ipfs();
});
};
2016-08-18 00:29:41 +00:00
Cmd.prototype.otherCommands = function() {
program
.action(function(env){
console.log('unknown command "%s"'.red, env);
});
};
module.exports = Cmd;