Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #5 from petebacondarwin/master

Relative compilation
  • Loading branch information...
commit b90ac32b4293ebebaa3e4a8a95a7d122c9df26e6 2 parents 123414e + 9b89279
@avalade authored
Showing with 41 additions and 20 deletions.
  1. +5 −4 tasks/coffee.js
  2. +36 −16 test/coffee_test.js
View
9 tasks/coffee.js
@@ -36,8 +36,8 @@ module.exports = function(grunt) {
var coffee = require('coffee-script'),
js = '';
- var dest = path.join(destPath,
- path.basename(src, '.coffee') + '.js');
+ destPath = destPath ? destPath : path.dirname(src);
+ var dest = path.join(destPath, path.basename(src, '.coffee') + '.js');
options = options || {};
if( options.bare !== false ) {
@@ -46,10 +46,11 @@ module.exports = function(grunt) {
try {
js = coffee.compile(grunt.file.read(src), options);
+ grunt.file.write(dest, js);
} catch (e) {
grunt.log.error("Error in " + src + ":\n" + e);
+ return false;
}
- if (this.errorCount) { return false; }
- grunt.file.write(dest, js);
});
+
};
View
52 test/coffee_test.js
@@ -2,6 +2,8 @@ var grunt = require('grunt'),
fs = require('fs'),
path = require('path');
+fs.existsSync = fs.existsSync ? fs.existsSync : path.existsSync;
+
/*
======== A Handy Little Nodeunit Reference ========
https://github.com/caolan/nodeunit
@@ -22,34 +24,52 @@ var grunt = require('grunt'),
test.ifError(value)
*/
+var src = 'test/fixtures/hello_world.coffee';
+var destFolder = 'tmp/js';
+var relativeDest = function(src) {
+ var out = path.resolve(path.dirname(src),path.basename(src, '.coffee') + '.js');
+ return out;
+};
+
exports['coffee'] = {
setUp: function(done) {
- // setup here
- fs.exists('tmp/coffee', function(exists) {
- if (exists) {
- fs.rmdir('tmp/coffee', done);
- } else {
- done();
+ done();
+ },
+
+ tearDown: function(done) {
+ if (fs.existsSync(destFolder)) {
+ if ( fs.existsSync(destFolder + '/hello_world.js') ) {
+ fs.unlinkSync(destFolder + '/hello_world.js');
}
- });
+ fs.rmdirSync(destFolder);
+ }
+ if (fs.existsSync(relativeDest(src))) {
+ fs.unlinkSync(relativeDest(src));
+ }
+ done();
},
+
'helper': function(test) {
test.expect(2);
- var files = [
- 'test/fixtures/hello_world.coffee'
- ];
- var dest = 'tmp/js';
- // tests here
- grunt.helper('coffee', files, dest);
- test.equal(grunt.file.read(dest + '/hello_world.js'),
+
+ grunt.helper('coffee', [src], destFolder);
+ test.equal(grunt.file.read(destFolder + '/hello_world.js'),
'\nconsole.log("Hello CoffeeScript!");\n',
'it should compile the coffee');
- grunt.helper('coffee', files, dest, { bare:false });
- test.equal(grunt.file.read(dest + '/hello_world.js'),
+ grunt.helper('coffee', [src], destFolder, { bare:false });
+ test.equal(grunt.file.read(destFolder + '/hello_world.js'),
'(function() {\n\n console.log("Hello CoffeeScript!");\n\n}).call(this);\n',
'it should compile the coffee');
test.done();
+ },
+
+ 'helper-nodest': function(test) {
+ grunt.helper('coffee', [src], null);
+ test.equal(grunt.file.read(relativeDest(src)),
+ '\nconsole.log("Hello CoffeeScript!");\n',
+ 'it should compile the coffee');
+ test.done();
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.