TypeScript foundation for Ionic Native plugin wrappers providing decorators, base classes, and utilities for Cordova/Capacitor integration
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
The IonicNativePlugin class serves as the foundation for all Ionic Native plugin wrappers, providing standardized plugin metadata management and availability checking functionality.
Base class that all Ionic Native plugin wrappers must extend to provide consistent plugin metadata and availability checking.
/**
* Base class for all Ionic Native plugin wrappers
* Provides common functionality for plugin metadata and availability checking
*/
class IonicNativePlugin {
/** Display name of the plugin */
static pluginName: string;
/** Reference path to the plugin object on the global scope */
static pluginRef: string;
/** NPM package name for plugin installation */
static plugin: string;
/** GitHub repository URL */
static repo: string;
/** Array of supported platforms (e.g., ["Android", "iOS"]) */
static platforms: string[];
/** Installation command or instructions */
static install: string;
}/**
* Returns whether the plugin is installed and available
* @returns True if plugin is available, false otherwise
*/
static installed(): boolean;Usage Example:
import { ExamplePlugin } from "@ionic-native/example";
if (ExamplePlugin.installed()) {
// Plugin is available, safe to use
ExamplePlugin.someMethod();
} else {
// Plugin not installed or Cordova not available
console.log("Example plugin not available");
}/**
* Returns the original plugin object from the global scope
* @returns The original plugin object or null if not available
*/
static getPlugin(): any;Usage Example:
const nativePlugin = ExamplePlugin.getPlugin();
if (nativePlugin) {
// Access the native plugin directly
nativePlugin.nativeMethod();
}/**
* Returns the plugin's display name
* @returns The plugin display name
*/
static getPluginName(): string;
/**
* Returns the plugin's reference path
* @returns The plugin reference path (e.g., "cordova.plugins.Example")
*/
static getPluginRef(): string;
/**
* Returns the plugin's NPM package install name
* @returns The NPM package name
*/
static getPluginInstallName(): string;
/**
* Returns the plugin's supported platforms
* @returns Array of platform names
*/
static getSupportedPlatforms(): string[];Usage Examples:
console.log("Plugin name:", ExamplePlugin.getPluginName());
console.log("Plugin reference:", ExamplePlugin.getPluginRef());
console.log("Install with:", ExamplePlugin.getPluginInstallName());
console.log("Supported platforms:", ExamplePlugin.getSupportedPlatforms());When creating a new plugin wrapper, extend IonicNativePlugin and define the static metadata:
import { IonicNativePlugin, Plugin } from "@ionic-native/core";
@Plugin({
pluginName: "MyPlugin",
plugin: "cordova-plugin-myplugin",
pluginRef: "cordova.plugins.MyPlugin",
repo: "https://github.com/example/cordova-plugin-myplugin",
platforms: ["Android", "iOS"],
install: "ionic cordova plugin add cordova-plugin-myplugin"
})
export class MyPlugin extends IonicNativePlugin {
// Plugin methods go here
}The @Plugin decorator will automatically set the static properties on the class based on the configuration provided.