@nestia/sdk
Version:
Nestia SDK and Swagger generator
88 lines • 4.04 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NestiaSdkCommand = void 0;
const NestiaSdkApplication_1 = require("../../NestiaSdkApplication");
const NestiaConfigLoader_1 = require("./NestiaConfigLoader");
var NestiaSdkCommand;
(function (NestiaSdkCommand) {
NestiaSdkCommand.sdk = () => main({
title: "SDK library",
generate: (app) => app.sdk(),
validate: (config) => !!config.output,
solution: "configure INestiaConfig.output property.",
});
NestiaSdkCommand.swagger = () => main({
title: "Swagger Document",
generate: (app) => app.swagger(),
validate: (config) => { var _a; return !!((_a = config.swagger) === null || _a === void 0 ? void 0 : _a.output); },
solution: "configure INestiaConfig.swagger property.",
});
NestiaSdkCommand.e2e = () => main({
title: "E2E Functions",
generate: (app) => app.e2e(),
validate: (config) => !!config.e2e,
solution: [
"configure two properties:",
"",
" - INestiaConfig.output",
" - INestiaConfig.e2e",
].join("\n"),
});
NestiaSdkCommand.all = () => main({
title: "everything",
generate: (app) => app.all(),
validate: () => true,
solution: [
"configure at laest one property of below:",
"",
" - INestiaConfig.output",
" - INestiaConfig.swagger.output",
].join("\n"),
});
const main = (props) => __awaiter(this, void 0, void 0, function* () {
var _a, _b;
// LOAD CONFIG INFO
const command = yield NestiaConfigLoader_1.NestiaConfigLoader.compilerOptions((_a = getFileArgument({
type: "project",
extension: "json",
})) !== null && _a !== void 0 ? _a : "tsconfig.json");
const configurations = yield NestiaConfigLoader_1.NestiaConfigLoader.configurations((_b = getFileArgument({
type: "config",
extension: "ts",
})) !== null && _b !== void 0 ? _b : "nestia.config.ts", command.raw.compilerOptions);
// GENERATE
if (configurations.length > 1 &&
configurations.some(props.validate) === false)
throw new Error(`Every configurations are invalid to generate ${props.title}, ${props.solution}`);
for (const config of configurations) {
if (configurations.length > 1 && props.validate(config) === false)
continue;
const app = new NestiaSdkApplication_1.NestiaSdkApplication(config);
yield props.generate(app);
}
});
const getFileArgument = (props) => {
const argv = process.argv.slice(3);
if (argv.length === 0)
return null;
const index = argv.findIndex((str) => str === `--${props.type}`);
if (index === -1)
return null;
else if (argv.length === 1)
throw new Error(`${props.type} file must be provided`);
const file = argv[index + 1];
if (file.endsWith(props.extension) === false)
throw new Error(`${props.type} file must be ${props.extension} file`);
return file;
};
})(NestiaSdkCommand || (exports.NestiaSdkCommand = NestiaSdkCommand = {}));
//# sourceMappingURL=NestiaSdkCommand.js.map
;