UNPKG

@protocolnebula/ts-openapi-generator

Version:

Build API and models from Swagger/OpenAPI to use in any project type

101 lines 3.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.config = void 0; const path_1 = require("path"); const files_util_1 = require("../utils/files.util"); const config_mock_model_1 = require("./config-mock.model"); const template_config_model_1 = require("./template-config.model"); class ConfigModel { constructor() { this._outputBaseFolder = ''; this._outputModelsFolder = 'models'; this._outputApisFolder = 'apis'; } get outputPath() { return this._outputPath; } set outputPath(outputPath) { this._outputPath = (0, path_1.resolve)(outputPath); } get exportPath() { return (0, path_1.resolve)(this.outputPath, this._outputBaseFolder); } get outputModelsPath() { return (0, path_1.resolve)(this.exportPath, this._outputModelsFolder); } get outputApisPath() { return (0, path_1.resolve)(this.exportPath, this._outputApisFolder); } get tempFilePath() { return this._tempFilePath; } set tempFilePath(tempFilePath) { this._tempFilePath = (0, path_1.resolve)(tempFilePath); } get template() { return this._template; } set template(template) { this._template = template; this._templatePath = null; this._templateConfig = null; } get templatePath() { if (!this.template) { return null; } if (!this._templatePath) { this._templatePath = (0, files_util_1.resolvePluggablePath)(this.template, 'templates'); } return this._templatePath; } get templateConfig() { if (!this._templateConfig) { this._templateConfig = new template_config_model_1.TemplateConfigModel((0, path_1.resolve)(this.templatePath, 'config')); } return this._templateConfig; } get mockConfig() { return this._mockConfig; } set mockConfig(config) { this._mockConfig = config; ; } setConfig(config) { for (const key in config) { const value = config[key]; if (value) { this[key] = value; } else { console.warn(`${key} in config not recognized`); } } } parseYargs(yargs) { const config = {}; if (yargs.saveFile) { config.tempFilePath = yargs.saveFile; } if (yargs.file) { config.fileURI = yargs.file; } if (yargs.template) { config.template = yargs.template; } if (yargs.outputFolder) { config.outputPath = yargs.outputFolder; } if (this.cleanFolder === undefined || yargs.clean === false) { config.cleanFolder = yargs.clean; } if (yargs.mockGenerator) { config.mock = new config_mock_model_1.ConfigMockModel(); config.mock.parseYargs(yargs); } this.setConfig(config); } } exports.config = new ConfigModel(); //# sourceMappingURL=config.model.js.map