@kui-shell/core
Version:
An Electron-based shell for cloud-native development
175 lines (173 loc) • 6.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.clientGuidebooks = clientGuidebooks;
exports.firstOpenGuidebook = firstOpenGuidebook;
exports.guidebooksMenu = guidebooksMenu;
exports.hideReplayOutput = hideReplayOutput;
exports.isExecutable = isExecutable;
exports.isExecutableClient = isExecutableClient;
exports.isOffline = isOffline;
exports.isOfflineClient = isOfflineClient;
Object.defineProperty(exports, "isPopup", {
enumerable: true,
get: function () {
return _popupCore.isPopup;
}
});
exports.isReadOnly = isReadOnly;
exports.isReadOnlyClient = isReadOnlyClient;
exports.showGuidebooksSidebar = showGuidebooksSidebar;
exports.singletonGuidebooks = singletonGuidebooks;
var _debug = _interopRequireDefault(require("debug"));
var _load = _interopRequireWildcard(require("../main/load"));
var _popupCore = require("../webapp/popup-core");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/*
* Copyright 2019 The Kubernetes Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const debug = (0, _debug.default)('core/api/client');
/** Is the current client running in offline/disconnected mode? */
function isOfflineClient() {
try {
const {
offline: offlineFromClientSpec,
readonly,
executable
} = require('@kui-shell/client/config.d/client.json');
// see @kui-shell/webpack/offline.js for injecting the env var
const offline = process.env.IS_OFFLINE_CLIENT || offlineFromClientSpec;
if (offline === undefined && readonly !== undefined && executable !== undefined) {
return readonly && !executable;
} else {
return offline;
}
} catch (err) {
debug('Client did not define an offline status, assuming not offline');
return false;
}
}
function isOffline() {
return isOfflineClient();
}
/** Is the current client running in readonly mode? */
function isReadOnlyClient() {
try {
const {
offline,
readonly
} = require('@kui-shell/client/config.d/client.json');
if (offline) {
return true;
} else {
return readonly;
}
} catch (err) {
debug('Client did not define a readonly status, assuming not readonly');
return false;
}
}
function isReadOnly() {
return isReadOnlyClient();
}
/** Is the current client running in an executable mode? */
function isExecutableClient() {
try {
const {
offline,
executable
} = require('@kui-shell/client/config.d/client.json');
if (offline) {
return false;
} else {
return executable === undefined ? true : executable;
}
} catch (err) {
debug('Client did not define an executable status, assuming executable');
return true;
}
}
function isExecutable() {
return isExecutableClient();
}
function hideReplayOutput() {
try {
const {
hideReplayOutput
} = require('@kui-shell/client/config.d/client.json');
return hideReplayOutput;
} catch (err) {
debug('Client did not define a hideReplayOutput status, assuming no');
return false;
}
}
/** @return the model specified by `@kui-shell/client/config.d/notebooks.json` */
function guidebooksMenu() {
const model = (0, _load.default)();
if (model) {
return model.submenu;
}
}
/** @return first guidebook from Client.guidebooksMenu() with an `open` property */
function firstOpenGuidebook() {
const scan = menu => {
for (let idx = 0; idx < menu.length; idx++) {
const item = menu[idx];
if ((0, _load.isLeaf)(item) && item.open) {
return item.filepath;
} else if ((0, _load.isMenu)(item)) {
const found = scan(item.submenu);
if (found) {
return found;
}
}
}
return undefined;
};
return scan(guidebooksMenu());
}
/** @return a list of guidebook filepaths that `@kui-shell/client` offers */
function clientGuidebooks() {
try {
const guidebooks = require('@kui-shell/build/client-guidebooks.json');
if (!Array.isArray(guidebooks) || !guidebooks.every(_ => typeof _ === 'string')) {
debug('Client did not properly define guidebooks', guidebooks);
} else {
return guidebooks;
}
} catch (err) {
debug('Client did not define any guidebooks');
return [];
}
}
/** @return whether to show the Sidebar onload */
function showGuidebooksSidebar() {
try {
return window.innerHeight >= 450 && window.innerWidth >= 800 && require('@kui-shell/client/config.d/client.json').showGuidebooksSidebar;
} catch (err) {
return false;
}
}
/** @return whether to present guidebooks one-at-a-time */
function singletonGuidebooks() {
try {
return require('@kui-shell/client/config.d/client.json').singletonGuidebooks;
} catch (err) {
return false;
}
}