Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It would be nice to have the source and destination filename available to the "to" function #2

Open
stuartf opened this issue Jan 17, 2013 · 10 comments

Comments

@stuartf
Copy link

stuartf commented Jan 17, 2013

I'd like to do something like:

replacements: [{
  from: /foo/,
  to: function(matchedWord, index, fullText, regexMatches, sourceFile) {
    grunt.log.writeln('Found "foo" in ' + sourceFile + ' replacing with "bar".');
    return 'bar';
  }
}]

Maybe I'm missing something and this is available through something like grunt.task, but the closest I've found is grunt.task.current.file.src which gives me the unexpanded path (something like ['**/*.js']).

@yoniholmes
Copy link
Owner

Hi Stuart, thanks for your suggestion. It's a good idea, I'll try to get this for the next update. I don't believe there's a way to achieve this at present, without a refactor to the plugin itself.

One factor in the potential solution is that the number of parameters in the callback is rather high: matchedWord, index, fullText, regexMatches, pathToSource, pathToDestination, it might be best to have a single object returned, with each of these properties hanging off it. It would also be more extensible in future. It's just not backwards compatible. Will let you know when it lands. Cheers, Jonathan

@spyro1st
Copy link

Hi Jonathan,

is there any update on this issue? Accessing the src and dst in the "to" function would be great for my current issue. I understand that this will be a breaking change, maybe an script to upgrade the gruntfile would reduce the pain.

@snostorm
Copy link

Based on the fork from #7 I added awareness for the "src" and "dest" via snostorm@d49925b

I wasn't confident to post it yet as a pull request as the tests weren't passing for me on the base #7 commits I started with.

@yoniholmes
Copy link
Owner

Hi guys, thanks for the comments. I can see how this would be helpful. I had a go at implementing this after my previous comment. Unfortunately, it required such a fundamental rewrite that it would have forced a different approach, and a rewrite of the test suite. I'm still open to the idea of getting this into a future realise, but I haven't immediate plans to add this new feature. I hope you might be able to find a work around in the meantime. If someone however is able to implement the new functionality, and pass the current test suite, then I will of course consider accepting a pull request. Many thanks, Jonathan

@e1024kb
Copy link

e1024kb commented Aug 8, 2013

yoniholmes, any news about approving the pull request?

@yoniholmes
Copy link
Owner

Hi @ebaranov. Based on your recent request, I've had a go a merging the pull request but found the merge request didn't pass the unit tests. If someone can have a go a updating the pull request so that it passes all the tests, then I'll be happy to merge this in. I expect I won't look at this until someone sends the request though, as unfortunately this isn't a feature I need myself. Many thanks & sorry for the delay in getting back to you. Cheers, Jonathan

@e1024kb
Copy link

e1024kb commented Aug 26, 2013

Thanks @yoniholmes, I think I will have a time to check it this week.

@pfrankov
Copy link

So, what's news?

@running-coder
Copy link

+1, I need this feature to solve my current issue where I have to apply different operations based on the source file matched by the regex. I'll use seanzarrin's "passSourceFile" branch for now.
Thanks!

@Skwal
Copy link

Skwal commented Aug 18, 2015

Same problem here. This thread is more than 2 years old, and this is still no implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants