UNPKG

3.87 kBJavaScriptView Raw
1"use strict";
2// Copyright (c) Jupyter Development Team.
3// Distributed under the terms of the Modified BSD License.
4Object.defineProperty(exports, "__esModule", { value: true });
5exports.BuildManager = void 0;
6const coreutils_1 = require("@jupyterlab/coreutils");
7const serverconnection_1 = require("../serverconnection");
8/**
9 * The url for the lab build service.
10 */
11const BUILD_SETTINGS_URL = 'api/build';
12/**
13 * The build API service manager.
14 */
15class BuildManager {
16 /**
17 * Create a new setting manager.
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 * Test whether the build service is available.
29 */
30 get isAvailable() {
31 return coreutils_1.PageConfig.getOption('buildAvailable').toLowerCase() === 'true';
32 }
33 /**
34 * Test whether to check build status automatically.
35 */
36 get shouldCheck() {
37 return coreutils_1.PageConfig.getOption('buildCheck').toLowerCase() === 'true';
38 }
39 /**
40 * Get whether the application should be built.
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 * Build the application.
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 * Cancel an active build.
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}
97exports.BuildManager = BuildManager;
98//# sourceMappingURL=index.js.map
\No newline at end of file