1 // Generated by CoffeeScript 1.8.0
3 var CoffeeScript, cakefileDirectory, fatalError, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
7 path = require('path');
9 helpers = require('./helpers');
11 optparse = require('./optparse');
13 CoffeeScript = require('./coffee-script');
15 CoffeeScript.register();
25 helpers.extend(global, {
26 task: function(name, description, action) {
29 _ref = [description, action], action = _ref[0], description = _ref[1];
31 return tasks[name] = {
33 description: description,
37 option: function(letter, flag, description) {
38 return switches.push([letter, flag, description]);
40 invoke: function(name) {
44 return tasks[name].action(options);
48 exports.run = function() {
49 var arg, args, e, _i, _len, _ref, _results;
50 global.__originalDirname = fs.realpathSync('.');
51 process.chdir(cakefileDirectory(__originalDirname));
52 args = process.argv.slice(2);
53 CoffeeScript.run(fs.readFileSync('Cakefile').toString(), {
56 oparse = new optparse.OptionParser(switches);
61 options = oparse.parse(args);
64 return fatalError("" + e);
66 _ref = options["arguments"];
68 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
70 _results.push(invoke(arg));
75 printTasks = function() {
76 var cakefilePath, desc, name, relative, spaces, task;
77 relative = path.relative || path.resolve;
78 cakefilePath = path.join(relative(__originalDirname, process.cwd()), 'Cakefile');
79 console.log("" + cakefilePath + " defines the following tasks:\n");
82 spaces = 20 - name.length;
83 spaces = spaces > 0 ? Array(spaces + 1).join(' ') : '';
84 desc = task.description ? "# " + task.description : '';
85 console.log("cake " + name + spaces + " " + desc);
87 if (switches.length) {
88 return console.log(oparse.help());
92 fatalError = function(message) {
93 console.error(message + '\n');
94 console.log('To see a list of all tasks/options, run "cake"');
95 return process.exit(1);
98 missingTask = function(task) {
99 return fatalError("No such task: " + task);
102 cakefileDirectory = function(dir) {
104 if (fs.existsSync(path.join(dir, 'Cakefile'))) {
107 parent = path.normalize(path.join(dir, '..'));
108 if (parent !== dir) {
109 return cakefileDirectory(parent);
111 throw new Error("Cakefile not found in " + (process.cwd()));