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
Add scoped helpers environments from file-utils #378
Conversation
requires a rebase :) |
Tests don't really work for me. In interactive sessions I get assertion errors because of color codes, non-interactive sessions choke on missing inputs in the conflicter. Could you check if this is happening for you as well, @SBoudrias? |
Base generator now expose `.src` and `.dest` who're file-utils environment scope as the sourceRoot and destinationRoot. This will allow access to more file helpers method, and also more transparent process for filtering, transpiling and validation (conflicter).
OK, fixed the failing test on Node 0.8 - the build failed because Coveralls seems down. |
Quite interested in using this PR asap it will be merged ;) |
Working fine now. Thanks! :) |
Add scoped helpers environments from file-utils
You think we should release this with 0.14? |
I'd say so. Can't really break anything and waiting for |
Yeah, make sense, plus we can consider it as beta feature an improve it from real word usage. |
And, fmi, have you some release date for the 0.14? |
Probably this week. |
I'm testing this PR, but I'm quite lost... I have some yeoman prototype function in order to test
When I launch the generator, it finds my I have the same problem with:
The fact is I have Am I using Thanks for your help |
Can you report what value you get here: console.log( this.destinationRoot() );
console.log( this.sourceRoot() ); |
@SBoudrias I get (in the same order as you ask for):
I've tried to add more log on Maybe the problem comes from |
Okay, can you log |
Well the strange thing is that |
In order to quickly and dirty overcome this path problem, I use an hardcoded absolute path as destination, and all is ok.
With |
Is your generator public, I'll fork it and test it later today. |
I think those problems are global and don't depend on a specific generator Here is a minimalistic generator that exposes both problem (
I hope you'll be able to reproduce both problems |
@jdespatis Yup, been able to reproduce. I'll send fixes a little bit later. |
@jdespatis Bugs fixed:
|
@SBoudrias feedbacks:
-> yes it fixes the issue
I was getting (previously yesterday), which is much cleaner:
Maybe this strange behavior is a drawback from your fix, or from #401. I do more tests to check |
Well after a quick test, here are the results:
I should get:
I guess your fix is involved here Maybe the fix for both would be to just add a cosmetic change when showing |
@jdespatis Checkout #409, let me know what you think. |
I have another question when using I use in fact a filter that beautifies the content of a file, but for some reason, one of my files is invalid and crashes my filter As Here is a simple generator that shows that the writeFilter is triggerered whatever the validationFilter returns:
I get this on my console:
I keep on getting It would be better I think if the validationFilter could be launched first, That way, it would avoid to print What do you think of it? |
This is expected. The idea behind write filters is that they modify the file contents or the file name. So, they need to be run before validation in order to validate the actual file to be written. In your case, the logic should be in the write filter. Can this file be used with the filter? Yes: apply the filter. No: return the file unchanged. You can also use try/catch inside the write filters or anything really. As a TL;DR
|
ok, but I still have problem to understand the benefit of validationFilter indeed. Maybe it would be nice to have some examples in the doc ? For the exception to be catched, I've added in my writeFilter the following code (
|
try/catch being synchronous, you're doing a unecessary async handling. Still, write filters don't expect to be returned an error. If you want to abort when beautification fails, then throw the error... But I think you should work around the error so your generator still produce the expected code (I don't see why beautification failing should break your generator). I'd simply catch the error, and write the file as is without beautification. The trouble with the logging here, is that all the logging happens in the yeoman conflicter handler (so this is the incorrect behaviour). For the same reason, the error returned by your validation filter is silenced because the conflicter handle the logging. This should be fixed somewhere in the future (there's a lot of work to be done), but it seems to me it is a "minor" bug; I don't see huge use case to custom validation filters on the generator author side. |
I was doing the In my case, I beautify files, but a file is not a valid json (due to a bug from the generator of sencha grr), and I prefer to break the generator, because this invalid file is really a big error I need to give an attention to And I'll do an option somewhere to let the filter continue, even for those kind of errors I've ended with the following strategy:
|
Well sorry, but I come back on previous remark. If I create a generator in order to create a png file:
You'll see that the 2 png are different, the source is good, but the destination |
Fixed cosmetic relative shown by conflicter due to #378
Is this your code exactly? (Without filters) |
The code in my previous post is exactly the code I've used to make the bug appear (png file copied is broken) You don't succeed in reproducing the problem @SBoudrias ? |
Yup, I just pushed a fixed on the lastest master of File-utils. Let me know if it works for you. Basically, I was pretty wrong in the first fix I made on your comments here. The issue was pretty deep in Grunt.file core and I had to change the default behavior of |
That's strange, I've seen your update, I'm plugged to your master, and on yeoman-generator master, and I still have the problem of png broken My example of generator previously given is working for you @SBoudrias ? |
No, but it was working after my last update. I didn't publish to NPM though, you'd need to fetch the lastest master to test it. (npm link and etc) |
Ok sorry, I've had mixed up the As a conclusion, after tests, it works now, png images are all ok Could you know create a new release and publish it to npm please ? |
I have another question @SBoudrias The fact is, when using So when using the handy functions you've put into It comes from the fact that It's not blocking as |
Yeah, that was the expected behavior, but it may indeed need changes. Also note that you can use
|
Yes, no disturbance with this format Well now, I'm happy to wait for the final |
One more thing @SBoudrias , It would be nice there to use So what would you suggest @SBoudrias ? add |
@SBoudrias After some tests, adding The quickly patch I've added into my generator is:
Well, patch is crappy of course as it modifies private vars of Therefore, why not:
What do you think of it @SBoudrias ? |
pfiou... Always look an API twice!, once is not enough... |
Ant the quick patch is not good, |
That's the way I'd do it, create a new |
Yes I'll push one soon |
@SBoudrias new bug I'm afraid, The fact is Here is a simple example to reproduce the bug:
with You should then notice that |
Another thing, I'm now intensively using And I really think that the handy functions in it like |
That make sense. Would you mind opening issues on file-utils repository so it is easier to track? |
Right |
And However, I've seen some commits on Ring a bell when you'll publish a new version of Thanks for reactivity |
Base generator now expose
.src
and.dest
who're file-utilsenvironment scope as the sourceRoot and destinationRoot. This will allow
access to more file helpers method, and also more transparent process
for filtering, transpiling and validation (conflicter).
This is a follow up commit after #313 discussion. As Grunt team ain't yet moving on exporting Grunt.file into a standalone module, it felt important to me we moved on this one as it felt a major piece for future generator user customization (style guide, JS || coffeescript, etc).
The standalone module is here: https://github.com/SBoudrias/file-utils
And I implemented a simple demo on Generator-bbb: https://github.com/backbone-boilerplate/generator-bbb/compare/remove-grunt (Generator-bbb was using grunt.file so the file methods stay the same and ain't shown clearly in the diff, but the filters are used extensively to write file in the correct style guide).