#!/usr/bin/env node import * as fs from 'fs-extra'; import * as path from 'path'; import readline from 'readline'; import yargs from 'yargs'; import { loadEnvironment } from '@squeebot/core/lib/core'; import { IEnvironment } from '@squeebot/core/lib/types'; import { Squeebot } from './core'; 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 enviroFile = path.resolve(process.cwd(), argv.environment); const env: IEnvironment = await loadEnvironment(argv.environment, root); const sb = new Squeebot(env); sb.stream.on('logger', 'debug', (data: string) => console.log('DEBUG', data)); await sb.initialize(); 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', }); }); start(yargs.argv).catch((e) => console.error(e.stack));