@golemio/cli
Version:
Collection of executables intended for use with Golemio services and modules
63 lines • 3.22 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const swagger_utils_1 = require("../utils/swagger.utils");
const command = {
description: "Generate OAS config or run Portman tests",
alias: "oas",
run: async ({ parameters, print }) => {
const [action] = parameters.array;
let { header: oasHeaderFilePath, output: oasMergedOutputFilePath, oas: oasFilePath, filter: oasFilterFilePath, script: scriptFilePath, config: portmanConfigPath, } = parameters.options;
const swaggerConfig = {
oasHeaderFilePath: oasHeaderFilePath !== null && oasHeaderFilePath !== void 0 ? oasHeaderFilePath : null,
oasFilesGlob: oasFilePath !== null && oasFilePath !== void 0 ? oasFilePath : null,
oasFilePath: oasFilePath !== null && oasFilePath !== void 0 ? oasFilePath : null,
oasMergedOutputFilePath: oasMergedOutputFilePath !== null && oasMergedOutputFilePath !== void 0 ? oasMergedOutputFilePath : null,
oasFilterFilePath: oasFilterFilePath !== null && oasFilterFilePath !== void 0 ? oasFilterFilePath : null,
scriptFilePath: scriptFilePath !== null && scriptFilePath !== void 0 ? scriptFilePath : null,
portmanConfigPath: portmanConfigPath !== null && portmanConfigPath !== void 0 ? portmanConfigPath : null,
};
switch (action) {
case "help":
case "h":
default:
(0, swagger_utils_1.printCommandHelp)();
return;
case "generate": {
if (!swaggerConfig.oasMergedOutputFilePath || !swaggerConfig.oasFilesGlob) {
print.error("Missing required parameters");
process.exitCode = 1;
return;
}
const { isError, message } = (0, swagger_utils_1.generateOpenApiConfig)(swaggerConfig.oasHeaderFilePath, swaggerConfig.oasFilesGlob, swaggerConfig.oasFilterFilePath, swaggerConfig.oasMergedOutputFilePath);
if (isError) {
print.error(message);
process.exitCode = 1;
}
else {
print.success(message);
}
break;
}
case "api-test":
case "test": {
if (!swaggerConfig.oasFilePath || !swaggerConfig.scriptFilePath) {
print.error("Missing required parameters");
process.exitCode = 1;
return;
}
const { isError, message } = await (0, swagger_utils_1.runPortmanTests)(swaggerConfig.oasFilePath, swaggerConfig.oasFilterFilePath, swaggerConfig.scriptFilePath, swaggerConfig.portmanConfigPath);
if (isError) {
print.error(message);
process.exitCode = 1;
}
else {
print.success(message);
}
// Workaround for Portman test runner not exiting properly for some reason
process.exit();
}
}
},
};
exports.default = command;
//# sourceMappingURL=swagger.js.map