@kui-shell/plugin-core-support
Version:
Kui plugin offering core extensions such as help and screenshot commands
99 lines (98 loc) • 5.09 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.NotebookVFS = void 0;
exports.preload = preload;
var _fs = require("@kui-shell/plugin-bash-like/fs");
/*
* Copyright 2020 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.
*/
var __awaiter = void 0 && (void 0).__awaiter || function (thisArg, _arguments, P, generator) {
function adopt(value) {
return value instanceof P ? value : new P(function (resolve) {
resolve(value);
});
}
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
}
function rejected(value) {
try {
step(generator["throw"](value));
} catch (e) {
reject(e);
}
}
function step(result) {
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
}
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
// type NotebookEntry = TrieVFS.Directory | NotebookLeaf
class NotebookVFS extends _fs.TrieVFS.TrieVFS {
viewer() {
return 'replay';
}
nameForDisplay(name) {
return __awaiter(this, void 0, void 0, function* () {
return name;
});
}
loadAsString(leaf) {
return __awaiter(this, void 0, void 0, function* () {
const notebook = yield this.load(leaf.data);
return /\.json$/.test(leaf.mountPath) ? JSON.stringify(notebook, undefined, 2) : notebook.toString();
});
}
/** Load Notebook data from bundles */
load(data) {
return __awaiter(this, void 0, void 0, function* () {
const {
srcFilepath
} = data;
const match1 = srcFilepath.match(/^plugin:\/\/plugin-(.*)\/notebooks\/(.*)\.(md|json)$/);
const match2 = srcFilepath.match(/^plugin:\/\/client\/notebooks\/(.*)\.(md|json|yml|yaml|txt|py)$/);
const match3 = srcFilepath.match(/^plugin:\/\/client\/(.*)\.(md|json)$/);
const match = match1 || match2 || match3;
if (match) {
try {
const file = match1 ? match1[2] : match2 ? match2[1] : match3[1];
const extension = match1 ? match1[3] : match2 ? match2[2] : match3[2];
const data = yield match1 ? extension === 'md' ? Promise.resolve().then(() => require(`${/* webpackExclude: /tsconfig\.json/ */ /* webpackChunkName: "plugin-notebooks" */ /* webpackMode: "lazy" */'@kui-shell/plugin-' + match1[1] + '/notebooks/' + file + '.md'}`)) : Promise.resolve().then(() => require(`${/* webpackExclude: /tsconfig\.json/ */ /* webpackChunkName: "plugin-notebooks" */ /* webpackMode: "lazy" */'@kui-shell/plugin-' + match1[1] + '/notebooks/' + file + '.json'}`)) : match2 ? extension === 'md' ? Promise.resolve().then(() => require(`${/* webpackChunkName: "client-notebooks" */ /* webpackMode: "lazy" */'@kui-shell/client/notebooks/' + file + '.md'}`)) : extension === 'yml' ? Promise.resolve().then(() => require(`${/* webpackChunkName: "client-notebooks" */ /* webpackMode: "lazy" */'@kui-shell/client/notebooks/' + file + '.yml'}`)) : extension === 'yaml' ? Promise.resolve().then(() => require(`${/* webpackChunkName: "client-notebooks" */ /* webpackMode: "lazy" */'@kui-shell/client/notebooks/' + file + '.yaml'}`)) : extension === 'txt' ? Promise.resolve().then(() => require(`${/* webpackChunkName: "client-notebooks" */ /* webpackMode: "lazy" */'@kui-shell/client/notebooks/' + file + '.txt'}`)) : extension === 'py' ? Promise.resolve().then(() => require(`${/* webpackChunkName: "client-notebooks" */ /* webpackMode: "lazy" */'@kui-shell/client/notebooks/' + file + '.py'}`)) : Promise.resolve().then(() => require(`${/* webpackChunkName: "client-notebooks" */ /* webpackMode: "lazy" */'@kui-shell/client/notebooks/' + file + '.json'}`)) : extension === 'md' ? Promise.resolve().then(() => require(`${/* webpackChunkName: "client-markdown" */ /* webpackMode: "lazy" */'@kui-shell/client/' + file + '.md'}`)) : Promise.resolve().then(() => require(`${/* webpackChunkName: "client-markdown" */ /* webpackMode: "lazy" */'@kui-shell/client/' + file + '.json'}`));
return data.default;
} catch (err) {
console.error(err);
throw new Error(`Unable to load Notebook: ${err.message}`);
}
} else {
throw new Error('Unsupported filepath for Notebook');
}
});
}
}
exports.NotebookVFS = NotebookVFS;
const vfs = new NotebookVFS();
var _default = vfs;
exports.default = _default;
function preload() {
(0, _fs.mount)(vfs);
}