refactor: use arrow functions where applicable (#113)
This commit makes use of arrow function expressions wherever applicable. Focus
is put on minimizing the diff instead of optimizing or formatting the code
touched by this commit.
diff --git a/src/ConfigChanges/ConfigChanges.js b/src/ConfigChanges/ConfigChanges.js
index 4feeeb2..bec51e5 100644
--- a/src/ConfigChanges/ConfigChanges.js
+++ b/src/ConfigChanges/ConfigChanges.js
@@ -39,7 +39,7 @@
exports.PlatformMunger = PlatformMunger;
-exports.process = function (plugins_dir, project_dir, platform, platformJson, pluginInfoProvider) {
+exports.process = (plugins_dir, project_dir, platform, platformJson, pluginInfoProvider) => {
var munger = new PlatformMunger(platform, project_dir, platformJson, pluginInfoProvider);
munger.process(plugins_dir);
munger.save_all();
@@ -274,8 +274,8 @@
id = config.id;
}
- config_changes.forEach(function (change) {
- change.xmls.forEach(function (xml) {
+ config_changes.forEach(change => {
+ change.xmls.forEach(xml => {
// 1. stringify each xml
var stringified = (new et.ElementTree(xml)).write({ xml_declaration: false });
// 2. add into munge
@@ -303,13 +303,13 @@
Array.prototype.push.apply(changes, edit_config_changes);
}
- changes.forEach(function (change) {
- change.xmls.forEach(function (xml) {
+ changes.forEach(change => {
+ change.xmls.forEach(xml => {
// 1. stringify each xml
var stringified = (new et.ElementTree(xml)).write({ xml_declaration: false });
// interp vars
if (vars) {
- Object.keys(vars).forEach(function (key) {
+ Object.keys(vars).forEach(key => {
var regExp = new RegExp('\\$' + key, 'g');
stringified = stringified.replace(regExp, vars[key]);
});
@@ -336,7 +336,7 @@
var conflictingParent;
var conflictingPlugin;
- editchanges.forEach(function (editchange) {
+ editchanges.forEach(editchange => {
if (files[editchange.file]) {
var parents = files[editchange.file].parents;
var target = parents[editchange.target];
@@ -409,13 +409,13 @@
var platform_config = self.platformJson.root;
// Uninstallation first
- platform_config.prepare_queue.uninstalled.forEach(function (u) {
+ platform_config.prepare_queue.uninstalled.forEach(u => {
var pluginInfo = self.pluginInfoProvider.get(path.join(plugins_dir, u.plugin));
self.remove_plugin_changes(pluginInfo, u.topLevel);
});
// Now handle installation
- platform_config.prepare_queue.installed.forEach(function (u) {
+ platform_config.prepare_queue.installed.forEach(u => {
var pluginInfo = self.pluginInfoProvider.get(path.join(plugins_dir, u.plugin));
self.add_plugin_changes(pluginInfo, u.vars, u.topLevel, true, u.force);
});
diff --git a/src/ConfigChanges/ConfigKeeper.js b/src/ConfigChanges/ConfigKeeper.js
index 6e1d3f3..7016c26 100644
--- a/src/ConfigChanges/ConfigKeeper.js
+++ b/src/ConfigChanges/ConfigKeeper.js
@@ -54,7 +54,7 @@
ConfigKeeper.prototype.save_all = function ConfigKeeper_save_all () {
var self = this;
- Object.keys(self._cached).forEach(function (fake_path) {
+ Object.keys(self._cached).forEach(fake_path => {
var config_file = self._cached[fake_path];
if (config_file.is_changed) config_file.save();
});
diff --git a/src/ConfigChanges/munge-util.js b/src/ConfigChanges/munge-util.js
index 275eb59..3e89103 100644
--- a/src/ConfigChanges/munge-util.js
+++ b/src/ConfigChanges/munge-util.js
@@ -23,10 +23,8 @@
keys = Array.prototype.slice.call(arguments, 1);
}
- return exports.process_munge(obj, true/* createParents */, function (parentArray, k) {
- var found = _.find(parentArray, function (element) {
- return element.xml === k.xml;
- });
+ return exports.process_munge(obj, true/* createParents */, (parentArray, k) => {
+ var found = _.find(parentArray, element => element.xml === k.xml);
if (found) {
found.after = found.after || k.after;
found.count += k.count;
@@ -44,9 +42,9 @@
keys = Array.prototype.slice.call(arguments, 1);
}
- var result = exports.process_munge(obj, false/* createParents */, function (parentArray, k) {
+ var result = exports.process_munge(obj, false/* createParents */, (parentArray, k) => {
var index = -1;
- var found = _.find(parentArray, function (element) {
+ var found = _.find(parentArray, element => {
index++;
return element.xml === k.xml;
});
@@ -74,10 +72,8 @@
keys = Array.prototype.slice.call(arguments, 1);
}
- return exports.process_munge(obj, false/* createParents? */, function (parentArray, k) {
- return _.find(parentArray, function (element) {
- return element.xml === (k.xml || k);
- });
+ return exports.process_munge(obj, false/* createParents? */, (parentArray, k) => {
+ return _.find(parentArray, element => element.xml === (k.xml || k));
}, keys);
};
diff --git a/src/ConfigParser/ConfigParser.js b/src/ConfigParser/ConfigParser.js
index e64e891..7c34303 100644
--- a/src/ConfigParser/ConfigParser.js
+++ b/src/ConfigParser/ConfigParser.js
@@ -76,11 +76,11 @@
function findElementAttributeValue (attributeName, elems) {
elems = Array.isArray(elems) ? elems : [elems];
- var value = elems.filter(function (elem) {
- return elem.attrib.name.toLowerCase() === attributeName.toLowerCase();
- }).map(function (filteredElems) {
- return filteredElems.attrib.value;
- }).pop();
+ var value = elems.filter(elem =>
+ elem.attrib.name.toLowerCase() === attributeName.toLowerCase()
+ ).map(filteredElems =>
+ filteredElems.attrib.value
+ ).pop();
return value || '';
}
@@ -173,9 +173,9 @@
throw new CordovaError('platform does not exist (received platform: ' + platform + ')');
}
const elems = this.doc.findall('./platform[@name="' + platform + '"]/preference');
- let pref = elems.filter(function (elem) {
- return elem.attrib.name.toLowerCase() === name.toLowerCase();
- }).pop();
+ let pref = elems.filter(elem =>
+ elem.attrib.name.toLowerCase() === name.toLowerCase()
+ ).pop();
if (!pref) {
pref = new et.Element('preference');
@@ -216,7 +216,7 @@
var ret = [];
var staticResources = [];
if (platform) { // platform specific icons
- this.doc.findall('./platform[@name="' + platform + '"]/' + resourceName).forEach(function (elt) {
+ this.doc.findall('./platform[@name="' + platform + '"]/' + resourceName).forEach(elt => {
elt.platform = platform; // mark as platform specific resource
staticResources.push(elt);
});
@@ -225,7 +225,7 @@
staticResources = staticResources.concat(this.doc.findall(resourceName));
// parse resource elements
var that = this;
- staticResources.forEach(function (elt) {
+ staticResources.forEach(elt => {
var res = {};
res.src = elt.attrib.src;
res.target = elt.attrib.target || undefined;
@@ -249,8 +249,8 @@
* @param {number} height Height of resource.
* @return {Resource} Resource object or null if not found.
*/
- ret.getBySize = function (width, height) {
- return ret.filter(function (res) {
+ ret.getBySize = (width, height) => {
+ return ret.filter(res => {
if (!res.width && !res.height) {
return false;
}
@@ -264,16 +264,12 @@
* @param {string} density Density of resource.
* @return {Resource} Resource object or null if not found.
*/
- ret.getByDensity = function (density) {
- return ret.filter(function (res) {
- return res.density === density;
- })[0] || null;
+ ret.getByDensity = density => {
+ return ret.filter(res => res.density === density)[0] || null;
};
/** Returns default icons */
- ret.getDefault = function () {
- return ret.defaultResource;
- };
+ ret.getDefault = () => ret.defaultResource;
return ret;
},
@@ -307,20 +303,18 @@
var fileResources = [];
if (platform) { // platform specific resources
- fileResources = this.doc.findall('./platform[@name="' + platform + '"]/resource-file').map(function (tag) {
- return {
- platform: platform,
- src: tag.attrib.src,
- target: tag.attrib.target,
- versions: tag.attrib.versions,
- deviceTarget: tag.attrib['device-target'],
- arch: tag.attrib.arch
- };
- });
+ fileResources = this.doc.findall('./platform[@name="' + platform + '"]/resource-file').map(tag => ({
+ platform: platform,
+ src: tag.attrib.src,
+ target: tag.attrib.target,
+ versions: tag.attrib.versions,
+ deviceTarget: tag.attrib['device-target'],
+ arch: tag.attrib.arch
+ }));
}
if (includeGlobal) {
- this.doc.findall('resource-file').forEach(function (tag) {
+ this.doc.findall('resource-file').forEach(tag => {
fileResources.push({
platform: platform || null,
src: tag.attrib.src,
@@ -346,7 +340,7 @@
var scriptElements = self.doc.findall('./hook');
if (platforms) {
- platforms.forEach(function (platform) {
+ platforms.forEach(platform => {
scriptElements = scriptElements.concat(self.doc.findall('./platform[@name="' + platform + '"]/hook'));
});
}
@@ -366,11 +360,9 @@
*/
getPluginIdList: function () {
var plugins = this.doc.findall('plugin');
- var result = plugins.map(function (plugin) {
- return plugin.attrib.name;
- });
+ var result = plugins.map(plugin => plugin.attrib.name);
var features = this.doc.findall('feature');
- features.forEach(function (element) {
+ features.forEach(element => {
var idTag = element.find('./param[@name="id"]');
if (idTag) {
result.push(idTag.attrib.value);
@@ -400,14 +392,14 @@
// support arbitrary object as variables source
if (variables && typeof variables === 'object' && !Array.isArray(variables)) {
- variables = Object.keys(variables)
- .map(function (variableName) {
- return { name: variableName, value: variables[variableName] };
- });
+ variables = Object.keys(variables).map(variableName => ({
+ name: variableName,
+ value: variables[variableName]
+ }));
}
if (variables) {
- variables.forEach(function (variable) {
+ variables.forEach(variable => {
el.append(new et.Element('variable', { name: variable.name, value: variable.value }));
});
}
@@ -442,7 +434,7 @@
plugin.spec = pluginElement.attrib.spec || pluginElement.attrib.src || pluginElement.attrib.version;
plugin.variables = {};
var variableElements = pluginElement.findall('variable');
- variableElements.forEach(function (varElement) {
+ variableElements.forEach(varElement => {
var name = varElement.attrib.name;
var value = varElement.attrib.value;
if (name) {
@@ -499,7 +491,7 @@
},
getEngines: function () {
var engines = this.doc.findall('./engine');
- return engines.map(function (engine) {
+ return engines.map(engine => {
var spec = engine.attrib.spec || engine.attrib.version;
return {
name: engine.attrib.name,
@@ -510,7 +502,7 @@
/* Get all the access tags */
getAccesses: function () {
var accesses = this.doc.findall('./access');
- return accesses.map(function (access) {
+ return accesses.map(access => {
var minimum_tls_version = access.attrib['minimum-tls-version']; /* String */
var requires_forward_secrecy = access.attrib['requires-forward-secrecy']; /* Boolean */
var requires_certificate_transparency = access.attrib['requires-certificate-transparency']; /* Boolean */
@@ -534,7 +526,7 @@
/* Get all the allow-navigation tags */
getAllowNavigations: function () {
var allow_navigations = this.doc.findall('./allow-navigation');
- return allow_navigations.map(function (allow_navigation) {
+ return allow_navigations.map(allow_navigation => {
var minimum_tls_version = allow_navigation.attrib['minimum-tls-version']; /* String */
var requires_forward_secrecy = allow_navigation.attrib['requires-forward-secrecy']; /* Boolean */
var requires_certificate_transparency = allow_navigation.attrib['requires-certificate-transparency']; /* Boolean */
@@ -550,18 +542,16 @@
/* Get all the allow-intent tags */
getAllowIntents: function () {
var allow_intents = this.doc.findall('./allow-intent');
- return allow_intents.map(function (allow_intent) {
- return {
- href: allow_intent.attrib.href
- };
- });
+ return allow_intents.map(allow_intent => ({
+ href: allow_intent.attrib.href
+ }));
},
/* Get all edit-config tags */
getEditConfigs: function (platform) {
var platform_edit_configs = this.doc.findall('./platform[@name="' + platform + '"]/edit-config');
var edit_configs = this.doc.findall('edit-config').concat(platform_edit_configs);
- return edit_configs.map(function (tag) {
+ return edit_configs.map(tag => {
var editConfig = {
file: tag.attrib.file,
target: tag.attrib.target,
@@ -578,7 +568,7 @@
var platform_config_files = this.doc.findall('./platform[@name="' + platform + '"]/config-file');
var config_files = this.doc.findall('config-file').concat(platform_config_files);
- return config_files.map(function (tag) {
+ return config_files.map(tag => {
var configFile = {
target: tag.attrib.target,
parent: tag.attrib.parent,
@@ -604,7 +594,7 @@
pluginSrc;
var nodes = featureElement.findall('param');
- nodes.forEach(function (element) {
+ nodes.forEach(element => {
var n = element.attrib.name;
var v = element.attrib.value;
if (n === 'id') {
diff --git a/src/FileUpdater.js b/src/FileUpdater.js
index 6f384b5..b3da56d 100644
--- a/src/FileUpdater.js
+++ b/src/FileUpdater.js
@@ -173,7 +173,7 @@
throw new Error('A target path is required.');
}
- log = log || function () { };
+ log = log || (() => { });
return updatePathInternal(sourcePath, targetPath, options, log);
}
@@ -200,12 +200,12 @@
throw new Error('An object mapping from target paths to source paths is required.');
}
- log = log || function () { };
+ log = log || (() => { });
var updated = false;
// Iterate in sorted order to ensure directories are created before files under them.
- Object.keys(pathMap).sort().forEach(function (targetPath) {
+ Object.keys(pathMap).sort().forEach(targetPath => {
var sourcePath = pathMap[targetPath];
updated = updatePathInternal(sourcePath, targetPath, options, log) || updated;
});
@@ -253,7 +253,7 @@
throw new Error('A target directory path is required.');
}
- log = log || function () { };
+ log = log || (() => { });
var rootDir = (options && options.rootDir) || '';
@@ -272,9 +272,9 @@
}
// Scan the files in each of the source directories.
- var sourceMaps = sourceDirs.map(function (sourceDir) {
- return path.join(rootDir, sourceDir);
- }).map(function (sourcePath) {
+ var sourceMaps = sourceDirs.map(sourceDir =>
+ path.join(rootDir, sourceDir)
+ ).map(sourcePath => {
if (!fs.existsSync(sourcePath)) {
throw new Error('Source directory does not exist: ' + sourcePath);
}
@@ -293,7 +293,7 @@
var updated = false;
// Iterate in sorted order to ensure directories are created before files under them.
- Object.keys(pathMap).sort().forEach(function (subPath) {
+ Object.keys(pathMap).sort().forEach(subPath => {
var entry = pathMap[subPath];
updated = updatePathWithStats(
entry.sourcePath,
@@ -319,7 +319,7 @@
var itemMapped = false;
var items = fs.readdirSync(path.join(rootDir, subDir, relativeDir));
- items.forEach(function (item) {
+ items.forEach(item => {
var relativePath = path.join(relativeDir, item);
if (!matchGlobArray(relativePath, exclude)) {
// Stats obtained here (required at least to know where to recurse in directories)
@@ -349,9 +349,7 @@
}
function matchGlobArray (path, globs) {
- return globs.some(function (elem) {
- return minimatch(path, elem, { dot: true });
- });
+ return globs.some(elem => minimatch(path, elem, { dot: true }));
}
}
@@ -364,8 +362,8 @@
// Entries in later source maps override those in earlier source maps.
// Target stats will be filled in below for targets that exist.
var pathMap = {};
- sourceMaps.forEach(function (sourceMap) {
- Object.keys(sourceMap).forEach(function (sourceSubPath) {
+ sourceMaps.forEach(sourceMap => {
+ Object.keys(sourceMap).forEach(sourceSubPath => {
var sourceEntry = sourceMap[sourceSubPath];
pathMap[sourceSubPath] = {
targetPath: path.join(targetDir, sourceSubPath),
@@ -378,7 +376,7 @@
// Fill in target stats for targets that exist, and create entries
// for targets that don't have any corresponding sources.
- Object.keys(targetMap).forEach(function (subPath) {
+ Object.keys(targetMap).forEach(subPath => {
var entry = pathMap[subPath];
if (entry) {
entry.targetStats = targetMap[subPath].stats;
diff --git a/src/PlatformJson.js b/src/PlatformJson.js
index 0a87983..2a0a515 100644
--- a/src/PlatformJson.js
+++ b/src/PlatformJson.js
@@ -25,7 +25,7 @@
this.root = fix_munge(root || {});
}
-PlatformJson.load = function (plugins_dir, platform) {
+PlatformJson.load = (plugins_dir, platform) => {
var filePath = path.join(plugins_dir, platform + '.json');
var root = null;
if (fs.existsSync(filePath)) {
@@ -91,18 +91,12 @@
PlatformJson.prototype.addPluginMetadata = function (pluginInfo) {
var installedModules = this.root.modules || [];
- var installedPaths = installedModules.map(function (installedModule) {
- return installedModule.file;
- });
+ var installedPaths = installedModules.map(m => m.file);
var modulesToInstall = pluginInfo.getJsModules(this.platform)
- .map(function (module) {
- return new ModuleMetadata(pluginInfo.id, module);
- })
- .filter(function (metadata) {
- // Filter out modules which are already added to metadata
- return !installedPaths.includes(metadata.file);
- });
+ .map(module => new ModuleMetadata(pluginInfo.id, module))
+ // Filter out modules which are already added to metadata
+ .filter(metadata => !installedPaths.includes(metadata.file));
this.root.modules = installedModules.concat(modulesToInstall);
@@ -133,16 +127,12 @@
*/
PlatformJson.prototype.removePluginMetadata = function (pluginInfo) {
var modulesToRemove = pluginInfo.getJsModules(this.platform)
- .map(function (jsModule) {
- return ['plugins', pluginInfo.id, jsModule.src].join('/');
- });
+ .map(jsModule => ['plugins', pluginInfo.id, jsModule.src].join('/'));
var installedModules = this.root.modules || [];
this.root.modules = installedModules
- .filter(function (installedModule) {
- // Leave only those metadatas which 'file' is not in removed modules
- return !modulesToRemove.includes(installedModule.file);
- });
+ // Leave only those metadatas which 'file' is not in removed modules
+ .filter(m => !modulesToRemove.includes(m.file));
if (this.root.plugin_metadata) {
delete this.root.plugin_metadata[pluginInfo.id];
@@ -249,10 +239,10 @@
this.pluginId = pluginId;
if (jsModule.clobbers && jsModule.clobbers.length > 0) {
- this.clobbers = jsModule.clobbers.map(function (o) { return o.target; });
+ this.clobbers = jsModule.clobbers.map(o => o.target);
}
if (jsModule.merges && jsModule.merges.length > 0) {
- this.merges = jsModule.merges.map(function (o) { return o.target; });
+ this.merges = jsModule.merges.map(o => o.target);
}
if (jsModule.runs) {
this.runs = true;
diff --git a/src/PluginInfo/PluginInfo.js b/src/PluginInfo/PluginInfo.js
index c4617dd..7a467cb 100644
--- a/src/PluginInfo/PluginInfo.js
+++ b/src/PluginInfo/PluginInfo.js
@@ -43,7 +43,7 @@
self.getPreferences = getPreferences;
function getPreferences (platform) {
return _getTags(self._et, 'preference', platform, _parsePreference)
- .reduce(function (preferences, pref) {
+ .reduce((preferences, pref) => {
preferences[pref.preference] = pref.default;
return preferences;
}, {});
@@ -165,7 +165,7 @@
self._et,
'info',
platform,
- function (elem) { return elem.text; }
+ elem => elem.text
);
// Filter out any undefined or empty strings.
infos = infos.filter(Boolean);
@@ -198,14 +198,12 @@
// <header-file src="CDVFoo.h" />
self.getHeaderFiles = getHeaderFiles;
function getHeaderFiles (platform) {
- var headerFiles = _getTagsInPlatform(self._et, 'header-file', platform, function (tag) {
- return {
- itemType: 'header-file',
- src: tag.attrib.src,
- targetDir: tag.attrib['target-dir'],
- type: tag.attrib.type
- };
- });
+ var headerFiles = _getTagsInPlatform(self._et, 'header-file', platform, tag => ({
+ itemType: 'header-file',
+ src: tag.attrib.src,
+ targetDir: tag.attrib['target-dir'],
+ type: tag.attrib.type
+ }));
return headerFiles;
}
@@ -214,17 +212,15 @@
// <resource-file src="FooPluginStrings.xml" target="res/values/FooPluginStrings.xml" device-target="win" arch="x86" versions=">=8.1" />
self.getResourceFiles = getResourceFiles;
function getResourceFiles (platform) {
- var resourceFiles = _getTagsInPlatform(self._et, 'resource-file', platform, function (tag) {
- return {
- itemType: 'resource-file',
- src: tag.attrib.src,
- target: tag.attrib.target,
- versions: tag.attrib.versions,
- deviceTarget: tag.attrib['device-target'],
- arch: tag.attrib.arch,
- reference: tag.attrib.reference
- };
- });
+ var resourceFiles = _getTagsInPlatform(self._et, 'resource-file', platform, tag => ({
+ itemType: 'resource-file',
+ src: tag.attrib.src,
+ target: tag.attrib.target,
+ versions: tag.attrib.versions,
+ deviceTarget: tag.attrib['device-target'],
+ arch: tag.attrib.arch,
+ reference: tag.attrib.reference
+ }));
return resourceFiles;
}
@@ -233,16 +229,14 @@
// <lib-file src="src/BlackBerry10/native/device/libfoo.so" arch="device" />
self.getLibFiles = getLibFiles;
function getLibFiles (platform) {
- var libFiles = _getTagsInPlatform(self._et, 'lib-file', platform, function (tag) {
- return {
- itemType: 'lib-file',
- src: tag.attrib.src,
- arch: tag.attrib.arch,
- Include: tag.attrib.Include,
- versions: tag.attrib.versions,
- deviceTarget: tag.attrib['device-target'] || tag.attrib.target
- };
- });
+ var libFiles = _getTagsInPlatform(self._et, 'lib-file', platform, tag => ({
+ itemType: 'lib-file',
+ src: tag.attrib.src,
+ arch: tag.attrib.arch,
+ Include: tag.attrib.Include,
+ versions: tag.attrib.versions,
+ deviceTarget: tag.attrib['device-target'] || tag.attrib.target
+ }));
return libFiles;
}
@@ -264,30 +258,28 @@
// </podspec>
self.getPodSpecs = getPodSpecs;
function getPodSpecs (platform) {
- var podSpecs = _getTagsInPlatform(self._et, 'podspec', platform, function (tag) {
+ var podSpecs = _getTagsInPlatform(self._et, 'podspec', platform, tag => {
var declarations = null;
var sources = null;
var libraries = null;
var config = tag.find('config');
var pods = tag.find('pods');
if (config != null) {
- sources = config.findall('source').map(function (t) {
- return {
- url: t.attrib.url
- };
- }).reduce(function (acc, val) {
+ sources = config.findall('source').map(t => ({
+ url: t.attrib.url
+ })).reduce((acc, val) => {
return Object.assign({}, acc, { [val.url]: { source: val.url } });
}, {});
}
if (pods != null) {
- declarations = Object.keys(pods.attrib).reduce(function (acc, key) {
+ declarations = Object.keys(pods.attrib).reduce((acc, key) => {
return pods.attrib[key] === undefined ? acc : Object.assign({}, acc, { [key]: pods.attrib[key] });
}, {});
- libraries = pods.findall('pod').map(function (t) {
- return Object.keys(t.attrib).reduce(function (acc, key) {
+ libraries = pods.findall('pod').map(t => {
+ return Object.keys(t.attrib).reduce((acc, key) => {
return t.attrib[key] === undefined ? acc : Object.assign({}, acc, { [key]: t.attrib[key] });
}, {});
- }).reduce(function (acc, val) {
+ }).reduce((acc, val) => {
return Object.assign({}, acc, { [val.name]: val });
}, {});
}
@@ -308,7 +300,7 @@
var scriptElements = self._et.findall('./hook');
if (platforms) {
- platforms.forEach(function (platform) {
+ platforms.forEach(platform => {
scriptElements = scriptElements.concat(self._et.findall('./platform[@name="' + platform + '"]/hook'));
});
}
@@ -331,8 +323,8 @@
itemType: 'js-module',
name: tag.attrib.name,
src: tag.attrib.src,
- clobbers: tag.findall('clobbers').map(function (tag) { return { target: tag.attrib.target }; }),
- merges: tag.findall('merges').map(function (tag) { return { target: tag.attrib.target }; }),
+ clobbers: tag.findall('clobbers').map(tag => ({ target: tag.attrib.target })),
+ merges: tag.findall('merges').map(tag => ({ target: tag.attrib.target })),
runs: tag.findall('runs').length > 0
};
@@ -340,30 +332,26 @@
}
self.getEngines = function () {
- return self._et.findall('engines/engine').map(function (n) {
- return {
- name: n.attrib.name,
- version: n.attrib.version,
- platform: n.attrib.platform,
- scriptSrc: n.attrib.scriptSrc
- };
- });
+ return self._et.findall('engines/engine').map(n => ({
+ name: n.attrib.name,
+ version: n.attrib.version,
+ platform: n.attrib.platform,
+ scriptSrc: n.attrib.scriptSrc
+ }));
};
self.getPlatforms = function () {
- return self._et.findall('platform').map(function (n) {
- return { name: n.attrib.name };
- });
+ return self._et.findall('platform').map(n => ({
+ name: n.attrib.name
+ }));
};
self.getPlatformsArray = function () {
- return self._et.findall('platform').map(function (n) {
- return n.attrib.name;
- });
+ return self._et.findall('platform').map(n => n.attrib.name);
};
self.getFrameworks = function (platform, options) {
- return _getTags(self._et, 'framework', platform, function (el) {
+ return _getTags(self._et, 'framework', platform, el => {
var src = el.attrib.src;
if (options) {
var vars = options.cli_variables || {};
@@ -375,7 +363,7 @@
var regExp;
// Iterate over plugin variables.
// Replace them in framework src if they exist
- Object.keys(vars).forEach(function (name) {
+ Object.keys(vars).forEach(name => {
if (vars[name]) {
regExp = new RegExp('\\$' + name, 'g');
src = src.replace(regExp, vars[name]);
@@ -437,9 +425,9 @@
self.keywords = pelem.findtext('keywords');
self.info = pelem.findtext('info');
if (self.keywords) {
- self.keywords = self.keywords.split(',').map(function (s) { return s.trim(); });
+ self.keywords = self.keywords.split(',').map(s => s.trim());
}
- self.getKeywordsAndPlatforms = function () {
+ self.getKeywordsAndPlatforms = () => {
var ret = self.keywords || [];
return ret.concat('ecosystem:cordova').concat(addCordova(self.getPlatformsArray()));
};
@@ -448,9 +436,7 @@
// Helper function used to prefix every element of an array with cordova-
// Useful when we want to modify platforms to be cordova-platform
function addCordova (someArray) {
- var newArray = someArray.map(function (element) {
- return 'cordova-' + element;
- });
+ var newArray = someArray.map(element => 'cordova-' + element);
return newArray;
}
@@ -488,7 +474,7 @@
module.exports = PluginInfo;
// Backwards compat:
PluginInfo.PluginInfo = PluginInfo;
-PluginInfo.loadPluginsDir = function (dir) {
+PluginInfo.loadPluginsDir = dir => {
var PluginInfoProvider = require('./PluginInfoProvider');
return new PluginInfoProvider().getAllWithinSearchPath(dir);
};
diff --git a/src/PluginManager.js b/src/PluginManager.js
index 6a4be32..72f2151 100644
--- a/src/PluginManager.js
+++ b/src/PluginManager.js
@@ -54,7 +54,7 @@
* @param {IDEProject} ideProject The IDE project to add/remove plugin changes to/from
* @returns new PluginManager instance
*/
-PluginManager.get = function (platform, locations, ideProject) {
+PluginManager.get = (platform, locations, ideProject) => {
return new PluginManager(platform, locations, ideProject);
};
@@ -96,7 +96,7 @@
.concat(plugin.getAssets(this.platform))
.concat(plugin.getJsModules(this.platform))
// ... put them into stack ...
- .forEach(function (item) {
+ .forEach(item => {
var installer = self.project.getInstaller(item.itemType);
var uninstaller = self.project.getUninstaller(item.itemType);
var actionArgs = [item, plugin, self.project, options];
@@ -112,7 +112,7 @@
// ... and run through the action stack
return actions.process(this.platform)
- .then(function () {
+ .then(() => {
if (self.project.write) {
self.project.write();
}
diff --git a/src/superspawn.js b/src/superspawn.js
index 7c999a1..a87d4ef 100644
--- a/src/superspawn.js
+++ b/src/superspawn.js
@@ -57,7 +57,7 @@
* 'stderr': ...
* }
*/
-exports.spawn = function (cmd, args, opts) {
+exports.spawn = (cmd, args, opts) => {
args = args || [];
opts = opts || {};
var spawnOpts = {};
@@ -101,7 +101,7 @@
if (child.stdout) {
child.stdout.setEncoding('utf8');
- child.stdout.on('data', function (data) {
+ child.stdout.on('data', data => {
capturedOut += data;
d.notify({ stdout: data });
});
@@ -109,7 +109,7 @@
if (child.stderr) {
child.stderr.setEncoding('utf8');
- child.stderr.on('data', function (data) {
+ child.stderr.on('data', data => {
capturedErr += data;
d.notify({ stderr: data });
});
@@ -147,7 +147,7 @@
return d.promise;
};
-exports.maybeSpawn = function (cmd, args, opts) {
+exports.maybeSpawn = (cmd, args, opts) => {
if (fs.existsSync(cmd)) {
return exports.spawn(cmd, args, opts);
}
diff --git a/src/util/xml-helpers.js b/src/util/xml-helpers.js
index ad2fdb3..6133090 100644
--- a/src/util/xml-helpers.js
+++ b/src/util/xml-helpers.js
@@ -70,7 +70,7 @@
if (!parent) return false;
}
- nodes.forEach(function (node) {
+ nodes.forEach(node => {
// check if child is unique first
if (uniqueChild(node, parent)) {
var children = parent.getchildren();
@@ -93,7 +93,7 @@
// saves the attributes of the original xml before making changes
xml.oldAttrib = _.extend({}, target.attrib);
- nodes.forEach(function (node) {
+ nodes.forEach(node => {
var attributes = node.attrib;
for (var attribute in attributes) {
target.attrib[attribute] = node.attrib[attribute];
@@ -119,7 +119,7 @@
}
// add new attributes to target
- nodes.forEach(function (node) {
+ nodes.forEach(node => {
var attributes = node.attrib;
for (var attribute in attributes) {
target.attrib[attribute] = node.attrib[attribute];
@@ -134,7 +134,7 @@
var parent = module.exports.resolveParent(doc, selector);
if (!parent) return false;
- nodes.forEach(function (node) {
+ nodes.forEach(node => {
var matchingKid = findChild(node, parent);
if (matchingKid !== undefined) {
// stupid elementtree takes an index argument it doesn't use
@@ -162,7 +162,7 @@
var target = module.exports.resolveParent(doc, selector);
if (!target) return false;
- nodes.forEach(function (node) {
+ nodes.forEach(node => {
var attributes = node.attrib;
for (var attribute in attributes) {
if (target.attrib[attribute]) {
@@ -218,10 +218,10 @@
// insert an element C, and the rule is that the order of children has to be
// As, Bs, Cs. After will be equal to "C;B;A".
function findInsertIdx (children, after) {
- var childrenTags = children.map(function (child) { return child.tag; });
+ var childrenTags = children.map(child => child.tag);
var afters = after.split(';');
- var afterIndexes = afters.map(function (current) { return childrenTags.lastIndexOf(current); });
- var foundIndex = _.find(afterIndexes, function (index) { return index !== -1; });
+ var afterIndexes = afters.map(current => childrenTags.lastIndexOf(current));
+ var foundIndex = _.find(afterIndexes, index => index !== -1);
// add to the beginning if no matching nodes are found
return typeof foundIndex === 'undefined' ? 0 : foundIndex + 1;
@@ -234,7 +234,7 @@
if (BLACKLIST.includes(src.tag)) return;
// Handle attributes
- Object.getOwnPropertyNames(src.attrib).forEach(function (attribute) {
+ Object.getOwnPropertyNames(src.attrib).forEach(attribute => {
if (clobber || !dest.attrib[attribute]) {
dest.attrib[attribute] = src.attrib[attribute];
}
@@ -248,7 +248,7 @@
// Handle platform
if (platform) {
- src.findall('platform[@name="' + platform + '"]').forEach(function (platformElement) {
+ src.findall('platform[@name="' + platform + '"]').forEach(platformElement => {
platformElement.getchildren().forEach(mergeChild);
});
}
@@ -274,9 +274,9 @@
} else {
// Check for an exact match and if you find one don't add
var mergeCandidates = dest.findall(query)
- .filter(function (foundChild) {
- return foundChild && textMatch(srcChild, foundChild) && attribMatch(srcChild, foundChild);
- });
+ .filter(foundChild =>
+ foundChild && textMatch(srcChild, foundChild) && attribMatch(srcChild, foundChild)
+ );
if (mergeCandidates.length > 0) {
destChild = mergeCandidates[0];
@@ -291,13 +291,13 @@
function removeDuplicatePreferences (xml) {
// reduce preference tags to a hashtable to remove dupes
- var prefHash = xml.findall('preference[@name][@value]').reduce(function (previousValue, currentValue) {
+ var prefHash = xml.findall('preference[@name][@value]').reduce((previousValue, currentValue) => {
previousValue[currentValue.attrib.name] = currentValue.attrib.value;
return previousValue;
}, {});
// remove all preferences
- xml.findall('preference[@name][@value]').forEach(function (pref) {
+ xml.findall('preference[@name][@value]').forEach(pref => {
xml.remove(pref);
});