Skip to content

Commit

Permalink
feat(plugin): show instructions if plugin not installed
Browse files Browse the repository at this point in the history
  • Loading branch information
tlancina committed Mar 4, 2016
1 parent ea00672 commit c48a851
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/plugins/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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'
});
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit c48a851

Please sign in to comment.