Skip to content
Browse files

added recursive search for jakefile in parent directories

  • Loading branch information...
1 parent f727e97 commit 573a5e4bdc0898925e53fbacea29d1dbf9694b85 Gord Tanner committed Feb 23, 2011
Showing with 25 additions and 12 deletions.
  1. +19 −12 lib/jake.js
  2. +6 −0 tests/subdir/subsubdir/Jakefile.coffee
View
31 lib/jake.js
@@ -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 = ''
@@ -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);
@@ -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 {
@@ -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) {
@@ -599,7 +607,6 @@ if (opts.tasks) {
jake.showAllTaskDescriptions();
}
else {
- process.chdir(dirname);
jake.runTask(taskName, cmds);
}
View
6 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.
Something went wrong with that request. Please try again.