-
Notifications
You must be signed in to change notification settings - Fork 3
/
bin.js
executable file
·57 lines (52 loc) · 1.38 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
#!/usr/bin/env node
'use strict'
const crypto = require('crypto')
const path = require('path')
const fs = require('fs')
const Server = require('.')
const log = require('pino')({name: 'apkmirror2fdroid'})
/* eslint-disable no-console */
process.on('unhandledRejection', (err) => {
console.log(err)
process.exit(1)
})
require('yargs') // eslint-disable-line
.command({
command: 'genconf',
description: 'Generate a config file',
builder: yargs => yargs,
handler (argv) {
const config = {
redis: 'redis://127.0.0.1:6379',
mongodb: 'mongodb://localhost/apk2fdroid',
adminPW: crypto.randomBytes(8).toString('hex'),
secret: crypto.randomBytes(32).toString('hex'),
fdroidRepoPath: path.join(process.cwd(), 'repo'),
port: 5334,
host: 'localhost',
updateCheckInterval: 6 * 3600 * 1000
}
console.log(JSON.stringify(config, 0, 2))
}
})
.command({
command: 'launch <config>',
description: 'Launch the service',
builder: {
config: {
type: 'string',
required: true,
desc: 'Path to config file'
}
},
handler (argv) {
const conf = JSON.parse(fs.readFileSync(argv.config))
const server = Server(conf)
server.start().then((url) => {
log.info({url}, 'Running on %s!', url)
})
}
})
.demandCommand(1)
.help()
.argv