diff --git a/lib/clientlib.js b/lib/clientlib.js index 1255069..ff5affe 100644 --- a/lib/clientlib.js +++ b/lib/clientlib.js @@ -381,12 +381,25 @@ function normalizeAssets(clientLibPath, assets) { } }); + mapping = removeDuplicates(mapping, 'src'); + asset.files = mapping; }); return list; } +/** + * Removes duplicates in array of Objects based on the provided key + * From: https://firstclassjs.com/remove-duplicate-objects-from-javascript-array-how-to-performance-comparison/ + * @param {Array} array - array of Objects that will be filtered + * @param {String} key - key that will be used for filter comparison + */ +function removeDuplicates(array, key) { + let lookup = new Set(); + return array.filter(obj => !lookup.has(obj[key]) && lookup.add(obj[key])); +} + /** * Process the given clientlib configuration object. * @param {ClientLibItem} item - clientlib configuration object @@ -409,7 +422,7 @@ function processItem(item, options, processDone) { // create clientlib directory fse.mkdirsSync(clientLibPath); - var serializationFormat = (item.serializationFormat === SERIALIZATION_FORMAT_XML) ? SERIALIZATION_FORMAT_XML + var serializationFormat = (item.serializationFormat === SERIALIZATION_FORMAT_XML) ? SERIALIZATION_FORMAT_XML : (item.serializationFormat === SERIALIZATION_FORMAT_SLING_XML) ? SERIALIZATION_FORMAT_SLING_XML : SERIALIZATION_FORMAT_JSON; diff --git a/package-lock.json b/package-lock.json index da3e2b7..91a2d10 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "aem-clientlib-generator", - "version": "1.6.0", + "version": "1.7.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 2663d27..fc65bbf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aem-clientlib-generator", - "version": "1.7.2", + "version": "1.7.3", "description": "Creates configuration files for AEM ClientLibs and synchronizes assets.", "author": { "name": "pro!vision GmbH", diff --git a/test/clientlib.config.js b/test/clientlib.config.js index 127c077..1d211fb 100644 --- a/test/clientlib.config.js +++ b/test/clientlib.config.js @@ -99,6 +99,7 @@ module.exports = { flatten: false, // remove this option if you like a flat list of files in your clientlib cwd: "src/frontend/js/", // change working directory (will be stripped from destination) files: [ + "**/app.js", // this file should be included only once "**/*.js", // match all js files recursively "**/*.js.map" ]