Dropped 'this' in Cmd and set internal var Embar to self execute

This commit is contained in:
Todd Baur 2017-03-11 00:07:08 +09:00
parent 835899cf6e
commit dc9084b8a6
1 changed files with 18 additions and 19 deletions

View File

@ -1,10 +1,9 @@
var program = require('commander');
var colors = require('colors');
var shelljs = require('shelljs');
var Embark = require('../lib/index');
var Embark = require('../lib/index')();
var Cmd = function() {
this.Embark = Embark;
program.version(Embark.version);
};
@ -28,7 +27,7 @@ Cmd.prototype.process = function(args) {
};
Cmd.prototype.newApp = function() {
var self = this;
program
.command('new [name]')
.description('new application')
@ -40,32 +39,32 @@ Cmd.prototype.newApp = function() {
console.log("e.g embark new --help for more information".green);
process.exit(9);
}
self.Embark.generateTemplate('boilerplate', './', name);
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');
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) {
self.Embark.build({env: env || 'development'});
Embark.build({env: env || 'development'});
});
};
Cmd.prototype.run = function() {
var self = this;
program
.command('run [environment]')
.option('-p, --port [port]', 'port to run the dev webserver (default: 8000)')
@ -75,7 +74,7 @@ Cmd.prototype.run = function() {
.option('--no-color', 'no colors in case it\'s needed for compatbility purposes')
.description('run dapp (default: development)')
.action(function(env, options) {
self.Embark.run({
Embark.run({
env: env || 'development',
serverPort: options.port,
serverHost: options.host,
@ -86,22 +85,22 @@ Cmd.prototype.run = function() {
};
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) {
self.Embark.initConfig(env || 'development', {
Embark.initConfig(env || 'development', {
embarkConfig: 'embark.json',
interceptLogs: false
});
self.Embark.blockchain(env || 'development', options.client || 'geth');
Embark.blockchain(env || 'development', options.client || 'geth');
});
};
Cmd.prototype.simulator = function() {
var self = this;
program
.command('simulator [environment]')
.description('run a fast ethereum rpc simulator')
@ -109,11 +108,11 @@ Cmd.prototype.simulator = function() {
.option('-p, --port [port]', 'port to run the rpc simulator (default: 8000)')
.option('-h, --host [host]', 'host to run the rpc simulator (default: localhost)')
.action(function(env, options) {
self.Embark.initConfig(env || 'development', {
Embark.initConfig(env || 'development', {
embarkConfig: 'embark.json',
interceptLogs: false
});
self.Embark.simulator({port: options.port, host: options.host});
Embark.simulator({port: options.port, host: options.host});
});
};
@ -127,16 +126,16 @@ Cmd.prototype.test = function() {
};
Cmd.prototype.upload = function() {
var self = this;
program
.command('upload [platform] [environment]')
.description('upload your dapp to a decentralized storage. possible options: ipfs, swarm (e.g embark upload swarm)')
.action(function(platform, env, options) {
// TODO: get env in cmd line as well
self.Embark.initConfig(env || 'development', {
Embark.initConfig(env || 'development', {
embarkConfig: 'embark.json', interceptLogs: false
});
self.Embark.upload(platform);
Embark.upload(platform);
});
};