kui-shell
Version:
This is the monorepo for Kui, the hybrid command-line/GUI electron-based Kubernetes tool
79 lines • 3.51 kB
JavaScript
;
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const debug_1 = require("debug");
const debug = debug_1.default('core/plugins/preloader');
debug('loading');
const command_tree_1 = require("../core/command-tree");
const registrars_1 = require("../api/registrars");
class PreloaderRegistrarImpl extends command_tree_1.ImplForPlugins {
constructor(plugin) {
super(plugin);
}
registerMode(registration) {
registrars_1.registerMode(registration);
}
registerModes(...registrations) {
registrations.forEach(_ => this.registerMode(_));
}
registerBadge(registration) {
registrars_1.registerBadge(registration);
}
registerBadges(...registrations) {
registrations.forEach(_ => this.registerBadge(_));
}
}
exports.default = (prescan) => __awaiter(void 0, void 0, void 0, function* () {
debug('init');
const jobs = Promise.all(prescan.preloads.map((module) => __awaiter(void 0, void 0, void 0, function* () {
try {
debug('preloading capabilities.1 %s', module.path);
const registrationRef = module.path.charAt(0) === '/'
? yield Promise.resolve().then(() => require(module.path))
: yield Promise.resolve().then(() => require('@kui-shell/plugin-' + module.path.replace(/^plugin-/, '')));
debug('preloading capabilities.2 %s', module.path);
const registration = registrationRef.registerCapability;
if (registration) {
yield registration();
debug('registered capabilities %s', module.path);
}
else {
debug('no registered capabilities %s', module.path);
}
}
catch (err) {
debug('error registering capabilities', module.path, err);
console.error(err);
}
}))).then(() => Promise.all(prescan.preloads.map((module) => __awaiter(void 0, void 0, void 0, function* () {
try {
debug('preloading misc %s', module.path);
const registrationRef = module.path.charAt(0) === '/'
? yield Promise.resolve().then(() => require(module.path))
: yield Promise.resolve().then(() => require('@kui-shell/plugin-' + module.path.replace(/^plugin-/, '')));
const registration = registrationRef.default || registrationRef;
yield registration(new PreloaderRegistrarImpl(module.route));
debug('done preloading %s', module.path);
}
catch (err) {
debug('error invoking preload', module.path, err);
console.error(err);
}
}))));
try {
yield jobs;
}
catch (err) {
console.error(err);
}
debug('done');
});
//# sourceMappingURL=preloader.js.map