UNPKG

4.06 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const command_1 = require("@oclif/command");
5// @ts-ignore
6const suggest = require("inquirer-prompt-suggest");
7const base_command_1 = require("../../base-command");
8const commands_1 = require("../../utils/commands");
9const decorators_1 = require("../../utils/decorators");
10const prompts_1 = require("../../utils/prompts");
11const inquirer = require("inquirer");
12class IntegrationsCreate extends base_command_1.default {
13 async run() {
14 const { flags } = this.parse(IntegrationsCreate);
15 const name = flags.name || (await this.askForName());
16 const description = flags.description || (await prompts_1.askForString('Description (optional)'));
17 try {
18 const { data } = await this.devPortalClient.request({
19 query: MUTATION,
20 variables: { name, description }
21 });
22 if (data.data) {
23 const { integration } = data.data.createIntegration;
24 this.success('Integration successfully created');
25 this.log(' name: %s\n uuid: %s\nidentifier: %s\n Url:', integration.name, integration.uuid, `${this.constants.DeveloperPortalUrl}integrations/${integration.uuid}`);
26 if (this.isIntegrationLocation) {
27 // tslint:disable-next-line no-boolean-literal-compare
28 if (!flags.skipLink) {
29 await commands_1.linkIntegration.bind(this)(integration.uuid);
30 }
31 }
32 }
33 else {
34 this.debug(data);
35 this.error('Unable to create this integration, please retry');
36 }
37 }
38 catch (e) {
39 this.debug('%j', e.response);
40 this.error(e);
41 }
42 }
43 async askForName() {
44 inquirer.registerPrompt('suggest', suggest);
45 const suggestions = Array.from(Array(30).keys()).map(randomName);
46 this.debug('%j', suggestions);
47 return prompts_1.askForString('Integration name', {
48 suggestions,
49 validate: (input) => {
50 return input.length > 0;
51 },
52 type: 'suggest'
53 });
54 }
55}
56IntegrationsCreate.description = 'create a new Integration';
57IntegrationsCreate.flags = Object.assign({}, base_command_1.default.flags, { description: command_1.flags.string({ char: 'd' }), name: command_1.flags.string({ char: 'n' }), skipLink: command_1.flags.boolean({ char: 'l' }) });
58tslib_1.__decorate([
59 decorators_1.ensureFreshToken()
60], IntegrationsCreate.prototype, "run", null);
61exports.default = IntegrationsCreate;
62function randomName() {
63 return [bearSample(), nameSample()].join(' ');
64}
65function bearSample() {
66 return bears[Math.floor(Math.random() * bears.length)];
67}
68function nameSample() {
69 return names[Math.floor(Math.random() * names.length)];
70}
71const bears = [
72 'Cinnamon',
73 'Florida',
74 'Glacier',
75 'Haida Gwaii',
76 'Kermode',
77 'Spirit',
78 'Louisiana',
79 'Newfoundland',
80 'Baluchistan',
81 'Formosan',
82 'Himalayan',
83 'Ussuri',
84 'Alaska Peninsula',
85 'Atlas',
86 'Bergman',
87 'Cantabrian',
88 'Gobi',
89 'Grizzly',
90 'Kamchatka',
91 'Kodiak',
92 'Marsican',
93 'Sitka',
94 'Stickeen',
95 'Ussuri',
96 'Giant',
97 'Qinling',
98 'Sloth',
99 'Sun',
100 'Polar',
101 'Ursid hybrid',
102 'Spectacled'
103];
104const names = [
105 'Alpha',
106 'Bravo',
107 'Charlie',
108 'Delta',
109 'Echo',
110 'Foxtrot',
111 'Golf',
112 'Hotel',
113 'India',
114 'Juliet',
115 'Kilo',
116 'Lima',
117 'Mike',
118 'November',
119 'Oscar',
120 'Papa',
121 'Quebec',
122 'Romeo',
123 'Sierra',
124 'Tango',
125 'Uniform',
126 'Victor',
127 'Whiskey',
128 'X-ray',
129 'Yankee',
130 'Zulu'
131];
132const MUTATION = `
133mutation CLICreateIntegration($name: String!, $description: String!) {
134 createIntegration(name: $name, description: $description) {
135 integration {
136 uuid: uuidv2
137 name
138 }
139 }
140}
141`;