@kui-shell/plugin-core-support
Version:
Kui plugin offering core extensions such as help and screenshot commands
121 lines • 6.51 kB
JavaScript
/*
* 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 = (this && this.__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());
});
};
import { TrieVFS, mount } from '@kui-shell/plugin-bash-like/fs';
// type NotebookEntry = TrieVFS.Directory | NotebookLeaf
export class NotebookVFS extends 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'
? import(
/* webpackExclude: /tsconfig\.json/ */ /* webpackChunkName: "plugin-notebooks" */ /* webpackMode: "lazy" */ '@kui-shell/plugin-' +
match1[1] +
'/notebooks/' +
file +
'.md')
: import(
/* webpackExclude: /tsconfig\.json/ */ /* webpackChunkName: "plugin-notebooks" */ /* webpackMode: "lazy" */ '@kui-shell/plugin-' +
match1[1] +
'/notebooks/' +
file +
'.json')
: match2
? extension === 'md'
? import(
/* webpackChunkName: "client-notebooks" */ /* webpackMode: "lazy" */ '@kui-shell/client/notebooks/' +
file +
'.md')
: extension === 'yml'
? import(
/* webpackChunkName: "client-notebooks" */ /* webpackMode: "lazy" */ '@kui-shell/client/notebooks/' +
file +
'.yml')
: extension === 'yaml'
? import(
/* webpackChunkName: "client-notebooks" */ /* webpackMode: "lazy" */ '@kui-shell/client/notebooks/' +
file +
'.yaml')
: extension === 'txt'
? import(
/* webpackChunkName: "client-notebooks" */ /* webpackMode: "lazy" */ '@kui-shell/client/notebooks/' +
file +
'.txt')
: extension === 'py'
? import(
/* webpackChunkName: "client-notebooks" */ /* webpackMode: "lazy" */ '@kui-shell/client/notebooks/' +
file +
'.py')
: import(
/* webpackChunkName: "client-notebooks" */ /* webpackMode: "lazy" */ '@kui-shell/client/notebooks/' +
file +
'.json')
: extension === 'md'
? import(
/* webpackChunkName: "client-markdown" */ /* webpackMode: "lazy" */ '@kui-shell/client/' + file + '.md')
: import(
/* 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');
}
});
}
}
const vfs = new NotebookVFS();
export default vfs;
export function preload() {
mount(vfs);
}
//# sourceMappingURL=index.js.map