openapi-ts-request
Version:
Swagger2/OpenAPI3/Apifox to TypeScript/JavaScript, request client(support any client), request mock service, enum and enum translation, react-query/vue-query, type field label, JSON Schemas
56 lines (55 loc) • 2.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const chalk_1 = tslib_1.__importDefault(require("chalk"));
const commander_1 = require("commander");
const index_1 = require("../index");
const readConfig_1 = require("../readConfig");
commander_1.program
.option('-cfn, --configFileName <string>', 'config file name')
.option('-cfp, --configFilePath <string>', 'config file path')
.option('-u, --uniqueKey <string>', 'unique key');
commander_1.program.parse();
const options = commander_1.program.opts();
function run() {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const config = yield (0, readConfig_1.readConfig)({
fallbackName: 'openapi-ts-request',
filePath: options.filePath,
fileName: options.fileName,
});
try {
const tasks = [];
if (config) {
let configs = Array.isArray(config)
? config
: [config];
if (options.uniqueKey) {
configs = configs.filter((config) => config.uniqueKey === options.uniqueKey);
}
for (const config of configs) {
tasks.push((0, index_1.generateService)(config));
}
const results = yield Promise.allSettled(tasks);
const errors = results.filter((result) => result.status === 'rejected');
let errorMsg = '';
for (let i = 0; i < errors.length; i++) {
const error = errors[i];
const cnf = configs[i];
errorMsg += `${cnf.uniqueKey}${cnf.uniqueKey && ':'}${error.reason}\n`;
}
if (errorMsg) {
throw new Error(errorMsg);
}
}
else {
throw new Error('config is not found');
}
}
catch (error) {
console.log(chalk_1.default.red(error));
}
});
}
void run();