[Pkg-javascript-commits] [less.js] 123/285: sort out usage and allow a plugin argument

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:23:46 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag v2.0.0
in repository less.js.

commit 771ab4e430485d18a707ace7482bfafb64df71ec
Author: Luke Page <luke.a.page at gmail.com>
Date:   Wed Sep 17 21:14:40 2014 +0100

    sort out usage and allow a plugin argument
---
 bin/lessc                            | 28 ++++++++++++++++++++++------
 lib/less-node/lessc-helper.js        | 11 ++++++-----
 lib/less-node/node-plugin-manager.js | 22 ++++++++++++++++------
 lib/less/plugin-manager.js           |  2 ++
 4 files changed, 46 insertions(+), 17 deletions(-)

diff --git a/bin/lessc b/bin/lessc
index 021b4ce..129b74a 100755
--- a/bin/lessc
+++ b/bin/lessc
@@ -63,6 +63,12 @@ var parseVariableOption = function(option) {
 var warningMessages = "";
 var sourceMapFileInline = false;
 
+function printUsage() {
+    require('../lib/less-node/lessc-helper').printUsage();
+    pluginManager.printUsage();
+    continueProcessing = false;
+}
+
 args = args.filter(function (arg) {
     var match;
 
@@ -98,8 +104,7 @@ args = args.filter(function (arg) {
             break;
         case 'h':
         case 'help':
-            require('../lib/less-node/lessc-helper').printUsage();
-            continueProcessing = false;
+            printUsage();
             break;
         case 'x':
         case 'compress':
@@ -210,12 +215,23 @@ args = args.filter(function (arg) {
                 options.urlArgs = match[2];
             }
             break;
+        case 'plugin':
+            var splitupArg = match[2].match(/^([^=]+)(=(.*))?/),
+                name = splitupArg[1],
+                pluginOptions = splitupArg[3];
+
+            if (!pluginManager.tryLoadPlugin(name, pluginOptions)) {
+                console.log("Unable to load plugin " + name + " please make sure that it is installed under at the same level as less");
+                console.log();
+                printUsage();
+                currentErrorcode = 1;
+            }
+            break;
         default:
-            if (!pluginManager.interpretCommandLineArgument(arg, match[2])) {
+            if (!pluginManager.tryLoadPlugin("less-plugin-" + arg, match[2])) {
                 console.log("Unable to interpret argument " + arg + " - if it is a plugin (less-plugin-" + arg + "), make sure that it is installed under at the same level as less");
                 console.log();
-                require('../lib/less-node/lessc-helper').printUsage();
-                continueProcessing = false;
+                printUsage();
                 currentErrorcode = 1;
             }
             break;
@@ -254,7 +270,7 @@ if (options.sourceMap === true) {
 if (! input) {
     console.log("lessc: no input files");
     console.log("");
-    require('../lib/less/lessc_helper').printUsage();
+    printUsage();
     currentErrorcode = 1;
     return;
 }
diff --git a/lib/less-node/lessc-helper.js b/lib/less-node/lessc-helper.js
index 811895d..ac5d3de 100644
--- a/lib/less-node/lessc-helper.js
+++ b/lib/less-node/lessc-helper.js
@@ -38,11 +38,6 @@ var lessc_helper = {
         console.log("  --insecure               Allow imports from insecure https hosts.");
         console.log("  -v, --version            Print version number and exit.");
         console.log("  -x, --compress           Compress output by removing some whitespaces.");
-        console.log("  --clean-css              Compress output using clean-css");
-        console.log("  --clean-option=opt:val   Pass an option to clean css, using CLI arguments from ");
-        console.log("                           https://github.com/GoalSmashers/clean-css e.g.");
-        console.log("                           --clean-option=--selectors-merge-mode:ie8");
-        console.log("                           and to switch on advanced use --clean-option=--advanced");
         console.log("  --source-map[=FILENAME]  Outputs a v3 sourcemap to the filename (or output filename.map)");
         console.log("  --source-map-rootpath=X  adds this path onto the sourcemap filename and less file paths");
         console.log("  --source-map-basepath=X  Sets sourcemap base path, defaults to current working directory.");
@@ -60,6 +55,12 @@ var lessc_helper = {
         console.log("  --global-var='VAR=VALUE' Defines a variable that can be referenced by the file.");
         console.log("  --modify-var='VAR=VALUE' Modifies a variable already declared in the file.");
         console.log("  --url-args='QUERYSTRING' Adds params into url tokens (e.g. 42, cb=42 or 'a=1&b=2')");
+        console.log("  --plugin=PLUGIN=OPTIONS  Loads a plugin. You can also omit the --plugin= if the plugin begins");
+        console.log("                           less-plugin. E.g. the clean css plugin is called less-plugin-clean-css");
+        console.log("                           once installed (npm install less-plugin-clean-css), use either with");
+        console.log("                           --plugin=less-plugin-clean-css or just --clean-css");
+        console.log("                           specify options afterwards e.g. --plugin=less-plugin-clean-css=\"advanced\"");
+        console.log("                           or --clean-css=\"advanced\"");
         console.log("");
         console.log("-------------------------- Deprecated ----------------");
         console.log("  --line-numbers=TYPE      Outputs filename and line numbers.");
diff --git a/lib/less-node/node-plugin-manager.js b/lib/less-node/node-plugin-manager.js
index 465570a..2e06de7 100644
--- a/lib/less-node/node-plugin-manager.js
+++ b/lib/less-node/node-plugin-manager.js
@@ -6,7 +6,7 @@ var NodePluginManager = function(less) {
     PluginManager.call(this, less);
 };
 NodePluginManager.prototype = new PluginManager();
-NodePluginManager.prototype.interpretCommandLineArgument = function(name, argument) {
+NodePluginManager.prototype.tryLoadPlugin = function(name, argument) {
     var plugin = this.tryRequirePlugin(name);
     if (plugin) {
         this.addPlugin(plugin, argument);
@@ -15,15 +15,25 @@ NodePluginManager.prototype.interpretCommandLineArgument = function(name, argume
     return false;
 };
 NodePluginManager.prototype.tryRequirePlugin = function(name) {
-    try {
-        return require("less-plugin-"+name);
-    }
-    catch(e) {
+    if (name[0] !== '.') {
+        try {
+            return require(name);
+        }
+        catch(e) {
+        }
     }
     try {
-        return require("../../../less-plugin-" + name);
+        return require("../../../" + name);
     }
     catch(e) {
     }
 };
+NodePluginManager.prototype.printUsage = function() {
+    for(var i = 0; i < this.installedPlugins.length; i++) {
+        var plugin = this.installedPlugins[i];
+        if (plugin.printUsage) {
+            plugin.printUsage();
+        }
+    }
+};
 module.exports = NodePluginManager;
diff --git a/lib/less/plugin-manager.js b/lib/less/plugin-manager.js
index a093aa4..721faf4 100644
--- a/lib/less/plugin-manager.js
+++ b/lib/less/plugin-manager.js
@@ -5,8 +5,10 @@ var PluginManager = function(less) {
     this.less = less;
     this.visitors = [];
     this.postProcessors = [];
+    this.installedPlugins = [];
 };
 PluginManager.prototype.addPlugin = function(plugin, options) {
+    this.installedPlugins.push(plugin);
     plugin.install(this.less, this, options);
 };
 PluginManager.prototype.addVisitor = function(visitor) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git



More information about the Pkg-javascript-commits mailing list