@finos/legend-shared
Version:
Legend Studio shared utilities and helpers
165 lines • 4.58 kB
JavaScript
/**
* Copyright (c) 2020-present, Goldman Sachs
*
* 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.
*/
import { uuid } from '../CommonUtils.js';
export class PluginInfo {
name;
version;
signature;
uuid;
}
export class AbstractPlugin {
name;
version;
uuid = uuid();
constructor(name, version) {
this.name = name;
this.version = version;
}
getName() {
return this.name;
}
getVersion() {
return this.version;
}
getSignature() {
return `${this.getName()}@${this.getVersion()}`;
}
getUUID() {
return this.uuid;
}
getInfo() {
const info = new PluginInfo();
info.name = this.getName();
info.version = this.getVersion();
info.signature = this.getSignature();
info.uuid = this.getUUID();
return info;
}
configure(configData) {
return this;
}
}
export class PresetInfo {
name;
version;
signature;
uuid;
plugins = [];
}
export class AbstractPreset {
name;
version;
uuid = uuid();
plugins = [];
constructor(name, version, plugins) {
this.name = name;
this.version = version;
this.plugins = plugins;
}
getName() {
return this.name;
}
getVersion() {
return this.version;
}
getSignature() {
return `${this.getName()}@${this.getVersion()}`;
}
getUUID() {
return this.uuid;
}
getPlugins() {
return [...this.plugins];
}
getInfo() {
const info = new PresetInfo();
info.name = this.getName();
info.version = this.getVersion();
info.signature = this.getSignature();
info.uuid = this.getUUID();
info.plugins = this.plugins
.map((plugin) => plugin.getInfo())
.sort((a, b) => a.name.localeCompare(b.name));
return info;
}
configure(configData) {
return this;
}
install(pluginManager) {
this.plugins.forEach((plugin) => plugin.install(pluginManager));
}
}
export class AbstractPluginManager {
plugins = [];
presets = [];
usePlugins(plugins) {
this.plugins = plugins;
return this;
}
usePresets(presets) {
this.presets = presets;
return this;
}
configure(configData) {
Object.keys(configData).forEach((key) => {
const configObj = configData[key];
this.presets.forEach((preset) => {
if (preset.getName() === key) {
preset.configure(configObj);
}
});
this.plugins.forEach((plugin) => {
if (plugin.getName() === key) {
plugin.configure(configObj);
}
});
});
}
install() {
// Plugins run before presets
// Plugins ordering is first to last
this.plugins.forEach((plugin) => plugin.install(this));
// Presets ordering is first to last
this.presets.forEach((plugin) => plugin.install(this));
}
getInfo() {
return {
plugins: this.plugins
.filter((plugin) => !this.getHiddenPluginNames().includes(plugin.getName()))
.map((plugin) => plugin.getInfo())
.sort((a, b) => a.name.localeCompare(b.name)),
presets: this.presets
.filter((preset) => !this.getHiddenPresetNames().includes(preset.getName()))
.map((preset) => preset.getInfo())
.sort((a, b) => a.name.localeCompare(b.name)),
};
}
/**
* Return the list of core plugin names to be hidden
* when getting plugin manager info, such as core plugins.
*/
getHiddenPluginNames() {
return [];
}
/**
* Return the list of core presets names to be hidden
* when getting plugin manager info, such as core presets.
*/
getHiddenPresetNames() {
return [];
}
}
//# sourceMappingURL=AbstractPluginManager.js.map