mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-01-19 08:32:52 +08:00
feat(plugin): show instructions if plugin not installed
This commit is contained in:
parent
ea0067297c
commit
c48a851d87
@ -15,14 +15,15 @@ export const getPlugin = function(pluginRef: string): any {
|
||||
export const isInstalled = function(pluginRef: string): boolean {
|
||||
return !!getPlugin(pluginRef);
|
||||
}
|
||||
export const pluginWarn = function(pluginName: string, method: string, plugin: string) {
|
||||
export const pluginWarn = function(pluginObj: any, method: string) {
|
||||
var pluginName = pluginObj.name;
|
||||
var plugin = pluginObj.plugin;
|
||||
if(method) {
|
||||
console.warn('Native: tried calling ' + pluginName + '.' + method +
|
||||
', but the ' + pluginName + ' plugin is not installed. Install the ' +
|
||||
plugin + ' plugin');
|
||||
console.warn('Native: tried calling ' + pluginName + '.' + method + ', but the ' + pluginName + ' plugin is not installed.');
|
||||
} else {
|
||||
console.warn('Native: tried accessing the ' + pluginName + ' plugin but it\'s not installed. Install the ' + plugin + ' plugin');
|
||||
console.warn('Native: tried accessing the ' + pluginName + ' plugin but it\'s not installed.');
|
||||
}
|
||||
console.warn('Install the ' + pluginName + ' plugin: \'cordova plugin add ' + plugin + '\'');
|
||||
}
|
||||
export const cordovaWarn = function(pluginName: string, method: string) {
|
||||
if(method) {
|
||||
@ -64,7 +65,7 @@ function callCordovaPlugin(pluginObj:any, methodName:string, args:any[], opts:an
|
||||
return;
|
||||
}
|
||||
|
||||
pluginWarn(pluginObj.name, methodName, pluginObj.name);
|
||||
pluginWarn(pluginObj, methodName);
|
||||
reject({
|
||||
error: 'plugin_not_installed'
|
||||
});
|
||||
@ -181,7 +182,7 @@ export function RequiresPlugin(target: Function, key: string, descriptor: TypedP
|
||||
|
||||
let pluginInstance = getPlugin(this.pluginRef);
|
||||
if(!pluginInstance) {
|
||||
pluginWarn(this.name, null, this.name);
|
||||
pluginWarn(this, key);
|
||||
return;
|
||||
}
|
||||
return originalMethod.apply(this, args);
|
||||
|
Loading…
Reference in New Issue
Block a user