File
usedBuildingBlocks
|
Type
|
BuildingBlockMetaData[]
|
usedLibraryNames
|
Type
|
Set<string>
|
import { PagesConfigurationWithTransformedDynamicForms } from '@allianz/taly-sdk';
import { getAllBuildingBlocksInPage } from '@allianz/taly-sdk';
import { posix } from 'path';
export interface BuildingBlockMetaData {
aclTag: string;
selector: string;
library: string;
}
interface UsedBuildingBlocksAndLibraries {
usedBuildingBlocks: BuildingBlockMetaData[];
usedLibraryNames: Set<string>;
}
/**
* collects building block metadata and the used libraries from a pages.json configuration.
*
* @param pagesJson pages.json configuration to extract building blocks and libraries from
*/
export function collectUsedBuildingBlocksAndLibraries(
pagesJson: PagesConfigurationWithTransformedDynamicForms
): UsedBuildingBlocksAndLibraries {
const usedLibraryNames = new Set<string>();
const usedBuildingBlocks: BuildingBlockMetaData[] = [];
pagesJson.pages.forEach((page) => {
const allBlocks = getAllBuildingBlocksInPage(page);
allBlocks?.forEach((block) => {
usedBuildingBlocks.push({
// we use path.posix here to join the acl resources because it conveniently
// joins two (or more) strings with a forward slash (/) on all platforms as
// well as takes care of avoiding any duplicate separators.
// The aclResourcePath is not a file path but the path tools are very well
// suited for working with acl paths.
aclTag: posix.join(page.id, block.aclTag ?? block.id),
selector: block.selector,
library: block.package
});
// keep track of used libraries to avoid another loop over all pages and blocks
usedLibraryNames.add(block.package);
});
});
pagesJson.frame?.header?.actions?.forEach((headerAction) => {
usedBuildingBlocks.push({
aclTag: posix.join('header-actions', headerAction.aclTag ?? headerAction.id),
selector: headerAction.selector,
library: headerAction.package
});
usedLibraryNames.add(headerAction.package);
});
return { usedBuildingBlocks, usedLibraryNames };
}