Browse files

added handling also Jakefile.coffee file

  • Loading branch information...
1 parent 1f64c2d commit 0b91dd8cc0dd49aeb6090fb34007b1befca6286c @andrzejsliwa andrzejsliwa committed Sep 9, 2010
Showing with 19 additions and 13 deletions.
  1. +18 −13 lib/jake.js
  2. +1 −0 package.json
View
31 lib/jake.js
@@ -1,6 +1,6 @@
#!/usr/bin/env node
/*
- * Node-Jake JavaScript build tool
+ * Node-Jake JavaScript build tool
* Copyright 2112 Matthew Eernisse (mde@fleegix.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -37,7 +37,7 @@ var usage = ''
+ ' -h, --help Outputs help information\n'
+ ' -V, --version Outputs Node-Jake version\n'
+ '';
-
+
var parseopts = {};
/**
@@ -48,11 +48,11 @@ var parseopts = {};
* [{full: 'foo', abbr: 'f'}, {full: 'bar', abbr: 'b'}]]
*/
parseopts.Parser = function (opts) {
- // Positional commands parse out of the args
+ // Positional commands parse out of the args
this.cmds = [];
// A key/value object of matching options parsed out of the args
this.opts = {};
-
+
// Data structures used for parsing
this.reg = [];
this.shortOpts = {};
@@ -137,7 +137,7 @@ var jake = new function () {
, _taskList = []
// The args passed to the 'jake' invocation, after the task name
, _args;
-
+
// Private functions
// =================
/**
@@ -183,7 +183,7 @@ var jake = new function () {
this.namespaceTasks = {
'default': {}
};
-
+
/**
* Initial function called to run the specified task. Parses all the
* dependencies and then kick off the queue-processing
@@ -209,7 +209,7 @@ var jake = new function () {
};
/**
- * Looks up a function object based on its name or namespace:name
+ * Looks up a function object based on its name or namespace:name
* @param {String} name The name of the task to look up
*/
this.getTask = function (name) {
@@ -223,7 +223,7 @@ var jake = new function () {
nsName = 'default';
taskName = name;
}
-
+
var task = jake.namespaceTasks[nsName][taskName];
if (!task) {
throw new Error('Task "' + name + '" is not defined in the Jakefile.');
@@ -257,7 +257,7 @@ var jake = new function () {
// Run this mofo
task.handler.apply(task, passArgs);
-
+
// Async tasks call this themselves
if (!task.async) {
complete();
@@ -288,7 +288,7 @@ var jake = new function () {
}
}
if (!hasOpts) { opts = null; }
- return {cmds: cmds, opts: opts};
+ return {cmds: cmds, opts: opts};
};
/**
@@ -403,7 +403,7 @@ var dirname = opts.directory || process.cwd();
taskName = taskName || 'default';
jakefile = opts.jakefile ?
- opts.jakefile.replace(/\.js$/, '') : dirname + '/Jakefile';
+ opts.jakefile.replace(/\.js$/, '').replace(/\.coffee$/, '') : dirname + '/Jakefile';
if (jakefile[0] != '/') {
jakefile = path.join(dirname, jakefile);
}
@@ -416,14 +416,19 @@ if (typeof opts.version != 'undefined') {
jake.die(JAKE_VERSION);
}
-var exists = path.existsSync(jakefile) || path.existsSync(jakefile + '.js');
+var exists = path.existsSync(jakefile) || path.existsSync(jakefile + '.js') || path.existsSync(jakefile + '.coffee')
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.');
}
try {
- var tasks = require(jakefile);
+ if (jakefile.search(/\.js/) != -1) {
+ var tasks = require(jakefile);
+ } else {
+ CoffeeScript = require('coffee-script');
+ CoffeeScript.run(fs.readFileSync(jakefile + '.coffee').toString(), { fileName: 'Jakefile', global: true });
+ }
}
catch (e) {
jake.die('Could not load Jakefile.');
View
1 package.json
@@ -3,4 +3,5 @@
, "author" : "Matthew Eernisse <mde@fleegix.org> (http://fleegix.org)"
, "main" : "./lib/jake"
, "bin" : { "jake" : "./lib/jake.js" }
+, "dependencies": { "coffee-script" : "" }
}

0 comments on commit 0b91dd8

Please sign in to comment.