europa-build
Version:
Tool for generating and maintaining Europa plugins and presets
96 lines • 3.83 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.CommonTemplateProvider = void 0;
const MustacheTemplateGenerator_1 = require("../MustacheTemplateGenerator");
const _parentLogger = Symbol();
/**
* An abstract {@link TemplateProvider} that provides common logic that is useful for the majority of implementations.
*/
class CommonTemplateProvider {
/**
* Creates an instance of {@link CommonTemplateProvider} using the `options` provided.
*
* @param options - The options to be used.
*/
constructor(options) {
this[_parentLogger] = options.parentLogger;
}
createCliOptions() {
const commonCliOptions = this.createCommonCliOptions();
return this.extendCommonCliOptions(commonCliOptions);
}
async createContext(options) {
const commonContext = await this.createCommonContext(options);
return this.extendCommonContext(commonContext, options);
}
createGenerator() {
return new MustacheTemplateGenerator_1.MustacheTemplateGenerator({
parentLogger: this[_parentLogger],
provider: this,
});
}
/**
* Extends the specified common command-line options with provider-specific command-line options.
*
* By default, this method returns a copy of `commonCliOptions`.
*
* @param commonCliOptions - The common command-line options to be extended.
* @return The extended command-line options.
*/
extendCommonCliOptions(commonCliOptions) {
return commonCliOptions.slice();
}
/**
* Extends the specified common context with a provider-specific context.
*
* By default, this method returns a copy of `commonContext`.
*
* @param commonContext - The common context to be extended.
* @param options - The options to be used.
* @return The extended context.
*/
extendCommonContext(commonContext, options) {
return Object.assign({}, commonContext);
}
getDirectories() {
return ['.common', this.getName()];
}
/**
* Returns the value of the named option.
*
* @param options - The options to be used.
* @param name - The name of the option whose value is to be returned.
* @return The value of the named option.
* @throws If the named option does not exist.
*/
getRequiredContextOption(options, name) {
const value = options[name];
if (typeof value === 'undefined') {
throw new Error(`Missing required option: ${String(name)}`);
}
return value;
}
}
exports.CommonTemplateProvider = CommonTemplateProvider;
//# sourceMappingURL=CommonTemplateProvider.js.map