Skip to content

Commit

Permalink
fix: enforce typing
Browse files Browse the repository at this point in the history
  • Loading branch information
riderx committed Jan 12, 2023
1 parent c2843ea commit ded6f7f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,32 @@ Run `npx capacitor-plugin-standard-version` for update main version or `npx capa
This package will automatically manage your changelog and the version number in 4 places:
- package.json (version key)
- package-lock.json (version key) optional
- Your main iOS file (guessed) (PLUGIN_VERSION key)
- your main android file (guessed) (PLUGIN_VERSION key)

If not present in your package add the variable `PLUGIN_VERSION` in Android and iOS.
- Your main iOS file (guessed) search for `private let PLUGIN_VERSION: String = "(.*)"`
- your main android file (guessed) search for `private final String PLUGIN_VERSION = "(.*)"`

If not present in your package add:
in Android `private final String PLUGIN_VERSION = "1.2.3"`
in iOS `private let PLUGIN_VERSION: String = "1.2.3"`

Add in android then
```java
@PluginMethod
public void getPluginVersion(final PluginCall call) {
try {
final JSObject ret = new JSObject();
ret.put("version", this.PLUGIN_VERSION);
call.resolve(ret);
} catch (final Exception e) {
call.reject("Could not get plugin version", e);
}
}
```
And in IOS
```swift
@objc func getPluginVersion(_ call: CAPPluginCall) {
call.resolve(["version": self.PLUGIN_VERSION])
}
```
Add a method `getNativeVersion()` in native who will return the version, that useful for Capgo auto-update context when dev want to be certain they don't make a breaking change in production.
Add `getJsVersion()` in JS code to allow user to check the JS version, who can be updated by updater.
Add `checkVersionMatch()` in JS code to allow user to check if the JS and native version match.
Expand Down
7 changes: 5 additions & 2 deletions src/bin/android.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const regexAndroid = /String\sPLUGIN_VERSION\s=\s"(.*)";/g;
const regexAndroid = /private\sfinal\sString\sPLUGIN_VERSION\s=\s"(.*)";/g;

export function readVersion(contents) {
const vString = contents.match(regexAndroid);
Expand All @@ -7,6 +7,9 @@ export function readVersion(contents) {
}

export function writeVersion(contents, version) {
const newContent = contents.replace(regexAndroid, `String PLUGIN_VERSION = "${version}";`);
const newContent = contents.replace(
regexAndroid,
`private\sfinal\sString\sPLUGIN_VERSION\s=\s"${version}";`
);
return newContent;
}
7 changes: 5 additions & 2 deletions src/bin/ios.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const regexIos = /let\sPLUGIN_VERSION:\sString\s=\s"(.*)"/g;
const regexIos = /private\slet\sPLUGIN_VERSION:\sString\s=\s"(.*)"/g;

export function readVersion(contents) {
const vString = contents.match(regexIos);
Expand All @@ -7,6 +7,9 @@ export function readVersion(contents) {
}

export function writeVersion(contents, version) {
const newContent = contents.replace(regexIos, `let PLUGIN_VERSION = "${version}"`);
const newContent = contents.replace(
regexIos,
`private\slet\sPLUGIN_VERSION:\sString\s=\s"${version}"`
);
return newContent;
}

0 comments on commit ded6f7f

Please sign in to comment.