Permalink
Browse files

switching to UglifyJS for browser version of CoffeeScript.

  • Loading branch information...
1 parent 5ec7e88 commit 2c7f6d8bfe610513f800c65b7a606b10edf2cf9d @jashkenas committed Nov 11, 2010
Showing with 31 additions and 405 deletions.
  1. +30 −2 Cakefile
  2. +0 −32 Rakefile
  3. +1 −371 extras/coffee-script.js
View
@@ -8,6 +8,17 @@ red = '\033[0;31m'
green = '\033[0;32m'
reset = '\033[0m'
+# Built file header.
+header = """
+ /**
+ * CoffeeScript Compiler v#{CoffeeScript.VERSION}
+ * http://coffeescript.org
+ *
+ * Copyright 2010, Jeremy Ashkenas
+ * Released under the MIT License
+ */
+"""
+
# Run a CoffeeScript through our node/coffee interpreter.
run = (args) ->
proc = spawn 'bin/coffee', args
@@ -66,8 +77,25 @@ task 'build:ultraviolet', 'build and install the Ultraviolet syntax highlighter'
task 'build:browser', 'rebuild the merged script for inclusion in the browser', ->
- exec 'rake browser', (err) ->
- throw err if err
+ code = ''
+ for name in ['helpers', 'rewriter', 'lexer', 'parser', 'scope', 'nodes', 'coffee-script', 'browser']
+ code += """
+ require['./#{name}'] = new function() {
+ var exports = this;
+ #{fs.readFileSync "lib/#{name}.js"}
+ };
+ """
+ {parser, uglify} = require 'uglify-js'
+ ast = parser.parse """
+ this.CoffeeScript = function() {
+ function require(path){ return require[path]; }
+ #{code}
+ return require['./coffee-script']
+ }()
+ """
+ code = uglify.gen_code uglify.ast_squeeze uglify.ast_mangle ast, extra: yes
+ fs.writeFileSync 'extras/coffee-script.js', header + '\n' + code
+ invoke 'test:browser'
task 'doc:site', 'watch and continually rebuild the documentation for the website', ->
View
@@ -1,18 +1,6 @@
require 'erb'
require 'fileutils'
require 'rake/testtask'
-require 'rubygems'
-require 'closure-compiler'
-
-HEADER = <<-EOS
-/**
- * CoffeeScript Compiler v0.9.4
- * http://coffeescript.org
- *
- * Copyright 2010, Jeremy Ashkenas
- * Released under the MIT License
- */
-EOS
desc "Build the documentation page"
task :doc do
@@ -31,23 +19,3 @@ task :doc do
end
end
-desc "Build the single concatenated and minified script for the browser"
-task :browser do
- sources = %w(helpers rewriter lexer parser scope nodes coffee-script browser)
- code = sources.inject '' do |js, name|
- js << <<-"JS"
- require['./#{name}'] = new function(){
- var exports = this;
- #{ File.read "lib/#{name}.js" }
- }
- JS
- end
- code = Closure::Compiler.new.compress(<<-"JS")
- this.CoffeeScript = function(){
- function require(path){ return require[path] }
- #{ code }
- return require['./coffee-script']
- }()
- JS
- File.open('extras/coffee-script.js', 'wb+') {|f| f.write(HEADER + code) }
-end
Oops, something went wrong.

0 comments on commit 2c7f6d8

Please sign in to comment.