Skip to content

Commit

Permalink
Added option to filter out duplicated entry files - allows for orderi…
Browse files Browse the repository at this point in the history
…ng output files (#30)

Co-authored-by: Maciej Panecki <[email protected]>
  • Loading branch information
panec and maciej-panecki-wttech authored May 22, 2020
1 parent fde80ea commit 3d613d0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
15 changes: 14 additions & 1 deletion lib/clientlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
1 change: 1 addition & 0 deletions test/clientlib.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
Expand Down

0 comments on commit 3d613d0

Please sign in to comment.