|
| 1 | +fs: require 'fs' |
| 2 | +{helpers}: require('./lib/helpers') |
| 3 | +CoffeeScript: require './lib/coffee-script' |
| 4 | +{spawn, exec}: require('child_process') |
| 5 | + |
| 6 | +# Run a CoffeeScript through our node/coffee interpreter. |
| 7 | +run: (args) -> |
| 8 | + proc: spawn 'bin/coffee', args |
| 9 | + proc.stderr.addListener 'data', (buffer) -> puts buffer.toString() |
| 10 | + proc.addListener 'exit', (status) -> process.exit(1) if status != 0 |
| 11 | + |
| 12 | +option '-p', '--prefix [DIR]', 'set the installation prefix for `cake install`' |
| 13 | + |
| 14 | +task 'install', 'install CoffeeScript into /usr/local (or --prefix)', (options) -> |
| 15 | + base: options.prefix or '/usr/local' |
| 16 | + lib: "$base/lib/coffee-script" |
| 17 | + bin: "$base/bin" |
| 18 | + exec([ |
| 19 | + "mkdir -p $lib $bin" |
| 20 | + "cp -rf bin lib LICENSE README package.json src vendor $lib" |
| 21 | + "ln -sf $lib/bin/coffee $base/bin/coffee" |
| 22 | + "ln -sf $lib/bin/cake $base/bin/cake" |
| 23 | + "mkdir -p ~/.node_libraries" |
| 24 | + "ln -sf $lib/lib ~/.node_libraries/coffee-script" |
| 25 | + ].join(' && '), (err, stdout, stderr) -> |
| 26 | + if err then print stderr |
| 27 | + ) |
| 28 | + |
| 29 | + |
| 30 | +task 'build', 'build the CoffeeScript language from source', -> |
| 31 | + files: fs.readdirSync 'src' |
| 32 | + files: 'src/' + file for file in files when file.match(/\.coffee$/) |
| 33 | + run ['-c', '-o', 'lib'].concat(files) |
| 34 | + |
| 35 | + |
| 36 | +task 'build:full', 'rebuild the source twice, and run the tests', -> |
| 37 | + exec 'bin/cake build && bin/cake build && bin/cake test', (err, stdout, stderr) -> |
| 38 | + print stdout if stdout |
| 39 | + print stderr if stderr |
| 40 | + throw err if err |
| 41 | + |
| 42 | + |
| 43 | +task 'build:parser', 'rebuild the Jison parser (run build first)', -> |
| 44 | + require.paths.unshift 'vendor/jison/lib' |
| 45 | + parser: require('./lib/grammar').parser |
| 46 | + js: parser.generate() |
| 47 | + parser_path: 'lib/parser.js' |
| 48 | + fs.writeFile parser_path, js |
| 49 | + |
| 50 | + |
| 51 | +task 'build:ultraviolet', 'build and install the Ultraviolet syntax highlighter', -> |
| 52 | + exec 'plist2syntax ../coffee-script-tmbundle/Syntaxes/CoffeeScript.tmLanguage', (err) -> |
| 53 | + throw err if err |
| 54 | + exec 'sudo mv coffeescript.yaml /usr/local/lib/ruby/gems/1.8/gems/ultraviolet-0.10.2/syntax/coffeescript.syntax' |
| 55 | + |
| 56 | + |
| 57 | +task 'build:browser', 'rebuild the merged script for inclusion in the browser', -> |
| 58 | + exec 'rake browser', (err) -> |
| 59 | + throw err if err |
| 60 | + |
| 61 | + |
| 62 | +task 'doc:site', 'watch and continually rebuild the documentation for the website', -> |
| 63 | + exec 'rake doc' |
| 64 | + |
| 65 | + |
| 66 | +task 'doc:source', 'rebuild the internal documentation', -> |
| 67 | + exec 'docco src/*.coffee && cp -rf docs documentation && rm -r docs', (err) -> |
| 68 | + throw err if err |
| 69 | + |
| 70 | + |
| 71 | +task 'doc:underscore', 'rebuild the Underscore.coffee documentation page', -> |
| 72 | + exec 'docco examples/underscore.coffee && cp -rf docs documentation && rm -r docs', (err) -> |
| 73 | + throw err if err |
| 74 | + |
| 75 | + |
| 76 | +task 'test', 'run the CoffeeScript language test suite', -> |
| 77 | + helpers.extend global, require 'assert' |
| 78 | + passed_tests: failed_tests: 0 |
| 79 | + start_time: new Date() |
| 80 | + original_ok: ok |
| 81 | + helpers.extend global, { |
| 82 | + ok: (args...) -> passed_tests += 1; original_ok(args...) |
| 83 | + CoffeeScript: CoffeeScript |
| 84 | + } |
| 85 | + red: '\033[0;31m' |
| 86 | + green: '\033[0;32m' |
| 87 | + reset: '\033[0m' |
| 88 | + process.addListener 'exit', -> |
| 89 | + time: ((new Date() - start_time) / 1000).toFixed(2) |
| 90 | + message: "passed $passed_tests tests in $time seconds$reset" |
| 91 | + puts(if failed_tests then "${red}failed $failed_tests and $message" else "$green$message") |
| 92 | + fs.readdir 'test', (err, files) -> |
| 93 | + files.forEach (file) -> |
| 94 | + return unless file.match(/\.coffee$/i) |
| 95 | + source: path.join 'test', file |
| 96 | + fs.readFile source, (err, code) -> |
| 97 | + try |
| 98 | + CoffeeScript.run code.toString(), {source: source} |
| 99 | + catch err |
| 100 | + failed_tests += 1 |
| 101 | + puts "${red}failed:${reset} $source" |
| 102 | + puts err.stack |
0 commit comments