Skip to content

Commit

Permalink
rename coffee-script -> caffeine
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeeich committed Sep 27, 2012
1 parent f3329f1 commit f1d953d
Show file tree
Hide file tree
Showing 26 changed files with 162 additions and 165 deletions.
58 changes: 29 additions & 29 deletions Cakefile
@@ -1,7 +1,7 @@
fs = require 'fs'
path = require 'path'
{extend} = require './lib/coffee-script/helpers'
CoffeeScript = require './lib/coffee-script'
{extend} = require './lib/caffeine/helpers'
Caffeine = require './lib/caffeine'
{spawn, exec} = require 'child_process'

# ANSI Terminal Colors.
Expand All @@ -19,7 +19,7 @@ if enableColors
# Built file header.
header = """
/**
* Caffeine Compiler v#{CoffeeScript.VERSION}
* Caffeine Compiler v#{Caffeine.VERSION}
* http://ich.github.com/caffeine
*
* Copyright 2009-2012, Jeremy Ashkenas
Expand All @@ -29,11 +29,11 @@ header = """
"""

sources = [
'coffee-script', 'grammar', 'helpers'
'caffeine', 'grammar', 'helpers'
'lexer', 'nodes', 'rewriter', 'scope'
].map (filename) -> "src/#{filename}.coffee"

# Run a CoffeeScript through our node/coffee interpreter.
# Run a CoffeeScript through our node/caffeine interpreter.
run = (args, cb) ->
proc = spawn 'node', ['bin/caffeine'].concat(args)
proc.stderr.on 'data', (buffer) -> console.log buffer.toString()
Expand All @@ -52,7 +52,7 @@ task 'install', 'install Caffeine into /usr/local (or --prefix)', (options) ->
lib = "#{base}/lib/caffeine"
bin = "#{base}/bin"
node = "~/.node_libraries/caffeine"
console.log "Installing CoffeeScript to #{lib}"
console.log "Installing Caffeine to #{lib}"
console.log "Linking to #{node}"
console.log "Linking 'caffeine' to #{bin}/caffeine"
exec([
Expand All @@ -61,22 +61,22 @@ task 'install', 'install Caffeine into /usr/local (or --prefix)', (options) ->
"ln -sfn #{lib}/bin/caffeine #{bin}/caffeine"
# "ln -sfn #{lib}/bin/cake #{bin}/cake"
"mkdir -p ~/.node_libraries"
"ln -sfn #{lib}/lib/coffee-script #{node}"
"ln -sfn #{lib}/lib/caffeine #{node}"
].join(' && '), (err, stdout, stderr) ->
if err then console.log stderr.trim() else log 'done', green
)


task 'build', 'build the CoffeeScript language from source', build = (cb) ->
task 'build', 'build the Caffeine language from source', build = (cb) ->
files = fs.readdirSync 'src'
files = ('src/' + file for file in files when file.match(/\.coffee$/))
run ['-c', '-o', 'lib/coffee-script'].concat(files), cb
run ['-c', '-o', 'lib/caffeine'].concat(files), cb


task 'build:full', 'rebuild the source twice, and run the tests', ->
build ->
build ->
csPath = './lib/coffee-script'
csPath = './lib/caffeine'
delete require.cache[require.resolve csPath]
unless runTests require csPath
process.exit 1
Expand All @@ -85,8 +85,8 @@ task 'build:full', 'rebuild the source twice, and run the tests', ->
task 'build:parser', 'rebuild the Jison parser (run build first)', ->
extend global, require('util')
require 'jison'
parser = require('./lib/coffee-script/grammar').parser
fs.writeFile 'lib/coffee-script/parser.js', parser.generate()
parser = require('./lib/caffeine/grammar').parser
fs.writeFile 'lib/caffeine/parser.js', parser.generate()


task 'build:ultraviolet', 'build and install the Ultraviolet syntax highlighter', ->
Expand All @@ -97,25 +97,25 @@ task 'build:ultraviolet', 'build and install the Ultraviolet syntax highlighter'

task 'build:browser', 'rebuild the merged script for inclusion in the browser', ->
code = ''
for name in ['helpers', 'rewriter', 'lexer', 'parser', 'scope', 'nodes', 'coffee-script', 'browser']
for name in ['helpers', 'rewriter', 'lexer', 'parser', 'scope', 'nodes', 'caffeine', 'browser']
code += """
require['./#{name}'] = new function() {
var exports = this;
#{fs.readFileSync "lib/coffee-script/#{name}.js"}
#{fs.readFileSync "lib/caffeine/#{name}.js"}
};
"""
code = """
(function(root) {
var CoffeeScript = function() {
var Caffeine = function() {
function require(path){ return require[path]; }
#{code}
return require['./coffee-script'];
return require['./caffeine'];
}();
if (typeof define === 'function' && define.amd) {
define(function() { return CoffeeScript; });
define(function() { return Caffeine; });
} else {
root.CoffeeScript = CoffeeScript;
root.Caffeine = Caffeine;
}
}(this));
"""
Expand All @@ -142,29 +142,29 @@ task 'doc:underscore', 'rebuild the Underscore.coffee documentation page', ->
throw err if err

task 'bench', 'quick benchmark of compilation time', ->
{Rewriter} = require './lib/coffee-script/rewriter'
{Rewriter} = require './lib/caffeine/rewriter'
co = sources.map((name) -> fs.readFileSync name).join '\n'
fmt = (ms) -> " #{bold}#{ " #{ms}".slice -4 }#{reset} ms"
total = 0
now = Date.now()
time = -> total += ms = -(now - now = Date.now()); fmt ms
tokens = CoffeeScript.tokens co, rewrite: false
tokens = Caffeine.tokens co, rewrite: false
console.log "Lex #{time()} (#{tokens.length} tokens)"
tokens = new Rewriter().rewrite tokens
console.log "Rewrite#{time()} (#{tokens.length} tokens)"
nodes = CoffeeScript.nodes tokens
nodes = Caffeine.nodes tokens
console.log "Parse #{time()}"
js = nodes.compile bare: true
console.log "Compile#{time()} (#{js.length} chars)"
console.log "total #{ fmt total }"

task 'loc', 'count the lines of source code in the CoffeeScript compiler', ->
task 'loc', 'count the lines of source code in the Caffeine compiler', ->
exec "cat #{ sources.join(' ') } | grep -v '^\\( *#\\|\\s*$\\)' | wc -l | tr -s ' '", (err, stdout) ->
console.log stdout.trim()


# Run the CoffeeScript test suite.
runTests = (CoffeeScript) ->
# Run the Caffeine test suite.
runTests = (Caffeine) ->
startTime = Date.now()
currentFile = null
passedTests = 0
Expand All @@ -173,7 +173,7 @@ runTests = (CoffeeScript) ->
global[name] = func for name, func of require 'assert'

# Convenience aliases.
global.CoffeeScript = CoffeeScript
global.Caffeine = Caffeine

# Our test helper function for delimiting different test cases.
global.test = (description, fn) ->
Expand Down Expand Up @@ -230,19 +230,19 @@ runTests = (CoffeeScript) ->
currentFile = filename = path.join 'test', file
code = fs.readFileSync filename
try
CoffeeScript.run code.toString(), {filename}
Caffeine.run code.toString(), {filename}
catch error
failures.push {filename, error}
return !failures.length


task 'test', 'run the CoffeeScript language test suite', ->
runTests CoffeeScript
task 'test', 'run the Caffeine language test suite', ->
runTests Caffeine


task 'test:browser', 'run the test suite against the merged browser script', ->
source = fs.readFileSync 'extras/caffeine.js', 'utf-8'
result = {}
global.testingBrowser = yes
(-> eval source).call result
runTests result.CoffeeScript
runTests result.Caffeine
2 changes: 1 addition & 1 deletion bin/caffeine
Expand Up @@ -4,4 +4,4 @@ var path = require('path');
var fs = require('fs');
var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');

require(lib + '/coffee-script/command').run();
require(lib + '/caffeine/command').run();
2 changes: 1 addition & 1 deletion bin/cake
Expand Up @@ -4,4 +4,4 @@ var path = require('path');
var fs = require('fs');
var lib = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');

require(lib + '/coffee-script/cake').run();
require(lib + '/caffeine/cake').run();
File renamed without changes.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -12,9 +12,9 @@
"node": ">=0.4.0"
},
"directories" : {
"lib" : "./lib/coffee-script"
"lib" : "./lib/caffeine"
},
"main" : "./lib/coffee-script/coffee-script",
"main" : "./lib/caffeine/caffeine",
"bin": {
"caffeine": "./bin/caffeine"
},
Expand Down
22 changes: 11 additions & 11 deletions src/browser.coffee
@@ -1,23 +1,23 @@
# Override exported methods for non-Node.js engines.

CoffeeScript = require './coffee-script'
CoffeeScript.require = require
Caffeine = require './caffeine'
Caffeine.require = require

# Use standard JavaScript `eval` to eval code.
CoffeeScript.eval = (code, options = {}) ->
Caffeine.eval = (code, options = {}) ->
options.bare ?= on
eval CoffeeScript.compile code, options
eval Caffeine.compile code, options

# Running code does not provide access to this scope.
CoffeeScript.run = (code, options = {}) ->
Caffeine.run = (code, options = {}) ->
options.bare = on
Function(CoffeeScript.compile code, options)()
Function(Caffeine.compile code, options)()

# If we're not in a browser environment, we're finished with the public API.
return unless window?

# Load a remote script from the current domain via XHR.
CoffeeScript.load = (url, callback) ->
Caffeine.load = (url, callback) ->
xhr = if window.ActiveXObject
new window.ActiveXObject('Microsoft.XMLHTTP')
else
Expand All @@ -27,13 +27,13 @@ CoffeeScript.load = (url, callback) ->
xhr.onreadystatechange = ->
if xhr.readyState is 4
if xhr.status in [0, 200]
CoffeeScript.run xhr.responseText
Caffeine.run xhr.responseText
else
throw new Error "Could not load #{url}"
callback() if callback
xhr.send null

# Activate CoffeeScript in the browser by having it compile and evaluate
# Activate Caffeine in the browser by having it compile and evaluate
# all script tags with a content-type of `text/coffeescript`.
# This happens on page load.
runScripts = ->
Expand All @@ -45,9 +45,9 @@ runScripts = ->
script = coffees[index++]
if script?.type is 'text/coffeescript'
if script.src
CoffeeScript.load script.src, execute
Caffeine.load script.src, execute
else
CoffeeScript.run script.innerHTML
Caffeine.run script.innerHTML
execute()
null

Expand Down
6 changes: 3 additions & 3 deletions src/coffee-script.coffee → src/caffeine.coffee
@@ -1,4 +1,4 @@
# CoffeeScript can be used both on the server, as a command-line compiler based
# Caffeine can be used both on the server, as a command-line compiler based
# on Node.js/V8, or to run CoffeeScripts directly in the browser. This module
# contains the main entry functions for tokenizing, parsing, and compiling
# source CoffeeScript into JavaScript.
Expand Down Expand Up @@ -29,7 +29,7 @@ exports.RESERVED = RESERVED
# Expose helpers for testing.
exports.helpers = require './helpers'

# Compile a string of CoffeeScript code to JavaScript, using the Coffee/Jison
# Compile a string of CoffeeScript code to JavaScript, using the Caffeine/Jison
# compiler.
exports.compile = compile = (code, options = {}) ->
{merge} = exports.helpers
Expand Down Expand Up @@ -77,7 +77,7 @@ exports.run = (code, options = {}) ->
mainModule._compile code, mainModule.filename

# Compile and evaluate a string of CoffeeScript (in a Node.js-like environment).
# The CoffeeScript REPL uses this to run the input.
# The Caffeine REPL uses this to run the input.
exports.eval = (code, options = {}) ->
return unless code = code.trim()
Script = vm.Script
Expand Down
6 changes: 3 additions & 3 deletions src/cake.coffee
@@ -1,6 +1,6 @@
# `cake` is a simplified version of [Make](http://www.gnu.org/software/make/)
# ([Rake](http://rake.rubyforge.org/), [Jake](http://github.com/280north/jake))
# for CoffeeScript. You define tasks with names and descriptions in a Cakefile,
# for Caffeine. You define tasks with names and descriptions in a Cakefile,
# and can call them from the command line, or invoke them from other tasks.
#
# Running `cake` with no arguments will print out a list of all the tasks in the
Expand All @@ -11,7 +11,7 @@ fs = require 'fs'
path = require 'path'
helpers = require './helpers'
optparse = require './optparse'
CoffeeScript = require './coffee-script'
Caffeine = require './caffeine'

existsSync = fs.existsSync or path.existsSync

Expand Down Expand Up @@ -49,7 +49,7 @@ exports.run = ->
global.__originalDirname = fs.realpathSync '.'
process.chdir cakefileDirectory __originalDirname
args = process.argv[2..]
CoffeeScript.run fs.readFileSync('Cakefile').toString(), filename: 'Cakefile'
Caffeine.run fs.readFileSync('Cakefile').toString(), filename: 'Cakefile'
oparse = new optparse.OptionParser switches
return printTasks() unless args.length
try
Expand Down
28 changes: 14 additions & 14 deletions src/command.coffee
Expand Up @@ -9,15 +9,15 @@ fs = require 'fs'
path = require 'path'
helpers = require './helpers'
optparse = require './optparse'
CoffeeScript = require './coffee-script'
Caffeine = require './caffeine'
{Import} = require './nodes'
{spawn, exec} = require 'child_process'
{EventEmitter} = require 'events'

exists = fs.exists or path.exists

# Allow CoffeeScript to emit Node.js events.
helpers.extend CoffeeScript, new EventEmitter
# Allow Caffeine to emit Node.js events.
helpers.extend Caffeine, new EventEmitter

printLine = (line) -> process.stdout.write line + '\n'
printWarn = (line) -> process.stderr.write line + '\n'
Expand Down Expand Up @@ -124,23 +124,23 @@ compileScript = (file, input, base) ->
options = compileOptions file
try
t = task = {file, input, options}
CoffeeScript.emit 'compile', task
if o.tokens then printTokens CoffeeScript.tokens t.input
else if o.nodes then printLine CoffeeScript.nodes(t.input).toString().trim()
else if o.run then CoffeeScript.run t.input, t.options
Caffeine.emit 'compile', task
if o.tokens then printTokens Caffeine.tokens t.input
else if o.nodes then printLine Caffeine.nodes(t.input).toString().trim()
else if o.run then Caffeine.run t.input, t.options
else if o.join and t.file isnt o.join
sourceCode[sources.indexOf(t.file)] = t.input
compileJoin()
else
time = new Date()
t.output = CoffeeScript.compile t.input, t.options
CoffeeScript.emit 'success', task
t.output = Caffeine.compile t.input, t.options
Caffeine.emit 'success', task
if o.print then printLine t.output.trim()
else if o.compile then writeJs t.file, t.output, base, new Date() - time
else if o.lint then lint t.file, t.output
catch err
CoffeeScript.emit 'failure', err, task
return if CoffeeScript.listeners('failure').length
Caffeine.emit 'failure', err, task
return if Caffeine.listeners('failure').length
return printLine err.message + '\x07' if o.watch
printWarn err instanceof Error and err.stack or "ERROR: #{err}"
process.exit 1
Expand Down Expand Up @@ -244,7 +244,7 @@ watch = (source, base) ->
importExists = no

try
nodes = CoffeeScript.nodes code.toString()
nodes = Caffeine.nodes code.toString()
catch ex
# ignore parse errors on this step

Expand Down Expand Up @@ -368,7 +368,7 @@ parseOptions = ->
sourceCode[i] = null for source, i in sources
return

# The compile-time options to pass to the CoffeeScript compiler.
# The compile-time options to pass to the Caffeine compiler.
compileOptions = (filename) ->
{filename, bare: opts.bare, header: opts.compile}

Expand All @@ -390,4 +390,4 @@ usage = ->

# Print the `--version` message and exit.
version = ->
printLine "Caffeine version #{CoffeeScript.VERSION}"
printLine "Caffeine version #{Caffeine.VERSION}"

0 comments on commit f1d953d

Please sign in to comment.