1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const inquirer = require("inquirer");
|
4 | const link_1 = require("../actions/link");
|
5 | const createIntegration_1 = require("../actions/createIntegration");
|
6 | function skipIfNoViews(displayError = false) {
|
7 | return function (_target, _propertyKey, descriptor) {
|
8 | const originalMethod = descriptor.value;
|
9 | descriptor.value = async function () {
|
10 | if (this.hasViews) {
|
11 | await originalMethod.apply(this, arguments);
|
12 | }
|
13 | else {
|
14 | if (displayError) {
|
15 | this.error(
|
16 |
|
17 | 'This integration does not contain any views. If you want to use this command please generate a new integration with --withViews flag');
|
18 | }
|
19 | else {
|
20 | this.debug('No views present, skipping');
|
21 | }
|
22 | }
|
23 | };
|
24 | return descriptor;
|
25 | };
|
26 | }
|
27 | exports.skipIfNoViews = skipIfNoViews;
|
28 |
|
29 | function RequireIntegrationFolder() {
|
30 | return function (_target, _propertyKey, descriptor) {
|
31 | const originalMethod = descriptor.value;
|
32 | descriptor.value = async function () {
|
33 | if (this.isIntegrationLocation) {
|
34 | await originalMethod.apply(this, arguments);
|
35 | }
|
36 | else {
|
37 | this.warn(
|
38 |
|
39 | `We couldn't find any auth.config.json file, please make sure this file exists at the root of your integration`);
|
40 | this.error('This command must be run within a integration folder.');
|
41 | }
|
42 | };
|
43 | return descriptor;
|
44 | };
|
45 | }
|
46 | exports.RequireIntegrationFolder = RequireIntegrationFolder;
|
47 |
|
48 | function RequireLinkedIntegration(prompt = true) {
|
49 | return function (_target, _propertyKey, descriptor) {
|
50 | const originalMethod = descriptor.value;
|
51 | descriptor.value = async function () {
|
52 | if (!this.bearerConfig.hasIntegrationLinked) {
|
53 | if (!prompt) {
|
54 | this.error('Can not run this command, please run link command before');
|
55 | }
|
56 | const { choice } = await inquirer.prompt([
|
57 | {
|
58 | name: 'choice',
|
59 | message: "Your integration isn't linked, what would you like to do?",
|
60 | type: 'list',
|
61 | choices: [
|
62 | {
|
63 | name: 'Create a new integration',
|
64 | value: 'create'
|
65 | },
|
66 | {
|
67 | name: 'Select an integration from my list',
|
68 | value: 'select'
|
69 | }
|
70 | ]
|
71 | }
|
72 | ]);
|
73 | switch (choice) {
|
74 | case 'create':
|
75 | await createIntegration_1.default(this, { link: true });
|
76 | break;
|
77 | case 'select':
|
78 | await link_1.default(this);
|
79 | default:
|
80 | break;
|
81 | }
|
82 | }
|
83 | await originalMethod.apply(this, arguments);
|
84 | };
|
85 | return descriptor;
|
86 | };
|
87 | }
|
88 | exports.RequireLinkedIntegration = RequireLinkedIntegration;
|