From 32cccc6151834643f0eee8e0b339ac5f5387d502 Mon Sep 17 00:00:00 2001 From: Gregory Waxman Date: Mon, 28 May 2012 19:31:19 -0300 Subject: [PATCH 1/2] Support for IcedCoffeeScript. If iced is not found it will fallback to coffee. --- lib/node.io/utils.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/node.io/utils.js b/lib/node.io/utils.js index 397dcd4..066c2fe 100644 --- a/lib/node.io/utils.js +++ b/lib/node.io/utils.js @@ -79,9 +79,20 @@ exports.removeOnExit = function (file) { * @api public */ exports.compileCoffee = function (coffee_file, compiled_file, callback) { - exec('coffee -p -c "' + coffee_file + '"', {cwd: cwd}, function (err, stdout, stderr) { + exec('iced -p -c "' + coffee_file + '"', {cwd: cwd}, function (err, stdout, stderr) { if (err || stderr) { - callback(err || stderr); + if (!stderr || (stderr && stderr.indexOf("iced: not found") === -1)) { + callback(err || stderr); + } else { + exec('coffee -p -c "' + coffee_file + '"', {cwd: cwd}, function (err, stdout, stderr) { + if (err || stderr) { + callback(err || stderr); + } else { + exports.removeOnExit(compiled_file); + fs.writeFile(compiled_file, stdout, callback); + } + }); + } } else { exports.removeOnExit(compiled_file); fs.writeFile(compiled_file, stdout, callback); From 61b67c29fc844e6b9c5f092bce795fd09e57efe5 Mon Sep 17 00:00:00 2001 From: Gregory Waxman Date: Tue, 29 May 2012 16:22:06 -0400 Subject: [PATCH 2/2] Added a command line option to specify the compiler, which defaults to coffee. Removed hardcoded use of iced compiler and allow compilation from anything that supports the same command line arguments as coffee. --- lib/node.io/interfaces/cli.js | 5 +++++ lib/node.io/processor.js | 2 +- lib/node.io/utils.js | 17 +++-------------- 3 files changed, 9 insertions(+), 15 deletions(-) diff --git a/lib/node.io/interfaces/cli.js b/lib/node.io/interfaces/cli.js index 34a2212..a575964 100755 --- a/lib/node.io/interfaces/cli.js +++ b/lib/node.io/interfaces/cli.js @@ -30,6 +30,7 @@ var usage = '' + ' -g, --debug Debug the operation\n' + ' -v, --version Display the current version\n' + ' -h, --help Display help information\n' + + ' -c, --compiler Set an alternate compiler to use\n' ; /** @@ -118,6 +119,10 @@ exports.cli = function (args, exit) { case '--unpack': options.unpack = args.shift(); break; + case '-c': + case '--compiler': + options.compiler = args.shift(); + break; default: job_path = arg; if (args.length) { diff --git a/lib/node.io/processor.js b/lib/node.io/processor.js index 070f223..5ebe03b 100644 --- a/lib/node.io/processor.js +++ b/lib/node.io/processor.js @@ -335,7 +335,7 @@ Processor.prototype.loadJob = function (job, options, callback) { //If we're the master, compile and load the .coffee file this.status('Compiling ' + job + ' => ' + compiled_js, 'debug'); - utils.compileCoffee(job, compiled_js, function(err) { + utils.compile(options.compiler || 'coffee', job, compiled_js, function(err) { if (err) { callback(err); } else { diff --git a/lib/node.io/utils.js b/lib/node.io/utils.js index 066c2fe..ea1a1af 100644 --- a/lib/node.io/utils.js +++ b/lib/node.io/utils.js @@ -78,21 +78,10 @@ exports.removeOnExit = function (file) { * @param {Function} callback * @api public */ -exports.compileCoffee = function (coffee_file, compiled_file, callback) { - exec('iced -p -c "' + coffee_file + '"', {cwd: cwd}, function (err, stdout, stderr) { +exports.compile = function (compiler, coffee_file, compiled_file, callback) { + exec(compiler + ' -p -c "' + coffee_file + '"', {cwd: cwd}, function (err, stdout, stderr) { if (err || stderr) { - if (!stderr || (stderr && stderr.indexOf("iced: not found") === -1)) { - callback(err || stderr); - } else { - exec('coffee -p -c "' + coffee_file + '"', {cwd: cwd}, function (err, stdout, stderr) { - if (err || stderr) { - callback(err || stderr); - } else { - exports.removeOnExit(compiled_file); - fs.writeFile(compiled_file, stdout, callback); - } - }); - } + callback(err || stderr); } else { exports.removeOnExit(compiled_file); fs.writeFile(compiled_file, stdout, callback);