Skip to content

Commit

Permalink
feat(spm): Add method to determine if a plugin is a Swift package
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Nov 11, 2024
1 parent 24f7fa2 commit 5005e3f
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
12 changes: 12 additions & 0 deletions spec/PluginInfo/PluginInfo.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,16 @@ describe('PluginInfo', function () {
expect(platforms[0].anattrib).toBe('value');
});
});

describe('isSwiftPackage', () => {
it('Test 020: returns false for non-annotated plugins', function () {
const p = new PluginInfo(path.join(pluginsDir, 'org.test.plugins.withcocoapods'));
expect(p.isSwiftPackage()).toBe(false);
});

it('Test 021: returns true for annotated plugins', function () {
const p = new PluginInfo(path.join(pluginsDir, 'org.test.plugins.swiftpackage'));
expect(p.isSwiftPackage()).toBe(true);
});
});
});
38 changes: 38 additions & 0 deletions spec/fixtures/plugins/org.test.plugins.swiftpackage/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?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>swiftpackage</name>
<!-- These are going to be required by plugman-registry -->
<description>my description</description>
<author>Darryl Pogue</author>
<keywords>dummy,plugin,swift</keywords>
<license>BSD</license>
<!-- end plugman-registry requirements -->

<!-- ios -->
<platform name="ios" package="swift">
</platform>
</plugin>
13 changes: 13 additions & 0 deletions src/PluginInfo/PluginInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,19 @@ class PluginInfo {
.concat(this.getPlatformsArray().map(p => `cordova-${p}`));
}

/**
* Helper method to determine if this plugin is distributed as a Swift
* package.
*
* @example
* <platform name="ios" package="swift">
* </platform>
*/
isSwiftPackage () {
const platformTag = this._et.find('./platform[@name="ios"]');
return !!platformTag.attrib.package;
}

/**
* Helper method used by most of the getSomething methods of PluginInfo.
*
Expand Down

0 comments on commit 5005e3f

Please sign in to comment.