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 | try {
|
19 | bearer_tst_js_1.default([
|
20 | '--no-watcher',
|
21 | '--prefix-tag',
|
22 | 'bearer',
|
23 | '--suffix-tag',
|
24 | this.bearerConfig.bearerUid,
|
25 | '--no-process',
|
26 | '--build',
|
27 | true,
|
28 | '--fail-fast',
|
29 | true,
|
30 | '--buid',
|
31 | this.bearerConfig.bearerUid
|
32 | ]);
|
33 | }
|
34 | catch (e) {
|
35 | this.error(e);
|
36 | }
|
37 | };
|
38 | this.watchNonTsFiles = async (watchedPath, destPath) => {
|
39 | return new Promise((resolve, _reject) => {
|
40 | const callback = (error) => {
|
41 | if (error) {
|
42 | this.error(error);
|
43 | }
|
44 | };
|
45 | const watcher = chokidar.watch(`${watchedPath}/**`, {
|
46 | ignored: /\.tsx?$/,
|
47 | persistent: true,
|
48 | followSymlinks: false
|
49 | });
|
50 | watcher.on('ready', () => {
|
51 | resolve(watcher);
|
52 | });
|
53 | watcher.on('all', (event, filePath) => {
|
54 | const relativePath = filePath.replace(watchedPath, '');
|
55 | const targetPath = path.join(destPath, relativePath);
|
56 |
|
57 | if (event === 'add') {
|
58 | this.debug('creating symlink', filePath, targetPath);
|
59 | fs.ensureSymlink(filePath, targetPath, callback);
|
60 | }
|
61 |
|
62 | if (event === 'unlink') {
|
63 | this.debug('deleting symlink');
|
64 | fs.unlink(targetPath, err => {
|
65 | if (err)
|
66 | throw err;
|
67 | this.debug(`${targetPath} was deleted`);
|
68 | });
|
69 | }
|
70 | });
|
71 | });
|
72 | };
|
73 | }
|
74 | async run() {
|
75 | const { flags } = this.parse(BuildViews);
|
76 | const tasks = [
|
77 | {
|
78 | title: 'Transpile views',
|
79 | task: async (_ctx, _task) => this.transpile()
|
80 | },
|
81 | {
|
82 | title: 'Link non TS files',
|
83 | task: async (_ctx, _task) => {
|
84 | const watcher = await this.watchNonTsFiles(this.locator.srcViewsDir, this.locator.buildViewsComponentsDir);
|
85 |
|
86 |
|
87 | watcher.close();
|
88 |
|
89 | }
|
90 | }
|
91 | ];
|
92 | if (!flags[skipInstall]) {
|
93 | tasks.unshift(install_dependencies_1.default({ cwd: this.locator.integrationRoot }));
|
94 | }
|
95 | try {
|
96 | await new Listr(tasks).run();
|
97 | this.success('Built views');
|
98 | }
|
99 | catch (e) {
|
100 | this.error(e);
|
101 | }
|
102 | }
|
103 | }
|
104 | BuildViews.description = 'Build integration views';
|
105 | BuildViews.hidden = true;
|
106 | BuildViews.flags = Object.assign({}, base_command_1.default.flags, { [skipInstall]: command_1.flags.boolean({}) });
|
107 | BuildViews.args = [];
|
108 | tslib_1.__decorate([
|
109 | decorators_1.skipIfNoViews(),
|
110 | decorators_1.RequireIntegrationFolder(),
|
111 | decorators_1.RequireLinkedIntegration(false)
|
112 | ], BuildViews.prototype, "run", null);
|
113 | exports.default = BuildViews;
|