Skip to content

Commit

Permalink
Merge pull request #73 from quaderi/master
Browse files Browse the repository at this point in the history
Filepath Bug Fix + Nonblocking Filereads
  • Loading branch information
appleboy committed Oct 17, 2014
2 parents 441b178 + c716e4e commit 9a5533a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
28 changes: 17 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = function(opt) {
return cb();
}

compass(file.path, opt, function(code, stdout, stderr, path) {
compass(file.path, opt, function(code, stdout, stderr, pathToCss) {
if (code === 127) {
return cb(new gutil.PluginError(PLUGIN_NAME, 'You need to have Ruby and Compass installed ' +
'and in your system PATH for this task to work.'));
Expand All @@ -34,18 +34,24 @@ module.exports = function(opt) {
return cb(new gutil.PluginError(PLUGIN_NAME, stdout || 'Compass failed', {fileName: file.path}));
}

// excute callback
var pathToCss = gutil.replaceExtension(path, '.css'),
contents = fs.readFileSync(pathToCss);

// Fix garbled output.
if (!(contents instanceof Buffer)) {
contents = new Buffer(contents);
}
file.contents = null;
file.path = pathToCss;

fs.readFile(pathToCss, function (err, contents) {
if (err) {
return cb(new gutil.PluginError(PLUGIN_NAME, 'Failure reading in the CSS output file'));
}

// Fix garbled output.
if (!(contents instanceof Buffer)) {
contents = new Buffer(contents);
}

file.contents = contents;
return cb(null, file);

file.path = gutil.replaceExtension(file.path, '.css');
file.contents = contents;
cb(null, file);
});
});
};

Expand Down
7 changes: 3 additions & 4 deletions lib/compass.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ module.exports = function(file, opts, callback) {

var compassExecutable = 'compass',
file_path = file.replace(/\\/g, '/'),
relative_file_name = path.relative(path.join(opts.project || process.cwd(), opts.sass), file);
relPathToSass = path.relative(path.join(opts.project || process.cwd(), opts.sass), file),
pathToCss = path.join(opts.project, opts.css, gutil.replaceExtension(relPathToSass, '.css'));

// check command exist
try {
Expand Down Expand Up @@ -132,10 +133,8 @@ module.exports = function(file, opts, callback) {

// support callback
child.on('close', function(code) {
var new_path;
new_path = path.join(opts.project, opts.css, relative_file_name);
if(callback){
callback(code, stdout, stderr, new_path);
callback(code, stdout, stderr, pathToCss);
}
});
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-compass",
"version": "1.3.2",
"version": "1.3.3",
"description": "Compile Compass files",
"main": "index.js",
"repository": {
Expand Down

0 comments on commit 9a5533a

Please sign in to comment.