1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const bearer_tst_js_1 = require("@bearer/transpiler/lib/bin/bearer-tst.js");
|
5 | const command_1 = require("@oclif/command");
|
6 | const chokidar = require("chokidar");
|
7 | const fs = require("fs-extra");
|
8 | const Listr = require("listr");
|
9 | const path = require("path");
|
10 | const base_command_1 = require("../../base-command");
|
11 | const install_dependencies_1 = require("../../tasks/install-dependencies");
|
12 | const decorators_1 = require("../../utils/decorators");
|
13 | const skipInstall = 'skip-install';
|
14 | class BuildViews extends base_command_1.default {
|
15 | constructor() {
|
16 | super(...arguments);
|
17 | this.transpile = () => {
|
18 | const prefix = ['bearer', this.bearerConfig.orgId].join('-');
|
19 | const suffix = this.bearerConfig.integrationId;
|
20 | try {
|
21 | bearer_tst_js_1.default(['--no-watcher', '--prefix-tag', prefix, '--suffix-tag', suffix, '--no-process', '--build', true]);
|
22 | }
|
23 | catch (e) {
|
24 | this.error(e);
|
25 | }
|
26 | };
|
27 | this.watchNonTsFiles = async (watchedPath, destPath) => {
|
28 | return new Promise((resolve, _reject) => {
|
29 | const callback = (error) => {
|
30 | if (error) {
|
31 | this.error(error);
|
32 | }
|
33 | };
|
34 | const watcher = chokidar.watch(`${watchedPath}/**`, {
|
35 | ignored: /\.tsx?$/,
|
36 | persistent: true,
|
37 | followSymlinks: false
|
38 | });
|
39 | watcher.on('ready', () => {
|
40 | resolve(watcher);
|
41 | });
|
42 | watcher.on('all', (event, filePath) => {
|
43 | const relativePath = filePath.replace(watchedPath, '');
|
44 | const targetPath = path.join(destPath, relativePath);
|
45 |
|
46 | if (event === 'add') {
|
47 | this.debug('creating symlink', filePath, targetPath);
|
48 | fs.ensureSymlink(filePath, targetPath, callback);
|
49 | }
|
50 |
|
51 | if (event === 'unlink') {
|
52 | this.debug('deleting symlink');
|
53 | fs.unlink(targetPath, err => {
|
54 | if (err)
|
55 | throw err;
|
56 | this.debug(`${targetPath} was deleted`);
|
57 | });
|
58 | }
|
59 | });
|
60 | });
|
61 | };
|
62 | }
|
63 | async run() {
|
64 | const { flags } = this.parse(BuildViews);
|
65 | const tasks = [
|
66 | {
|
67 | title: 'Transpile views',
|
68 | task: async (_ctx, _task) => this.transpile()
|
69 | },
|
70 | {
|
71 | title: 'Link non TS files',
|
72 | task: async (_ctx, _task) => {
|
73 | const watcher = await this.watchNonTsFiles(this.locator.srcViewsDir, this.locator.buildViewsComponentsDir);
|
74 |
|
75 |
|
76 | watcher.close();
|
77 |
|
78 | }
|
79 | }
|
80 | ];
|
81 | if (!flags[skipInstall]) {
|
82 | tasks.unshift(install_dependencies_1.default({ cwd: this.locator.integrationRoot }));
|
83 | }
|
84 | try {
|
85 | await new Listr(tasks).run();
|
86 | this.success('Built views');
|
87 | }
|
88 | catch (e) {
|
89 | this.error(e);
|
90 | }
|
91 | }
|
92 | }
|
93 | BuildViews.description = 'Build integration views';
|
94 | BuildViews.hidden = true;
|
95 | BuildViews.flags = Object.assign({}, base_command_1.default.flags, { [skipInstall]: command_1.flags.boolean({}) });
|
96 | BuildViews.args = [];
|
97 | tslib_1.__decorate([
|
98 | decorators_1.skipIfNoViews(),
|
99 | decorators_1.RequireIntegrationFolder()
|
100 | ], BuildViews.prototype, "run", null);
|
101 | exports.default = BuildViews;
|