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() {
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');
path = require('path');
helpers = require('./helpers');
@ -30,24 +30,22 @@
}
});
exports.run = function() {
return path.exists('Cakefile', function(exists) {
var arg, args, _i, _len, _ref, _results;
if (!exists) throw new Error("Cakefile not found in " + (process.cwd()));
args = process.argv.slice(2);
CoffeeScript.run(fs.readFileSync('Cakefile').toString(), {
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;
var arg, args, _i, _len, _ref, _results;
process.chdir(findCakefilePathSync(fs.realpathSync('.')));
args = process.argv.slice(2);
CoffeeScript.run(fs.readFileSync('Cakefile').toString(), {
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;
};
printTasks = function() {
var desc, name, spaces, task;
@ -65,4 +63,11 @@
console.log("No such task: \"" + task + "\"");
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);

View file

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