UNPKG

2.46 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 // TODO: fix typing
31 get ux() {
32 return cli_ux_1.default;
33 }
34 get colors() {
35 return colors;
36 }
37 get integrationAuthConfig() {
38 return require(this.locator.authConfigPath);
39 }
40 get hasViews() {
41 return fs.existsSync(this.locator.srcViewsDir);
42 }
43 success(message) {
44 this.log(this.colors.green(message));
45 }
46 log(_message, ..._args) {
47 if (!this.silent) {
48 // @ts-ignore
49 super.log.apply(this, arguments);
50 }
51 }
52 warn(_input) {
53 if (!this.silent) {
54 // @ts-ignore
55 super.warn.apply(this, arguments);
56 }
57 }
58 get devPortalClient() {
59 return devPortal_1.devPortalClient(this);
60 }
61 // protected logLevel: any
62 async init() {
63 const { flags } = this.parse(this.constructor);
64 const path = flags.path || undefined;
65 const { constants, config } = setup_config_1.default(path);
66 this.bearerConfig = config;
67 this.constants = constants;
68 this.silent = flags.silent;
69 }
70 /**
71 * Interactivity helpers
72 */
73 async askForString(phrase, options = {}) {
74 const { response } = await this.inquirer.prompt([
75 Object.assign({ message: `${phrase}:`, name: 'response' }, options)
76 ]);
77 return response;
78 }
79}
80default_1.flags = {
81 help: command_1.flags.help({ char: 'h' }),
82 path: command_1.flags.string({}),
83 silent: command_1.flags.boolean({})
84 // logLevel: flags.string({ options: ['error', 'warn', 'info', 'debug'], default: 'info' })
85};
86exports.default = default_1;