forked from ajaxorg/ace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate_deps.js
119 lines (105 loc) · 2.7 KB
/
update_deps.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
var https = require("https")
, http = require("http")
, url = require("url")
, fs = require("fs")
var rootDir = __dirname + "/../lib/ace/"
var deps = [{
path: "worker/jshint.js",
url: "https://raw.github.com/jshint/jshint/master/jshint.js",
needsFixup: true
}, {
path: "worker/jslint.js",
url: "https://raw.github.com/douglascrockford/JSLint/master/jslint.js",
needsFixup: true
}, {
path: "mode/css/csslint.js",
url: "https://raw.github.com/stubbornella/csslint/master/release/csslint-node.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")
res.on("data", function(chunk){
data += chunk
})
res.on("end", function(){
callback(data)
})
})
}
var getDep = function(dep) {
download(dep.url, function(data) {
if (dep.needsFixup)
data = "define(function(require, exports, module) {\n"
+ data
+ "\n});"
fs.writeFile(rootDir + dep.path, data, "utf-8", function(err){
if (err) throw err
console.log("File " + dep.path + " saved.")
})
})
}
deps.forEach(getDep)
// coffee-script
void function(){
var rootHref = "https://raw.github.com/jashkenas/coffee-script/master/"
var path = "mode/coffee/"
var subDir = "lib/coffee-script/"
var deps = [
"helpers.js",
"lexer.js",
"nodes.js",
"parser.js",
"rewriter.js",
"scope.js"
].map(function(x) {
return {
name: x,
href: rootHref + subDir + x,
path: rootDir + path + x
}
});
deps.push({name:"LICENSE", href: rootHref + "LICENSE"})
var downloads = {}, counter = 0
deps.forEach(function(x) {
download(x.href, function(data) {
counter++
downloads[x.name] = data
if (counter == deps.length)
allDone()
})
})
function allDone() {
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)
if (!data)
return
if (x.name == "parser.js") {
console.log(data)
data = data.replace("var parser = (function(){", "")
.replace(/\nreturn parser[\x00-\uffff]*$/, "\n\nmodule.exports = parser;\n\n")
} else {
data = data.replace("(function() {", "")
.replace(/}\).call\(this\);\s*$/, "")
}
data = license
+ "\n\n"
+ "define(function(require, exports, module) {\n"
+ data
+ "\n});"
fs.writeFile(x.path, data, "utf-8", function(err){
if (err) throw err
console.log("File " + x.name + " saved.")
})
})
}
}()