Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Eliminate duplicated src-dest file mappings in task configurations due to multiple html files #324

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion lib/configwriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,34 @@ var deepMerge = function(origCfg, cfg) {
var outCfg = origCfg;

if (origCfg.files && cfg.files) {
outCfg.files = _.union(origCfg.files, cfg.files);
// outCfg.files = _.union(origCfg.files, cfg.files);
// Eliminate duplicated or conflicted file mappings
var origFiles = origCfg.files.slice();
_.each(cfg.files, function(fm) {
// Loop for file mappings of new configuration
var matchFm = _.find(origFiles, function(origFm) {
// Loop for file mappings of original configuration
if (fm.dest === origFm.dest) {
// A match is found: same destination for two file mappings
if (!_.isEqual(fm, origFm)) {
// Conflict destination with different sources. Throw an error
var util = require('util');
var inspect = function (obj) {
return util.inspect(obj, false, 4, true);
};
throw new Error('Conflict destination with different sources:\n ' + inspect(origFm) + '\n ' + inspect(fm));
}
// Stop looping when a match is found
return true;
}
});
// End of loop for file mappings of original configuration
if (_.isUndefined(matchFm)) {
// No match. A new file mapping should be added
outCfg.files.push(fm);
}
});
// End of loop for file mappings of new configuration
} else if (cfg.files) {
outCfg.files = cfg.files;
}
Expand Down