add method getPodSpecs and add related tests
authorknaito <knaito@asial.co.jp>
Wed, 29 Aug 2018 06:51:25 +0000 (15:51 +0900)
committerDarryl Pogue <dvpdiner2@gmail.com>
Thu, 1 Nov 2018 14:58:26 +0000 (07:58 -0700)
spec/PluginInfo/PluginInfo.spec.js
spec/fixtures/plugins/org.test.plugins.withcocoapods/plugin.xml [new file with mode: 0644]
src/PluginInfo/PluginInfo.js

index 5fdaf87..ba20526 100644 (file)
@@ -70,4 +70,18 @@ describe('PluginInfo', function () {
         var result = p.getFrameworks('android', {});
         expect(result[2].src).toBe('com.google.firebase:firebase-messaging:11.0.1');
     });
+
+    it('Test 005: read podspec', function () {
+        var p = new PluginInfo(path.join(pluginsDir, 'org.test.plugins.withcocoapods'));
+        var result = p.getPodSpecs('ios');
+        expect(result.length).toBe(1);
+        var podSpec = result[0];
+        expect(Object.keys(podSpec.declarations).length).toBe(2);
+        expect(Object.keys(podSpec.sources).length).toBe(1);
+        expect(Object.keys(podSpec.libraries).length).toBe(4);
+        expect(podSpec.declarations['use-frameworks']).toBe('true');
+        expect(podSpec.sources['https://github.com/CocoaPods/Specs.git'].source).toBe('https://github.com/CocoaPods/Specs.git');
+        expect(podSpec.libraries['AFNetworking'].spec).toBe('~> 3.2');
+        expect(podSpec.libraries['Eureka']['swift-version']).toBe('4.1');
+    });
 });
diff --git a/spec/fixtures/plugins/org.test.plugins.withcocoapods/plugin.xml b/spec/fixtures/plugins/org.test.plugins.withcocoapods/plugin.xml
new file mode 100644 (file)
index 0000000..2f6b623
--- /dev/null
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+-->
+
+<plugin xmlns="http://cordova.apache.org/ns/plugins/1.0"
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    id="org.test.plugins.withcocoapods"
+    version="0.6.0">
+
+    <!-- new requirement: NO SPACES -->
+    <name>withcocoapods</name>
+    <!-- These are going to be required by plugman-registry -->
+    <description>my description</description>
+    <author>Ken Naito</author>
+    <keywords>dummy,plugin,cocoapods</keywords>
+    <license>BSD</license>
+    <!-- end plugman-registry requirements -->
+
+    <!-- ios -->
+    <platform name="ios">
+      <podspec>
+        <config>
+          <source url="https://github.com/CocoaPods/Specs.git"/>
+        </config>
+        <pods use-frameworks="true" inhibit-all-warnings="true">
+          <pod name="AFNetworking" spec="~> 3.2" />
+          <pod name="SDWebImage" />
+          <pod name="Eureka" swift-version="4.1" />
+          <pod name="AcknowList" />
+        </pods>
+      </podspec>
+    </platform>
+</plugin>
index 8355f10..0550cb1 100644 (file)
@@ -246,6 +246,60 @@ function PluginInfo (dirname) {
         return libFiles;
     }
 
+    // <podspec>
+    // Example:
+    // <podspec>
+    //   <config>
+    //     <source url="https://github.com/brightcove/BrightcoveSpecs.git" />
+    //     <source url="https://github.com/CocoaPods/Specs.git"/>
+    //   </config>
+    //   <pods>
+    //   <pod name="PromiseKit" />
+    //   <pod name="Foobar1" spec="~> 2.0.0" />
+    //   <pod name="Foobar2" git="git@github.com:hoge/foobar1.git" />
+    //     <pod name="Foobar3" git="git@github.com:hoge/foobar2.git" branch="next" />
+    //     <pod name="Foobar4" swift-version="4.1" />
+    //     <pod name="Foobar5" swift-version="3.0" />
+    //   </pods>
+    // </podspec>
+    self.getPodSpecs = getPodSpecs;
+    function getPodSpecs (platform) {
+        var podSpecs = _getTagsInPlatform(self._et, 'podspec', platform, function (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) {
+                    return Object.assign({}, acc, {[val.url]: { source: val.url }});
+                }, {});
+            }
+            if (pods != null) {
+                declarations = Object.keys(pods.attrib).reduce(function (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) {
+                        return t.attrib[key] === undefined ? acc : Object.assign({}, acc, {[key]: t.attrib[key]});
+                    }, {});
+                }).reduce(function (acc, val) {
+                    return Object.assign({}, acc, {[val.name]: val});
+                }, {});
+            }
+            return {
+                declarations: declarations,
+                sources: sources,
+                libraries: libraries
+            };
+        });
+        return podSpecs;
+    }
+
     // <hook>
     // Example:
     // <hook type="before_build" src="scripts/beforeBuild.js" />