Skip to content

Commit

Permalink
make _getTags* private methods
Browse files Browse the repository at this point in the history
  • Loading branch information
raphinesse committed Jan 8, 2020
1 parent f51c277 commit a5e4bff
Showing 1 changed file with 44 additions and 29 deletions.
73 changes: 44 additions & 29 deletions src/PluginInfo/PluginInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class PluginInfo {
* @return {Object} { key : default | null}
*/
getPreferences (platform) {
return _getTags(this._et, 'preference', platform).map(({ attrib }) => ({
return this._getTags('preference', platform).map(({ attrib }) => ({
[attrib.name.toUpperCase()]: attrib.default || null
}))
.reduce((acc, pref) => Object.assign(acc, pref), {});
Expand All @@ -76,7 +76,7 @@ class PluginInfo {
* @param {string} platform
*/
getAssets (platform) {
return _getTags(this._et, 'asset', platform).map(({ attrib }) => {
return this._getTags('asset', platform).map(({ attrib }) => {
const src = attrib.src;
const target = attrib.target;

Expand All @@ -100,7 +100,7 @@ class PluginInfo {
* @param {string} platform
*/
getDependencies (platform) {
return _getTags(this._et, 'dependency', platform).map(({ attrib }) => {
return this._getTags('dependency', platform).map(({ attrib }) => {
if (!attrib.id) {
throw new CordovaError(`<dependency> tag is missing id attribute in ${this.filepath}`);
}
Expand All @@ -122,7 +122,7 @@ class PluginInfo {
* @param {string} platform
*/
getConfigFiles (platform) {
return _getTags(this._et, 'config-file', platform).map(tag => ({
return this._getTags('config-file', platform).map(tag => ({
target: tag.attrib.target,
parent: tag.attrib.parent,
after: tag.attrib.after,
Expand All @@ -139,7 +139,7 @@ class PluginInfo {
* @param {string} platform
*/
getEditConfigs (platform) {
return _getTags(this._et, 'edit-config', platform).map(tag => ({
return this._getTags('edit-config', platform).map(tag => ({
file: tag.attrib.file,
target: tag.attrib.target,
mode: tag.attrib.mode,
Expand All @@ -154,7 +154,7 @@ class PluginInfo {
*/
// TODO (kamrik): Do we ever use <info> under <platform>? Example wanted.
getInfo (platform) {
return _getTags(this._et, 'info', platform).map(elem => elem.text)
return this._getTags('info', platform).map(elem => elem.text)
// Filter out any undefined or empty strings.
.filter(Boolean);
}
Expand All @@ -169,7 +169,7 @@ class PluginInfo {
* @param {string} platform
*/
getSourceFiles (platform) {
return _getTagsInPlatform(this._et, 'source-file', platform).map(({ attrib }) => ({
return this._getTagsInPlatform('source-file', platform).map(({ attrib }) => ({
itemType: 'source-file',
src: attrib.src,
framework: isStrTrue(attrib.framework),
Expand All @@ -187,7 +187,7 @@ class PluginInfo {
* @param {string} platform
*/
getHeaderFiles (platform) {
return _getTagsInPlatform(this._et, 'header-file', platform).map(({ attrib }) => ({
return this._getTagsInPlatform('header-file', platform).map(({ attrib }) => ({
itemType: 'header-file',
src: attrib.src,
targetDir: attrib['target-dir'],
Expand All @@ -210,7 +210,7 @@ class PluginInfo {
* @param {string} platform
*/
getResourceFiles (platform) {
return _getTagsInPlatform(this._et, 'resource-file', platform).map(({ attrib }) => ({
return this._getTagsInPlatform('resource-file', platform).map(({ attrib }) => ({
itemType: 'resource-file',
src: attrib.src,
target: attrib.target,
Expand All @@ -230,7 +230,7 @@ class PluginInfo {
* @param {string} platform
*/
getLibFiles (platform) {
return _getTagsInPlatform(this._et, 'lib-file', platform).map(({ attrib }) => ({
return this._getTagsInPlatform('lib-file', platform).map(({ attrib }) => ({
itemType: 'lib-file',
src: attrib.src,
arch: attrib.arch,
Expand Down Expand Up @@ -262,7 +262,7 @@ class PluginInfo {
* @param {string} platform
*/
getPodSpecs (platform) {
return _getTagsInPlatform(this._et, 'podspec', platform).map(tag => {
return this._getTagsInPlatform('podspec', platform).map(tag => {
const config = tag.find('config');
const pods = tag.find('pods');

Expand Down Expand Up @@ -290,7 +290,7 @@ class PluginInfo {
* @param {string} platforms
*/
getHookScripts (hook, platforms) {
return _getTags(this._et, 'hook', platforms)
return this._getTags('hook', platforms)
.filter(({ attrib }) =>
attrib.src && attrib.type &&
attrib.type.toLowerCase() === hook
Expand All @@ -303,7 +303,7 @@ class PluginInfo {
* @param {string} platform
*/
getJsModules (platform) {
return _getTags(this._et, 'js-module', platform).map(tag => ({
return this._getTags('js-module', platform).map(tag => ({
itemType: 'js-module',
name: tag.attrib.name,
src: tag.attrib.src,
Expand Down Expand Up @@ -346,7 +346,7 @@ class PluginInfo {
// Replaces plugin variables in s if they exist
const expandVars = s => varExpansions.reduce((acc, fn) => fn(acc), s);

return _getTags(this._et, 'framework', platform).map(({ attrib }) => ({
return this._getTags('framework', platform).map(({ attrib }) => ({
itemType: 'framework',
type: attrib.type,
parent: attrib.parent,
Expand Down Expand Up @@ -380,24 +380,39 @@ class PluginInfo {
.concat('ecosystem:cordova')
.concat(this.getPlatformsArray().map(p => `cordova-${p}`));
}
}

// Helper function used by most of the getSomething methods of PluginInfo.
// Get all elements of a given name. Both in root and in platform sections
// for the given platform.
function _getTags (pelem, tag, platform) {
return pelem.findall(tag)
.concat(_getTagsInPlatform(pelem, tag, platform));
}
/**
* Helper method used by most of the getSomething methods of PluginInfo.
*
* Get all elements of a given name. Both in root and in platform sections
* for the given platform.
*
* @private
*
* @param {string} tag
* @param {string|string[]} platform
*/
_getTags (tag, platform) {
return this._et.findall(tag)
.concat(this._getTagsInPlatform(tag, platform));
}

// Same as _getTags() but only looks inside a platform section.
function _getTagsInPlatform (pelem, tag, platform) {
const platforms = [].concat(platform);
/**
* Same as _getTags() but only looks inside a platform section.
*
* @private
*
* @param {string} tag
* @param {string|string[]} platform
*/
_getTagsInPlatform (tag, platform) {
const platforms = [].concat(platform);

return [].concat(...platforms.map(platform => {
const platformTag = pelem.find(`./platform[@name="${platform}"]`);
return platformTag ? platformTag.findall(tag) : [];
}));
return [].concat(...platforms.map(platform => {
const platformTag = this._et.find(`./platform[@name="${platform}"]`);
return platformTag ? platformTag.findall(tag) : [];
}));
}
}

// Check if x is a string 'true'.
Expand Down

0 comments on commit a5e4bff

Please sign in to comment.