@hp4k1h5/terminordle
Version:
> multiplayer [wordle](https://www.powerlanguage.co.uk/wordle/) clone in your terminal
69 lines (68 loc) • 2.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.wss = void 0;
const path = require("path");
const commander_1 = require("commander");
const chalk = require("chalk");
const ws_1 = require("../ws");
const cli_1 = require("../cli");
const util_1 = require("../util");
const package_json_1 = require("../../package.json");
const program = new commander_1.Command();
program.version(package_json_1.version);
program
.command('play')
.description(`${b `play`} terminordle locally`)
.action(async () => {
setTimeout(async () => {
await (0, cli_1.repl)();
}, 0);
});
program
.command('join')
.description(`${b `join`} ${y `[url]`} -s ${y `<session_id>`} or leave blank to create new. Ex:
terminordle join
terminordle join terminordle.fun -s session-name
terminordle join wss://secserver.notld:8080 -s random-words
`)
.addArgument(new commander_1.Argument('[url]', 'location of the terminordle server').default('wss://terminordle.fun'))
.option('-s, --session <session_id>', 'join session with id')
.action(async (url, options) => {
const cnx = await (0, ws_1.requestSession)(url, options.session);
await (0, cli_1.repl)(cnx);
});
program
.command('serve')
.description(`${b `serve`} terminordle on ${y `[port]`} Ex:
terminordle serve
terminordle serve -h localhost 8080
`)
.addArgument(new commander_1.Argument('[port]', 'port to listen on').default(8080))
.option('-h, --host <host>', 'specify hostname', 'localhost')
.option('-l, --logfile [filepath]', 'specify logfile path', '/tmp/terminordle-log.jsonl')
.action((port, options) => {
let log;
if (options.logfile) {
log = new util_1.Log(options.logfile, true);
}
exports.wss = (0, ws_1.createWSS)(port, options.host, log);
setTimeout(() => {
console.log('serving...', exports.wss.address());
console.log('see log @', options.logfile);
log && log.log({ 'serving...': exports.wss.address() });
}, 1000);
});
program
.command('whereami')
.description('get full path of this app')
.action(() => {
console.log(path.dirname(path.join(__dirname, '../../')));
});
program.parse(process.argv);
//colors
function b(txt) {
return chalk.blueBright(txt);
}
function y(txt) {
return chalk.yellowBright(txt);
}