UmbServerExtensionRegistrator
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
"invariantable",
|
||||
"Niels",
|
||||
"pickable",
|
||||
"Registrator",
|
||||
"templating",
|
||||
"tinymce",
|
||||
"umbraco",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { UmbBackofficeContext, UMB_BACKOFFICE_CONTEXT_TOKEN } from './backoffice.context.js';
|
||||
import { UmbExtensionInitializer } from './extension-initializer.controller.js';
|
||||
import { UmbServerExtensionRegistrator } from './server-extension-registrator.controller.js';
|
||||
import { css, html, customElement } from '@umbraco-cms/backoffice/external/lit';
|
||||
import { UUITextStyles } from '@umbraco-cms/backoffice/external/uui';
|
||||
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry';
|
||||
@@ -43,9 +43,13 @@ export class UmbBackofficeElement extends UmbLitElement {
|
||||
this.provideContext(UMB_BACKOFFICE_CONTEXT_TOKEN, new UmbBackofficeContext(this));
|
||||
new UmbBundleExtensionInitializer(this, umbExtensionsRegistry);
|
||||
new UmbEntryPointExtensionInitializer(this, umbExtensionsRegistry);
|
||||
new UmbServerExtensionRegistrator(this, umbExtensionsRegistry);
|
||||
|
||||
const extensionInitializer = new UmbExtensionInitializer(this, umbExtensionsRegistry);
|
||||
extensionInitializer.setLocalPackages(CORE_PACKAGES);
|
||||
// So far local packages are this simple to registerer, so no need for a manager to do that:
|
||||
CORE_PACKAGES.forEach(async (packageImport) => {
|
||||
const packageModule = await packageImport;
|
||||
umbExtensionsRegistry.registerMany(packageModule.extensions);
|
||||
});
|
||||
}
|
||||
|
||||
render() {
|
||||
|
||||
@@ -1,44 +1,22 @@
|
||||
import { Subject } from '@umbraco-cms/backoffice/external/rxjs';
|
||||
import { PackageResource, OpenAPI } from '@umbraco-cms/backoffice/backend-api';
|
||||
import { UmbBaseController, UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbBackofficeExtensionRegistry } from '@umbraco-cms/backoffice/extension-registry';
|
||||
import { tryExecuteAndNotify } from '@umbraco-cms/backoffice/resources';
|
||||
import { ManifestBase, isManifestJSType } from '@umbraco-cms/backoffice/extension-api';
|
||||
|
||||
// TODO: consider if this can be replaced by the new extension controllers.
|
||||
// TODO: consider if this can be replaced by the new extension controllers
|
||||
// TODO: move local part out of this, and name something with server.
|
||||
export class UmbExtensionInitializer extends UmbBaseController {
|
||||
export class UmbServerExtensionRegistrator extends UmbBaseController {
|
||||
#extensionRegistry: UmbBackofficeExtensionRegistry;
|
||||
#unobserve = new Subject<void>();
|
||||
#localPackages: Array<Promise<any>> = [];
|
||||
#apiBaseUrl = OpenAPI.BASE;
|
||||
|
||||
constructor(host: UmbControllerHost, extensionRegistry: UmbBackofficeExtensionRegistry) {
|
||||
super(host, UmbExtensionInitializer.name);
|
||||
super(host, UmbServerExtensionRegistrator.name);
|
||||
this.#extensionRegistry = extensionRegistry;
|
||||
}
|
||||
|
||||
setLocalPackages(localPackages: Array<Promise<any>>) {
|
||||
this.#localPackages = localPackages;
|
||||
this.#loadLocalPackages();
|
||||
}
|
||||
|
||||
hostConnected(): void {
|
||||
// TODO: This was before in hostConnected(), but I don't see the reason to wait. lets just do it right away.
|
||||
this.#loadServerPackages();
|
||||
}
|
||||
|
||||
hostDisconnected(): void {
|
||||
this.#unobserve.next();
|
||||
this.#unobserve.complete();
|
||||
}
|
||||
|
||||
async #loadLocalPackages() {
|
||||
this.#localPackages.forEach(async (packageImport) => {
|
||||
const packageModule = await packageImport;
|
||||
this.#extensionRegistry.registerMany(packageModule.extensions);
|
||||
});
|
||||
}
|
||||
|
||||
async #loadServerPackages() {
|
||||
/* TODO: we need a new endpoint here, to remove the dependency on the package repository, to get the modules available for the backoffice scope
|
||||
/ we will need a similar endpoint for the login, installer etc at some point.
|
||||
@@ -1,15 +1,16 @@
|
||||
import type { ManifestBase, ManifestBundle } from './types.js';
|
||||
import { loadExtension } from './load-extension.function.js';
|
||||
import { UmbExtensionRegistry } from './registry/extension.registry.js';
|
||||
import { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
|
||||
import { UmbBaseController, UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
|
||||
|
||||
export class UmbBundleExtensionInitializer {
|
||||
export class UmbBundleExtensionInitializer extends UmbBaseController {
|
||||
#extensionRegistry;
|
||||
#bundleMap = new Map();
|
||||
|
||||
constructor(host: UmbControllerHostElement, extensionRegistry: UmbExtensionRegistry<ManifestBundle>) {
|
||||
super(host);
|
||||
this.#extensionRegistry = extensionRegistry;
|
||||
extensionRegistry.extensionsOfType('bundle').subscribe((bundles) => {
|
||||
this.observe(extensionRegistry.extensionsOfType('bundle'), (bundles) => {
|
||||
// Unregister removed bundles:
|
||||
this.#bundleMap.forEach((existingBundle) => {
|
||||
if (!bundles.find((b) => b.alias === existingBundle.alias)) {
|
||||
|
||||
Reference in New Issue
Block a user