@@ -28,6 +28,25 @@ header = """
2828majorVersion = parseInt CoffeeScript .VERSION .split (' .' )[0 ], 10
2929
3030
31+ # Log a message with a color.
32+ log = (message , color , explanation ) ->
33+ console .log color + message + reset + ' ' + (explanation or ' ' )
34+
35+
36+ spawnNodeProcess = (args , output = ' stderr' , callback ) ->
37+ relayOutput = (buffer ) -> console .log buffer .toString ()
38+ proc = spawn ' node' , args
39+ proc .stdout .on ' data' , relayOutput if output is ' both' or output is ' stdout'
40+ proc .stderr .on ' data' , relayOutput if output is ' both' or output is ' stderr'
41+ proc .on ' exit' , (status ) -> callback (status) if typeof callback is ' function'
42+
43+ # Run a CoffeeScript through our node/coffee interpreter.
44+ run = (args , callback ) ->
45+ spawnNodeProcess [' bin/coffee' ].concat (args), ' stderr' , (status ) ->
46+ process .exit (1 ) if status isnt 0
47+ callback () if typeof callback is ' function'
48+
49+
3150# Build the CoffeeScript language from source.
3251buildParser = ->
3352 helpers .extend global , require ' util'
@@ -42,14 +61,14 @@ buildParser = ->
4261 source = fs"""
4362 fs .writeFileSync ' lib/coffee-script/parser.js' , parser
4463
45- buildExceptParser = (cb ) ->
64+ buildExceptParser = (callback ) ->
4665 files = fs .readdirSync ' src'
4766 files = (' src/' + file for file in files when file .match (/ \. (lit)? coffee$ / ))
48- run [' -c' , ' -o' , ' lib/coffee-script' ].concat (files), cb
67+ run [' -c' , ' -o' , ' lib/coffee-script' ].concat (files), callback
4968
50- build = (cb ) ->
69+ build = (callback ) ->
5170 buildParser ()
52- buildExceptParser cb
71+ buildExceptParser callback
5372
5473testBuiltCode = (watch = no ) ->
5574 csPath = ' ./lib/coffee-script'
@@ -62,19 +81,32 @@ testBuiltCode = (watch = no) ->
6281 unless watch
6382 process .exit 1 unless testResults
6483
65-
66- # Run a CoffeeScript through our node/coffee interpreter.
67- run = (args , cb ) ->
68- proc = spawn ' node' , [' bin/coffee' ].concat (args)
69- proc .stderr .on ' data' , (buffer ) -> console .log buffer .toString ()
70- proc .on ' exit' , (status ) ->
71- process .exit (1 ) if status isnt 0
72- cb () if typeof cb is ' function'
73-
74-
75- # Log a message with a color.
76- log = (message , color , explanation ) ->
77- console .log color + message + reset + ' ' + (explanation or ' ' )
84+ buildAndTest = (includingParser = yes , harmony = no ) ->
85+ process .stdout .write ' \x1B c' # Clear terminal screen.
86+ execSync ' git checkout lib/*' , stdio : [0 ,1 ,2 ] # Reset the generated compiler.
87+
88+ buildArgs = [' bin/cake' ]
89+ buildArgs .push if includingParser then ' build' else ' build:except-parser'
90+ log " building#{ if includingParser then ' , including parser' else ' ' } ..." , green
91+ spawnNodeProcess buildArgs, ' both' , ->
92+ log ' testing...' , green
93+ testArgs = if harmony then [' --harmony' ] else []
94+ testArgs = testArgs .concat [' bin/cake' , ' test' ]
95+ spawnNodeProcess testArgs, ' both'
96+
97+ watchAndBuildAndTest = (harmony = no ) ->
98+ buildAndTest yes , harmony
99+ fs .watch ' src/' , interval : 200 , (eventType , filename ) ->
100+ if eventType is ' change'
101+ log " src/#{ filename} changed, rebuilding..."
102+ buildAndTest (filename is ' grammar.coffee' ), harmony
103+ fs .watch ' test/' ,
104+ interval : 200
105+ recursive : yes
106+ , (eventType , filename ) ->
107+ if eventType is ' change'
108+ log " test/#{ filename} changed, rebuilding..."
109+ buildAndTest no , harmony
78110
79111
80112task ' build' , ' build the CoffeeScript compiler from source' , build
@@ -128,6 +160,12 @@ task 'build:browser', 'build the merged script for inclusion in the browser', ->
128160 console .log " built ... running browser tests:"
129161 invoke ' test:browser'
130162
163+ task ' build:watch' , ' watch and continually rebuild the CoffeeScript compiler, running tests on each build' , ->
164+ watchAndBuildAndTest ()
165+
166+ task ' build:watch:harmony' , ' watch and continually rebuild the CoffeeScript compiler, running harmony tests on each build' , ->
167+ watchAndBuildAndTest yes
168+
131169
132170buildDocs = (watch = no ) ->
133171 # Constants
0 commit comments