2010-02-16 20:42:10 -05:00
|
|
|
# `cake` is a simplified version of Make (Rake, Jake) for CoffeeScript.
|
2010-02-25 01:17:43 -05:00
|
|
|
# You define tasks with names and descriptions in a Cakefile, and can call them
|
|
|
|
# from the command line, or invoke them from other tasks.
|
2010-02-16 20:42:10 -05:00
|
|
|
|
|
|
|
fs: require 'fs'
|
|
|
|
path: require 'path'
|
|
|
|
coffee: require 'coffee-script'
|
|
|
|
|
|
|
|
tasks: {}
|
|
|
|
|
2010-02-25 01:17:43 -05:00
|
|
|
# Mixin the top-level Cake functions for Cakefiles to use.
|
2010-02-16 20:42:10 -05:00
|
|
|
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) ->
|
2010-02-17 20:37:30 -05:00
|
|
|
no_such_task name unless tasks[name]
|
2010-02-16 20:42:10 -05:00
|
|
|
tasks[name].action()
|
|
|
|
}
|
|
|
|
|
2010-02-16 23:23:43 -05:00
|
|
|
# Running `cake` runs the tasks you pass asynchronously (node-style), or
|
|
|
|
# prints them out, with no arguments.
|
2010-02-16 20:42:10 -05:00
|
|
|
exports.run: ->
|
|
|
|
path.exists 'Cakefile', (exists) ->
|
|
|
|
throw new Error('Cakefile not found in ' + process.cwd()) unless exists
|
|
|
|
args: process.ARGV[2...process.ARGV.length]
|
2010-02-21 14:06:01 -05:00
|
|
|
fs.readFile 'Cakefile', (err, source) ->
|
2010-02-16 20:42:10 -05:00
|
|
|
eval coffee.compile source
|
|
|
|
return print_tasks() unless args.length
|
2010-02-25 01:17:43 -05:00
|
|
|
invoke arg for arg in args
|
2010-02-16 20:42:10 -05:00
|
|
|
|
2010-02-25 01:17:43 -05:00
|
|
|
# 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
|
|
|
|
|
|
|
|
# Print an error and exit when attempting to all an undefined task.
|
|
|
|
no_such_task: (task) ->
|
|
|
|
process.stdio.writeError('No such task: "' + task + '"\n')
|
|
|
|
process.exit(1)
|