@tsed/cli-core
Version:
Build your CLI with TypeScript and Decorators
24 lines (23 loc) • 837 B
JavaScript
import { injectable, injector } from "@tsed/di";
export class CliHooks {
async emit(hookName, cmd, ...args) {
const inj = injector();
const providers = inj.getProviders();
let results = [];
for (const provider of providers) {
if (provider.useClass) {
const instance = inj.get(provider.token);
if (provider.store.has(hookName)) {
const props = provider.store.get(hookName)[cmd];
if (props) {
for (const propertyKey of props) {
results = results.concat(await instance[propertyKey](...args));
}
}
}
}
}
return results.filter((o) => o !== undefined);
}
}
injectable(CliHooks);