import {Directive} from "../Directive" import {Injectable} from "@extollo/di" import {Unit} from "@extollo/lib" import {ErrorWithContext} from "@extollo/util" import {CommandLineApplication} from "../service" /** * A directive that starts the framework's final target normally. * In most cases, this runs the HTTP server, which would have been replaced * by the CommandLineApplication unit. */ @Injectable() export class RunDirective extends Directive { getDescription(): string { return 'run the application normally' } getKeywords(): string | string[] { return ['run', 'up'] } async handle(): Promise { if ( !CommandLineApplication.getReplacement() ) { throw new ErrorWithContext(`Cannot run application: no run target specified.`) } const unit = this.make(CommandLineApplication.getReplacement()) await this.app().startUnit(unit) await this.app().stopUnit(unit) } }