honojs / create-hono

CLI for creating a Hono app
54 stars 16 forks source link

feat: support for external templates #62

Closed MathurAditya724 closed 1 month ago

MathurAditya724 commented 3 months ago

Can we add support for --template or something through which we can use external templates?

This is how the usage will be pnpm create hono@latest --template=repo_addr. I understand that we can use degit but it's mainly useful because of the hooks.

If you want I can create the PR for this

MathurAditya724 commented 3 months ago

Found this issue which is similar to this one - https://github.com/honojs/starter/issues/14, we can do something similar here.

yusukebe commented 3 months ago

Hi @MathurAditya724 !

I've also thought it would be good if create-hono could support external templates. But we have to consider whether we do or not.

Currently, we use tiged, a forked project of degit. This means create-hono gets the template with a git base. On the other hand, I'm recently been thinking create-hono should not depend on git. A similar matter is raised as the issue: https://github.com/honojs/create-hono/issues/50

Or, in the future, we can't say it's 100% No that create-hono includes all template files. If so, it does not use external repositories and download templates. Then, to have degit or tiged for just the supporting external template feature does not make sense.

Anyway, this should be considered. Plus, regarding create-hono, we want to discuss not using a git- based command. Thanks!

MathurAditya724 commented 3 months ago

I propose using giget to address the dependency on git. Embedding templates in create-hono may not be necessary because giget and similar tools can cache templates once downloaded, and most users typically use only 2-3 templates.

To implement this, we can use regex to determine the appropriate git provider for the templates. I need to investigate whether giget supports custom providers, but overall, this approach seems feasible.

Please let me know if you have any further concerns or suggestions. Otherwise, I will start working on the PR so we can evaluate this approach more thoroughly.

yusukebe commented 3 months ago

@MathurAditya724

Cool!

Shall we start to work on replacing tiged with giget (#50)? I think we have to think of these as separate issues that support external templates(#62) and replace tiged with giget (#50).

cc: @goisaki @ryuapp If you have any opinions on these issues, please share them. @MathurAditya724 can create a PR, and you can review it.

MathurAditya724 commented 2 months ago

Created the first PR for removing tiged #63, Kindly have a look

ryuapp commented 2 months ago

It's hard to support completely external community templates. create-hono should only support external templates that have been checked by Hono community. For those that do not apply, we will guide you on how to download them using giget or digit.

The reason is security and reliability issues. For example, using create-hono, what the user expects to do is download a Hono template project. If we can download completely external projects, we can also download malicious ones. The same thing is possible with giget, but the reason the user use the command is to download templates, so the responsibility is clearly on you.

Therefore, I think that unless create-hono has any special functionality other than downloading templates, it should not support completely external templates. My concerns may disappear if a warning dialog is displayed.

MathurAditya724 commented 2 months ago

I will start working on the new PR for adding commander described here https://github.com/honojs/create-hono/pull/63#issuecomment-2262009192. I believe it will benefit this issue because we need the --template option.

yusukebe commented 2 months ago

@MathurAditya724

Still, we have to consider if it should have --template option or not.

I agree @ryuapp 's opinion:

The reason is security and reliability issues.

MathurAditya724 commented 2 months ago

For security, I agree with @ryuapp. Adding a warning banner when accessing 3rd party repositories is a good approach because hosting all the templates in a single repository can be challenging to maintain and scale.

This is how I have planned to resolve this issue, I have divided this issue into 3 parts (3 PRs) -

  1. Remove tiged, completed ✅
  2. Introduce commander so that in place of always adding the options manually we can write them in a single line, eg - pnpm create hono@latest my-app --template=cloudflare-workers -Y. This will not add functionality for external templates, only CLI options for better DX.
  3. The main PR to resolve this issue.