Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

104 lines (82 sloc) 2.8 KB
{exec} = require 'child_process'
fs = require 'fs'
path = require 'path'
os = require 'os'
# Gain access through PATH to all binaries added by `npm install`
npm_bin = path.resolve(path.join('node_modules', '.bin'))
path_sep = if os.platform() == 'win32' then ";" else ":"
process.env.PATH = "#{npm_bin}#{path_sep}#{process.env.PATH}"
task 'test', 'Run all tests', ->
# run directly to get all the delicious output
console.log 'Running tests... (is your webclient up-to-date?)'
exec 'nodeunit', (err, stdout, stderr) ->
throw err if err
# This is only needed to be able to refer to the line numbers of crashes
task 'build', 'Build the .js files', (options) ->
console.log('Compiling Coffee from src to lib')
exec "coffee --compile --bare --output lib/ src/", (err, stdout, stderr) ->
throw err if err
console.log stdout + stderr
client = [
extras = [
# Backticks
e = (str, callback) ->
console.log str
exec str, (err, stdout, stderr) ->
throw err if err
out = stdout + stderr
console.log out if out != ''
callback() if callback?
makeUgly = (infile, outfile) ->
# Uglify compile the JS
source = fs.readFileSync infile, 'utf8'
{parser, uglify} = require 'uglify-js'
opts =
WEB: ['name', 'true']
ast = parser.parse source
ast = uglify.ast_lift_variables ast
ast = uglify.ast_mangle ast, opts
ast = uglify.ast_squeeze ast
code = uglify.gen_code ast
smaller = Math.round((1 - (code.length / source.length)) * 100)
output = outfile
fs.writeFileSync output, code
console.log "Uglified: #{smaller}% smaller (#{code.length} bytes} written to #{output}"
expandNames = (names) -> ("src/#{c}.coffee" for c in names).join ' '
compile = (filenames, dest) ->
filenames = expandNames filenames
# I would really rather do this in pure JS.
e "coffee -j #{dest}.uncompressed.js -c #{filenames}", ->
console.log "Uglifying #{dest}"
makeUgly "#{dest}.uncompressed.js", "#{dest}.js"
buildtype = (name) ->
filenames = ['types/web-prelude', "types/#{name}"]
fs.statSync "src/types/#{name}"
filenames.push "types/#{name}-api"
compile filenames, "webclient/#{name}"
task 'webclient', 'Build the web client into one file', ->
compile client, 'webclient/share'
buildtype 'json'
buildtype 'text-tp2'
# TODO: This should also be closure compiled.
extrafiles = expandNames extras
e "coffee --compile --output webclient/ #{extrafiles}", ->
# For backwards compatibility. (The ace.js file used to be called share-ace.js)
e "cp webclient/ace.js webclient/share-ace.js"
#task 'lightwave', ->
# buildclosure ['client/web-prelude', 'client/microevent', 'types/text-tp2'], 'lightwave'
Jump to Line
Something went wrong with that request. Please try again.