UNPKG

@vulcan-sql/core

Version:
56 lines 2.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.templateEngineModule = void 0; const tslib_1 = require("tslib"); const types_1 = require("../types"); const template_engine_1 = require("../../lib/template-engine/index"); const inversify_1 = require("inversify"); const options_1 = require("../../options"); const templateEngineModule = (options = {}) => new inversify_1.AsyncContainerModule((bind) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { // Options bind(types_1.TYPES.TemplateEngineInputOptions).toConstantValue(options); bind(types_1.TYPES.TemplateEngineOptions) .to(options_1.TemplateEngineOptions) .inSingletonScope(); // TemplateProvider bind(types_1.TYPES.Factory_TemplateProvider).toAutoNamedFactory(types_1.TYPES.Extension_TemplateProvider); if (options.provider) { // Template provider is an optional component, but we can't use templateEngine.compile() if provider wasn't bound. bind(types_1.TYPES.TemplateProvider) .toDynamicValue((context) => { const factory = context.container.get(types_1.TYPES.Factory_TemplateProvider); return factory(options.provider); }) .inSingletonScope(); } // Compiler environment, we need to initialize them manually because they extends some old js libraries. bind(types_1.TYPES.CompilerEnvironment) .toDynamicValue((context) => { return new template_engine_1.RuntimeCompilerEnvironment(context.container.get(types_1.TYPES.CompilerLoader), context.container.getAll(types_1.TYPES.Extension_TemplateEngine), context.container.get(types_1.TYPES.ValidatorLoader)); }) .inSingletonScope() .whenTargetNamed('runtime'); bind(types_1.TYPES.CompilerEnvironment) .toDynamicValue((context) => { return new template_engine_1.BuildTimeCompilerEnvironment(context.container.getAll(types_1.TYPES.Extension_TemplateEngine), context.container.get(types_1.TYPES.ValidatorLoader)); }) .inSingletonScope() .whenTargetNamed('compileTime'); // Loader bind(types_1.TYPES.Factory_CompilerLoader).toAutoNamedFactory(types_1.TYPES.Extension_CompilerLoader); bind(types_1.TYPES.CompilerLoader) .toDynamicValue((context) => { const loaderFactory = context.container.get(types_1.TYPES.Factory_CompilerLoader); const options = context.container.get(types_1.TYPES.TemplateEngineOptions); return loaderFactory(options.codeLoader); }) .inSingletonScope(); // Compiler bind(types_1.TYPES.Compiler).to(template_engine_1.NunjucksCompiler).inSingletonScope(); // Template Engine bind(types_1.TYPES.TemplateEngine) .to(template_engine_1.TemplateEngine) .inSingletonScope(); })); exports.templateEngineModule = templateEngineModule; //# sourceMappingURL=templateEngine.js.map