europa-build
Version:
Tool for generating and maintaining Europa plugins and presets
80 lines • 3.91 kB
JavaScript
;
/*
* Copyright (C) 2022 neocotic
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.TemplateManager = void 0;
const Logger_1 = require("../logger/Logger");
const ContribPluginTemplateProvider_1 = require("./provider/plugin/ContribPluginTemplateProvider");
const OfficialPluginTemplateProvider_1 = require("./provider/plugin/OfficialPluginTemplateProvider");
const ContribPresetTemplateProvider_1 = require("./provider/preset/ContribPresetTemplateProvider");
const OfficialPresetTemplateProvider_1 = require("./provider/preset/OfficialPresetTemplateProvider");
const _logger = Symbol();
const _providers = Symbol();
/**
* A basic manager for template providers that are mapped to their general names and types.
*/
class TemplateManager {
/**
* Creates an instance of {@link TemplateManager} using the `options` provided.
*
* @param [options] - The options to be used.
*/
constructor(options = {}) {
var _a;
const parentLogger = (_a = options.parentLogger) !== null && _a !== void 0 ? _a : (0, Logger_1.createLogger)({ outputStream: options.outputStream });
this[_logger] = parentLogger.child({ name: 'TemplateManager' });
this[_providers] = [
new ContribPluginTemplateProvider_1.ContribPluginTemplateProvider({ parentLogger }),
new ContribPresetTemplateProvider_1.ContribPresetTemplateProvider({ parentLogger }),
new OfficialPluginTemplateProvider_1.OfficialPluginTemplateProvider({ parentLogger }),
new OfficialPresetTemplateProvider_1.OfficialPresetTemplateProvider({ parentLogger }),
];
}
/**
* Returns the template provider with the specified `name` and `type`.
*
* @param name - The name of the template provider to be returned.
* @param type - The {@link TemplateProviderType} of the template provider to be returned.
* @return The template provider matching `name` and `type`.
* @throws If no template provider could be found with `name` and `type`.
*/
getProvider(name, type) {
const provider = this[_providers].find((provider) => {
return provider.getName() === name && provider.getType() === type;
});
if (!provider) {
throw new Error(`Failed to find ${type} TemplateProvider: ${name}`);
}
return provider;
}
/**
* Returns all template providers with the specified `type`.
*
* @param type - The {@link TemplateProviderType} of the template providers to be returned.
* @return The template providers matching `type`.
*/
getProvidersForType(type) {
return this[_providers].filter((provider) => provider.getType() === type);
}
}
exports.TemplateManager = TemplateManager;
//# sourceMappingURL=TemplateManager.js.map