mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-19 03:44:23 -05:00
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:
39
src/cake.coffee
Normal file
39
src/cake.coffee
Normal 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()
|
||||
|
||||
Reference in New Issue
Block a user