Permalink
Browse files

.coffee ext is now auto-detected

  • Loading branch information...
1 parent 288faea commit 48b0c593a139bc645977bfa631a553515c28f608 @chriso chriso committed Dec 16, 2010
Showing with 42 additions and 11 deletions.
  1. +24 −8 lib/node.io/cli.js
  2. +18 −3 lib/node.io/processor.js
View
@@ -230,8 +230,8 @@ exports.cli = function (args) {
temp_job += '});';
//Remove the temp file when the process exits
- //utils.removeOnExit(temp_filename);
-
+ utils.removeOnExit(temp_filename);
+
fs.writeFile(temp_filename, temp_job, function(err) {
if (err) {
exit(err, true);
@@ -246,12 +246,31 @@ exports.cli = function (args) {
return;
}
+ var ext = path.extname(job_path), is_coffee = false;
+
+ if (ext) {
+
+ is_coffee = ext === '.coffee' ? true : false
+
+ } else {
+
+ //No extension provided. Check to see if it's a .coffee file, otherwise let NodeJS determine the ext
+ try {
+ fs.lstatSync(job_path + '.coffee');
+ job_path += '.coffee';
+ is_coffee = true;
+ } catch (e) {}
+ }
+
//Normally we would compile .coffee files in Processor.loadJob(), but
//since we're modifying the job using one or more switches, we need to
//compile it here first
- if (path.extname(job_path) === '.coffee') {
-
- is_coffee = true;
+ if (is_coffee) {
+
+ //Make it a full path
+ if (job_path.indexOf('/') === -1) {
+ job_path = process.cwd() + '/' + job_path;
+ }
var basename = path.basename(job_path, '.coffee');
var job_compiled = '/tmp/' + basename + '_compiled.js';
@@ -275,11 +294,8 @@ exports.cli = function (args) {
}
});
- return;
-
} else {
create_temp_job(job_path, start_processor);
- return;
}
}
};
View
@@ -228,13 +228,28 @@ Processor.prototype.loadJob = function (job, callback) {
} else if (typeof job === 'string') {
- if (path.extname(job) !== '.coffee') {
+ var ext = path.extname(job), is_coffee = false;
+
+ if (ext) {
+
+ is_coffee = ext === '.coffee' ? true : false
+
+ } else {
+
+ //No extension provided. Check to see if it's a .coffee file, otherwise let NodeJS determine the ext
+ try {
+ fs.lstatSync(job + '.coffee');
+ job += '.coffee';
+ is_coffee = true;
+ } catch (e) {}
+ }
+
+ if (!is_coffee) {
- //Let node determine the extension and load
try {
callback(null, job, require(job).job);
} catch (e) {
- callback('Failed to load job "' + job + '"');
+ callback('Failed to load job "' + job + '". Node.io accepts CoffeeScript and JS modules (.js/.coffee).');
}
} else {

0 comments on commit 48b0c59

Please sign in to comment.