Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add method getPodSpecs and add related tests #48

Merged
merged 1 commit into from
Nov 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions spec/PluginInfo/PluginInfo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
49 changes: 49 additions & 0 deletions spec/fixtures/plugins/org.test.plugins.withcocoapods/plugin.xml
Original file line number Diff line number Diff line change
@@ -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>
54 changes: 54 additions & 0 deletions src/PluginInfo/PluginInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down