@athenna/core
Version:
One foundation for multiple applications.
52 lines (51 loc) • 1.77 kB
JavaScript
/**
* @athenna/core
*
* (c) João Lenon <lenon@athenna.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import figlet from 'figlet';
import chalkRainbow from 'chalk-rainbow';
import { debug } from '#src/debug';
import { Log } from '@athenna/logger';
import { Ls } from '#src/repl/commands/Ls';
import { Color, Is } from '@athenna/common';
import { Logger } from '#src/repl/ui/Logger';
import { Clean } from '#src/repl/commands/Clean';
export class Repl {
/**
* Boot the Repl application and session.
*/
static async boot() {
const repl = ioc.safeUse('Athenna/Core/Repl');
debug('booting repl application');
await repl.start();
repl.removeDomainErrorHandler().clean();
Logger.write(chalkRainbow(figlet.textSync('REPL\n')));
Logger.gray('To import your modules use dynamic imports:\n');
Logger.gray("const { User } = await import('#src/models/User')\n");
Logger.write(`${Color.yellow.bold('To see all commands available type:')} .help\n`);
repl
.setPrompt(Color.purple.bold('Athenna ') + Color.green.bold('❯ '))
.displayPrompt(false)
.shutdownProviders()
.commandImpl(Ls)
.commandImpl(Clean);
return repl;
}
/**
* REPL error handler for errors that
* happens inside the session.
*/
static handleError(error) {
if (!Is.Exception(error)) {
error = error.toAthennaException();
}
error.prettify().then(prettified => {
Log.channelOrVanilla('exception').fatal(prettified);
ioc.use('Athenna/Core/Repl').displayPrompt();
});
}
}