32 lines
985 B
TypeScript
32 lines
985 B
TypeScript
|
|
import {Directive} from "../Directive"
|
||
|
|
import {CommandLineApplication} from "../service"
|
||
|
|
import {Injectable} from "../../di"
|
||
|
|
import {ErrorWithContext} from "../../util"
|
||
|
|
import {Unit} from "../../lifecycle/Unit";
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 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<void> {
|
||
|
|
if ( !CommandLineApplication.getReplacement() ) {
|
||
|
|
throw new ErrorWithContext(`Cannot run application: no run target specified.`)
|
||
|
|
}
|
||
|
|
|
||
|
|
const unit = <Unit> this.make(CommandLineApplication.getReplacement())
|
||
|
|
await this.app().startUnit(unit)
|
||
|
|
await this.app().stopUnit(unit)
|
||
|
|
}
|
||
|
|
}
|