mirror of
https://github.com/apache/cordova-android.git
synced 2026-04-04 00:02:03 +08:00
CB-11138 Bump cordova-common to 1.2.0
This commit is contained in:
29
node_modules/cordova-common/src/util/xml-helpers.js
generated
vendored
29
node_modules/cordova-common/src/util/xml-helpers.js
generated
vendored
@@ -194,7 +194,7 @@ function findInsertIdx(children, after) {
|
||||
}
|
||||
|
||||
var BLACKLIST = ['platform', 'feature','plugin','engine'];
|
||||
var SINGLETONS = ['content', 'author'];
|
||||
var SINGLETONS = ['content', 'author', 'name'];
|
||||
function mergeXml(src, dest, platform, clobber) {
|
||||
// Do nothing for blacklisted tags.
|
||||
if (BLACKLIST.indexOf(src.tag) != -1) return;
|
||||
@@ -209,6 +209,9 @@ function mergeXml(src, dest, platform, clobber) {
|
||||
if (src.text && (clobber || !dest.text)) {
|
||||
dest.text = src.text;
|
||||
}
|
||||
//Handle children
|
||||
src.getchildren().forEach(mergeChild);
|
||||
|
||||
//Handle platform
|
||||
if (platform) {
|
||||
src.findall('platform[@name="' + platform + '"]').forEach(function (platformElement) {
|
||||
@@ -216,8 +219,8 @@ function mergeXml(src, dest, platform, clobber) {
|
||||
});
|
||||
}
|
||||
|
||||
//Handle children
|
||||
src.getchildren().forEach(mergeChild);
|
||||
//Handle duplicate preference tags (by name attribute)
|
||||
removeDuplicatePreferences(dest);
|
||||
|
||||
function mergeChild (srcChild) {
|
||||
var srcTag = srcChild.tag,
|
||||
@@ -254,6 +257,26 @@ function mergeXml(src, dest, platform, clobber) {
|
||||
dest.append(destChild);
|
||||
}
|
||||
}
|
||||
|
||||
function removeDuplicatePreferences(xml) {
|
||||
// reduce preference tags to a hashtable to remove dupes
|
||||
var prefHash = xml.findall('preference[@name][@value]').reduce(function(previousValue, currentValue) {
|
||||
previousValue[ currentValue.attrib.name ] = currentValue.attrib.value;
|
||||
return previousValue;
|
||||
}, {});
|
||||
|
||||
// remove all preferences
|
||||
xml.findall('preference[@name][@value]').forEach(function(pref) {
|
||||
xml.remove(pref);
|
||||
});
|
||||
|
||||
// write new preferences
|
||||
Object.keys(prefHash).forEach(function(key, index) {
|
||||
var element = et.SubElement(xml, 'preference');
|
||||
element.set('name', key);
|
||||
element.set('value', this[key]);
|
||||
}, prefHash);
|
||||
}
|
||||
}
|
||||
|
||||
// Expose for testing.
|
||||
|
||||
Reference in New Issue
Block a user