UNPKG

1.71 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const authentications_1 = require("@bearer/types/lib/authentications");
5const function_types_1 = require("@bearer/types/lib/function-types");
6const base_command_1 = require("../../base-command");
7const decorators_1 = require("../../utils/decorators");
8const functions_1 = require("../../utils/templates/functions");
9class 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 // TODO: better error output
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}
31GenerateFunction.description = 'Generate a Bearer Function';
32GenerateFunction.aliases = ['g:f'];
33GenerateFunction.flags = Object.assign({}, base_command_1.default.flags);
34GenerateFunction.args = [{ name: 'name' }];
35tslib_1.__decorate([
36 decorators_1.RequireIntegrationFolder()
37], GenerateFunction.prototype, "run", null);
38exports.default = GenerateFunction;