Make @import (plugin) environment-dependant

Shifts some logic around and extends some of the management classes in
such a way that plugins loaded via an `@import (plugin) "..."`
declaration are only loaded in environments that have support for
loading plugins. (i.e. Node.js)
This commit is contained in:
rjgotten
2015-02-26 13:32:28 +01:00
parent 83db6e8d90
commit 39c6aa65f3
4 changed files with 54 additions and 15 deletions

View File

@@ -5,6 +5,28 @@ var path = require("path");
var PluginLoader = function(less) {
this.less = less;
};
PluginLoader.prototype.tryImportPlugin = function(resolvedFileName) {
var plugin;
try {
plugin = require(resolvedFileName);
if (plugin) {
// support plugins being a function
// so that the plugin can be more usable programmatically
if (typeof plugin === "function") {
plugin = new plugin();
}
if (plugin.minVersion) {
if (this.compareVersion(plugin.minVersion, this.less.version) < 0) {
console.log("plugin " + name + " requires version " + this.versionToString(plugin.minVersion));
return null;
}
}
return plugin;
}
} catch(e) {}
return null;
};
PluginLoader.prototype.tryLoadPlugin = function(name, argument) {
var plugin = this.tryRequirePlugin(name);
if (plugin) {