Sha256: 54f61743dda5ddbd2625e7e5b78ebca5e512310b0c166d3ffdc43412e4f1e698

Contents?: true

Size: 1.51 KB

Versions: 4

Compression:

Stored size: 1.51 KB

Contents

# `cake` is a simplified version of Make (Rake, Jake) for CoffeeScript.
# You define tasks with names and descriptions in a Cakefile, and can call them
# from the command line, or invoke them from other tasks.

fs:       require 'fs'
path:     require 'path'
coffee:   require 'coffee-script'

tasks: {}

# Mixin the top-level Cake functions for Cakefiles to use.
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) ->
    no_such_task name unless tasks[name]
    tasks[name].action()
}

# Running `cake` runs the tasks you pass asynchronously (node-style), or
# prints them out, with no arguments.
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.readFile 'Cakefile', (err, source) ->
      eval coffee.compile source
      return print_tasks() unless args.length
      invoke arg for arg in args

# 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)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
haml-more-0.5.1 vendor/coffee-script/src/cake.coffee
haml-more-0.5.0 vendor/coffee-script/src/cake.coffee
haml-more-0.4.0 vendor/coffee-script/src/cake.coffee
haml-more-0.4.0.d vendor/coffee-script/src/cake.coffee