-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaugury.js
executable file
·43 lines (38 loc) · 1.54 KB
/
augury.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
#!/usr/bin/env node
import { cwd } from "node:process";
import { isAbsolute, join, dirname } from "node:path";
import { readFile } from "node:fs/promises";
import { program } from 'commander';
import InterplanetaryNostrum from "./nostr.js";
import makeRel from './lib/rel.js';
const rel = makeRel(import.meta.url);
const { version } = JSON.parse(await readFile(rel('./package.json')));
program
.name('augury')
.description('An experimental Nostr server that integrates with IPFS')
.version(version)
.option('-p, --port <number>', 'the port on which the WSS server runs', 6455)
.option('-c, --config <path>', 'a configuration file')
.option('-s, --store', 'path to the directory in which the data is saved')
.option('-l, --log-level', 'logging level (verbose|log|warn|error)', 'log')
.action(async (options) => {
let cfg = {};
let cfgFile;
if (options.config) {
cfgFile = absolutise(options.config);
cfg = JSON.parse(await readFile(cfgFile));
}
// CLI overrides config
if (options.port) cfg.port = options.port;
if (options.logLevel) cfg.logLevel = options.logLevel;
if (options.store) cfg.store = absolutise(options.store);
else if (cfgFile && cfg.store) cfg.store = absolutise(cfg.store, dirname(cfgFile));
if (!cfg.store) throw new Error(`A store path must be given either in the configuration or as argument.`);
const n = new InterplanetaryNostrum(cfg);
await n.run();
})
;
program.parse();
function absolutise (pth, relTo = cwd()) {
return isAbsolute(pth) ? pth : join(relTo, pth);
}