-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.jpr
58 lines (50 loc) · 1.4 KB
/
compile.jpr
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
(def parse (data f)
(let (err res) (read-file (str data) 0)
(if err
(prn err)
(f res))))
(def gather-callbacks (cbs f)
(let res (map (fn () undefined) cbs)
(cbs.map (fn (cb i)
(cb (fn (x)
(= (get res i) x)
(if (res.every [! (is _ undefined)])
(f res))))))))
(assign run-repl (is (get process.argv 2) '-i))
(assign watch (is (get process.argv 2) '-w))
(assign files (slice process.argv (if (or run-repl watch) 3 2)))
(def now ()
(/ ((new Date).getTime) 1000))
(def repl ()
(let rl ((require 'readline).createInterface (obj input process.stdin
output process.stdout))
(rl.setPrompt "¿ ")
(rl.prompt)
(callback (rl.on 'line) (line)
(prn (cmd-handler line))
(rl.prompt))))
(with (fs (require 'fs)
files `(,(str __dirname "/jasper.jpr") ,@files)
foo (fn ()
(let start (now)
(callback (gather-callbacks (map (fn (file)
(fn (f)
(callback (fs.readFile file) (err data)
(if err
(prn err)
(parse data f)))))
files))
(codes)
(prn (- (now) start))
(with (code (apply cat codes)
output (compile code))
(if (no run-repl)
(fs.writeFileSync (str (get files (- files.length 1)) ".js") output)))
(prn (- (now) start))
(if run-repl
(repl))))))
(foo)
(if watch
(map (fn (path)
(fs.watch path foo))
files)))