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
|
#!/usr/bin/env node
import { argv, IEither, Either } from '@emprespresso/pengueno';
import { runServer } from '@emprespresso/uptime';
const main = (_argv = process.argv.slice(2)): Promise<IEither<Error, void>> =>
argv(
['--run-server', '--port', '--host'],
{
'--run-server': { absent: false, unspecified: true, present: () => true },
'--port': { absent: 9000, present: (port) => parseInt(port) },
'--host': { absent: '0.0.0.0', present: (host) => host },
},
_argv,
)
.mapRight((args) => ({
server_mode: args['--run-server'],
port: args['--port'],
host: args['--host'],
}))
.flatMapAsync(async (runConfig) => {
if (!runConfig.server_mode) {
return Either.right(<void>undefined);
}
return runServer(runConfig.port, runConfig.host);
});
if (process.argv[1] === import.meta.filename) {
await main().then((eitherDone) =>
eitherDone.mapLeft((err) => {
console.error('error:', err);
process.exit(1);
}),
);
}
|