Merge pull request #242 from toadkicker/make_cli_faster
this is a quick attempt at speeding up the init of CLI…
This commit is contained in:
commit
1534bf6207
|
@ -1,4 +1,4 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
var Cmd = require('../lib/cmd');
|
||||||
var Embark = require('..');
|
var cli = new Cmd();
|
||||||
Embark.process(process.argv);
|
cli.process(process.argv);
|
||||||
|
|
31
lib/cmd.js
31
lib/cmd.js
|
@ -1,9 +1,9 @@
|
||||||
var program = require('commander');
|
var program = require('commander');
|
||||||
var colors = require('colors');
|
var colors = require('colors');
|
||||||
var shelljs = require('shelljs');
|
var shelljs = require('shelljs');
|
||||||
|
var Embark = require('../lib/index')();
|
||||||
|
|
||||||
var Cmd = function(Embark) {
|
var Cmd = function() {
|
||||||
this.Embark = Embark;
|
|
||||||
program.version(Embark.version);
|
program.version(Embark.version);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ Cmd.prototype.process = function(args) {
|
||||||
};
|
};
|
||||||
|
|
||||||
Cmd.prototype.newApp = function() {
|
Cmd.prototype.newApp = function() {
|
||||||
var self = this;
|
|
||||||
program
|
program
|
||||||
.command('new [name]')
|
.command('new [name]')
|
||||||
.description('new application')
|
.description('new application')
|
||||||
|
@ -39,32 +38,29 @@ Cmd.prototype.newApp = function() {
|
||||||
console.log("e.g embark new --help for more information".green);
|
console.log("e.g embark new --help for more information".green);
|
||||||
process.exit(9);
|
process.exit(9);
|
||||||
}
|
}
|
||||||
self.Embark.generateTemplate('boilerplate', './', name);
|
Embark.generateTemplate('boilerplate', './', name);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Cmd.prototype.demo = function() {
|
Cmd.prototype.demo = function() {
|
||||||
var self = this;
|
|
||||||
program
|
program
|
||||||
.command('demo')
|
.command('demo')
|
||||||
.description('create a working dapp with a SimpleStorage contract')
|
.description('create a working dapp with a SimpleStorage contract')
|
||||||
.action(function() {
|
.action(function() {
|
||||||
self.Embark.generateTemplate('demo', './', 'embark_demo');
|
Embark.generateTemplate('demo', './', 'embark_demo');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Cmd.prototype.build = function() {
|
Cmd.prototype.build = function() {
|
||||||
var self = this;
|
|
||||||
program
|
program
|
||||||
.command('build [environment]')
|
.command('build [environment]')
|
||||||
.description('deploy and build dapp at dist/ (default: development)')
|
.description('deploy and build dapp at dist/ (default: development)')
|
||||||
.action(function(env, options) {
|
.action(function(env, options) {
|
||||||
self.Embark.build({env: env || 'development'});
|
Embark.build({env: env || 'development'});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Cmd.prototype.run = function() {
|
Cmd.prototype.run = function() {
|
||||||
var self = this;
|
|
||||||
program
|
program
|
||||||
.command('run [environment]')
|
.command('run [environment]')
|
||||||
.option('-p, --port [port]', 'port to run the dev webserver (default: 8000)')
|
.option('-p, --port [port]', 'port to run the dev webserver (default: 8000)')
|
||||||
|
@ -74,7 +70,7 @@ Cmd.prototype.run = function() {
|
||||||
.option('--no-color', 'no colors in case it\'s needed for compatbility purposes')
|
.option('--no-color', 'no colors in case it\'s needed for compatbility purposes')
|
||||||
.description('run dapp (default: development)')
|
.description('run dapp (default: development)')
|
||||||
.action(function(env, options) {
|
.action(function(env, options) {
|
||||||
self.Embark.run({
|
Embark.run({
|
||||||
env: env || 'development',
|
env: env || 'development',
|
||||||
serverPort: options.port,
|
serverPort: options.port,
|
||||||
serverHost: options.host,
|
serverHost: options.host,
|
||||||
|
@ -85,22 +81,20 @@ Cmd.prototype.run = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Cmd.prototype.blockchain = function() {
|
Cmd.prototype.blockchain = function() {
|
||||||
var self = this;
|
|
||||||
program
|
program
|
||||||
.command('blockchain [environment]')
|
.command('blockchain [environment]')
|
||||||
.option('-c, --client [client]', 'Use a specific ethereum client or simulator (supported: geth, parity, ethersim, testrpc')
|
.option('-c, --client [client]', 'Use a specific ethereum client or simulator (supported: geth, parity, ethersim, testrpc')
|
||||||
.description('run blockchain server (default: development)')
|
.description('run blockchain server (default: development)')
|
||||||
.action(function(env ,options) {
|
.action(function(env ,options) {
|
||||||
self.Embark.initConfig(env || 'development', {
|
Embark.initConfig(env || 'development', {
|
||||||
embarkConfig: 'embark.json',
|
embarkConfig: 'embark.json',
|
||||||
interceptLogs: false
|
interceptLogs: false
|
||||||
});
|
});
|
||||||
self.Embark.blockchain(env || 'development', options.client || 'geth');
|
Embark.blockchain(env || 'development', options.client || 'geth');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
Cmd.prototype.simulator = function() {
|
Cmd.prototype.simulator = function() {
|
||||||
var self = this;
|
|
||||||
program
|
program
|
||||||
.command('simulator [environment]')
|
.command('simulator [environment]')
|
||||||
.description('run a fast ethereum rpc simulator')
|
.description('run a fast ethereum rpc simulator')
|
||||||
|
@ -108,11 +102,11 @@ Cmd.prototype.simulator = function() {
|
||||||
.option('-p, --port [port]', 'port to run the rpc simulator (default: 8000)')
|
.option('-p, --port [port]', 'port to run the rpc simulator (default: 8000)')
|
||||||
.option('-h, --host [host]', 'host to run the rpc simulator (default: localhost)')
|
.option('-h, --host [host]', 'host to run the rpc simulator (default: localhost)')
|
||||||
.action(function(env, options) {
|
.action(function(env, options) {
|
||||||
self.Embark.initConfig(env || 'development', {
|
Embark.initConfig(env || 'development', {
|
||||||
embarkConfig: 'embark.json',
|
embarkConfig: 'embark.json',
|
||||||
interceptLogs: false
|
interceptLogs: false
|
||||||
});
|
});
|
||||||
self.Embark.simulator({port: options.port, host: options.host});
|
Embark.simulator({port: options.port, host: options.host});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -126,16 +120,15 @@ Cmd.prototype.test = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Cmd.prototype.upload = function() {
|
Cmd.prototype.upload = function() {
|
||||||
var self = this;
|
|
||||||
program
|
program
|
||||||
.command('upload [platform] [environment]')
|
.command('upload [platform] [environment]')
|
||||||
.description('upload your dapp to a decentralized storage. possible options: ipfs, swarm (e.g embark upload swarm)')
|
.description('upload your dapp to a decentralized storage. possible options: ipfs, swarm (e.g embark upload swarm)')
|
||||||
.action(function(platform, env, options) {
|
.action(function(platform, env, options) {
|
||||||
// TODO: get env in cmd line as well
|
// TODO: get env in cmd line as well
|
||||||
self.Embark.initConfig(env || 'development', {
|
Embark.initConfig(env || 'development', {
|
||||||
embarkConfig: 'embark.json', interceptLogs: false
|
embarkConfig: 'embark.json', interceptLogs: false
|
||||||
});
|
});
|
||||||
self.Embark.upload(platform);
|
Embark.upload(platform);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
73
lib/index.js
73
lib/index.js
|
@ -6,58 +6,46 @@ var colors = require('colors');
|
||||||
|
|
||||||
var Engine = require('./core/engine.js');
|
var Engine = require('./core/engine.js');
|
||||||
|
|
||||||
var Blockchain = require('./cmds/blockchain/blockchain.js');
|
|
||||||
var Simulator = require('./cmds/simulator.js');
|
|
||||||
var TemplateGenerator = require('./cmds/template_generator.js');
|
|
||||||
|
|
||||||
var Test = require('./core/test.js');
|
var Test = require('./core/test.js');
|
||||||
var Logger = require('./core/logger.js');
|
|
||||||
var Config = require('./core/config.js');
|
|
||||||
var Events = require('./core/events.js');
|
|
||||||
|
|
||||||
var Dashboard = require('./dashboard/dashboard.js');
|
|
||||||
|
|
||||||
var IPFS = require('./upload/ipfs.js');
|
var IPFS = require('./upload/ipfs.js');
|
||||||
var Swarm = require('./upload/swarm.js');
|
var Swarm = require('./upload/swarm.js');
|
||||||
|
|
||||||
var Cmd = require('./cmd.js');
|
|
||||||
var version = require('../package.json').version;
|
var version = require('../package.json').version;
|
||||||
|
|
||||||
var Embark = {
|
var Embark = function () {
|
||||||
|
function initConfig (env, options) {
|
||||||
|
var Events = require('./core/events.js');
|
||||||
|
var Logger = require('./core/logger.js');
|
||||||
|
var Config = require('./core/config.js');
|
||||||
|
|
||||||
version: version,
|
|
||||||
|
|
||||||
process: function(args) {
|
|
||||||
var cmd = new Cmd(Embark);
|
|
||||||
cmd.process(args);
|
|
||||||
},
|
|
||||||
|
|
||||||
initConfig: function(env, options) {
|
|
||||||
this.events = new Events();
|
this.events = new Events();
|
||||||
this.logger = new Logger({logLevel: 'debug'});
|
this.logger = new Logger({logLevel: 'debug'});
|
||||||
|
|
||||||
this.config = new Config({env: env, logger: this.logger, events: this.events});
|
this.config = new Config({env: env, logger: this.logger, events: this.events});
|
||||||
this.config.loadConfigFiles(options);
|
this.config.loadConfigFiles(options);
|
||||||
this.plugins = this.config.plugins;
|
this.plugins = this.config.plugins;
|
||||||
},
|
}
|
||||||
|
|
||||||
blockchain: function(env, client) {
|
function blockchain (env, client) {
|
||||||
var blockchain = Blockchain(this.config.blockchainConfig, client, env);
|
return require('./cmds/blockchain/blockchain.js')(this.config.blockchainConfig, client, env).run();
|
||||||
blockchain.run();
|
}
|
||||||
},
|
|
||||||
|
|
||||||
simulator: function(options) {
|
function simulator (options) {
|
||||||
|
var Simulator = require('./cmds/simulator.js');
|
||||||
var simulator = new Simulator({blockchainConfig: this.config.blockchainConfig});
|
var simulator = new Simulator({blockchainConfig: this.config.blockchainConfig});
|
||||||
simulator.run(options);
|
simulator.run(options);
|
||||||
},
|
}
|
||||||
|
|
||||||
generateTemplate: function(templateName, destinationFolder, name) {
|
function generateTemplate (templateName, destinationFolder, name) {
|
||||||
|
var TemplateGenerator = require('./cmds/template_generator.js');
|
||||||
var templateGenerator = new TemplateGenerator(templateName);
|
var templateGenerator = new TemplateGenerator(templateName);
|
||||||
templateGenerator.generate(destinationFolder, name);
|
templateGenerator.generate(destinationFolder, name);
|
||||||
},
|
}
|
||||||
|
|
||||||
|
function run (options) {
|
||||||
|
var Dashboard = require('./dashboard/dashboard.js');
|
||||||
|
|
||||||
run: function(options) {
|
|
||||||
var self = this;
|
|
||||||
var env = options.env;
|
var env = options.env;
|
||||||
|
|
||||||
var engine = new Engine({
|
var engine = new Engine({
|
||||||
|
@ -139,10 +127,9 @@ var Embark = {
|
||||||
engine.events.emit('firstDeploymentDone');
|
engine.events.emit('firstDeploymentDone');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
build: function(options) {
|
function build (options) {
|
||||||
var self = this;
|
|
||||||
|
|
||||||
var engine = new Engine({
|
var engine = new Engine({
|
||||||
env: options.env,
|
env: options.env,
|
||||||
|
@ -177,14 +164,14 @@ var Embark = {
|
||||||
// needed due to child processes
|
// needed due to child processes
|
||||||
process.exit();
|
process.exit();
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
|
|
||||||
initTests: function(options) {
|
function initTests (options) {
|
||||||
return new Test(options);
|
return new Test(options);
|
||||||
},
|
}
|
||||||
|
|
||||||
// TODO: should deploy if it hasn't already
|
// TODO: should deploy if it hasn't already
|
||||||
upload: function(platform) {
|
function upload (platform) {
|
||||||
if (platform === 'ipfs') {
|
if (platform === 'ipfs') {
|
||||||
var ipfs = new IPFS({buildDir: 'dist/', plugins: this.plugins, storageConfig: this.config.storageConfig});
|
var ipfs = new IPFS({buildDir: 'dist/', plugins: this.plugins, storageConfig: this.config.storageConfig});
|
||||||
ipfs.deploy();
|
ipfs.deploy();
|
||||||
|
@ -197,6 +184,18 @@ var Embark = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
version: version,
|
||||||
|
initConfig: initConfig,
|
||||||
|
blockchain: blockchain,
|
||||||
|
simulator: simulator,
|
||||||
|
generateTemplate: generateTemplate,
|
||||||
|
run: run,
|
||||||
|
build: build,
|
||||||
|
initTests: initTests,
|
||||||
|
upload: upload
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Embark;
|
module.exports = Embark;
|
||||||
|
|
Loading…
Reference in New Issue