This repository has been archived by the owner on Jul 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
cli.js
executable file
·130 lines (113 loc) · 2.96 KB
/
cli.js
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
var url = require('url');
var program = require('commander');
var Client = require('./lib/client');
var find = require('./lib/find');
program
.version('0.0.1')
.option('-H, --host <host>', 'hostname of edison')
.option('-q, --quite', 'supress logging');
function initClient(options, cb) {
if (!options.parent.host) {
console.log('no host')
return cb(new Error('err'));
}
var host = options.parent.host;
var u = url.parse(host);
if (!u.protocol) host = 'ws://' + host;
if (!u.port) host = host + ':58888';
var c = new Client(host);
c.on('message', function (msg) {
if (msg.channel === 'console' && !options.parent.quite) {
process.stdout.write(msg.message);
} else if(msg.channel === 'error') {
process.stderr.write(msg.message);
}
});
c.on('open', function() {
cb(null, c);
});
}
program
.command('deploy [dir]')
.description('deploy node app directory to edison')
.option("-f, --force", "force rebuild on edison")
.option("-o, --onlyDeploy", "do not keep process open waiting for applications output")
.action(function(dir, options){
dir = dir || process.cwd();
initClient(options, function(err, client) {
if (err) {
console.error(err);
process.exit(1);
}
client.sendDirectory(dir, true, function(err) {
if (err) {
console.error(err);
process.exit(1);
}
client.start(function() {
console.log('Application restarted')
if (options.parent.quite || options.onlyDeploy) {
process.exit(0);
}
});
});
});
});
program
.command('start')
.description('start node app on edison')
.action(function(options){
initClient(options, function(err, client) {
if (err) {
console.error(err);
process.exit(1);
}
client.start(function(err) {
if (err) {
console.error(err);
process.exit(1);
}
});
});
});
program
.command('stop')
.description('stop node app on edison')
.action(function(options){
initClient(options, function(err, client) {
if (err) {
console.error(err);
process.exit(1);
}
client.stop(function(err) {
if (err) {
console.error(err);
process.exit(1);
}
console.log('App stoped');
process.exit(0);
});
});
});
program
.command('list [timeout]')
.description('find edisons on your network and list them.')
.action(function(timeout, options){
if (!timeout) {
timeout = 5000;
}
find({timeout: timeout}, function(err, devices) {
if (err) {
console.error(err);
process.exit(1);
}
console.log('Edison Devices Found:', devices.length);
devices.forEach(function(ip, i) {
console.log(i+1 + ' - ' + ip);
});
});
});
program.parse(process.argv);
if (program.args.length === 0) {
return program.help();
}