-
Notifications
You must be signed in to change notification settings - Fork 841
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
stack new
for creating new projects with templates
#137
Comments
Depending on when we get around to #138, or perhaps depending on the "template" being used, I like the idea of having a cli for tasks like "stack create module Foo.Bar", which creates |
Just realized I haven't commented here yet, so: I'm +1 on doing this, and thank you for writing up a detailed description. We need to think about how this will play in with some kind of a Pinging @khanage, you have interest in working on this issue? |
I've been half starting on this for a bit now, so I'm happy to take it on (and happy to hand it over to someone a bit more experienced as well). My vision for this is something very much like lein. One of the best stories I have demo'ing functional programming with coworkers is to get them to
And they've got a web site up and running, which they modify without learning much. I'd like to replicate that (indeed that's the goal of hein), so that means for To create that stack.yaml file - perhaps it's best to try and call |
Here's my recommendation: start on the general templating stuff now, not worrying too much about the interplay with |
I've opened #253 to try and discuss this and other related topics together |
Just full disclosure, I'm fairly new to haskell at the level of doing things, so I'm going to be pretty slow with this. I've made a small start on this, but my question is: how should I check this in? Should I create a branch on this repo, or fork the stack project completely? (Pretty new to open source as well ;)). Sorry if this isn't the right forum for this, but I think it's better to be upfront about my ignorance. |
No problem at all, feel free to ask questions :) I'd recommend committing to a separate branch. I like the convention of using the issue number in the branch new, so maybe 137-template or something like that. |
There is prior art in this area that should be considered. One is Michael's project-template. Another is hi https://github.com/fujimura/hi/blob/master/README.md |
@khanage Just an FYI, we all seem to be in alignment now about the project initialization approach, and the description laid out here for what |
All good - like I said, I'm fairly new, so it takes me time to learn all the libraries that are in use (e.g. optparse). I'm kind of stuck on deciding on a design for the templates - I was thinking of trying to create an ADT which represents possible actions templates can take (e.g. createFile, createDir, runCommand, assertFile) and wrapping that up in a free monad. Any suggestions anyone? I'm open for guidance :). |
why do you need a free monad? you might be overthinking things and be better off just cranking out some code right now. |
After experience with the Yesod scaffolding, we eventually came down to maintaining the scaffolding in its own repo with different branches for the various flavors (which, in Yesod's case, was mostly about database backends). This made it easy to maintain multiple flavors, merge changes between them, and test them automatically. My experience with that has only been positive. Trying to maintain a complicated scaffolding inside Haskell code itself will likely be quite difficult to manage. |
@radix I read through your list most closely, and I really like your plugins idea. To elaborate: this would essentially be a collection of different templates that stack could download and offer to the user, right? If we do this well, it could completely subsume functionality like @khanage I'd be happy to work through some of the architectural issues around something like that, which would leave you free to come up with a good project template itself. Does that sound like a good plan? |
@gregwebs - I take your point, I'll get something that just works (by that I mean barely) out and we can go from there. I was thinking of using the free monad so that it provides a convenient syntax for template creators to use to create templates, but as @snoyberg points out, that might not be a scalable approach. @snoyberg the plugins part is exactly what I'm trying to work out. I'll build something naive, and we can go from there? |
Sounds good. Not to put pressure on, but do you have an ETA on something here? If it's going to be beyond this week, I'll add some brain dead code to get started so that stack is easy for new users to test out. |
I've got a referenced commit? 8a6d987 I'm happy for anyone to just scrap that with something better, or to give me some feedback and I can get on making some changes. |
It's a start, but my hope is to get to a place where we're not relying on cabal-install for anything. |
Yeah, I had a look at the relevant cabal source and there's a comment there saying it's ad-hoc. I was hoping to use that directly rather than calling out via shell commands. There's probably a bit of room for writing such a mapping, but I thought I'd push this up and get some feedback/assistance first before it looked like I'd abandoned it. |
I was thinking we could go for something much simpler than what |
This is how I see things: commands
flags:
Ability to pass in key:value list in params templates fetching
templates structure
possible template versioning built in:stack new mytemplate
templating ?
example for filenames
example for contents
or
various example syntaxesstack new yesod-handler name:launch-missiles renderer:lucid What do you think ? I think it provides enough flexibility and customization for everyone, and remains really simple |
@rvion - All the parts of templating that you suggest are implicit. Is it worthwhile to have an (optional) template configuration? It could hold things like help documentation, preprocessing commands, or other programmatic helpers? I like the idea that the templating can be extended to the rails use case of I'm a 👍 on the proposal. |
@cschneid can you explain what do you mean by Here are some more infos: in addition to commands like,
we could indeed come up with a config file storing default keys/values and functions available in templating. personnal config:
|
I think @rvion's idea is really cool, but it feels like a lot of scope creep. What mechanics of stack is it using? Could it be a separate tool? Should it? I also find the word 'new' to be unfriendly for a tool that can be used at any time to drop new templated files in. Maybe 'generate' as with rails? |
@chreekat I definitely think stack should have the project-generation functionality. I don't know so much about the modification functionality, but it seems to make some sense (especially given the concern I originally wrote in the ticket description about how it can feel paralyzing to generate a project without knowing exactly what you should decide on yet). Also, has anyone considered wrapping existing tools like this? https://github.com/fujimura/hi I just found it the other day. |
@chreekat My underlying issue that I'd like solved is much simpler than where this has gone. "I want to start a new haskell project, what am I doing". I've asked on IRC and the answer as of now is "use cabal-install to generate the .cabal file, then start using stack". I think a small first step that does belong in the stack project is generating a minimal compilable haskell project. So generating a stub Main.hs, a .cabal file and a stack.yml From there, it starts snowballing as an idea to making it a templating engine, since that has proven so useful in other programming environments (rails generate, yeoman...). |
I think my proposition have gone a bit too far away from the original need, but in the same time, I think a decent templating tool is a must have within stack. That's how good practice will spread and how people will becope productive. My proposition is not (yet?) good enough: there is no drop simple way how to generate new modules (and patching cabal files, etc etc), but I feel that the core is good: Indeed:
|
Here is a shorter / better proposal:
All uses-cases I can think of are covered: a template to create a module could be done like that:
and called via @radix @DanBurton @chreekat @cschneid @khanage @snoyberg : does it feels logic and simple enough ? |
I was in the middle of a response when my computer ran out of battery, so I may have forgotten something when rewriting it. I'm worried about the perfect becoming the enemy of the good here, and in the process scaring people away from writing something useful. In other words: I like the ideas I see here, but let's get something into people's hands quickly and iterate. I've implemented something very simple for now. It could certainly use improvement, but serves the purpose of getting someone started quickly. Let's make it better. |
Can you put that in a separate issue? It doesn't seem relevant to what's On Fri, Jun 26, 2015, 11:59 PM aceLren [email protected] wrote:
|
Self-assigning; I'm going to flesh this out a little bit more. |
(And by that I mean, I'm going to flesh out the code.) Tentative plan:
|
Logic was already in place for checking the absence of files to be written. I implemented the other things I mentioned. Intended next steps:
And then:
|
* master: Use `value` instead of fromMaybe for arguments Added in suppot for using the package option with ghci. Multiple test-suites with --coverage (WIP) Finish a comment Fix executing "test --coverage" on multi-package projects Reflect renamed file in stack.cabal extra-source-files #137 stack new now uses a mustache template, uses current dir name
Per @snoyberg's suggestion, I switched @chrisdone kindly review Stack/New.hs, and the associated parts of Stack/Options.hs (newOptsParser) and Main.hs (newCmd). Potential future work: template default args in a yaml file, other "calculated" default args such as timestamps. |
+1 for new-template names project according to current directory name instead of just |
@gibiansky it has! You can easily get the "latest Github stack" if you wish via |
Closing this issue. If people still want particular features described here but not yet implemented, feel free to open up a new issue and ping me. |
I'll let others determine whether this is in of scope, but I think it would be a good idea to build in a project-creating command that sets up a basic directory/file structure.
This would be kinda like
cabal init
, but wider in scope -- more like lein new.Here are some of the features I imagine it should have, perhaps to be split into separate tickets:
stack new myproj
would create amyproj
directory withsrc
,README
,LICENSE
,stack.yaml
src
based on module names provided by the user (as a command-line argument?)stack new
command line without installing that plugin ahead of time, e.g.stack new myproj --template=yesod-scaffold-stack[==x.x.x]
would automatically install the yesod-scaffold-stack plugin and use it to generate the new project.(see plugin discussion at #136)
It would be nice to also have commands for manipulating a project after it's been created. New users coming to the tooling may want to just play around, and having to decide up-front what "kind" of project they should make (library and/or executable? what should the targets be?) can be a bit paralyzing -- if they make one choice, and write some code, how will they change it later? The project-creation command should make this very clear and as easy as possible to change afterward.
Khan Thompson created http://hackage.haskell.org/package/hein recently, which is basically exactly what I'm suggesting here. On the reddit discussion at http://www.reddit.com/r/haskell/comments/37wsxc/hein_an_alpha_build_tool_modelled_after_lein/crqilmw he indicated he'd be happy to deprecate his in favor of this one (implicitly, anyway).
The text was updated successfully, but these errors were encountered: