Repository navigation
Expand file tree
/
Copy pathcmd.js
More file actions
210 lines (189 loc) · 6.2 KB
/
Copy pathcmd.js
File metadata and controls
210 lines (189 loc) · 6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
const program = require('commander');
const promptly = require('promptly');
const utils = require('./utils/utils.js');
const Embark = require('../lib/index');
let embark = new Embark;
class Cmd {
constructor() {
program.version(embark.version);
}
process(args) {
this.newApp();
this.demo();
this.build();
this.run();
this.blockchain();
this.simulator();
this.test();
this.reset();
this.upload();
this.versionCmd();
this.otherCommands();
//If no arguments are passed display help by default
if (!process.argv.slice(2).length) {
program.help();
}
program.parse(args);
}
newApp() {
let validateName = function (value) {
try {
if (value.match(/^[a-zA-Z\s-]+$/)) return value;
} catch (e) {
throw new Error('Name must be only letters, spaces, or dashes');
}
};
program
.command('new [name]')
.description('new application')
.action(function (name) {
if (name === undefined) {
return promptly.prompt("Name your app (default is embarkDApp):", {
default: "embarkDApp",
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 dif
C763
ferent assignment of name since it comes from child prompt
embark.generateTemplate('boilerplate', './', inputvalue);
}
});
} else {
embark.generateTemplate('boilerplate', './', name);
}
});
}
demo() {
program
.command('demo')
.description('create a working dapp with a SimpleStorage contract')
.action(function () {
embark.generateTemplate('demo', './', 'embark_demo');
});
}
build() {
program
.command('build [environment]')
.description('deploy and build dapp at dist/ (default: development)')
.action(function (env, _options) {
embark.build({env: env || 'development'});
});
}
run() {
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)')
.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')
.description('run dapp (default: development)')
.action(function (env, options) {
embark.run({
env: env || 'development',
serverPort: options.port,
serverHost: options.host,
runWebserver: !options.noserver,
useDashboard: !options.nodashboard
});
});
}
blockchain() {
program
.command('blockchain [environment]')
.option('-c, --client [client]', 'Use a specific ethereum client or simulator (supported: geth, testrpc')
.description('run blockchain server (default: development)')
.action(function (env, options) {
embark.initConfig(env || 'development', {
embarkConfig: 'embark.json',
interceptLogs: false
});
embark.blockchain(env || 'development', options.client || 'geth');
});
}
simulator() {
program
.command('simulator [environment]')
.description('run a fast ethereum rpc simulator')
.option('--testrpc', 'use testrpc as the rpc simulator [default]')
.option('-p, --port [port]', 'port to run the rpc simulator (default: 8545)')
.option('-h, --host [host]', 'host to run the rpc simulator (default: localhost)')
.option('-a, --accounts [numAccounts]', 'number of accounts (default: 10)')
.option('-e, --defaultBalanceEther [balance]', 'Amount of ether to assign each test account (default: 100)')
.option('-l, --gasLimit [gasLimit]', 'custom gas limit (default: 8000000)')
.action(function (env, options) {
embark.initConfig(env || 'development', {
embarkConfig: 'embark.json',
interceptLogs: false
});
embark.simulator({
port: options.port,
host: options.host,
numAccounts: options.numAccounts,
defaultBalance: options.balance,
gasLimit: options.gasLimit
});
});
}
test() {
program
.command('test [file]')
.description('run tests')
.action(function (file) {
embark.initConfig('development', {
embarkConfig: 'embark.json', interceptLogs: false
});
embark.runTests(file);
});
}
upload() {
program
.command('upload [platform] [environment]')
.description('upload your dapp to a decentralized storage (e.g embark upload ipfs)')
.action(function (platform, env, _options) {
// TODO: get env in cmd line as well
embark.initConfig(env || 'development', {
embarkConfig: 'embark.json', interceptLogs: false
});
embark.upload(platform);
});
}
reset() {
program
.command('reset')
.description('resets embarks state on this dapp including clearing cache')
.action(function () {
embark.initConfig('development', {
embarkConfig: 'embark.json', interceptLogs: false
});
embark.reset();
});
}
versionCmd() {
program
.command('version')
.description('output the version number')
.action(function () {
console.log(embark.version);
process.exit(0);
});
}
otherCommands() {
program
.action(function (cmd) {
console.log('unknown command "%s"'.red, cmd);
let dictionary = ['new', 'demo', 'build', 'run', 'blockchain', 'simulator', 'test', 'upload', 'version'];
let suggestion = utils.proposeAlternative(cmd, dictionary);
if (suggestion) {
console.log('did you mean "%s"?'.green, suggestion);
}
console.log("type embark --help to see the available commands");
process.exit(0);
});
}
}
module.exports = Cmd;