Merge pull request #1467 from ajaxorg/jshint

update jshint and coffee
This commit is contained in:
Ruben Daniels 2013-07-06 03:47:08 -07:00
commit 95e0f2fffd
12 changed files with 5860 additions and 2701 deletions

View file

@ -1,21 +1,11 @@
var https = require("https")
, http = require("http")
, url = require("url")
, fs = require("fs")
, fs = require("fs");
var rootDir = __dirname + "/../lib/ace/"
var rootDir = __dirname + "/../lib/ace/";
var deps = [{
path: "mode/javascript/jshint.js",
url: "https://raw.github.com/jshint/jshint/master/src/stable/jshint.js",
needsFixup: true,
postProcess: function(t) {
return t.replace(
/"Expected a conditional expression and instead saw an assignment."/g,
'"Assignment in conditional expression"'
);
}
}, {
path: "mode/css/csslint.js",
url: "https://raw.github.com/stubbornella/csslint/master/release/csslint-node.js",
needsFixup: true
@ -25,52 +15,52 @@ var deps = [{
needsFixup: false
}, {
path: "mode/lua/luaparse.js",
url: "https://raw.github.com/oxyc/luaparse/master/lib/luaparse.js",
url: "https://raw.github.com/oxyc/luaparse/master/luaparse.js",
needsFixup: true
}]
}];
var download = function(href, callback) {
var options = url.parse(href);
protocol = options.protocol === "https:" ? https : http;
console.log("connecting to " + options.host + " " + options.path)
var request = protocol.get(options, function(res) {
var data = ""
res.setEncoding("utf-8")
var protocol = options.protocol === "https:" ? https : http;
console.log("connecting to " + options.host + " " + options.path);
protocol.get(options, function(res) {
var data = "";
res.setEncoding("utf-8");
res.on("data", function(chunk){
data += chunk
})
data += chunk;
});
res.on("end", function(){
callback(data)
})
})
}
callback(data);
});
});
};
var getDep = function(dep) {
download(dep.url, function(data) {
if (dep.needsFixup)
data = "define(function(require, exports, module) {\n"
+ data
+ "\n});"
+ "\n});";
if (dep.postProcess)
data = dep.postProcess(data)
data = dep.postProcess(data);
fs.writeFile(rootDir + dep.path, data, "utf-8", function(err){
if (err) throw err
console.log("File " + dep.path + " saved.")
})
})
}
if (err) throw err;
console.log("File " + dep.path + " saved.");
});
});
};
deps.forEach(getDep)
deps.forEach(getDep);
// coffee-script
void function(){
var rootHref = "https://raw.github.com/jashkenas/coffee-script/master/"
var path = "mode/coffee/"
var rootHref = "https://raw.github.com/jashkenas/coffee-script/master/";
var path = "mode/coffee/";
var subDir = "lib/coffee-script/"
var subDir = "lib/coffee-script/";
var deps = [
"helpers.js",
"lexer.js",
@ -83,50 +73,110 @@ void function(){
name: x,
href: rootHref + subDir + x,
path: rootDir + path + x
}
};
});
deps.push({name:"LICENSE", href: rootHref + "LICENSE"})
deps.push({name:"LICENSE", href: rootHref + "LICENSE"});
var downloads = {}, counter = 0
var downloads = {}, counter = 0;
deps.forEach(function(x) {
download(x.href, function(data) {
counter++
downloads[x.name] = data
counter++;
downloads[x.name] = data;
if (counter == deps.length)
allDone()
})
})
allDone();
});
});
function allDone() {
deps.pop()
var license = downloads["LICENSE"].split('\n')
license = "/**\n * " + license.join("\n * ") + "\n */"
deps.pop();
var license = downloads.LICENSE.split('\n');
license = "/**\n * " + license.join("\n * ") + "\n */";
deps.forEach(function(x) {
var data = downloads[x.name]
console.log(x.name)
console.log(!data)
var data = downloads[x.name];
console.log(x.name);
console.log(!data);
if (!data)
return
return;
if (x.name == "parser.js") {
data = data.replace("var parser = (function(){", "")
.replace(/\nreturn (new Parser)[\s\S]*$/, "\n\nmodule.exports = $1;\n\n")
.replace(/\nreturn (new Parser)[\s\S]*$/, "\n\nmodule.exports = $1;\n\n");
} else {
data = data.replace("(function() {", "")
.replace(/}\).call\(this\);\s*$/, "")
.replace(/\}\).call\(this\);\s*$/, "");
}
data = license
+ "\n\n"
+ "define(function(require, exports, module) {\n"
+ data
+ "\n});"
+ "\n});";
fs.writeFile(x.path, data, "utf-8", function(err){
if (err) throw err
console.log("File " + x.name + " saved.")
console.warn("mode/coffee/coffee-script file needs to updated manually")
console.warn("mode/coffee/parser.js: parseError function needs to be modified")
})
})
if (err) throw err;
console.log("File " + x.name + " saved.");
console.warn("mode/coffee/coffee-script file needs to updated manually");
console.warn("mode/coffee/parser.js: parseError function needs to be modified");
});
});
}
}()
}();
var spawn = require("child_process").spawn;
var run = function(cmd, cb) {
var proc = spawn("cmd", ["/c " + cmd]);
proc.stderr.setEncoding("utf8");
proc.stderr.on('data', function (data) {
// console.error(data);
});
proc.stdout.setEncoding("utf8");
proc.stdout.on('data', function (data) {
//console.log(data);
});
proc.on('exit', done);
proc.on('close', done);
function done(code) {
if (code !== 0) {
console.error(cmd + '::: process exited with code :::' + code);
}
cb()
}
}
function unquote(str) {
return str.replace(/\\(.)/g, function(x, a) {
return a == "n" ? "\n"
: a == "t" ? "\t"
: a == "r" ? "\r"
: a
});
}
run("npm install jshint", function() {
var jshintDist = fs.readFileSync("node_modules/jshint/dist/jshint.js", "utf8");
jshintDist = jshintDist.replace(
/(require.define.*)Function\(\[([^\]]*?)\],\s*"(.*)"\s*\)/g,
function(a, def, args, content) {
return def + "function("+args.replace(/["']/g, "") + ") {\n"
+ unquote(content)
+ "\n}";
}
);
jshintDist = jshintDist.replace(
/"Expected a conditional expression and instead saw an assignment."/g,
'"Assignment in conditional expression"'
);
jshintDist = 'define(function() {\n'
+ jshintDist + '\n'
+ 'var jsHint = require("/src/stable/jshint.js");\n'
+ 'return function(require, exports, module) {module.exports = jsHint;}\n'
+'}())';
fs.writeFileSync(rootDir + "mode/javascript/jshint.js", jshintDist);
});