1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const command_1 = require("@oclif/command");
|
5 | const fs = require("fs-extra");
|
6 | const path = require("path");
|
7 | const base_command_1 = require("../../base-command");
|
8 | const decorators_1 = require("../../utils/decorators");
|
9 | const generators_1 = require("../../utils/generators");
|
10 | const OPEN_API_SPEC = 'openapi.json';
|
11 | class GenerateApiDocumentation extends base_command_1.default {
|
12 | async run() {
|
13 | try {
|
14 | const { flags } = this.parse(GenerateApiDocumentation);
|
15 | const { srcFunctionsDir, buildFunctionsDir } = this.locator;
|
16 | const { integrationTitle, bearerUid } = this.bearerConfig;
|
17 | const spec = flags.soft
|
18 | ? {}
|
19 | : await new generators_1.OpenApiSpecGenerator(srcFunctionsDir, { integrationTitle, buid: bearerUid }).build();
|
20 | fs.ensureDirSync(buildFunctionsDir);
|
21 | const openApiSpecPath = path.join(buildFunctionsDir, OPEN_API_SPEC);
|
22 | const fileExists = fs.existsSync(openApiSpecPath);
|
23 | await fs.writeFile(openApiSpecPath, spec);
|
24 | const action = fileExists ? 'updated' : 'generated';
|
25 | this.success(`File ${OPEN_API_SPEC} ${action}!`);
|
26 | }
|
27 | catch (e) {
|
28 | this.error(e);
|
29 | }
|
30 | }
|
31 | }
|
32 | GenerateApiDocumentation.description = 'Generate an openapi REST documentation';
|
33 | GenerateApiDocumentation.hidden = true;
|
34 | GenerateApiDocumentation.flags = Object.assign({}, base_command_1.default.flags, { soft: command_1.flags.boolean({}) });
|
35 | GenerateApiDocumentation.args = [];
|
36 | tslib_1.__decorate([
|
37 | decorators_1.RequireIntegrationFolder()
|
38 | ], GenerateApiDocumentation.prototype, "run", null);
|
39 | exports.default = GenerateApiDocumentation;
|