Adding a CoffeeScript equivalent to Rake/Make/Jake (Cake, naturally), and implementing all of our build and test tasks in the Cakefile. Run bin/cake to see the tasks.

This commit is contained in:
Jeremy Ashkenas
2010-02-16 20:42:10 -05:00
parent a8a46257ae
commit bedc005d67
4 changed files with 134 additions and 24 deletions

39
src/cake.coffee Normal file
View File

@@ -0,0 +1,39 @@
# `cake` is a simplified version of Make (Rake, Jake) for CoffeeScript.
fs: require 'fs'
path: require 'path'
coffee: require 'coffee-script'
tasks: {}
# Mixin the Cake functionality.
process.mixin {
# Define a task with a name, a description, and the action itself.
task: (name, description, action) ->
tasks[name]: {name: name, description: description, action: action}
# Invoke another task in the Cakefile.
invoke: (name) ->
tasks[name].action()
}
# Display the list of Cake tasks.
print_tasks: ->
for name, task of tasks
spaces: 20 - name.length
spaces: if spaces > 0 then (' ' for i in [0..spaces]).join('') else ''
puts "cake " + name + spaces + ' # ' + task.description
# The CommandLine handles all of the functionality of the `coffee` utility.
exports.run: ->
path.exists 'Cakefile', (exists) ->
throw new Error('Cakefile not found in ' + process.cwd()) unless exists
args: process.ARGV[2...process.ARGV.length]
fs.cat('Cakefile').addCallback (source) ->
eval coffee.compile source
return print_tasks() unless args.length
for arg in args
throw new Error('No such task: "' + arg + '"') unless tasks[arg]
tasks[arg].action()