1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

style tweaks for #1687

This commit is contained in:
Jeremy Ashkenas 2011-09-11 22:25:27 -04:00
parent bd1672621c
commit c1f9ae8208
2 changed files with 31 additions and 26 deletions

View file

@ -1,5 +1,5 @@
(function() { (function() {
var CoffeeScript, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks; var CoffeeScript, findCakefilePathSync, fs, helpers, missingTask, oparse, options, optparse, path, printTasks, switches, tasks;
fs = require('fs'); fs = require('fs');
path = require('path'); path = require('path');
helpers = require('./helpers'); helpers = require('./helpers');
@ -30,24 +30,22 @@
} }
}); });
exports.run = function() { exports.run = function() {
return path.exists('Cakefile', function(exists) { var arg, args, _i, _len, _ref, _results;
var arg, args, _i, _len, _ref, _results; process.chdir(findCakefilePathSync(fs.realpathSync('.')));
if (!exists) throw new Error("Cakefile not found in " + (process.cwd())); args = process.argv.slice(2);
args = process.argv.slice(2); CoffeeScript.run(fs.readFileSync('Cakefile').toString(), {
CoffeeScript.run(fs.readFileSync('Cakefile').toString(), { filename: 'Cakefile'
filename: 'Cakefile'
});
oparse = new optparse.OptionParser(switches);
if (!args.length) return printTasks();
options = oparse.parse(args);
_ref = options.arguments;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
arg = _ref[_i];
_results.push(invoke(arg));
}
return _results;
}); });
oparse = new optparse.OptionParser(switches);
if (!args.length) return printTasks();
options = oparse.parse(args);
_ref = options.arguments;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
arg = _ref[_i];
_results.push(invoke(arg));
}
return _results;
}; };
printTasks = function() { printTasks = function() {
var desc, name, spaces, task; var desc, name, spaces, task;
@ -65,4 +63,11 @@
console.log("No such task: \"" + task + "\""); console.log("No such task: \"" + task + "\"");
return process.exit(1); return process.exit(1);
}; };
findCakefilePathSync = function(curPath) {
var parent;
if (path.existsSync(path.join(curPath, 'Cakefile'))) return curPath;
parent = path.normalize(path.join(curPath, '..'));
if (parent !== curPath) return findCakefilePathSync(parent);
throw new Error("Cakefile not found in " + (process.cwd()));
};
}).call(this); }).call(this);

View file

@ -44,7 +44,7 @@ helpers.extend global,
# asynchrony may cause tasks to execute in a different order than you'd expect. # asynchrony may cause tasks to execute in a different order than you'd expect.
# If no tasks are passed, print the help screen. # If no tasks are passed, print the help screen.
exports.run = -> exports.run = ->
process.chdir findCakefilePathSync(fs.realpathSync '.') process.chdir cakefileDirectory fs.realpathSync '.'
args = process.argv.slice 2 args = process.argv.slice 2
CoffeeScript.run fs.readFileSync('Cakefile').toString(), filename: 'Cakefile' CoffeeScript.run fs.readFileSync('Cakefile').toString(), filename: 'Cakefile'
oparse = new optparse.OptionParser switches oparse = new optparse.OptionParser switches
@ -67,10 +67,10 @@ missingTask = (task) ->
console.log "No such task: \"#{task}\"" console.log "No such task: \"#{task}\""
process.exit 1 process.exit 1
# Search in current and parent directories for Cakefile # When `cake` is invoked, search in the current and all parent directories
findCakefilePathSync = (curPath) -> # to find the relevant Cakefile.
return curPath if path.existsSync path.join(curPath, 'Cakefile') cakefileDirectory = (dir) ->
parent = path.normalize path.join(curPath, '..') return dir if path.existsSync path.join dir, 'Cakefile'
return findCakefilePathSync parent unless parent == curPath parent = path.normalize path.join dir, '..'
# None found return cakefileDirectory parent unless parent is dir
throw new Error("Cakefile not found in #{process.cwd()}") throw new Error "Cakefile not found in #{process.cwd()}"