UNPKG

2.62 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const serviceClient_1 = require("@bearer/bearer-cli/lib/lib/serviceClient");
4const command_1 = require("@oclif/command");
5const Case = require("case");
6const cli_ux_1 = require("cli-ux");
7const colors = require("colors/safe");
8const copy = require("copy-template-dir");
9const inquirer = require("inquirer");
10const fs = require("fs");
11const locator_1 = require("./utils/locator");
12const integration_client_1 = require("./utils/integration-client");
13const setup_config_1 = require("./utils/setup-config");
14class default_1 extends command_1.default {
15 constructor() {
16 super(...arguments);
17 this.silent = false;
18 }
19 get locator() {
20 return new locator_1.default(this.bearerConfig);
21 }
22 get inquirer() {
23 return inquirer;
24 }
25 get copy() {
26 return copy;
27 }
28 get case() {
29 return Case;
30 }
31 // TODO: fix typing
32 get ux() {
33 return cli_ux_1.default;
34 }
35 get colors() {
36 return colors;
37 }
38 // TODO: fix typing
39 get serviceClient() {
40 return serviceClient_1.default(this.bearerConfig.IntegrationServiceUrl);
41 }
42 get integrationClient() {
43 return integration_client_1.default(this);
44 }
45 get integrationAuthConfig() {
46 return require(this.locator.authConfigPath);
47 }
48 get hasViews() {
49 return fs.existsSync(this.locator.srcViewsDir);
50 }
51 success(message) {
52 this.log(this.colors.green(message));
53 }
54 log(_message, ..._args) {
55 if (!this.silent) {
56 // @ts-ignore
57 super.log.apply(this, arguments);
58 }
59 }
60 warn(_input) {
61 if (!this.silent) {
62 // @ts-ignore
63 super.warn.apply(this, arguments);
64 }
65 }
66 // protected logLevel: any
67 async init() {
68 const { flags } = this.parse(this.constructor);
69 const path = flags.path || undefined;
70 this.silent = flags.silent;
71 this.bearerConfig = setup_config_1.default(path);
72 }
73 /**
74 * Interactivity helpers
75 */
76 async askForString(phrase) {
77 const { response } = await this.inquirer.prompt([
78 {
79 message: `${phrase}:`,
80 name: 'response'
81 }
82 ]);
83 return response;
84 }
85}
86default_1.flags = {
87 help: command_1.flags.help({ char: 'h' }),
88 path: command_1.flags.string({}),
89 silent: command_1.flags.boolean({})
90 // logLevel: flags.string({ options: ['error', 'warn', 'info', 'debug'], default: 'info' })
91};
92exports.default = default_1;