CB-8978: Add option to get resource-file from root
authorDarryl Pogue <darryl@dpogue.ca>
Fri, 21 Apr 2017 06:45:12 +0000 (23:45 -0700)
committerSteve Gill <stevengill97@gmail.com>
Tue, 25 Apr 2017 21:00:24 +0000 (14:00 -0700)
This will be needed for cleaning the resource-file targets, since they
are at the top level of the platform's config.xml.

 This closes #547

spec/ConfigParser/ConfigParser.spec.js
spec/fixtures/test-config.xml
src/ConfigParser/ConfigParser.js

index cfb125b..034f3d7 100644 (file)
@@ -313,6 +313,10 @@ describe('config.xml parser', function () {
                 expect(cfg.getFileResources('android').every(hasTargetPropertyDefined)).toBeTruthy();
                 expect(cfg.getFileResources('windows').every(hasArchPropertyDefined)).toBeTruthy();
             });
+
+            it('should find resources at the top level', function() {
+                expect(cfg.getFileResources('android', true).length).toBe(3);
+            });
         });
     });
 });
index 625d218..7969d64 100644 (file)
         <icon src="res/windows/logo-small.scale-400_48.png" height="48" target="logo.png"/>
         <resource-file src="windowsconfig.json" target="windowsconfig.json" arch="x86" device-target="all" />
     </platform>
+    <resource-file src="top-level-file.txt" target="toplevel.txt" />
     <plugin name="org.apache.cordova.pluginwithvars">
         <variable name="var" value="varvalue" />
     </plugin>
index cd718de..0b02b4c 100644 (file)
@@ -269,9 +269,11 @@ ConfigParser.prototype = {
     /**
      * Returns all resource-files for a specific platform.
      * @param  {string} platform Platform name
+     * @param  {boolean} includeGlobal Whether to return resource-files at the
+     *                                 root level.
      * @return {Resource[]}      Array of resource file objects.
      */
-    getFileResources: function(platform) {
+    getFileResources: function(platform, includeGlobal) {
         var fileResources = [];
 
         if (platform) { // platform specific resources
@@ -287,6 +289,19 @@ ConfigParser.prototype = {
             });
         }
 
+        if (includeGlobal) {
+            this.doc.findall('resource-file').forEach(function(tag) {
+                fileResources.push({
+                    platform: platform || null,
+                    src: tag.attrib.src,
+                    target: tag.attrib.target,
+                    versions: tag.attrib.versions,
+                    deviceTarget: tag.attrib['device-target'],
+                    arch: tag.attrib.arch
+                });
+            });
+        }
+
         return fileResources;
     },