1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const authentications_1 = require("@bearer/types/lib/authentications");
|
5 | const command_1 = require("@oclif/command");
|
6 | const base_command_1 = require("../../base-command");
|
7 | const decorators_1 = require("../../utils/decorators");
|
8 | const helpers_1 = require("../../utils/helpers");
|
9 | var TComponent;
|
10 | (function (TComponent) {
|
11 | TComponent["BLANK"] = "blank";
|
12 | TComponent["COLLECTION"] = "collection";
|
13 | TComponent["ROOT"] = "root";
|
14 | })(TComponent || (TComponent = {}));
|
15 | class GenerateComponent extends base_command_1.default {
|
16 | async run() {
|
17 | const { args, flags } = this.parse(GenerateComponent);
|
18 | const type = flags.type || (await this.askForComponentType());
|
19 | const name = args.name || (await this.askForString('Name'));
|
20 | const outDir = type === TComponent.ROOT ? this.locator.srcViewsDir : this.locator.srcViewsDirResource('components');
|
21 | try {
|
22 | await helpers_1.copyFiles(this, `generate/${type}Component`, outDir, this.getVars(name, this.integrationAuthConfig.authType));
|
23 |
|
24 | this.success(`\nComponent generated`);
|
25 | if (type === TComponent.ROOT) {
|
26 | this.warn(this.colors.italic(
|
27 |
|
28 | 'Please make sure to update the spec.ts file to reflect your new Root Component on the Developer Portal preview page.'));
|
29 | }
|
30 | }
|
31 | catch (e) {
|
32 | this.error(e);
|
33 | }
|
34 | }
|
35 | getVars(name, authType) {
|
36 | const componentName = this.case.pascal(name);
|
37 | return {
|
38 | componentName,
|
39 | fileName: name,
|
40 | componentClassName: componentName,
|
41 | componentTagName: this.case.kebab(componentName),
|
42 | groupName: this.case.kebab(componentName),
|
43 | withAuthScreen: authType === authentications_1.default.OAuth2 ? '<bearer-navigator-auth-screen />' : null
|
44 | };
|
45 | }
|
46 | async askForComponentType() {
|
47 | const { type } = await this.inquirer.prompt([
|
48 | {
|
49 | choices,
|
50 | message: 'What kind of component would you like to generate:',
|
51 | type: 'list',
|
52 | name: 'type'
|
53 | }
|
54 | ]);
|
55 | return type;
|
56 | }
|
57 | }
|
58 | GenerateComponent.description = 'Generate a Bearer component';
|
59 | GenerateComponent.aliases = ['g:c'];
|
60 | GenerateComponent.flags = Object.assign({}, base_command_1.default.flags, { type: command_1.flags.string({ char: 't', options: Object.values(TComponent) }) });
|
61 | GenerateComponent.args = [{ name: 'name' }];
|
62 | tslib_1.__decorate([
|
63 | decorators_1.RequireIntegrationFolder()
|
64 | ], GenerateComponent.prototype, "run", null);
|
65 | exports.default = GenerateComponent;
|
66 |
|
67 | const choices = [
|
68 | {
|
69 | name: 'Blank',
|
70 | value: TComponent.BLANK
|
71 | },
|
72 | {
|
73 | name: 'Collection',
|
74 | value: TComponent.COLLECTION
|
75 | },
|
76 | {
|
77 | name: 'Root component',
|
78 | value: TComponent.ROOT
|
79 | }
|
80 | ];
|