1 | "use strict";
|
2 |
|
3 |
|
4 | Object.defineProperty(exports, "__esModule", { value: true });
|
5 | exports.BuildManager = void 0;
|
6 | const coreutils_1 = require("@jupyterlab/coreutils");
|
7 | const serverconnection_1 = require("../serverconnection");
|
8 |
|
9 |
|
10 |
|
11 | const BUILD_SETTINGS_URL = 'api/build';
|
12 |
|
13 |
|
14 |
|
15 | class BuildManager {
|
16 | |
17 |
|
18 |
|
19 | constructor(options = {}) {
|
20 | var _a;
|
21 | this._url = '';
|
22 | this.serverSettings =
|
23 | (_a = options.serverSettings) !== null && _a !== void 0 ? _a : serverconnection_1.ServerConnection.makeSettings();
|
24 | const { baseUrl, appUrl } = this.serverSettings;
|
25 | this._url = coreutils_1.URLExt.join(baseUrl, appUrl, BUILD_SETTINGS_URL);
|
26 | }
|
27 | |
28 |
|
29 |
|
30 | get isAvailable() {
|
31 | return coreutils_1.PageConfig.getOption('buildAvailable').toLowerCase() === 'true';
|
32 | }
|
33 | |
34 |
|
35 |
|
36 | get shouldCheck() {
|
37 | return coreutils_1.PageConfig.getOption('buildCheck').toLowerCase() === 'true';
|
38 | }
|
39 | |
40 |
|
41 |
|
42 | getStatus() {
|
43 | const { _url, serverSettings } = this;
|
44 | const promise = serverconnection_1.ServerConnection.makeRequest(_url, {}, serverSettings);
|
45 | return promise
|
46 | .then(response => {
|
47 | if (response.status !== 200) {
|
48 | throw new serverconnection_1.ServerConnection.ResponseError(response);
|
49 | }
|
50 | return response.json();
|
51 | })
|
52 | .then(data => {
|
53 | if (typeof data.status !== 'string') {
|
54 | throw new Error('Invalid data');
|
55 | }
|
56 | if (typeof data.message !== 'string') {
|
57 | throw new Error('Invalid data');
|
58 | }
|
59 | return data;
|
60 | });
|
61 | }
|
62 | |
63 |
|
64 |
|
65 | build() {
|
66 | const { _url, serverSettings } = this;
|
67 | const init = { method: 'POST' };
|
68 | const promise = serverconnection_1.ServerConnection.makeRequest(_url, init, serverSettings);
|
69 | return promise.then(response => {
|
70 | if (response.status === 400) {
|
71 | throw new serverconnection_1.ServerConnection.ResponseError(response, 'Build aborted');
|
72 | }
|
73 | if (response.status !== 200) {
|
74 | const message = `Build failed with ${response.status}.
|
75 |
|
76 | If you are experiencing the build failure after installing an extension (or trying to include previously installed extension after updating JupyterLab) please check the extension repository for new installation instructions as many extensions migrated to the prebuilt extensions system which no longer requires rebuilding JupyterLab (but uses a different installation procedure, typically involving a package manager such as 'pip' or 'conda').
|
77 |
|
78 | If you specifically intended to install a source extension, please run 'jupyter lab build' on the server for full output.`;
|
79 | throw new serverconnection_1.ServerConnection.ResponseError(response, message);
|
80 | }
|
81 | });
|
82 | }
|
83 | |
84 |
|
85 |
|
86 | cancel() {
|
87 | const { _url, serverSettings } = this;
|
88 | const init = { method: 'DELETE' };
|
89 | const promise = serverconnection_1.ServerConnection.makeRequest(_url, init, serverSettings);
|
90 | return promise.then(response => {
|
91 | if (response.status !== 204) {
|
92 | throw new serverconnection_1.ServerConnection.ResponseError(response);
|
93 | }
|
94 | });
|
95 | }
|
96 | }
|
97 | exports.BuildManager = BuildManager;
|
98 |
|
\ | No newline at end of file |