@o3r/components
Version:
This module contains component-related features (Component replacement, CMS compatibility, helpers, pipes, debugging developer tools...) It comes with an integrated ng builder to help you generate components compatible with Otter features (CMS integration
32 lines • 1.74 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.componentMetadataComparator = void 0;
/**
* Returns an array of component metadata from a metadata file.
* To be easily parseable, the properties will be split in separate items of the array.
* @param content Content of a migration metadata files
* @example Array conversion
* ```javascript
* [{ library: '@o3r/demo', placeholders: [{id : 'id1', description: 'string'}, {id : 'id2', description: 'number'}] }]
* ```
* will become :
* ```javascript
* [{ library: '@o3r/demo', placeholders: [{id : 'id1', description: 'string'}] }, { library: '@o3r/demo', placeholders: [{id : 'id2', description: 'number'}] }]
* ```
*/
const getComponentArray = (content) => content.flatMap((component) => component.placeholders?.map((prop) => ({ ...component, placeholders: [prop] })) || []);
const getIdentifier = (component) => `${component.library}#${component.name}` + (component.placeholders?.length ? ` ${component.placeholders[0].id}` : '');
const isRelevantContentType = (contentType) => contentType === 'COMPONENT';
const isMigrationComponentDataMatch = (component, migrationData) => migrationData.libraryName === component.library
&& (!migrationData.componentName || migrationData.componentName === component.name)
&& (!migrationData.placeholderId || component.placeholders?.[0].id === migrationData.placeholderId);
/**
* Comparator used to compare one version of component metadata with another
*/
exports.componentMetadataComparator = {
getArray: getComponentArray,
getIdentifier,
isRelevantContentType,
isMigrationDataMatch: isMigrationComponentDataMatch
};
//# sourceMappingURL=component-metadata-comparison.helper.js.map