All files / helpers generic-constructor.ts

17.86% Statements 5/28
0% Branches 0/20
0% Functions 0/2
17.86% Lines 5/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 561x 1x   1x 1x   1x                                                                                                  
import { Container } from '../container';
import { ModuleService, BootstrapLogger } from '../services';
 
const moduleService = Container.get(ModuleService);
const bootstrapLogger = Container.get(BootstrapLogger);
 
export function GenericConstruct(module: any, original, currentModule) {
    return function construct(constructor, args) {
 
        if (!module) {
            return new constructor();
        }
 
 
        if (module.imports) {
            moduleService.setImports(module.imports, original);
        }
 
        if (module.services) {
            moduleService.setServices(module.services, original, currentModule);
        }
 
        if (module.controllers) {
            moduleService.setControllers(module.controllers, original, currentModule);
        }
 
        if (module.effects) {
            moduleService.setEffects(module.effects, original, currentModule);
        }
 
        if (module.components) {
            moduleService.setComponents(<any>module.components, original, currentModule);
        }
 
        if (module.beforePlugins) {
            moduleService.setBeforePlugins(module.beforePlugins, original, currentModule);
        }
 
        if (module.plugins) {
            moduleService.setPlugins(module.plugins, original, currentModule);
        }
 
        if (module.afterPlugins) {
            moduleService.setAfterPlugins(module.afterPlugins, original, currentModule);
        }
 
        if (module.bootstrap) {
            moduleService.setBootstraps(module.bootstrap, original, currentModule);
        }
 
        bootstrapLogger.log(`Bootstrap -> @Module('${constructor.originalName}')${bootstrapLogger.logHashes(`(${constructor.name})`)}: finished!`);
 
        return new constructor();
    };
}