Skip to content

Commit

Permalink
fixes in path finding, also added options baseDir and debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Wenqer committed Feb 4, 2014
1 parent d7783a8 commit a256aed
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
5 changes: 0 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ module.exports = function (opts) {
function rebase(file, encoding, callback) {
var self = this;

if (file.path.indexOf('src') === -1) {
self.push(file);
return callback();
}

encode.stylesheet(file, opts, function (err, src) {
if (err) {
console.error(err);
Expand Down
21 changes: 13 additions & 8 deletions lib/encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ module.exports = (function () {
is_local_file = !rData.test(img) && !rExternal.test(img);

// Resolve the image path relative to the CSS file
if(is_local_file) {
if (is_local_file) {
// local file system.. fix up the path
loc = path.join(path.dirname(file.path), img);
// loc = img.charAt(0) === "/" ?
// (opts.baseDir || "") + loc :
// path.join(path.dirname(srcFile), (opts.baseDir || "") + img);
// loc = path.join(path.dirname(file.path), img);

loc = opts.baseDir ? path.join(file.cwd, opts.baseDir, img) :
path.join(path.dirname(file.path), img);

// If that didn't work, try finding the image relative to
// the current file instead.
if(!fs.existsSync(loc)) {
loc = path.resolve(__dirname + img);
loc = path.resolve(file.cwd + img);
}
}

Expand Down Expand Up @@ -195,14 +195,19 @@ module.exports = (function () {
// Local file?
} else {
// Does the image actually exist?
if(!fs.existsSync(img)) {
if(!fs.existsSync(img) || !fs.lstatSync(img).isFile()) {
// grunt.fail.warn("File " + img + " does not exist");
if (opts.debug) {
console.warn("File " + img + " does not exist");
}
complete(null, img, false);
return;
}

// grunt.log.writeln("Encoding file: " + img);
// console.log("Encoding file: " + img);
if (opts.debug) {
console.info("Encoding file: " + img);
}

// Read the file in and convert it.
var src = fs.readFileSync(img);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gulp-base64",
"version": "0.0.1",
"version": "0.0.2",
"description": "gulp task to encode images to data-uti",
"main": "index.js",
"homepage": "http://github.com/Wenqer/gulp-base64",
Expand Down

0 comments on commit a256aed

Please sign in to comment.