Skip to content

Commit

Permalink
added recursive search for jakefile in parent directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Gord Tanner committed Feb 23, 2011
1 parent f727e97 commit 573a5e4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
31 changes: 19 additions & 12 deletions lib/jake.js
Expand Up @@ -33,7 +33,18 @@ var JAKE_VERSION = '0.1.8'
, jakefile
, dirname
, isCoffee
, exists
, exists = function () {
var cwd = process.cwd();

if (path.existsSync(jakefile) || path.existsSync(jakefile + '.js') || path.existsSync(jakefile + '.coffee')) {
return true;
}
process.chdir("..");
if (cwd === process.cwd()) {
return false;
}
return exists();
}
, tasks;

usage = ''
Expand Down Expand Up @@ -552,14 +563,11 @@ opts = Parser.opts;
cmds = Parser.cmds;
taskName = cmds.shift();
dirname = opts.directory || process.cwd();

process.chdir(dirname);
taskName = taskName || 'default';

jakefile = opts.jakefile ?
opts.jakefile.replace(/\.js$/, '').replace(/\.coffee$/, '') : dirname + '/Jakefile';
if (jakefile[0] != '/') {
jakefile = path.join(dirname, jakefile);
}
opts.jakefile.replace(/\.js$/, '').replace(/\.coffee$/, '') : 'Jakefile';

if (opts.help) {
jake.die(usage);
Expand All @@ -569,14 +577,14 @@ if (opts.version) {
jake.die(JAKE_VERSION);
}

isCoffee = path.existsSync(jakefile + '.coffee');
exists = path.existsSync(jakefile) || path.existsSync(jakefile + '.js') || isCoffee;

if(!exists) {
if (!exists()) {
jake.die('Could not load Jakefile.\nIf no Jakefile specified with -f or --jakefile, ' +
'jake looks for Jakefile or Jakefile.js in the current directory.');
'jake looks for Jakefile or Jakefile.js in the current directory or one of the parent directories.');
}

isCoffee = path.existsSync(jakefile + '.coffee');

try {
if (isCoffee) {
try {
Expand All @@ -586,7 +594,7 @@ try {
jake.die('CoffeeScript is missing! Try `npm install coffee-script`');
}
}
tasks = require(jakefile);
tasks = require(path.join(process.cwd(), jakefile));
}
catch (e) {
if (e.stack) {
Expand All @@ -599,7 +607,6 @@ if (opts.tasks) {
jake.showAllTaskDescriptions();
}
else {
process.chdir(dirname);
jake.runTask(taskName, cmds);
}

6 changes: 6 additions & 0 deletions tests/subdir/subsubdir/Jakefile.coffee
@@ -0,0 +1,6 @@
sys = require('sys')

desc 'This is the default task.'
task 'default', [], (params) ->
console.log 'This is the default task from the coffee script Jakefile'
console.log(sys.inspect(arguments))

0 comments on commit 573a5e4

Please sign in to comment.