UNPKG

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