2017-10-14 10:06:09 +00:00
|
|
|
const program = require('commander');
|
|
|
|
const promptly = require('promptly');
|
2017-12-19 19:07:48 +00:00
|
|
|
const utils = require('./utils/utils.js');
|
2017-03-30 13:16:46 +00:00
|
|
|
const Embark = require('../lib/index');
|
2018-05-08 21:49:46 +00:00
|
|
|
const i18n = require('i18n');
|
2017-03-30 13:16:46 +00:00
|
|
|
let embark = new Embark;
|
2016-08-18 00:29:41 +00:00
|
|
|
|
2018-05-08 21:49:46 +00:00
|
|
|
i18n.configure({
|
|
|
|
locales: ['en', 'pt'],
|
|
|
|
register: global,
|
|
|
|
//updateFiles: false,
|
|
|
|
directory: utils.joinPath(__dirname, '/../locales')
|
|
|
|
});
|
|
|
|
|
|
|
|
i18n.setLocale('pt');
|
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
class Cmd {
|
|
|
|
constructor() {
|
2017-03-30 13:16:46 +00:00
|
|
|
program.version(embark.version);
|
2017-02-17 19:34:07 +00:00
|
|
|
}
|
2016-08-18 00:29:41 +00:00
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
process(args) {
|
|
|
|
this.newApp();
|
|
|
|
this.demo();
|
|
|
|
this.build();
|
|
|
|
this.run();
|
|
|
|
this.blockchain();
|
|
|
|
this.simulator();
|
|
|
|
this.test();
|
2018-01-11 14:22:58 +00:00
|
|
|
this.reset();
|
2018-03-22 14:43:29 +00:00
|
|
|
this.graph();
|
2017-03-30 11:12:39 +00:00
|
|
|
this.upload();
|
2017-12-19 15:20:05 +00:00
|
|
|
this.versionCmd();
|
2017-03-30 11:12:39 +00:00
|
|
|
this.otherCommands();
|
|
|
|
|
|
|
|
//If no arguments are passed display help by default
|
|
|
|
if (!process.argv.slice(2).length) {
|
|
|
|
program.help();
|
2016-08-21 14:42:42 +00:00
|
|
|
}
|
2017-03-30 11:12:39 +00:00
|
|
|
|
|
|
|
program.parse(args);
|
|
|
|
}
|
|
|
|
|
2017-10-14 10:06:09 +00:00
|
|
|
newApp() {
|
2017-03-30 11:12:39 +00:00
|
|
|
|
|
|
|
let validateName = function (value) {
|
|
|
|
try {
|
2017-10-14 10:06:09 +00:00
|
|
|
if (value.match(/^[a-zA-Z\s-]+$/)) return value;
|
2017-03-30 11:12:39 +00:00
|
|
|
} catch (e) {
|
2018-05-08 21:49:46 +00:00
|
|
|
throw new Error(__('Name must be only letters, spaces, or dashes'));
|
2017-03-22 05:13:58 +00:00
|
|
|
}
|
2017-03-30 11:12:39 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
program
|
|
|
|
.command('new [name]')
|
2018-05-08 21:49:46 +00:00
|
|
|
.description(__('New Application'))
|
|
|
|
.option('--simple', __('create a barebones project meant only for contract development'))
|
2018-03-29 23:42:47 +00:00
|
|
|
.action(function (name, options) {
|
2017-03-30 11:12:39 +00:00
|
|
|
if (name === undefined) {
|
2018-05-08 21:49:46 +00:00
|
|
|
return promptly.prompt(__("Name your app (default is %s):", 'embarkDapp'), {
|
2017-06-27 19:45:30 +00:00
|
|
|
default: "embarkDApp",
|
2017-03-30 11:12:39 +00:00
|
|
|
validator: validateName
|
|
|
|
}, function (err, inputvalue) {
|
|
|
|
if (err) {
|
2018-05-08 21:49:46 +00:00
|
|
|
console.error(__('Invalid name') + ':', err.message);
|
2017-03-30 11:12:39 +00:00
|
|
|
// 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
|
2018-03-29 23:42:47 +00:00
|
|
|
if (options.simple) {
|
|
|
|
embark.generateTemplate('simple', './', inputvalue);
|
|
|
|
} else {
|
|
|
|
embark.generateTemplate('boilerplate', './', inputvalue);
|
|
|
|
}
|
2017-03-30 11:12:39 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2018-03-29 23:42:47 +00:00
|
|
|
if (options.simple) {
|
|
|
|
embark.generateTemplate('simple', './', name);
|
|
|
|
} else {
|
|
|
|
embark.generateTemplate('boilerplate', './', name);
|
|
|
|
}
|
2017-03-30 11:12:39 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
demo() {
|
|
|
|
program
|
|
|
|
.command('demo')
|
2018-05-08 21:49:46 +00:00
|
|
|
.description(__('create a working dapp with a SimpleStorage contract'))
|
2017-03-30 11:12:39 +00:00
|
|
|
.action(function () {
|
2017-03-30 13:16:46 +00:00
|
|
|
embark.generateTemplate('demo', './', 'embark_demo');
|
2017-03-30 11:12:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
build() {
|
|
|
|
program
|
|
|
|
.command('build [environment]')
|
2018-05-08 21:49:46 +00:00
|
|
|
.option('--logfile [logfile]', __('filename to output logs (default: none)'))
|
|
|
|
.option('--loglevel [loglevel]', __('level of logging to display') + ' ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug')
|
|
|
|
.description(__('deploy and build dapp at ') + 'dist/ (default: development)')
|
2017-10-14 10:06:09 +00:00
|
|
|
.action(function (env, _options) {
|
2018-04-19 04:25:43 +00:00
|
|
|
_options.env = env || 'development';
|
|
|
|
_options.logFile = _options.logfile; // fix casing
|
|
|
|
_options.logLevel = _options.loglevel; // fix casing
|
|
|
|
embark.build(_options);
|
2017-03-30 11:12:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
run() {
|
|
|
|
program
|
|
|
|
.command('run [environment]')
|
2018-05-08 21:49:46 +00:00
|
|
|
.option('-p, --port [port]', __('port to run the dev webserver (default: %s)', '8000'))
|
|
|
|
.option('-b, --host [host]', __('host to run the dev webserver (default: %s)', 'localhost'))
|
|
|
|
.option('--noserver', __('disable the development webserver'))
|
|
|
|
.option('--nodashboard', __('simple mode, disables the dashboard'))
|
|
|
|
.option('--no-color', __('no colors in case it\'s needed for compatbility purposes'))
|
|
|
|
.option('--logfile [logfile]', __('filename to output logs (default: %s)', 'none'))
|
|
|
|
.option('--loglevel [loglevel]', __('level of logging to display') + ' ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug')
|
|
|
|
.description(__('run dapp (default: %s)', 'development'))
|
2017-03-30 11:12:39 +00:00
|
|
|
.action(function (env, options) {
|
2017-03-30 13:16:46 +00:00
|
|
|
embark.run({
|
2017-03-30 11:12:39 +00:00
|
|
|
env: env || 'development',
|
|
|
|
serverPort: options.port,
|
|
|
|
serverHost: options.host,
|
|
|
|
runWebserver: !options.noserver,
|
2018-03-10 18:45:56 +00:00
|
|
|
useDashboard: !options.nodashboard,
|
2018-04-19 04:25:43 +00:00
|
|
|
logFile: options.logfile,
|
|
|
|
logLevel: options.loglevel
|
2017-03-30 11:12:39 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
blockchain() {
|
|
|
|
program
|
|
|
|
.command('blockchain [environment]')
|
2018-05-08 21:49:46 +00:00
|
|
|
.option('-c, --client [client]', __('Use a specific ethereum client or simulator (supported: %s)', 'geth, testrpc'))
|
|
|
|
.description(__('run blockchain server (default: %s)', 'development'))
|
2017-03-30 11:12:39 +00:00
|
|
|
.action(function (env, options) {
|
2017-03-30 13:16:46 +00:00
|
|
|
embark.initConfig(env || 'development', {
|
2017-03-30 11:12:39 +00:00
|
|
|
embarkConfig: 'embark.json',
|
|
|
|
interceptLogs: false
|
|
|
|
});
|
2017-03-30 13:16:46 +00:00
|
|
|
embark.blockchain(env || 'development', options.client || 'geth');
|
2017-03-30 11:12:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
simulator() {
|
|
|
|
program
|
|
|
|
.command('simulator [environment]')
|
2018-05-08 21:49:46 +00:00
|
|
|
.description(__('run a fast ethereum rpc simulator'))
|
|
|
|
.option('--testrpc', __('use testrpc as the rpc simulator [%s]', 'default'))
|
|
|
|
.option('-p, --port [port]', __('port to run the rpc simulator (default: %s)', '8545'))
|
|
|
|
.option('-h, --host [host]', __('host to run the rpc simulator (default: %s)', 'localhost'))
|
|
|
|
.option('-a, --accounts [numAccounts]', __('number of accounts (default: %s)', '10'))
|
|
|
|
.option('-e, --defaultBalanceEther [balance]', __('Amount of ether to assign each test account (default: %s)', '100'))
|
|
|
|
.option('-l, --gasLimit [gasLimit]', __('custom gas limit (default: %s)', '8000000'))
|
2017-12-27 22:48:33 +00:00
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
.action(function (env, options) {
|
2017-03-30 13:16:46 +00:00
|
|
|
embark.initConfig(env || 'development', {
|
2017-03-30 11:12:39 +00:00
|
|
|
embarkConfig: 'embark.json',
|
|
|
|
interceptLogs: false
|
|
|
|
});
|
2017-12-27 22:48:33 +00:00
|
|
|
embark.simulator({
|
|
|
|
port: options.port,
|
|
|
|
host: options.host,
|
|
|
|
numAccounts: options.numAccounts,
|
|
|
|
defaultBalance: options.balance,
|
|
|
|
gasLimit: options.gasLimit
|
|
|
|
});
|
2017-03-30 11:12:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
test() {
|
|
|
|
program
|
2017-07-02 15:32:16 +00:00
|
|
|
.command('test [file]')
|
2018-05-08 21:49:46 +00:00
|
|
|
.description(__('run tests'))
|
2017-07-02 15:32:16 +00:00
|
|
|
.action(function (file) {
|
2017-07-02 03:11:42 +00:00
|
|
|
embark.initConfig('development', {
|
|
|
|
embarkConfig: 'embark.json', interceptLogs: false
|
|
|
|
});
|
2017-07-02 15:32:16 +00:00
|
|
|
embark.runTests(file);
|
2017-03-30 11:12:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
upload() {
|
|
|
|
program
|
2018-04-19 04:25:43 +00:00
|
|
|
.command('upload <platform> [environment]')
|
2018-05-08 21:49:46 +00:00
|
|
|
.option('--logfile [logfile]', __('filename to output logs (default: %s)', 'none'))
|
|
|
|
.option('--loglevel [loglevel]', __('level of logging to display') + ' ["error", "warn", "info", "debug", "trace"]', /^(error|warn|info|debug|trace)$/i, 'debug')
|
|
|
|
.description(__('Upload your dapp to a decentralized storage') + ' (e.g embark upload ipfs).')
|
2017-10-14 10:06:09 +00:00
|
|
|
.action(function (platform, env, _options) {
|
2018-04-24 00:27:11 +00:00
|
|
|
_options.env = env || 'development';
|
2018-04-19 04:25:43 +00:00
|
|
|
_options.logFile = _options.logfile; // fix casing
|
|
|
|
_options.logLevel = _options.loglevel; // fix casing
|
2018-04-12 10:46:04 +00:00
|
|
|
embark.upload(platform, _options);
|
2017-03-30 11:12:39 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-22 14:43:29 +00:00
|
|
|
graph() {
|
|
|
|
program
|
|
|
|
.command('graph [environment]')
|
2018-05-08 21:49:46 +00:00
|
|
|
.option('--skip-undeployed', __('Graph will not include undeployed contracts'))
|
|
|
|
.option('--skip-functions', __('Graph will not include functions'))
|
|
|
|
.option('--skip-events', __('Graph will not include events'))
|
|
|
|
.description(__('generates documentation based on the smart contracts configured'))
|
2018-03-22 14:43:29 +00:00
|
|
|
.action(function (env, options) {
|
2018-03-22 19:09:01 +00:00
|
|
|
embark.graph({
|
|
|
|
env: env || 'development',
|
2018-05-04 20:17:12 +00:00
|
|
|
logFile: options.logfile,
|
|
|
|
skipUndeployed: options.skipUndeployed,
|
|
|
|
skipFunctions: options.skipFunctions,
|
|
|
|
skipEvents: options.skipEvents
|
2018-03-22 14:43:29 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-01-11 14:22:58 +00:00
|
|
|
reset() {
|
|
|
|
program
|
|
|
|
.command('reset')
|
2018-05-08 21:49:46 +00:00
|
|
|
.description(__('resets embarks state on this dapp including clearing cache'))
|
2018-01-12 19:21:36 +00:00
|
|
|
.action(function () {
|
2018-01-11 14:22:58 +00:00
|
|
|
embark.initConfig('development', {
|
|
|
|
embarkConfig: 'embark.json', interceptLogs: false
|
|
|
|
});
|
|
|
|
embark.reset();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-19 15:20:05 +00:00
|
|
|
versionCmd() {
|
|
|
|
program
|
|
|
|
.command('version')
|
2018-05-08 21:49:46 +00:00
|
|
|
.description(__('output the version number'))
|
2017-12-19 15:20:05 +00:00
|
|
|
.action(function () {
|
|
|
|
console.log(embark.version);
|
|
|
|
process.exit(0);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
otherCommands() {
|
|
|
|
program
|
2017-12-19 18:29:48 +00:00
|
|
|
.action(function (cmd) {
|
2018-05-08 21:49:46 +00:00
|
|
|
console.log((__('unknown command') + ' "%s"').red, cmd);
|
2017-12-19 20:48:56 +00:00
|
|
|
let dictionary = ['new', 'demo', 'build', 'run', 'blockchain', 'simulator', 'test', 'upload', 'version'];
|
2017-12-19 19:07:48 +00:00
|
|
|
let suggestion = utils.proposeAlternative(cmd, dictionary);
|
2017-12-19 18:29:48 +00:00
|
|
|
if (suggestion) {
|
2018-05-08 21:49:46 +00:00
|
|
|
console.log((__('did you mean') + ' "%s"?').green, suggestion);
|
2017-12-19 18:29:48 +00:00
|
|
|
}
|
2017-03-30 11:12:39 +00:00
|
|
|
console.log("type embark --help to see the available commands");
|
|
|
|
process.exit(0);
|
|
|
|
});
|
|
|
|
}
|
2018-03-22 14:43:29 +00:00
|
|
|
|
2017-03-22 05:13:58 +00:00
|
|
|
|
2017-03-30 11:12:39 +00:00
|
|
|
}
|
2016-08-18 00:29:41 +00:00
|
|
|
|
|
|
|
module.exports = Cmd;
|