Skip to content

Commit

Permalink
feat(Controller): load from multiple locations
Browse files Browse the repository at this point in the history
  • Loading branch information
RWOverdijk committed Sep 22, 2018
1 parent 9f9ad5f commit 069edd5
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Library/Controller/ControllerManager.ts
Expand Up @@ -11,8 +11,8 @@ export class ControllerManager extends AbstractPluginManager {
constructor(creationContext: ServiceManager, config: ControllerManagerConfigType) {
super(creationContext, config.controllers);

if (config.location) {
this.loadControllers(config.location);
if (config.locations) {
this.loadFromLocations(config.locations);
}
}

Expand All @@ -24,7 +24,13 @@ export class ControllerManager extends AbstractPluginManager {
return controller.name;
}

public loadControllers(controllerDirectory: string) {
public loadFromLocations(controllerDirectories: string[]): this {
controllerDirectories.forEach(directory => this.loadDirectory(directory));

return this;
}

public loadDirectory(controllerDirectory: string) {
const controllers: Array<typeof AbstractActionController> = fs.readdirSync(controllerDirectory)
.filter((fileName: string) => !!fileName.match(/^(?!(index)).+\.js$/))
.map((fileName: string) => fileName.replace(/\.js$/, ''))
Expand Down Expand Up @@ -60,7 +66,9 @@ export class ControllerManager extends AbstractPluginManager {
}

protected registerController(Controller: typeof AbstractActionController): this {
this.registerFactory(Controller.name, ControllerFactoryFactory(Controller));
this.registerFactory(Controller, ControllerFactoryFactory(Controller));

this.registerAlias(Controller.name, Controller);

return this;
}
Expand Down

0 comments on commit 069edd5

Please sign in to comment.