hi icon indicating copy to clipboard operation
hi copied to clipboard

Allow templates to be plain old cabal packages

Open hamishmack opened this issue 11 years ago • 5 comments

This is a cool tool, but I think it would be even nicer if it the templates were allowed to be regular cabal packages.

When there is no package-name.cabal.template hi could look for a ".cabal" file my-template.cabal (where my-template is the name of the template). It should be easy to locate as it will be the only ".cabal" file.

Instead of requiring...

Name:                   $packageName
Author:                 $author <$email>

...

Library
  Exposed-Modules:      $moduleName
  Other-Modules:        $moduleName.Internal

allow...

Name:                   my-template
Author:                 Hamish Mackenzie <[email protected]>

...

Library
  Exposed-Modules:      Module.Name
  Other-Modules:        Module.Name.Internal

We can still easily replace name and author (just find the line starting with "Author:"). I think other top level cabal properties should be handled in a similar way. The module names might be harder to handle and maybe we would need a hi.info file or something could tell you which modules to rename.

I think there are a lot of advantages to this approach

  • Users can see the info about the template (who is the author, what version is it)
  • Template packages could be uploaded to hackage to make them visible and haddock docs available
  • Hi could just run "cabal unpack" to download the template package
  • Users could "cabal install" the template package and try it out
  • Many existing packages would be valid hi templates (like hello)
  • To make a new template from an existing one just run "hi" on it and make the changes you want in your new template
  • Because the template is a valid package you can use cabal build (and cabal test) to check it
  • cabal-src-install can be used to install templates locally

hamishmack avatar Mar 08 '14 09:03 hamishmack

Thanks, sorry for delay. Making template a cabal package sounds great idea. I felt one of the best part of this approach is that the template package can be built in CI and users can know it's stable or not. But, please let me give some time to do this. I'm still not completely sure current design and implementation can fit with this approach.

fujimura avatar Jun 22 '14 06:06 fujimura

Looking through your code, you are only using git operations in place of two regular file system operations: Git.clone instead of just copying a directory tree, and Git.lsFiles. The only other export from Hi.Git is expandUrl, which is only used by Git.clone. Just replace those two by regular file system operations.

I think it's more than the advantages listed by @hamishmack. The basic concept of a template in hi is a directory tree. You implemented a nice extra fancy feature - getting the template tree via github - before the basic simplest interface (and most useful and flexible in my opinion) of just using a plain old directory tree.

This utility is great, I love it! Please don't limit it only to people who happen to be using github. Thanks!

ygale avatar Jun 26 '14 15:06 ygale

Sorry for late reply.

I found cabal package as a template is great idea. Having a list of templates which can be built will be beneficial for everyone. I'll work on this. Thanks for great suggestion!

fujimura avatar Jan 09 '15 09:01 fujimura

@fujimura, I'm happy to take a look at this it sounds like a very useful feature. If I send a PR with it, do you have time to review it?

adetokunbo avatar Jul 17 '18 06:07 adetokunbo

@adetokunbo Of course!

fujimura avatar Jul 19 '18 07:07 fujimura