@@ -10,18 +10,25 @@ JSLINT = ctx.JSLINT
10
10
11
11
VERBOSE = false
12
12
13
+ if process .argv .length < 4
14
+ console .error JSON .stringify {errors : [{id : " NOARGS" }]}
15
+ process .exit 1
16
+
13
17
try
14
- if process .argv .length < 3
15
- console .error JSON .stringify {errors : [{id : " INVALID" }]}
16
- process .exit 1
17
18
filename = process .argv [2 ]
18
19
script = fs .readFileSync filename, ' utf8'
19
20
catch e
20
21
console .error JSON .stringify {errors : [{id : " NOTFOUND" }]}
21
22
process .exit 1
22
23
24
+ try
25
+ overrideDetails = JSON .parse process .argv [3 ]
26
+ catch e
27
+ console .error JSON .stringify {errors : [{id : " INVALIDJSON" }]}
28
+ process .exit 1
29
+
23
30
details = null
24
- re = / \/\*\! (?:FLO | P)IM_PLUGIN ([\s\S ] + )\*\/ /
31
+ re = / \/\*\! [ A-Z _] + ([\s\S ] + )\*\/ /
25
32
script = script .replace re, (header ) ->
26
33
matches = header .match re
27
34
if matches
@@ -32,13 +39,16 @@ unless details?
32
39
console .error JSON .stringify {errors : [{id : " NOHEADER" }]}
33
40
process .exit 1
34
41
35
- details .id = 2
36
- details .revision = 1
42
+ for k,v of overrideDetails
43
+ details[k] = v
44
+
45
+ id = parseInt details .id
46
+ if isNaN (id) or ! isFinite (id)
47
+ console .error JSON .stringify {errors : [{id : " IDNAN" }]}
48
+ process .exit 1
37
49
38
50
# Alias dependencies.
39
51
accessList = details .access ? []
40
- accessList .unshift " app"
41
- accessList .unshift " plugin"
42
52
for access in accessList
43
53
script = " var #{ access} = lib.#{ access} ();\n #{ script} "
44
54
@@ -117,7 +127,6 @@ walk = (ast) ->
117
127
ast[2 ] = walk ast[2 ]
118
128
ast[3 ] = walk ast[3 ]
119
129
else if type is ' while'
120
- # skip
121
130
ast[2 ] = walk ast[2 ]
122
131
if ast[1 ][0 ] is ' assign'
123
132
# Rewrite this as a for loop
@@ -230,6 +239,7 @@ walk = (ast) ->
230
239
console .error " Unknown type: '#{ type} '"
231
240
console .error util .inspect ast, false , null , true
232
241
return ast
242
+
233
243
ast = parser .parse script
234
244
if VERBOSE
235
245
console .log util .inspect ast, false , null , true
@@ -244,7 +254,6 @@ script = uglify.gen_code ast, beautify: true, indent_start:4, indent_level:2, qu
244
254
if VERBOSE
245
255
console .log script
246
256
247
- script = script .replace / (\n | ^ )\/\/ . * (\n | $ )/ g , " $2"
248
257
num2alphabet = (num ) ->
249
258
chars = " ABCDEFGHIJ" .split (" " )
250
259
num = parseInt num
@@ -255,16 +264,18 @@ num2alphabet = (num) ->
255
264
for i in [0 ... num .length ]
256
265
out += chars[parseInt num .charAt (i)]
257
266
return out
258
- id = details . id
267
+
259
268
adsafeId = " ZZZ#{ num2alphabet id} _"
260
269
head = " <div id=\" #{ adsafeId} \" ><script>\n "
261
270
foot = " </script>\n </div>"
262
271
script = " #{ head} ADSAFE.go(\" #{ adsafeId} \" , function (dom, lib) {\n \" use strict\" ;\n #{ script} \n });#{ foot} "
272
+
263
273
ok = JSLINT script, {
264
274
adsafe : true , fragment : true , browser : true , safe : true , bitwise : true , continue : true , eqeq : true , es5 : true , evil : false , forin : true , newcap : true , nomen : true , plusplus : true , regexp : true , undef : true , unparam : true , sloppy : true , stupid : true , sub : true , vars : true , white : true , css : true
265
275
}, {
266
276
plugin : false
267
277
}
278
+
268
279
unless ok
269
280
result = JSLINT .data ()
270
281
if VERBOSE
0 commit comments