2017-03-29 17:18:00 +00:00
|
|
|
let program = require('commander');
|
|
|
|
let colors = require('colors');
|
|
|
|
let shelljs = require('shelljs');
|
|
|
|
let promptly = require('promptly');
|
|
|
|
let path = require('path');
|
|
|
|
let Embark = require('../lib/index');
|
2016-08-18 00:29:41 +00:00
|
|
|
|
2017-03-29 17:18:00 +00:00
|
|
|
let Cmd = function() {
|
2016-10-31 02:37:06 +00:00
|
|
|
program.version(Embark.version);
|
2016-08-18 00:29:41 +00:00
|
|
|
};
|
|
|
|
|
2017-03-22 05:13:58 +00:00
|
|
|
|
2016-08-18 00:29:41 +00:00
|
|
|
Cmd.prototype.process = function(args) {
|
2016-08-21 14:42:42 +00:00
|
|
|
this.newApp();
|
|
|
|
this.demo();
|
|
|
|
this.build();
|
2016-08-18 00:29:41 +00:00
|
|
|
this.run();
|
2016-08-21 14:42:42 +00:00
|
|
|
this.blockchain();
|
2016-08-18 00:29:41 +00:00
|
|
|
this.simulator();
|
2016-10-02 21:26:57 +00:00
|
|
|
this.test();
|
2017-01-08 01:37:48 +00:00
|
|
|
this.upload();
|
2016-08-18 00:29:41 +00:00
|
|
|
this.otherCommands();
|
2017-02-17 19:34:07 +00:00
|
|
|
|
|
|
|
//If no arguments are passed display help by default
|
|
|
|
if (!process.argv.slice(2).length) {
|
|
|
|
program.help();
|
|
|
|
}
|
|
|
|
|
2016-08-18 00:29:41 +00:00
|
|
|
program.parse(args);
|
|
|
|
};
|
|
|
|
|
2017-03-22 05:13:58 +00:00
|
|
|
Cmd.prototype.newApp = function(name) {
|
|
|
|
|
2017-03-29 17:18:00 +00:00
|
|
|
let validateName = function (value) {
|
2017-03-22 05:13:58 +00:00
|
|
|
try {
|
|
|
|
if(value.match(/^[a-zA-Z\s\-]+$/)) return value;
|
|
|
|
} catch (e) {
|
|
|
|
throw new Error('Name must be only letters, spaces, or dashes');
|
2016-08-21 14:42:42 +00:00
|
|
|
}
|
2017-03-22 05:13:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
program
|
|
|
|
.command('new [name]')
|
|
|
|
.description('new application')
|
|
|
|
.action(function (name) {
|
|
|
|
if (name === undefined) {
|
2017-03-29 17:18:00 +00:00
|
|
|
let parentDirectory = path.dirname(__dirname).split("/").pop();
|
2017-03-22 05:13:58 +00:00
|
|
|
return promptly.prompt("Name your app (default is " + parentDirectory + "):", {
|
|
|
|
default: parentDirectory,
|
|
|
|
validator: validateName
|
|
|
|
}, function (err, inputvalue) {
|
|
|
|
if (err) {
|
|
|
|
console.error('Invalid name:', err.message);
|
|
|
|
// Manually call retry
|
|
|
|
// The passed error has a retry method to easily prompt again.
|
|
|
|
err.retry();
|
|
|
|
} else {
|
|
|
|
//slightly different assignment of name since it comes from child prompt
|
|
|
|
Embark.generateTemplate('boilerplate', './', inputvalue);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
Embark.generateTemplate('boilerplate', './', name);
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
2016-08-21 14:42:42 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Cmd.prototype.demo = function() {
|
|
|
|
program
|
|
|
|
.command('demo')
|
|
|
|
.description('create a working dapp with a SimpleStorage contract')
|
|
|
|
.action(function() {
|
2017-03-10 15:07:08 +00:00
|
|
|
Embark.generateTemplate('demo', './', 'embark_demo');
|
2016-08-21 14:42:42 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
Cmd.prototype.build = function() {
|
|
|
|
program
|
|
|
|
.command('build [environment]')
|
|
|
|
.description('deploy and build dapp at dist/ (default: development)')
|
|
|
|
.action(function(env, options) {
|
2017-03-10 15:07:08 +00:00
|
|
|
Embark.build({env: env || 'development'});
|
2016-08-21 14:42:42 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-08-18 00:29:41 +00:00
|
|
|
Cmd.prototype.run = function() {
|
|
|
|
program
|
|
|
|
.command('run [environment]')
|
2016-10-30 01:41:50 +00:00
|
|
|
.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-10-30 02:35:22 +00:00
|
|
|
.option('--no-color', 'no colors in case it\'s needed for compatbility purposes')
|
2016-08-18 00:29:41 +00:00
|
|
|
.description('run dapp (default: development)')
|
|
|
|
.action(function(env, options) {
|
2017-03-10 15:07:08 +00:00
|
|
|
Embark.run({
|
2016-10-30 01:41:50 +00:00
|
|
|
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-10-30 01:41:50 +00:00
|
|
|
});
|
2016-08-18 00:29:41 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-08-21 14:42:42 +00:00
|
|
|
Cmd.prototype.blockchain = function() {
|
|
|
|
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) {
|
2017-03-10 15:07:08 +00:00
|
|
|
Embark.initConfig(env || 'development', {
|
2017-02-18 14:23:19 +00:00
|
|
|
embarkConfig: 'embark.json',
|
|
|
|
interceptLogs: false
|
2016-08-22 03:40:05 +00:00
|
|
|
});
|
2017-03-10 15:07:08 +00:00
|
|
|
Embark.blockchain(env || 'development', options.client || 'geth');
|
2016-08-21 14:42:42 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-08-18 00:29:41 +00:00
|
|
|
Cmd.prototype.simulator = function() {
|
|
|
|
program
|
2017-02-18 13:01:03 +00:00
|
|
|
.command('simulator [environment]')
|
2016-08-18 00:29:41 +00:00
|
|
|
.description('run a fast ethereum rpc simulator')
|
2016-10-02 22:45:55 +00:00
|
|
|
.option('--testrpc', 'use testrpc as the rpc simulator [default]')
|
2017-02-18 13:01:03 +00:00
|
|
|
.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) {
|
2017-03-10 15:07:08 +00:00
|
|
|
Embark.initConfig(env || 'development', {
|
2017-02-18 14:23:19 +00:00
|
|
|
embarkConfig: 'embark.json',
|
|
|
|
interceptLogs: false
|
2017-02-18 13:01:03 +00:00
|
|
|
});
|
2017-03-10 15:07:08 +00:00
|
|
|
Embark.simulator({port: options.port, host: options.host});
|
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() {
|
2017-03-08 14:41:16 +00:00
|
|
|
shelljs.exec('mocha test');
|
2016-10-02 21:26:57 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-01-08 01:37:48 +00:00
|
|
|
Cmd.prototype.upload = function() {
|
2016-10-02 21:26:57 +00:00
|
|
|
program
|
2017-02-10 12:44:06 +00:00
|
|
|
.command('upload [platform] [environment]')
|
2017-01-08 01:37:48 +00:00
|
|
|
.description('upload your dapp to a decentralized storage. possible options: ipfs, swarm (e.g embark upload swarm)')
|
2017-02-10 12:44:06 +00:00
|
|
|
.action(function(platform, env, options) {
|
2017-01-08 01:37:48 +00:00
|
|
|
// TODO: get env in cmd line as well
|
2017-03-10 15:07:08 +00:00
|
|
|
Embark.initConfig(env || 'development', {
|
2017-02-10 12:44:06 +00:00
|
|
|
embarkConfig: 'embark.json', interceptLogs: false
|
2017-01-08 01:37:48 +00:00
|
|
|
});
|
2017-03-10 15:07:08 +00:00
|
|
|
Embark.upload(platform);
|
2017-01-07 21:52:29 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2016-08-18 00:29:41 +00:00
|
|
|
Cmd.prototype.otherCommands = function() {
|
|
|
|
program
|
|
|
|
.action(function(env){
|
|
|
|
console.log('unknown command "%s"'.red, env);
|
2017-02-18 19:22:45 +00:00
|
|
|
console.log("type embark --help to see the available commands");
|
2017-02-26 01:45:40 +00:00
|
|
|
process.exit(0);
|
2016-08-18 00:29:41 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = Cmd;
|