mirror of
https://github.com/jashkenas/coffeescript.git
synced 2022-11-09 12:23:24 -05:00
switching to UglifyJS for browser version of CoffeeScript.
This commit is contained in:
parent
5ec7e885f1
commit
2c7f6d8bfe
3 changed files with 31 additions and 405 deletions
32
Cakefile
32
Cakefile
|
@ -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', ->
|
||||
|
|
32
Rakefile
32
Rakefile
|
@ -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
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue