UNPKG

2.27 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const command_1 = require("@oclif/command");
5const fs = require("fs");
6const path = require("path");
7const base_command_1 = require("../../base-command");
8const decorators_1 = require("../../utils/decorators");
9const helpers_1 = require("../../utils/helpers");
10const authentications_1 = require("@bearer/types/lib/authentications");
11class 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}
46GenerateSpec.description = 'Generate spec file for bearer integration';
47GenerateSpec.hidden = true;
48GenerateSpec.flags = Object.assign({}, base_command_1.default.flags, { force: command_1.flags.boolean({}) });
49GenerateSpec.args = [];
50tslib_1.__decorate([
51 decorators_1.skipIfNoViews(),
52 decorators_1.RequireIntegrationFolder()
53], GenerateSpec.prototype, "run", null);
54exports.default = GenerateSpec;
55// Note: using Or condition in case the developer delete one but customized the other component
56function specExists(location) {
57 return fs.existsSync(path.join(location, 'spec.ts'));
58}