-
Notifications
You must be signed in to change notification settings - Fork 40
/
bin.js
61 lines (51 loc) · 1.5 KB
/
bin.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
#!/usr/bin/env node
var os = require('os')
var path = require('path')
var updateNotifier = require('update-notifier')
var sudoBlock = require('sudo-block')
var startup = require('user-startup')
var chalk = require('chalk')
var got = require('got')
var address = require('network-address')
var pkg = require('./package.json')
sudoBlock('Should not be run as root, please retry without sudo.')
updateNotifier({pkg: pkg}).notify()
function stop () {
startup.remove('stop-server')
got.delete('localhost:' + 5709)
}
function start () {
var log = path.join(os.tmpdir(), 'stop-server')
startup.create('stop-server', process.execPath, [__dirname], log)
if (os.platform() !== 'win32') {
console.log(
[
'',
'---',
'To complete installation, you need to allow \'shutdown\' to be run without sudo.',
'Please run ' + chalk.cyan('sudo visudo') + ' and add ' + chalk.cyan('your-username ALL=NOPASSWD: /sbin/shutdown'),
'---'
].join('\n')
)
}
console.log(
[
'',
'To access stop-server from your phone, scan the QR code here',
chalk.cyan('http://localhost:5709/qr.html'),
'',
'Or go directly to',
chalk.cyan('http://' + address() + ':5709'),
''
].join('\n')
)
}
var yargs = require('yargs')
.version(pkg.version)
.alias('v', 'version')
.usage('Usage: $0 start|stop')
.demand(1)
var argv = yargs.argv
if (argv._[0] === 'start') return start()
if (argv._[0] === 'stop') return stop()
console.log(yargs.showHelp)