boats
Version:
Beautiful Open / Async Template System - Write less yaml with BOATS and Nunjucks.
39 lines (38 loc) • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const upath_1 = tslib_1.__importDefault(require("upath"));
const fs_extra_1 = tslib_1.__importDefault(require("fs-extra"));
const getVersion = (jsonObj, excludeVersion) => {
let swagVersion = '';
if (excludeVersion) {
return swagVersion;
}
if (jsonObj.info.version) {
swagVersion = jsonObj.info.version;
}
else {
let packageJson;
try {
packageJson = JSON.parse(fs_extra_1.default.readFileSync('./package.json').toString('utf8'));
// eslint-disable-next-line @typescript-eslint/no-unused-vars
}
catch (e) {
packageJson = {};
}
if (packageJson.version) {
swagVersion = packageJson.version;
}
else {
return swagVersion;
}
}
return '_' + swagVersion;
};
const getFileName = (filePath, openApiJson, excludeVersion) => {
const name = upath_1.default.basename(filePath).replace(upath_1.default.extname(filePath), '');
return name + getVersion(openApiJson, excludeVersion) + upath_1.default.extname(filePath);
};
exports.default = (filePath, openApiJson, excludeVersion) => {
return upath_1.default.join(upath_1.default.dirname(filePath), getFileName(filePath, openApiJson, excludeVersion));
};