-
Notifications
You must be signed in to change notification settings - Fork 103
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
have a post processing script in the root of the template #2
Comments
This is a good idea. It will require several pieces I think:
I suggest just using |
Since lazybones itself has a fairly simple set of arguments would it be possible to just pass additional arguments to the template like Yeoman does? |
Example? I don't have a problem with that, but it can be awkward to determine whose args are whose when one or more of the lazybones args are optional. |
https://github.com/yeoman/generator-angular#options-1 On Tue, Apr 30, 2013 at 9:05 AM, Peter Ledbrook notifications@github.comwrote:
|
So that makes sense for boolean type options, but I was thinking of key-value pairs with the -P option. For example, for variable substitution into templates. The disadvantage of -P and -D options is that Windows batch files inconveniently strip out the '='! Grails suffers from this, although I think that's mainly because you have We can probably do something similar to Grails where options such as |
So another idea I had.... which I think might be too ambitious, is supporting multiple languages. So a template would have 1 lazybones script at the root, but it could be lazybones.rb, lazybones.groovy or even lazybones.sh. Having a bash option, albeit not OS agnostic, might be an easier choice for certain templating problems. Of course I could just call a bash script in groovy too ;). |
Also... how far do we go. If lazybones can support arguments, should it resolve something other than templates? Should we resolve directory / package names as well? I can't tell if this should be handled 100% by the template author with their lazybones script. Also most people use IDEs for JVM projects.... maybe it isn't unreasonable to assume that the user can do some refactoring themselves. And finally, if the lazybones bones author is fully responsible managing templating outside of downloading and filtering files, how can lazybones promote code reuse? Given that groovy has grape, maybe this isn't such a big deal. |
I like the the idea of putting everything into an options map as @pledbrook described. If we do that do we really need -P or -D? just do --grailsVersion=2.2.1. If there is no key value pair (ie '=') then you revert to storing it as a boolean. |
On the options front, I prefer standard behaviour where possible. Unfortunately, there are several competing standards 😄 @tbarker9 The one you suggest is pretty much the Grails approach. The downside is that no argument parsing library can handle it IIRC. But then the 'parsing' logic isn't particularly complicated based on regular expressions. And I don't think any arg parsing library can handle dynamic options anyway (ones that aren't known in advance). So perhaps the Grails approach is the best one. As for multiple languages, that sounds like a step too far at this point in time. Keep it simple and narrowly focused until there is an identified need. The simpler it is, the easier it is to maintain - and that is a guiding principle of the project. That said, your point about promoting reuse is well taken, although perhaps I have a different interpretation. Filtering out files, variable substitution into files, etc. are things that lazybones can provide support for. But what happens if a template requires a particular feature that isn't in the version of lazybones the user is running? I think it would be nice to have |
Maybe for arg parsing lazybones should use the most popular one... even if it is not the coolest one;) Since most users of lazy bones will probably use gradle, and grails is moving to gradle, I suppose the -P convention makes more sense. Also, you have to use gradle to package the template so why deviate from the norm. I am trying to decide what I want lazybones to be. Its simplicity and integration with bintray put a big smile on my face. If it can handle variable and basic template filtering I will definitely use this. That said, I need to manipulate directory / packages based on passed variables; maybe the tools of the underlying platform are better for this.... or use the root script.... or force the user to manipulate this stuff themselves with an IDE. After all, it's just a template.... or a starting point. I think if the feature set for lazybones are well defined and fixed So here is the next question..... what should the root post processing script be? If the feature set for lazybones is well defined, should it be meta data / DSL about what files are included / excluded and filtered. Maybe add some processing hooks as closures such as postFilter, preFilter. Basically you would run the script, gather your defined variables and act appropriately. Or should it be directly called after the template is downloaded while containing helpful methods such as As for code reuse, it is so easy to address either by importing remote scripts or grape that I am not sure it is worth pursuing. Also if your template has an insanely complex root script... you are probably doing it wrong. Complex scaffolding / templating should probably be left to a build tool or custom processing. |
Or should it be directly called after the template is downloaded while containing helpful methods such as ask or filter or whatever. In the spirit of simplicity I think the last option is less disruptive and more in line with lazybones objectives. This. I don't think a DSL will add much, while adding the maintenance burden. I'm not even sure whether to have the helper methods on the script class or on a utility class such that they can be statically imported. The latter has the benefit of a namespace, but the former can store state. In fact, I think an So, here's what I think should happen:
A
More methods can be added later if common tasks are discovered in the future. But lazybones does not dictate how the post-install script should work or what it should do. That's not its job. |
Maybe for arg parsing lazybones should use the most popular one... even if it is not the coolest one;) Since most users of lazy bones will probably use gradle, and grails is moving to gradle, I suppose the -P convention makes more sense. Also, you have to use gradle to package the template so why deviate from the norm. Except users of Lazybones may not be into Gradle. I'm definitely cooling on the '-P' approach. It's ugly and I don't think the reasons for its use in Gradle apply here. The only other possibility is something like
I actually prefer the syntax, but I don't think regular expression matches would help parse it. Still, shouldn't be too hard as long as we require that all options come at the end of the normal I just realised we should probably add at least a --verbose/-v option to |
If user may not be into gradle should lazybones use it to upload a template? I understand its immediate need to pound something out useful and fast. I would say I am kind of indifferent. I am also java trained and am more comfortable with ugliness like this more than I should be ;) Haven't used the groovy cli helpers enough to know how hard this would be to parse, can't imagine it would be too hard by hand though. I assume all arguments after |
The script you proposed seems solid to me. I assume you would use it as the base to the root script... the user wouldn't extend it. Might even open doors in the future to swap in different base scripts..... essentially a micro plugin I guess. Could be handy for certain scopes... maybe grails projects could have a different base script vs other projects. Way in the future if ever. Fun to think about. |
The creator/uploader of a template is a small subset of the users of that template (hopefully). And to be honest, there's nothing that requires a template author to publish the template through Gradle. It's just the tool I use for building and publishing Lazybones itself, + any templates I create. And yes, |
Ah, great point. lazybones may give you a tool to upload templates, but that isn't its primary job, got it. Use gradle, groovy or just drop it in a http friendly vcs. Whatever. Hah, that is a humdinger. LazybonesScript looks weird, but lazyBones.groovy looks weird as well. |
I may give LazyBonesScript a shot today with a couple of assumptions:
I think I will use antbuilder file scanner for file filtering. If there is a more appropriate solution, maybe we can pursue it later on. |
If you want to use One thing I'm not sure about is whether |
I was thinking of using the filescanner just to grab files, then filter them in place by hand with SimpleTemplateEngine. So the workflow would be: find files with ant based filter (aka filescanner) -> create template from them -> erase template file -> write new result. I feel a little weird filtering files in place though. |
You can see what I mean here: https://github.com/tbarker9/lazybones/blob/lazyscriptroot/src/main/groovy/uk/co/cacoethes/lazybones/LazyBonesScript.groovy. Once I implement |
Pull request applied, but of course we still need to invoke the post-installation script 😄 And before this feature goes into a release, we need a packaged template that includes such a script such that we can add an integration test. |
Understood, see my comment at the end of #14 |
I moved the command line options to #17. Figured there is enough going on in this issue without that. |
I should get this implemented by tomorow. Thanks for the integrated test harness, this is going to be really handy. Unless someone has a better idea I am going to create a basic gradle / groovy template that will include some basic questions and file filtering. |
I'm happy to close this now as the basic feature is now there. Any further changes should have their own issues. Sound OK? |
👍 |
Some project structures require a little more than just downloading files (maven, grails, etc.). If there was a root level script (maybe called lazybones.groovy?), post processing could adjust the files appropriately. Maybe it could even receive arguments for further customization.
The text was updated successfully, but these errors were encountered: