From 564abb55c7e14f12580d3ab4b68fe9b77ee16e55 Mon Sep 17 00:00:00 2001 From: garrettmills Date: Fri, 14 Jan 2022 14:44:54 -0600 Subject: [PATCH] add ability to access from cli --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ src/Units.extollo.ts | 10 ++++++++++ src/bootstrap.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ src/cli.ts | 15 +++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 src/Units.extollo.ts create mode 100644 src/bootstrap.ts create mode 100644 src/cli.ts diff --git a/README.md b/README.md index 08b5af8..686c3f9 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,42 @@ pnpm build The intermediate files are generated in the `exbuild/` directory, and the final compiled output is in the `lib/` directory. +Access the Zod schema: + +```txt +node --experimental-repl-await lib/cli.js shell +powered by Extollo, © 2022 Garrett Mills +Access your application using the "app" global. +(extollo) ➤ Home = require('./lib/app/http/controllers/main/Home.controller').Home +[class Home extends Controller] +(extollo) ➤ home = new Home +Home { request: undefined } +(extollo) ➤ home.getValidator().getZod().shape +{ + username: ZodString { + spa: [Function (anonymous)], + superRefine: [Function (anonymous)], + _def: { checks: [Array], typeName: 'ZodString' }, + transform: [Function: bound ], + default: [Function: bound ], + _regex: [Function (anonymous)], + nonempty: [Function (anonymous)] + }, + password: ZodString { + spa: [Function (anonymous)], + superRefine: [Function (anonymous)], + _def: { checks: [Array], typeName: 'ZodString' }, + transform: [Function: bound ], + default: [Function: bound ], + _regex: [Function (anonymous)], + nonempty: [Function (anonymous)] + }, + rememberMe: ZodOptional { + spa: [Function (anonymous)], + superRefine: [Function (anonymous)], + _def: { innerType: [ZodBoolean], typeName: 'ZodOptional' }, + transform: [Function: bound ], + default: [Function: bound ] + } +} +``` diff --git a/src/Units.extollo.ts b/src/Units.extollo.ts new file mode 100644 index 0000000..3c72a1d --- /dev/null +++ b/src/Units.extollo.ts @@ -0,0 +1,10 @@ +import { + Unit, + CommandLine, + ValidationUnit, +} from '@extollo/lib' + +export const Units = [ + ValidationUnit, + CommandLine, +] as (typeof Unit)[] diff --git a/src/bootstrap.ts b/src/bootstrap.ts new file mode 100644 index 0000000..38dd63f --- /dev/null +++ b/src/bootstrap.ts @@ -0,0 +1,43 @@ +import {Application, CommandLineApplication} from '@extollo/lib' +import {Units} from './Units.extollo' + +/* + * Helper functions to bootstrap the Application instance for different uses. + */ + +/** + * Get the base application with no final-target unit. + */ +export function base(): Application { + const app = Application.getApplication() + app.scaffold(__dirname, Units.slice(0, -1)) + return app +} + +/** + * Get the application with the final unit replaced with the CommandLineApplication + * for use on the CLI. + */ +export function cli(): Application { + const app = Application.getApplication() + app.forceStartupMessage = false + + const units = [...Units] + + units.reverse() + CommandLineApplication.setReplacement(units[0]) + units[0] = CommandLineApplication + units.reverse() + + app.scaffold(__dirname, units) + return app +} + +/** + * Get the application as it should be run normally. + */ +export function app(): Application { + const app = Application.getApplication() + app.scaffold(__dirname, Units) + return app +} diff --git a/src/cli.ts b/src/cli.ts new file mode 100644 index 0000000..b9b76ec --- /dev/null +++ b/src/cli.ts @@ -0,0 +1,15 @@ +#!/usr/bin/env -S node --experimental-repl-await +import {globalRegistry} from '@extollo/lib' +import {cli} from './bootstrap' + +globalRegistry.run(async () => { + /* + * The Application + * ----------------------------------------------------- + * The application instance is a global inversion of control container that + * ties your entire application together. The app container manages services + * and lifecycle. + */ + const app = cli() + await app.run() +})