@@ -24,65 +24,31 @@ header = """
2424 */
2525"""
2626
27- # Used in folder names like docs/v1
27+ # Used in folder names like ` docs/v1`.
2828majorVersion = parseInt CoffeeScript .VERSION .split (' .' )[0 ], 10
2929
30- # Build the CoffeeScript language from source.
31- build = (cb ) ->
32- files = fs .readdirSync ' src'
33- files = (' src/' + file for file in files when file .match (/ \. (lit)? coffee$ / ))
34- run [' -c' , ' -o' , ' lib/coffee-script' ].concat (files), cb
35-
36- # Run a CoffeeScript through our node/coffee interpreter.
37- run = (args , cb ) ->
38- proc = spawn ' node' , [' bin/coffee' ].concat (args)
39- proc .stderr .on ' data' , (buffer ) -> console .log buffer .toString ()
40- proc .on ' exit' , (status ) ->
41- process .exit (1 ) if status isnt 0
42- cb () if typeof cb is ' function'
4330
4431# Log a message with a color.
4532log = (message , color , explanation ) ->
4633 console .log color + message + reset + ' ' + (explanation or ' ' )
4734
48- option ' -p' , ' --prefix [DIR]' , ' set the installation prefix for `cake install`'
49-
50- task ' install' , ' install CoffeeScript into /usr/local (or --prefix)' , (options ) ->
51- base = options .prefix or ' /usr/local'
52- lib = " #{ base} /lib/coffee-script"
53- bin = " #{ base} /bin"
54- node = " ~/.node_libraries/coffee-script"
55- console .log " Installing CoffeeScript to #{ lib} "
56- console .log " Linking to #{ node} "
57- console .log " Linking 'coffee' to #{ bin} /coffee"
58- exec ([
59- " mkdir -p #{ lib} #{ bin} "
60- " cp -rf bin lib LICENSE README.md package.json src #{ lib} "
61- " ln -sfn #{ lib} /bin/coffee #{ bin} /coffee"
62- " ln -sfn #{ lib} /bin/cake #{ bin} /cake"
63- " mkdir -p ~/.node_libraries"
64- " ln -sfn #{ lib} /lib/coffee-script #{ node} "
65- ].join (' && ' ), (err , stdout , stderr ) ->
66- if err then console .log stderr .trim () else log ' done' , green
67- )
68-
69-
70- task ' build' , ' build the CoffeeScript language from source' , build
71-
72- task ' build:full' , ' rebuild the source twice, and run the tests' , ->
73- build ->
74- build ->
75- csPath = ' ./lib/coffee-script'
76- csDir = path .dirname require .resolve csPath
7735
78- for mod of require .cache when csDir is mod[0 ... csDir .length ]
79- delete require .cache [mod]
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'
8042
81- unless runTests require csPath
82- process .exit 1
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'
8348
8449
85- task ' build:parser' , ' rebuild the Jison parser (run build first)' , ->
50+ # Build the CoffeeScript language from source.
51+ buildParser = ->
8652 helpers .extend global , require ' util'
8753 require ' jison'
8854 parser = require (' ./lib/coffee-script/grammar' ).parser .generate ()
@@ -95,8 +61,62 @@ task 'build:parser', 'rebuild the Jison parser (run build first)', ->
9561 source = fs"""
9662 fs .writeFileSync ' lib/coffee-script/parser.js' , parser
9763
64+ buildExceptParser = (callback ) ->
65+ files = fs .readdirSync ' src'
66+ files = (' src/' + file for file in files when file .match (/ \. (lit)? coffee$ / ))
67+ run [' -c' , ' -o' , ' lib/coffee-script' ].concat (files), callback
68+
69+ build = (callback ) ->
70+ buildParser ()
71+ buildExceptParser callback
72+
73+ testBuiltCode = (watch = no ) ->
74+ csPath = ' ./lib/coffee-script'
75+ csDir = path .dirname require .resolve csPath
76+
77+ for mod of require .cache when csDir is mod[0 ... csDir .length ]
78+ delete require .cache [mod]
79+
80+ testResults = runTests require csPath
81+ unless watch
82+ process .exit 1 unless testResults
83+
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'
9896
99- task ' build:browser' , ' rebuild the merged script for inclusion in the browser' , ->
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/' , {interval : 200 , recursive : yes }, (eventType , filename ) ->
104+ if eventType is ' change'
105+ log " test/#{ filename} changed, rebuilding..."
106+ buildAndTest no , harmony
107+
108+
109+ task ' build' , ' build the CoffeeScript compiler from source' , build
110+
111+ task ' build:parser' , ' build the Jison parser only' , buildParser
112+
113+ task ' build:except-parser' , ' build the CoffeeScript compiler, except for the Jison parser' , buildExceptParser
114+
115+ task ' build:full' , ' build the CoffeeScript compiler from source twice, and run the tests' , ->
116+ build ->
117+ build testBuiltCode
118+
119+ task ' build:browser' , ' build the merged script for inclusion in the browser' , ->
100120 code = """
101121 require['../../package.json'] = (function() {
102122 return #{ fs .readFileSync " ./package.json" } ;
@@ -145,8 +165,14 @@ task 'build:browser', 'rebuild the merged script for inclusion in the browser',
145165 console .log " built ... running browser tests:"
146166 invoke ' test:browser'
147167
168+ task ' build:watch' , ' watch and continually rebuild the CoffeeScript compiler, running tests on each build' , ->
169+ watchAndBuildAndTest ()
170+
171+ task ' build:watch:harmony' , ' watch and continually rebuild the CoffeeScript compiler, running harmony tests on each build' , ->
172+ watchAndBuildAndTest yes
173+
148174
149- task ' doc:site ' , ' watch and continually rebuild the documentation for the website ' , ->
175+ buildDocs = ( watch = no ) ->
150176 # Constants
151177 indexFile = ' documentation/index.html'
152178 versionedSourceFolder = " documentation/v#{ majorVersion} "
@@ -219,12 +245,19 @@ task 'doc:site', 'watch and continually rebuild the documentation for the websit
219245 fs .symlinkSync " v#{ majorVersion} /index.html" , ' docs/index.html'
220246 catch exception
221247
222- for target in [indexFile, versionedSourceFolder, examplesSourceFolder, sectionsSourceFolder]
223- fs .watch target, interval : 200 , renderIndex
224- log ' watching...' , green
248+ if watch
249+ for target in [indexFile, versionedSourceFolder, examplesSourceFolder, sectionsSourceFolder]
250+ fs .watch target, interval : 200 , renderIndex
251+ log ' watching...' , green
225252
253+ task ' doc:site' , ' build the documentation for the website' , ->
254+ buildDocs ()
226255
227- task ' doc:test' , ' watch and continually rebuild the browser-based tests' , ->
256+ task ' doc:site:watch' , ' watch and continually rebuild the documentation for the website' , ->
257+ buildDocs yes
258+
259+
260+ buildDocTests = (watch = no ) ->
228261 # Constants
229262 testFile = ' documentation/test.html'
230263 testsSourceFolder = ' test'
@@ -262,14 +295,40 @@ task 'doc:test', 'watch and continually rebuild the browser-based tests', ->
262295 fs .writeFileSync " #{ outputFolder} /test.html" , output
263296 log ' compiled' , green, " #{ testFile} → #{ outputFolder} /test.html"
264297
265- for target in [testFile, testsSourceFolder]
266- fs .watch target, interval : 200 , renderTest
267- log ' watching...' , green
298+ if watch
299+ for target in [testFile, testsSourceFolder]
300+ fs .watch target, interval : 200 , renderTest
301+ log ' watching...' , green
302+
303+ task ' doc:test' , ' build the browser-based tests' , ->
304+ buildDocTests ()
305+
306+ task ' doc:test:watch' , ' watch and continually rebuild the browser-based tests' , ->
307+ buildDocTests yes
308+
309+
310+ buildAnnotatedSource = (watch = no ) ->
311+ do generateAnnotatedSource = ->
312+ exec " node_modules/docco/bin/docco src/*.*coffee --output docs/v#{ majorVersion} /annotated-source" , (err ) -> throw err if err
313+ log ' generated' , green, " annotated source in docs/v#{ majorVersion} /annotated-source/"
314+
315+ if watch
316+ fs .watch ' src/' , interval : 200 , generateAnnotatedSource
317+ log ' watching...' , green
318+
319+ task ' doc:source' , ' build the annotated source documentation' , ->
320+ buildAnnotatedSource ()
268321
322+ task ' doc:source:watch' , ' watch and continually rebuild the annotated source documentation' , ->
323+ buildAnnotatedSource yes
269324
270- task ' doc:source' , ' rebuild the annotated source documentation' , ->
271- exec " node_modules/docco/bin/docco src/*.*coffee --output docs/v#{ majorVersion} /annotated-source" , (err ) -> throw err if err
272325
326+ task ' release' , ' build and test the CoffeeScript source, and build the documentation' , ->
327+ invoke ' build:full'
328+ invoke ' build:browser'
329+ invoke ' doc:site'
330+ invoke ' doc:test'
331+ invoke ' doc:source'
273332
274333task ' bench' , ' quick benchmark of compilation time' , ->
275334 {Rewriter } = require ' ./lib/coffee-script/rewriter'
0 commit comments