import * as commands from './commands'; import { logFail } from './utils'; type Commands = typeof commands; type CommandNames = keyof Commands; interface HandleMessageArgs { type: T; args: Parameters[0]; } process.on('message', async ({ type, args }: HandleMessageArgs) => { const command: (a: typeof args) => Promise = commands[type]; if (typeof command === 'function') { try { await command(args); process.exit(0); } catch (err) { logFail(err.message); process.exit(1); } } });