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");
9const prompts_1 = require("../../utils/prompts");
10class GenerateFunction extends base_command_1.default {
11 async run() {
12 const { args } = this.parse(GenerateFunction);
13 const name = args.name || (await prompts_1.askForString('Function name'));
14 const authType = this.integrationAuthConfig.authType;
15 if (!Object.values(authentications_1.Authentications).includes(authType)) {
16 // TODO: better error output
17 this.error(`Incorrect AuthType please update "authType" field of auth.config.json within your integration,
18 with one of these values : ${Object.values(authentications_1.Authentications).join(' | ')}`);
19 }
20 try {
21 await functions_1.default(this, authType, function_types_1.default.FetchData, name);
22 this.success(`\nFunction generated`);
23 }
24 catch (e) {
25 this.error(e);
26 }
27 }
28}
29GenerateFunction.description = 'Generate a Bearer Function';
30GenerateFunction.aliases = ['g:f'];
31GenerateFunction.flags = Object.assign({}, base_command_1.default.flags);
32GenerateFunction.args = [{ name: 'name' }];
33tslib_1.__decorate([
34 decorators_1.RequireIntegrationFolder()
35], GenerateFunction.prototype, "run", null);
36exports.default = GenerateFunction;