Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added Windows Script Host CLI (fixes #198)

  • Loading branch information...
commit 334d0efd5c3f2781f830ab12858a328453029294 1 parent 4a1dc08
@nzakas nzakas authored
View
3  README.md
@@ -17,4 +17,5 @@ CSSLint is a tool to help point out problems with your CSS code. It does basic s
1. Eric Wendelin, http://eriwen.com (Output formatters)
1. Kasper Garnaes, http://reload.dk (Checkstyle XML format)
1. Gord Tanner, http://www.tinyhippos.com (CLI quiet option)
-1. Hans-Peter Buniat, https://github.com/hpbuniat (Duplicate background image rule)
+1. Hans-Peter Buniat, https://github.com/hpbuniat (Duplicate background image rule)
+1. Dino Chiesa, https://github.com/DinoChiesa (Windows Script Host CLI)
View
11 build.xml
@@ -30,6 +30,7 @@
<property name="worker.build.file" value="csslint-worker.js"/>
<property name="tests.build.file" value="csslint-tests.js"/>
<property name="rhino.build.file" value="csslint-rhino.js"/>
+ <property name="wsh.build.file" value="csslint-wsh.js"/>
<!-- embeddable license -->
<loadfile property="license.text" srcfile="LICENSE" />
@@ -204,6 +205,14 @@
</concat>
</target>
+ <!-- build for WSH CLI integration -->
+ <target name="build.wsh" depends="build.core">
+ <concat destfile="${build.dir}/${wsh.build.file}" fixlastline="true">
+ <filelist dir="${build.dir}" files="${core.build.file}" />
+ <filelist dir="${src.dir}/cli" files="common.js,wsh.js" />
+ </concat>
+ </target>
+
<!-- Create a release with version number embedded -->
<target name="release" depends="test,build.all,changelog.update">
<delete dir="${release.dir}" />
@@ -228,6 +237,6 @@
</target>
<!-- Build all files -->
- <target name="build.all" depends="clean,build.core,build.worker,build.node,build.tests,build.rhino"/>
+ <target name="build.all" depends="clean,build.core,build.worker,build.node,build.tests,build.rhino,build.wsh"/>
</project>
View
2  src/cli/common.js
@@ -203,7 +203,5 @@ function cli(api){
api.quit(0);
}
- //files = api.fixFilenames(files);
-
api.quit(processFiles(files,options));
}
View
8 src/cli/node.js
@@ -61,13 +61,7 @@ cli({
traverse(dir, []);
return files;
- },
-
- fixFilenames: function(files){
- return files.map(function(filename){
- return path.resolve(process.cwd(), filename);
- });
- },
+ },
getWorkingDirectory: function() {
return process.cwd();
View
4 src/cli/rhino.js
@@ -34,10 +34,6 @@ cli({
return files;
},
-
- fixFilenames: function(files){
- return files;
- },
getWorkingDirectory: function() {
return (new File(".")).getCanonicalPath();
View
134 src/cli/wsh.js
@@ -0,0 +1,134 @@
+/*
+ * Windows Script Host Command Line Interface
+ */
+/*global ActiveXObject, WScript, Enumerator, cli*/
+//TODO: This file needs major cleanup!!!
+
+var wshapi = (function(){
+ var fso = new ActiveXObject("Scripting.FileSystemObject");
+ var shell = WScript.CreateObject("WScript.Shell");
+ var finalArgs = [], i, args = WScript.Arguments;
+
+ if (typeof Array.prototype.forEach !== "function") {
+ Array.prototype.forEach = function(f,m) {
+ for (var i=0, L=this.length; i<L; ++i) {
+ f(this[i], i, m);
+ }
+ };
+ }
+
+ if (typeof Array.prototype.filter !== "function") {
+ Array.prototype.filter = function(fn /*, thisp*/) {
+ if (typeof fn != "function") {
+ throw new Error("not a function");
+ }
+ var res = [], val, thisp = finalArgs[1];
+ for (var i = 0, L = this.length; i < L; i++) {
+ if (i in this) {
+ val = this[i]; // in case fun mutates this
+ if (fn.call(thisp, val, i, this)){
+ res.push(val);
+ }
+ }
+ }
+
+ return res;
+ };
+ }
+
+ if (!Array.prototype.indexOf) {
+ Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
+ "use strict";
+ if (this === void 0 || this === null) {
+ throw new Error("unknown instance");
+ }
+ var t = this;
+ var len = t.length >>> 0;
+ if (len === 0) {
+ return -1;
+ }
+ var n = 0;
+ if (finalArgs.length > 0) {
+ n = Number(finalArgs[1]);
+ if (n !== n) { // shortcut for verifying if it's NaN
+ n = 0;
+ } else if (n !== 0 && n !== Infinity && n !== -Infinity) {
+ n = (n > 0 || -1) * Math.floor(Math.abs(n));
+ }
+ }
+ if (n >= len) {
+ return -1;
+ }
+ var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
+ for (; k < len; k++) {
+ if (k in t && t[k] === searchElement) {
+ return k;
+ }
+ }
+ return -1;
+ };
+ }
+
+ function traverseDir(files, path) {
+ var filename, folder = fso.GetFolder(path),
+ subFlds, fc = new Enumerator(folder.files);
+
+ for (; !fc.atEnd(); fc.moveNext()) {
+ filename = fc.item();
+ if (/\.css$/.test(filename)) {
+ files.push(filename);
+ }
+ }
+
+ subFlds = new Enumerator(folder.SubFolders);
+ for (; !subFlds.atEnd(); subFlds.moveNext()) {
+ traverseDir(files, subFlds.item());
+ }
+ }
+
+ // turn the WScript.Arguments thing into a regular array
+ if (args.Length > 0) {
+ for (i = 0; i < args.Length; i++) {
+ finalArgs.push(args(i));
+ }
+ }
+
+ return {
+ args: finalArgs,
+ print: function(s) { WScript.Echo(s);},
+ quit: function (v) { WScript.Quit(v);},
+
+ isDirectory: function(name){
+ return fso.FolderExists(name);
+ },
+
+ getFiles: function(dir){
+ var files = [];
+ traverseDir(files, dir);
+ return files;
+ },
+
+ fixFilenames: function(files){
+ return files;
+ },
+
+ getWorkingDirectory: function() {
+ return shell.CurrentDirectory;
+ },
+
+ getFullPath: function(filename){
+ return fso.GetAbsolutePathName(filename);
+ },
+
+ readFile: function(path){
+ var forReading = 1;
+ var tf = fso.OpenTextFile(path, forReading);
+ var allText = tf.ReadAll();
+ tf.Close();
+ return allText;
+ }
+ };
+
+}());
+
+cli(wshapi);
Please sign in to comment.
Something went wrong with that request. Please try again.