openapi-generator-plus
Version:
Modular OpenAPI code generator written in TypeScript and Node.js
45 lines • 1.53 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const yaml_1 = __importDefault(require("yaml"));
const fs_1 = require("fs");
const core_1 = require("@openapi-generator-plus/core");
const getopts_1 = __importDefault(require("getopts"));
const usage_1 = require("./usage");
async function bundleCommand(argv) {
const commandLineOptions = (0, getopts_1.default)(argv, {
alias: {
output: 'o',
},
unknown: (option) => {
console.log(`Unknown option: ${option}`);
return false;
},
});
const outputPath = commandLineOptions.output;
const inputPath = commandLineOptions._[0];
if (!inputPath) {
console.log('Input path not specified');
(0, usage_1.usage)();
process.exit(1);
}
const doc = await (0, core_1.bundleCodegenInput)(inputPath);
if (outputPath) {
if (outputPath.endsWith('.json')) {
const json = JSON.stringify(doc, undefined, 2);
await fs_1.promises.writeFile(outputPath, json);
}
else {
const yaml = yaml_1.default.stringify(doc);
await fs_1.promises.writeFile(outputPath, yaml);
}
}
else {
const yaml = yaml_1.default.stringify(doc);
console.log(yaml);
}
}
exports.default = bundleCommand;
//# sourceMappingURL=bundle.js.map
;