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 {
|
export const isInstalled = function(pluginRef: string): boolean {
|
||||||
return !!getPlugin(pluginRef);
|
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) {
|
if(method) {
|
||||||
console.warn('Native: tried calling ' + pluginName + '.' + method +
|
console.warn('Native: tried calling ' + pluginName + '.' + method + ', but the ' + pluginName + ' plugin is not installed.');
|
||||||
', but the ' + pluginName + ' plugin is not installed. Install the ' +
|
|
||||||
plugin + ' plugin');
|
|
||||||
} else {
|
} 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) {
|
export const cordovaWarn = function(pluginName: string, method: string) {
|
||||||
if(method) {
|
if(method) {
|
||||||
@ -64,7 +65,7 @@ function callCordovaPlugin(pluginObj:any, methodName:string, args:any[], opts:an
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
pluginWarn(pluginObj.name, methodName, pluginObj.name);
|
pluginWarn(pluginObj, methodName);
|
||||||
reject({
|
reject({
|
||||||
error: 'plugin_not_installed'
|
error: 'plugin_not_installed'
|
||||||
});
|
});
|
||||||
@ -181,7 +182,7 @@ export function RequiresPlugin(target: Function, key: string, descriptor: TypedP
|
|||||||
|
|
||||||
let pluginInstance = getPlugin(this.pluginRef);
|
let pluginInstance = getPlugin(this.pluginRef);
|
||||||
if(!pluginInstance) {
|
if(!pluginInstance) {
|
||||||
pluginWarn(this.name, null, this.name);
|
pluginWarn(this, key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return originalMethod.apply(this, args);
|
return originalMethod.apply(this, args);
|
||||||
|
Loading…
Reference in New Issue
Block a user