1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const authentications_1 = require("@bearer/types/lib/authentications");
|
5 | const function_types_1 = require("@bearer/types/lib/function-types");
|
6 | const base_command_1 = require("../../base-command");
|
7 | const decorators_1 = require("../../utils/decorators");
|
8 | const functions_1 = require("../../utils/templates/functions");
|
9 | class GenerateFunction extends base_command_1.default {
|
10 | async run() {
|
11 | const { args } = this.parse(GenerateFunction);
|
12 | const name = args.name || (await this.askForName());
|
13 | const authType = this.integrationAuthConfig.authType;
|
14 | if (!Object.values(authentications_1.Authentications).includes(authType)) {
|
15 |
|
16 | this.error(`Incorrect AuthType please update "authType" field of auth.config.json within your integration,
|
17 | with one of these values : ${Object.values(authentications_1.Authentications).join(' | ')}`);
|
18 | }
|
19 | try {
|
20 | await functions_1.default(this, authType, function_types_1.default.FetchData, name);
|
21 | this.success(`\nFunction generated`);
|
22 | }
|
23 | catch (e) {
|
24 | this.error(e);
|
25 | }
|
26 | }
|
27 | async askForName() {
|
28 | return this.askForString('Name');
|
29 | }
|
30 | }
|
31 | GenerateFunction.description = 'Generate a Bearer Function';
|
32 | GenerateFunction.aliases = ['g:f'];
|
33 | GenerateFunction.flags = Object.assign({}, base_command_1.default.flags);
|
34 | GenerateFunction.args = [{ name: 'name' }];
|
35 | tslib_1.__decorate([
|
36 | decorators_1.RequireIntegrationFolder()
|
37 | ], GenerateFunction.prototype, "run", null);
|
38 | exports.default = GenerateFunction;
|