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
|
#!/usr/bin/env -S deno run --allow-env --allow-net
import { argv, IEither, Either } from "@emprespresso/pengueno";
import { runServer } from "@emprespresso/ci_server";
const _defaults = {
"--port": "9000",
"--host": "0.0.0.0",
};
const main = (
_argv = Deno.args,
defaults = _defaults,
): Promise<IEither<Error, void>> =>
argv(["--run-server", "--port", "--host"], defaults, _argv)
.mapRight((args) => ({
server_mode: "--run-server" in args,
port: parseInt(args["--port"]),
host: args["--host"],
}))
.flatMapAsync((runConfig) => {
if (runConfig.server_mode) {
return runServer(runConfig.port, runConfig.host);
}
return Promise.resolve(Either.right(undefined));
});
if (import.meta.main) {
await main().then((eitherDone) =>
eitherDone.fold(({ isLeft, value }) => {
if (!isLeft) return;
console.error(value);
Deno.exit(1);
}),
);
}
|