rhiokim / grunt-sloc

Source line of codes plugin for Grunt.js
MIT License
23 stars 12 forks source link

grunt sloc ignores files - Maybe side effect fix for #14 #24

Open kayomarz opened 8 years ago

kayomarz commented 8 years ago

grunt sloc seems to be ignoring many files which are included in the src pattern.

To be more specific, here's my sloc config:

sloc: {
  'mylib': {
    files: {
      'mylib': ['*.js']
    }
  }
}

and here's my directory structure:

mylib/
mylib/one.js
mylib/two.js
mylib/util
mylib/util/three.js

number of files read by grunt sloc is zero. It should have been 2 files.

The problem does not occur after commenting out these lines related to solving issue #14:

    #14 negate match
     if (grunt.file.match(srcFilters, [f]).length === 0) {
        return;
     }

In the above code, f is an absolute path which seems to be the reason of the problem. One solution would have been to replace the above if condition with something like:

     var relPath = path.relative(path.join(process.cwd(), dest), f);
     if (grunt.file.match(srcFilters, [relPath ]).length === 0) {    

However after doing the above fix, src patterns such as **.js do not work.

I would think that instead of using readDir.readSync grunt's files.src.filter would do a better job. If you'd like to try this way, I can try to send a PR over the weekend.

MichaelPote commented 7 years ago

I also experience this issue with it returning 0 files found. I commented out the lines above and it worked again. Definitely a bug.