Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 174 lines (142 sloc) 5.819 kb
88847df @jashkenas tests are now passing on symbology
authored
1 fs = require 'fs'
bb05e07 @jashkenas light refactors + tweaks
authored
2 path = require 'path'
f0b73dc @jashkenas Building with latest version of Jison.
authored
3 {extend} = require './lib/helpers'
88847df @jashkenas tests are now passing on symbology
authored
4 CoffeeScript = require './lib/coffee-script'
5 {spawn, exec} = require 'child_process'
2f389f1 @jashkenas beginnings of a build script
authored
6
e4db6d4 @jashkenas Updated Cakefile from Tim_Smart with colorized, explained 'cake install'
authored
7 # ANSI Terminal Colors.
32bd1df @satyr rewrote "cake bench" to see more consistent results
satyr authored
8 bold = '\033[0;1m'
88847df @jashkenas tests are now passing on symbology
authored
9 red = '\033[0;31m'
10 green = '\033[0;32m'
11 reset = '\033[0m'
e4db6d4 @jashkenas Updated Cakefile from Tim_Smart with colorized, explained 'cake install'
authored
12
2c7f6d8 @jashkenas switching to UglifyJS for browser version of CoffeeScript.
authored
13 # Built file header.
14 header = """
15 /**
16 * CoffeeScript Compiler v#{CoffeeScript.VERSION}
17 * http://coffeescript.org
18 *
19 * Copyright 2010, Jeremy Ashkenas
20 * Released under the MIT License
21 */
22 """
23
32bd1df @satyr rewrote "cake bench" to see more consistent results
satyr authored
24 sources = [
25 'src/coffee-script.coffee', 'src/grammar.coffee'
26 'src/helpers.coffee', 'src/lexer.coffee', 'src/nodes.coffee'
27 'src/rewriter.coffee', 'src/scope.coffee'
28 ]
29
448ed36 @jashkenas got a build script for rebuilding the compiler, too
authored
30 # Run a CoffeeScript through our node/coffee interpreter.
88847df @jashkenas tests are now passing on symbology
authored
31 run = (args) ->
32 proc = spawn 'bin/coffee', args
26a115a @jashkenas Removing the mixed-in sys/util module. Switching from 'puts' to console....
authored
33 proc.stderr.on 'data', (buffer) -> console.log buffer.toString()
d017a8f @jashkenas Moving from '.addListener' to '.on' for Node v0.1.101
authored
34 proc.on 'exit', (status) -> process.exit(1) if status != 0
2f389f1 @jashkenas beginnings of a build script
authored
35
e4db6d4 @jashkenas Updated Cakefile from Tim_Smart with colorized, explained 'cake install'
authored
36 # Log a message with a color.
88847df @jashkenas tests are now passing on symbology
authored
37 log = (message, color, explanation) ->
26a115a @jashkenas Removing the mixed-in sys/util module. Switching from 'puts' to console....
authored
38 console.log color + message + reset + ' ' + (explanation or '')
e4db6d4 @jashkenas Updated Cakefile from Tim_Smart with colorized, explained 'cake install'
authored
39
5c7526a @jashkenas moving some of the fs methods over to sync methods, where it's alright a...
authored
40 option '-p', '--prefix [DIR]', 'set the installation prefix for `cake install`'
17ea48c @jashkenas first draft of options for Cakefiles, using optparse.coffee, as well as ...
authored
41
42 task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options) ->
88847df @jashkenas tests are now passing on symbology
authored
43 base = options.prefix or '/usr/local'
9df3e6a @jashkenas first step towards requiring #{ ... } interpolation -- removing naked in...
authored
44 lib = "#{base}/lib/coffee-script"
45 bin = "#{base}/bin"
88847df @jashkenas tests are now passing on symbology
authored
46 node = "~/.node_libraries/coffee-script"
26a115a @jashkenas Removing the mixed-in sys/util module. Switching from 'puts' to console....
authored
47 console.log "Installing CoffeeScript to #{lib}"
48 console.log "Linking to #{node}"
49 console.log "Linking 'coffee' to #{bin}/coffee"
0490cb2 @jashkenas added experimental (but working) method to install CoffeeScript: 'sudo b...
authored
50 exec([
9df3e6a @jashkenas first step towards requiring #{ ... } interpolation -- removing naked in...
authored
51 "mkdir -p #{lib} #{bin}"
52 "cp -rf bin lib LICENSE README package.json src #{lib}"
53 "ln -sf #{lib}/bin/coffee #{bin}/coffee"
54 "ln -sf #{lib}/bin/cake #{bin}/cake"
ce4e00e @jashkenas mistaken camelCase 'nodeLibraries' from the great under_score purge ... ...
authored
55 "mkdir -p ~/.node_libraries"
9df3e6a @jashkenas first step towards requiring #{ ... } interpolation -- removing naked in...
authored
56 "ln -sf #{lib}/lib #{node}"
93f644f @jashkenas finishing the second half of prefix installs. Using readLink to refer to...
authored
57 ].join(' && '), (err, stdout, stderr) ->
02e94cd @jashkenas removing forgotten print's
authored
58 if err then console.log stderr.trim() else log 'done', green
93f644f @jashkenas finishing the second half of prefix installs. Using readLink to refer to...
authored
59 )
0490cb2 @jashkenas added experimental (but working) method to install CoffeeScript: 'sudo b...
authored
60
61
5a81fcd @jashkenas we don't need relative require's because the paths are set up correctly ...
authored
62 task 'build', 'build the CoffeeScript language from source', ->
88847df @jashkenas tests are now passing on symbology
authored
63 files = fs.readdirSync 'src'
6347849 @jashkenas Switching parenthesized side in comprehensions.
authored
64 files = ('src/' + file for file in files when file.match(/\.coffee$/))
f4cd0bd @jashkenas making --run the default option for consistency. If you want to save the...
authored
65 run ['-c', '-o', 'lib'].concat(files)
448ed36 @jashkenas got a build script for rebuilding the compiler, too
authored
66
bedc005 @jashkenas Adding a CoffeeScript equivalent to Rake/Make/Jake (Cake, naturally), an...
authored
67
3396dce @jashkenas waypoint -- going to try to clean up regex_token
authored
68 task 'build:full', 'rebuild the source twice, and run the tests', ->
69 exec 'bin/cake build && bin/cake build && bin/cake test', (err, stdout, stderr) ->
02e94cd @jashkenas removing forgotten print's
authored
70 console.log stdout.trim() if stdout
71 console.log stderr.trim() if stderr
bcf7b3f @jashkenas CoffeeScript 0.5.5, with string interpolation and internal documentation
authored
72 throw err if err
73
74
ff25361 @jashkenas removing the build:parser -> build dependency in the Cakefile -- the asy...
authored
75 task 'build:parser', 'rebuild the Jison parser (run build first)', ->
f0b73dc @jashkenas Building with latest version of Jison.
authored
76 extend global, require('utils')
e56af49 @jashkenas removing our vendor'd copy of Jison ... you should install it from NPM n...
authored
77 require 'jison'
88847df @jashkenas tests are now passing on symbology
authored
78 parser = require('./lib/grammar').parser
6d8126e @jashkenas Removing the last Jison hack. (Jison 0.1.25)
authored
79 fs.writeFile 'lib/parser.js', parser.generate()
2f389f1 @jashkenas beginnings of a build script
authored
80
bedc005 @jashkenas Adding a CoffeeScript equivalent to Rake/Make/Jake (Cake, naturally), an...
authored
81
b674163 @jashkenas adding build:ultraviolet and build:underscore tasks to the Cakefile
authored
82 task 'build:ultraviolet', 'build and install the Ultraviolet syntax highlighter', ->
7499535 @jashkenas updating the Cakefile for the new tmbundle location.
authored
83 exec 'plist2syntax ../coffee-script-tmbundle/Syntaxes/CoffeeScript.tmLanguage', (err) ->
84 throw err if err
b674163 @jashkenas adding build:ultraviolet and build:underscore tasks to the Cakefile
authored
85 exec 'sudo mv coffeescript.yaml /usr/local/lib/ruby/gems/1.8/gems/ultraviolet-0.10.2/syntax/coffeescript.syntax'
86
87
c1427d6 @jashkenas adding a minified combined coffee-script.js. Include it on the page, aft...
authored
88 task 'build:browser', 'rebuild the merged script for inclusion in the browser', ->
2c7f6d8 @jashkenas switching to UglifyJS for browser version of CoffeeScript.
authored
89 code = ''
90 for name in ['helpers', 'rewriter', 'lexer', 'parser', 'scope', 'nodes', 'coffee-script', 'browser']
91 code += """
92 require['./#{name}'] = new function() {
93 var exports = this;
94 #{fs.readFileSync "lib/#{name}.js"}
95 };
96 """
97 {parser, uglify} = require 'uglify-js'
98 ast = parser.parse """
99 this.CoffeeScript = function() {
100 function require(path){ return require[path]; }
101 #{code}
102 return require['./coffee-script']
103 }()
104 """
105 code = uglify.gen_code uglify.ast_squeeze uglify.ast_mangle ast, extra: yes
106 fs.writeFileSync 'extras/coffee-script.js', header + '\n' + code
107 invoke 'test:browser'
c1427d6 @jashkenas adding a minified combined coffee-script.js. Include it on the page, aft...
authored
108
109
5b3ef78 @jashkenas adding a doc:source Cake task to document CoffeeScript's internals
authored
110 task 'doc:site', 'watch and continually rebuild the documentation for the website', ->
0e5dd3d @jashkenas First draft of recompiling examples for 0.9.9
authored
111 exec 'rake doc', (err) ->
112 throw err if err
c1427d6 @jashkenas adding a minified combined coffee-script.js. Include it on the page, aft...
authored
113
114
5b3ef78 @jashkenas adding a doc:source Cake task to document CoffeeScript's internals
authored
115 task 'doc:source', 'rebuild the internal documentation', ->
202ebf0 @jashkenas documentation for command.coffee
authored
116 exec 'docco src/*.coffee && cp -rf docs documentation && rm -r docs', (err) ->
e267226 @jashkenas commenting coffee-script.coffee for documentation
authored
117 throw err if err
5b3ef78 @jashkenas adding a doc:source Cake task to document CoffeeScript's internals
authored
118
119
a3e1693 @jashkenas waypoint -- docc'd down to the SplatNode
authored
120 task 'doc:underscore', 'rebuild the Underscore.coffee documentation page', ->
25438be @jashkenas new docs for underscore
authored
121 exec 'docco examples/underscore.coffee && cp -rf docs documentation && rm -r docs', (err) ->
122 throw err if err
a3e1693 @jashkenas waypoint -- docc'd down to the SplatNode
authored
123
32bd1df @satyr rewrote "cake bench" to see more consistent results
satyr authored
124 task 'bench', 'quick benchmark of compilation time', ->
125 cs = sources.map((name) -> fs.readFileSync name).join '\n'
126 now = Date.now()
127 js = CoffeeScript.compile cs, bare: true
128 console.log """
129 #{bold}#{ Date.now() - now }[ms]#{reset} compiling #{js.length} bytes
130 """
a3e1693 @jashkenas waypoint -- docc'd down to the SplatNode
authored
131
7e22568 @jashkenas making the 'cake loc' task reflect the lines of code in the compiler onl...
authored
132 task 'loc', 'count the lines of source code in the CoffeeScript compiler', ->
89cd25a @jashkenas finished moving over string and regex interpolation to use '#' instead o...
authored
133 exec "cat #{ sources.join(' ') } | grep -v '^\\( *#\\|\\s*$\\)' | wc -l | tr -s ' '", (err, stdout) ->
02e94cd @jashkenas removing forgotten print's
authored
134 console.log stdout.trim()
7987d4e @jashkenas adding a cake task to check loc
authored
135
136
f360fba @sstephenson Add test:browser task for running the test suite against the merged brow...
sstephenson authored
137 runTests = (CoffeeScript) ->
159150c @satyr "cake test" now wraps all of the "assert" module to update test counts
satyr authored
138 startTime = Date.now()
88847df @jashkenas tests are now passing on symbology
authored
139 passedTests = failedTests = 0
bb05e07 @jashkenas light refactors + tweaks
authored
140 for all name, func of require 'assert'
5b16d47 @jashkenas Removing/Reverting do ->
authored
141 global[name] = ->
142 passedTests += 1
143 func arguments...
159150c @satyr "cake test" now wraps all of the "assert" module to update test counts
satyr authored
144 global.eq = global.strictEqual
145 global.CoffeeScript = CoffeeScript
d017a8f @jashkenas Moving from '.addListener' to '.on' for Node v0.1.101
authored
146 process.on 'exit', ->
159150c @satyr "cake test" now wraps all of the "assert" module to update test counts
satyr authored
147 time = ((Date.now() - startTime) / 1000).toFixed(2)
9df3e6a @jashkenas first step towards requiring #{ ... } interpolation -- removing naked in...
authored
148 message = "passed #{passedTests} tests in #{time} seconds#{reset}"
e4db6d4 @jashkenas Updated Cakefile from Tim_Smart with colorized, explained 'cake install'
authored
149 if failedTests
9df3e6a @jashkenas first step towards requiring #{ ... } interpolation -- removing naked in...
authored
150 log "failed #{failedTests} and #{message}", red
e4db6d4 @jashkenas Updated Cakefile from Tim_Smart with colorized, explained 'cake install'
authored
151 else
152 log message, green
1f2c8df @jashkenas updating to latest Node (0.1.3) API -- callbacks, not promises
authored
153 fs.readdir 'test', (err, files) ->
a27f146 @jashkenas fixing 'cake test' to print out the name of the file with the failing te...
authored
154 files.forEach (file) ->
8553a89 @gfxmonk improve feedback when running the test task
gfxmonk authored
155 return unless file.match(/\.coffee$/i)
071b527 @jashkenas Issue #559, renaming {source} option to {fileName}, on CoffeeScript.comp...
authored
156 fileName = path.join 'test', file
157 fs.readFile fileName, (err, code) ->
8023041 @jashkenas merging in gfxmonk's major refactor to the way that returns are pushed d...
authored
158 try
071b527 @jashkenas Issue #559, renaming {source} option to {fileName}, on CoffeeScript.comp...
authored
159 CoffeeScript.run code.toString(), {fileName}
8023041 @jashkenas merging in gfxmonk's major refactor to the way that returns are pushed d...
authored
160 catch err
e14f4c5 @jashkenas First draft of switching the CoffeeScript Compiler over to camelCase. Po...
authored
161 failedTests += 1
6f47364 @jashkenas done refactoring Class for now...
authored
162 log "failed #{fileName}", red, '\n' + err.stack?.toString()
f360fba @sstephenson Add test:browser task for running the test suite against the merged brow...
sstephenson authored
163
164
165 task 'test', 'run the CoffeeScript language test suite', ->
166 runTests CoffeeScript
167
168
169 task 'test:browser', 'run the test suite against the merged browser script', ->
170 source = fs.readFileSync 'extras/coffee-script.js', 'utf-8'
5236bb2 @sstephenson Remove the window hack in test:browser.
sstephenson authored
171 result = {}
172 (-> eval source).call result
173 runTests result.CoffeeScript
Something went wrong with that request. Please try again.