-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
4 changed files
with
134 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env node -- | ||
|
||
process.mixin(require('sys')); | ||
|
||
require.paths.unshift('./lib/coffee_script'); | ||
|
||
require('cake').run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
(function(){ | ||
var coffee, fs, path, print_tasks, tasks; | ||
var __hasProp = Object.prototype.hasOwnProperty; | ||
// `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: function task(name, description, action) { | ||
return tasks[name] = { | ||
name: name, | ||
description: description, | ||
action: action | ||
}; | ||
}, | ||
// Invoke another task in the Cakefile. | ||
invoke: function invoke(name) { | ||
return tasks[name].action(); | ||
} | ||
}); | ||
// Display the list of Cake tasks. | ||
print_tasks = function print_tasks() { | ||
var _a, _b, _c, _d, _e, _f, _g, i, name, spaces, task; | ||
_a = []; _b = tasks; | ||
for (name in _b) if (__hasProp.call(_b, name)) { | ||
task = _b[name]; | ||
_a.push((function() { | ||
spaces = 20 - name.length; | ||
spaces = spaces > 0 ? ((function() { | ||
_c = []; _f = 0; _g = spaces; | ||
for (_e=0, i=_f; (_f <= _g ? i <= _g : i >= _g); (_f <= _g ? i += 1 : i -= 1), _e++) { | ||
_c.push(' '); | ||
} | ||
return _c; | ||
}).call(this)).join('') : ''; | ||
return puts("cake " + name + spaces + ' # ' + task.description); | ||
}).call(this)); | ||
} | ||
return _a; | ||
}; | ||
// The CommandLine handles all of the functionality of the `coffee` utility. | ||
exports.run = function run() { | ||
return path.exists('Cakefile', function(exists) { | ||
var args; | ||
if (!(exists)) { | ||
throw new Error('Cakefile not found in ' + process.cwd()); | ||
} | ||
args = process.ARGV.slice(2, process.ARGV.length); | ||
return fs.cat('Cakefile').addCallback(function(source) { | ||
var _a, _b, _c, arg; | ||
eval(coffee.compile(source)); | ||
if (!(args.length)) { | ||
return print_tasks(); | ||
} | ||
_a = []; _b = args; | ||
for (_c = 0; _c < _b.length; _c++) { | ||
arg = _b[_c]; | ||
if (!(tasks[arg])) { | ||
throw new Error('No such task: "' + arg + '"'); | ||
} | ||
tasks[arg].action(); | ||
} | ||
return _a; | ||
}); | ||
}); | ||
}; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
|