* merge libs rollup configs to one rollup * move css from libs to src/core * run rollup on cms build * move test-utils to /utils folder * move css to src/core * mark @umbraco-cms/backoffice as external when building for CMS * rename all models to include @umbraco-cms/backoffice in their path to allow us to publish as a single module * rename all imports to @umbraco-cms/backoffice/* * rename events to umb-events to avoid rollup error of protected module name(?) * test that libs can build * move css to src/core * move umb-lit-element and modal elements to src/core * move some modal interfaces back to libs/modal * move the icon store into src/core since it is very localized to the backoffice * comment out build:libs for now since Github runs out of memory * rename to match tsconfig alias * add package.json to libs * only make libs for lib folders * turn off emit for typescript since we are handling types for libs separately * build libs locally * add script to move libs to final destination with some transform * move libs after build * move package.json to dist folder first (so we can publish from there) * remove inline comments * ensure the outputDir exists * Remove re-export of extensions-registry library from models library * move to individual files to avoid circular imports * check if outputDir exists before trying to create it * write transforms first in dist file and then copy the file to outputDir * ensure all umbraco types are external * copy information from main package.json file
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { hasDefaultExport } from './has-default-export.function';
|
|
import { isManifestClassConstructorType } from './is-manifest-class-instance-type.function';
|
|
import { loadExtension } from './load-extension.function';
|
|
import type { ClassConstructor } from '@umbraco-cms/backoffice/models';
|
|
import type { ManifestClass } from '@umbraco-cms/backoffice/extensions-registry';
|
|
|
|
//TODO: Write tests for this method:
|
|
export async function createExtensionClass<T = unknown>(
|
|
manifest: ManifestClass,
|
|
constructorArguments: unknown[]
|
|
): Promise<T | undefined> {
|
|
const js = await loadExtension(manifest);
|
|
|
|
if (isManifestClassConstructorType(manifest)) {
|
|
return new manifest.class(...constructorArguments) as T;
|
|
}
|
|
|
|
if (js) {
|
|
if (hasDefaultExport<ClassConstructor<T>>(js)) {
|
|
return new js.default(...constructorArguments);
|
|
}
|
|
|
|
console.error(
|
|
'-- Extension did not succeed creating an class instance, missing a default export of the served JavaScript file',
|
|
manifest
|
|
);
|
|
|
|
return undefined;
|
|
}
|
|
|
|
console.error(
|
|
'-- Extension did not succeed creating an class instance, missing a default export or `class` in the manifest.',
|
|
manifest
|
|
);
|
|
return undefined;
|
|
}
|