diff options
author | Elizabeth Hunt <me@liz.coffee> | 2025-06-20 14:53:38 -0700 |
---|---|---|
committer | Elizabeth Hunt <me@liz.coffee> | 2025-06-20 14:53:38 -0700 |
commit | d4791f3d357634daf506fb8f91cc5332a794c421 (patch) | |
tree | 1bb01d2d4d8fa74d83bb6f99f2c8aa4146ca2d11 /index.ts | |
parent | d7e8d31c94cd713a2f4cf799e20e993acc69e361 (diff) | |
download | ci-d4791f3d357634daf506fb8f91cc5332a794c421.tar.gz ci-d4791f3d357634daf506fb8f91cc5332a794c421.zip |
Move to nodejs
Diffstat (limited to 'index.ts')
-rwxr-xr-x | index.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/index.ts b/index.ts new file mode 100755 index 0000000..a9defca --- /dev/null +++ b/index.ts @@ -0,0 +1,37 @@ +#!/usr/bin/env node + +import { argv, IEither, Either } from '@emprespresso/pengueno'; +import { runServer } from '@emprespresso/ci_server'; + +const main = (_argv = process.argv.slice(2)): Promise<IEither<Error, 0>> => + 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((runConfig) => { + if (runConfig.server_mode) { + return runServer(runConfig.port, runConfig.host); + } + return Promise.resolve(Either.right(0)); + }); + +if (process.argv[1] === import.meta.filename) { + await main().then((eitherDone) => + eitherDone.fold(({ isLeft, value }) => { + if (!isLeft) return; + + console.error(`failed to start`, value); + process.exit(1); + }), + ); +} |