#!/usr/bin/env node import * as path from 'path'; import readline from 'readline'; import yargs from 'yargs'; import { loadEnvironment } from '@squeebot/core/lib/core'; import { Squeebot } from './core'; import { SqueebotCLI } from './cli'; const rl = readline.createInterface({ input: process.stdin, output: process.stdout, }); async function start(argv: any): Promise { if (!argv.environment) { throw new Error('Environment file is missing.'); } let root; if (argv.root) { root = path.resolve(argv.root); } const env = await loadEnvironment(argv.environment, root); // Change working directory to the environment process.chdir(env.path as string); // Create and initialize the Squeebot instance const sb = new Squeebot(env); await sb.initialize(argv.e !== true); // Create a CLI if interactive mode is enabled if (argv.i === true) { const sbrl = new SqueebotCLI(sb); sbrl.attach(rl); } sb.attachReadline(rl); } yargs.scriptName('squeebotd') .command('$0 [environment]', 'start Squeebot daemon', (y) => { y.positional('environment', { demandOption: 'The environment file is mandatory.', describe: 'The environment file to use, in json format', }) .option('r', { alias: 'root', describe: 'Change the root directory of execution to differ from the one in your environment file', nargs: 1, type: 'string', }) .option('e', { alias: 'no-enable', describe: 'Do not automatically execute enabled plugins on startup', type: 'boolean', }) .option('i', { alias: 'interactive', describe: 'Enable built-in command line interface', type: 'boolean', }); }); start(yargs.argv).catch((e) => console.error(e.stack));