zcatalyst-cli
Version:
Command Line Tool for CATALYST
99 lines (98 loc) • 4.39 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
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());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const ansi_colors_1 = require("ansi-colors");
const error_js_1 = __importDefault(require("./error.js"));
const optional_import_js_1 = __importDefault(require("./optional-import.js"));
const runtime_store_js_1 = __importDefault(require("./runtime-store.js"));
const ClientConfig = __importStar(require("./util_modules/config/lib/client.js"));
const FunctionsConfig = __importStar(require("./util_modules/config/lib/functions.js"));
const config = {
client: {
plugin: ClientConfig.plugin,
source: ClientConfig.source
},
functions: {
plugin: FunctionsConfig.plugin,
source: FunctionsConfig.source
}
};
const loadedPlugins = {};
function pluginLoader(feature, name, source) {
return __awaiter(this, void 0, void 0, function* () {
const pluginConfig = config[feature];
if (pluginConfig === undefined) {
return;
}
const plugins = pluginConfig.plugin(name, source);
let specificPlugin;
if (typeof plugins === 'string') {
specificPlugin = plugins;
}
else {
specificPlugin = plugins !== undefined ? plugins[name] : undefined;
}
if (specificPlugin === undefined) {
return;
}
let pluginMod;
if (loadedPlugins[specificPlugin] !== undefined) {
pluginMod = loadedPlugins[specificPlugin];
}
else {
pluginMod = yield (0, optional_import_js_1.default)(specificPlugin, pluginConfig.source());
}
if (pluginMod === undefined) {
throw new error_js_1.default(`Configured plugin could not be found for [${feature}:${name}] - ${specificPlugin}`, {
exit: 1,
errorId: 'PLG-LDR-1',
arg: [ansi_colors_1.italic.red(specificPlugin), (0, ansi_colors_1.bold)(name), (0, ansi_colors_1.bold)(feature)]
});
}
loadedPlugins[specificPlugin] = pluginMod;
if (typeof pluginMod === 'function') {
runtime_store_js_1.default.set(`context.${feature}.plugins.${name}${source ? '.' + source : ''}`, specificPlugin);
return pluginMod;
}
else if (typeof pluginMod[name] === 'function') {
runtime_store_js_1.default.set(`context.${feature}.plugins.${name}${source ? '.' + source : ''}`, specificPlugin);
return pluginMod[name];
}
return;
});
}
exports.default = pluginLoader;