Permalink
Browse files

Merge branch 'master' of https://github.com/gtanner/node-jake into gt…

…anner-master
  • Loading branch information...
mde committed Feb 26, 2011
2 parents c2df30f + 573a5e4 commit f4b64ee34b616216a3ad4c8ff1d107bfe75d38a4
Showing with 25 additions and 12 deletions.
  1. +19 −12 lib/jake.js
  2. +6 −0 tests/subdir/subsubdir/Jakefile.coffee
View
@@ -34,7 +34,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 = ''
@@ -555,14 +566,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);
@@ -572,14 +580,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 {
@@ -589,7 +597,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) {
@@ -602,7 +610,6 @@ if (opts.tasks) {
jake.showAllTaskDescriptions();
}
else {
- process.chdir(dirname);
jake.runTask(taskName, cmds);
}
@@ -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 f4b64ee

Please sign in to comment.