-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
executable file
·60 lines (53 loc) · 1.49 KB
/
index.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
#!/bin/sh
":" //# comment; exec /usr/bin/env node "$0" "$@"
import ssbClient from 'ssb-client'
import yargs from 'yargs'
import fs from 'fs'
import bot from './src/bot.js'
import feedMonitor from './src/feedMonitor.js'
function main(argv) {
const { host, port, path, template, urls } = argv
const config = { feedUrls: urls, feedMonitor }
if (template) {
config.postTemplate = fs.readFileSync(template, {encoding: 'utf-8'})
}
const handler = bot(config)
ssbClient(
{ host, port, path },
handler
)
}
function mainBuilder(yargs) {
yargs.positional('urls', {
describe: 'List of feed URLs separated by spaces',
type: 'string'
})
}
yargs
.command('$0 <urls..>', 'Run the bot.', mainBuilder, main)
.help()
.option('host', {
alias: 'h',
default: 'localhost',
type: 'string',
description: 'ssb-server host'
})
.option('port', {
alias: 'p',
default: 8008,
type: 'number',
description: 'ssb-server port'
})
.option('path', {
alias: 'd',
default: undefined,
type: 'string',
description: 'ssb-server .ssb path'
})
.option('template', {
alias: 't',
default: undefined,
type: 'string',
description: 'Markdown file path to be used as template. {image}, {title}, {description} and {link} tokens are available.'
})
.argv