Feature/server packages v2 (#574)

* new api models

* use new PackageResource

* do not error out on missing default exports (esmodules auto-execute)

* do not check for js extensions (they might have been registered on the client without a js file)

* prepend the api baseurl to any relataive server JS dependencies

* ignore tsbuildinfo

* create base file for tsconfig

* extend from base config and optimise include/exclude paths

* install rollup plugin to handle json files

* use plugin to bundle json files

* call script for cms builds that builds libs

* add rollup config to utils lib

* add a context token to the extension registry instance itself and provide it through BackofficeElement

* add rollup node resolve

* add node resolve

* only include element mixin in element library

* add error description to module load error

* add types to UmbExtensionRegistry token

* set UmbNotificationService as string in its token to avoid minification

* correct comment

* reverse order of checks

* add host to server extensions and support life-cycle check

* add imports

* use lit rather than lit-html

* correct comment

* add PackageManifestModel

* add import

* run libs build for cms

* revert reorder

* use string name for NotificationContext token

* make alias public readonly of UmbContextToken

* remove TODO

* use UmbContextToken::toString() for all stores

* use string alias for contexts

* move default data so we avoid importing a big lit library just to get default data interface

* add rollup to two extra libraries

* make sure we build uui and lit into our libraries for the few cases we import something

* add lockfile

* add separate options for .js files

* add function to install types of module

* add types output

* remove unused tsconfig-base file for now
This commit is contained in:
Jacob Overgaard
2023-03-02 20:29:20 +01:00
committed by GitHub
parent 0fe3f8886c
commit 62f3c2d6fa
62 changed files with 372 additions and 132 deletions

View File

@@ -0,0 +1,67 @@
import * as fs from 'fs';
import { exec } from 'child_process';
const libsDistFolder = '../Umbraco.Cms.StaticAssets/wwwroot/umbraco/backoffice/libs';
const libs = fs.readdirSync('./libs');
for (let i = 0; i < libs.length; i++) {
const lib = libs[i];
const libFolder = './libs/' + lib;
if (fs.statSync(libFolder).isDirectory()) {
const libPackage = libFolder + '/rollup.config.js';
if (!fs.existsSync(libPackage)) {
continue;
}
console.log('Installing ' + lib + '...');
exec('npx rollup -c rollup.config.js', { cwd: libFolder }, function (error) {
if (error) {
console.error('Error installing ' + lib + '!');
console.error(error);
} else {
console.log('Installed ' + lib + '.');
copyDistFromLib(lib, `${libFolder}/dist`);
}
});
}
}
function copyDistFromLib(libName, distPath) {
console.log(`Copying ${libName} to StaticAssets`);
const targetFolder = `${libsDistFolder}/${libName}`;
fs.cp(distPath, targetFolder, { recursive: true }, function (err) {
if (err) {
console.error(`Error copying ${libName}`);
console.error(err);
} else {
console.log(`Copied ${libName}`);
findAndCopyTypesForLib(libName);
}
});
}
/**
* Look in the ./types/libs folder for a folder with the same name as the {libName} parameter
* and copy those types into the `${libsDistFolder}/${libName}` folder.
* Wrap the types from the index.d.ts file as a new module called "@umbraco-cms/{libName}".
*/
function findAndCopyTypesForLib(libName) {
console.log('Installing types for', libName);
const typesFolder = './types/libs';
const libTypesFolder = `${typesFolder}/${libName}`;
if (fs.existsSync(libTypesFolder)) {
const libTypesTargetFolder = `${libsDistFolder}/${libName}`;
fs.cpSync(libTypesFolder, `${libTypesTargetFolder}/types`, { recursive: true });
fs.writeFileSync(`${libTypesTargetFolder}/index.d.ts`, wrapLibTypeContent(libName), {});
}
}
function wrapLibTypeContent(libName) {
return `
import * as lib from './types';
declare module "@umbraco-cms/${libName}" {
export = lib;
}`;
}

View File

@@ -1,14 +1,15 @@
import esbuild from 'rollup-plugin-esbuild';
//import { nodeResolve } from '@rollup/plugin-node-resolve';
import pluginJson from '@rollup/plugin-json';
import { nodeResolve } from '@rollup/plugin-node-resolve';
/** @type {import('rollup').RollupOptions} */
export default {
input: 'index.ts',
external: [/^@umbraco-cms\//, /^@umbraco-ui\//, /^lit/, /^rxjs/],
external: [/^@umbraco-cms\//],
output: {
file: 'dist/index.js',
format: 'es',
sourcemap: true,
},
plugins: [esbuild({ sourceMap: true })],
plugins: [nodeResolve(), pluginJson(), esbuild({ sourceMap: true })],
};