1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const command_1 = require("@oclif/command");
|
5 | const fs = require("fs");
|
6 | const path = require("path");
|
7 | const base_command_1 = require("../../base-command");
|
8 | const decorators_1 = require("../../utils/decorators");
|
9 | const helpers_1 = require("../../utils/helpers");
|
10 | const authentications_1 = require("@bearer/types/lib/authentications");
|
11 | class GenerateSpec extends base_command_1.default {
|
12 | async run() {
|
13 | const { flags } = this.parse(GenerateSpec);
|
14 | const targetFolder = this.locator.integrationRoot;
|
15 | if (flags.force || !specExists(targetFolder)) {
|
16 | try {
|
17 | const setup = `
|
18 | {
|
19 | classname: 'SetupAction',
|
20 | isRoot: true,
|
21 | initialTagName: 'setup-action',
|
22 | name: 'setup-action',
|
23 | label: 'Setup Action Component'
|
24 | },
|
25 | {
|
26 | classname: 'SetupDisplay',
|
27 | isRoot: true,
|
28 | initialTagName: 'setup-view',
|
29 | name: 'setup-view',
|
30 | label: 'Setup Display Component'
|
31 | },`;
|
32 | const authType = this.integrationAuthConfig.authType;
|
33 | const vars = authType === authentications_1.default.NoAuth || authType === authentications_1.default.Custom ? {} : { setup };
|
34 | await helpers_1.copyFiles(this, 'generate/integration_specs', targetFolder, vars);
|
35 | this.success('Spec file successfully generated! 🎉');
|
36 | }
|
37 | catch (e) {
|
38 | this.error(e);
|
39 | }
|
40 | }
|
41 | else {
|
42 | this.warn('Spec file already exists, use --force flag to overwrite existing one.');
|
43 | }
|
44 | }
|
45 | }
|
46 | GenerateSpec.description = 'Generate spec file for bearer integration';
|
47 | GenerateSpec.hidden = true;
|
48 | GenerateSpec.flags = Object.assign({}, base_command_1.default.flags, { force: command_1.flags.boolean({}) });
|
49 | GenerateSpec.args = [];
|
50 | tslib_1.__decorate([
|
51 | decorators_1.skipIfNoViews(),
|
52 | decorators_1.RequireIntegrationFolder()
|
53 | ], GenerateSpec.prototype, "run", null);
|
54 | exports.default = GenerateSpec;
|
55 |
|
56 | function specExists(location) {
|
57 | return fs.existsSync(path.join(location, 'spec.ts'));
|
58 | }
|