-
Notifications
You must be signed in to change notification settings - Fork 1
/
bin.js
53 lines (41 loc) · 1.1 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
#!/usr/bin/env node
const yargs = require('yargs')
const SERVICE_NAME = 'websocket-shell'
yargs
.command('$0', 'Run the WebSocket Shell Service', addPort, run)
.command('install', 'Start the WebSocket Shell Service', addPort, install)
.command('uninstall', 'Start the WebSocket Shell Service', addPort, uninstall)
.parse(process.argv.slice(2))
function run () {
require('./service')
}
function install (args) {
const { port } = args
const service = require('os-service')
const programPath = getServiceLocation()
const programArgs = []
if (port) {
programArgs.push('--port', port)
}
service.add(SERVICE_NAME, { programPath, programArgs }, (e) => {
if (e) throw e
})
}
function uninstall () {
const service = require('os-service')
service.remove(SERVICE_NAME, (e) => {
if (e) throw e
})
}
function getServiceLocation () {
const path = require('path')
return path.join(__dirname, 'service.js')
}
function addPort (yargs) {
return yargs
.option('port', {
describe: 'The port to run the WebSocket server on',
default: 8080,
type: 'number'
})
}