-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support in Wasp for external/community starter templates #2402
base: main
Are you sure you want to change the base?
Conversation
Great analysis @Martinsos!
I'll review the code next :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Left some minor comments. I like the github:
implementation - but - as I said, let's remove features we don't believe would be used by our users.
@@ -1,11 +1,15 @@ | |||
# Changelog | |||
|
|||
## Next | |||
## [WIP] 0.16.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What was wrong with Next? 😢 I kinda liked it, you don't have to think about what the next version will be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Next is cool! But in this case I knew what next version is going to be, so I thought why not write it down? But yeah I could have left Next you are right, wouldn't be an issue. I can also roll with Next in the future.
case waspAppAiGenerator of | ||
WaspAI -> AI.createNewProjectInteractiveOnDisk absWaspProjectDir appName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we generalise this, do we expect different generators in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe :D! Not likely though. The reason why I generalized it is that it allowed me to treat this template the same way as other templates, most importantly I could put it into the "FeaturedStarterTemplates.hs" file in a nice way. As an "overengineering" it is really a tiny step, but it allows me that + I found it ok that it is explicit this will use Wasp AI, I don't think that makes code more complex.
@@ -33,7 +33,7 @@ parseNewProjectArgs newArgs = parserResultToEither $ execParserPure defaultPrefs | |||
Opt.strOption $ | |||
Opt.long "template" | |||
<> Opt.short 't' | |||
<> Opt.metavar "TEMPLATE_NAME" | |||
<> Opt.metavar "TEMPLATE" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we maybe want to go with TEMPLATE_ID
to keep it consistent with the record above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of didn't want to bother them with the details, I thought I will just put TEMPLATE and they will figure it out. TEMPLATE_ID sounded a bit low-level. I can put it thought if you think it is better DX / clearer.
|
||
readWaspProjectSkeletonFiles :: IO [(Path System (Rel WaspProjectDir) File', Text)] | ||
readWaspProjectSkeletonFiles = do | ||
skeletonFilesDir <- (</> [reldir|Cli/templates/skeleton|]) <$> Data.getAbsDataDirPath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had trouble parsing this line at first, can write in way that it reads like a path i.e. from left to right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure good idea, I did this:
skeletonFilesDir <- Data.getAbsDataDirPath <&> (</> [reldir|Cli/templates/skeleton|])
<&>
is flipped <$>
.
Btw this is old code actually, I just moved this file from one place to another. I commented on that when creating a PR, but I forgot to sumbit those comments :(.
} | ||
|
||
-- | AI generators that can generate Wasp apps. | ||
data WaspAppAiGenerator = WaspAI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we overengineerring here a bit? Are we working on other AI generators for Wasp or looking to support other AI external AI generators? Sorry if I missed that we are doing something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is my secret project :D! Kidding, it is a tiny bit of overengienerg that allowed me to treat AI starter template same as the rest while keeping compile time safety. Commented on it also in another comment in more details.
|
||
-- | Given a template id (as string), it will obtain the information on the template that this id references. | ||
-- It will throw if the id is invalid (can't be parsed, or information on the template can't be obtain based on it). | ||
getStarterTemplateByIdOrThrow :: (MonadError String m) => [ST.StarterTemplate] -> String -> m ST.StarterTemplate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool way of resolving the Github based templates 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Will likely be throwing away most of this though.
|
||
### ⚠️ Breaking Changes | ||
|
||
- Renamed and split `deserializeAndSanitizeProviderData` to `getProviderData` and `getProviderDataWithPassword` so it's more explicit if the resulting data will contain the hashed password or not. | ||
|
||
### 🎉 New Features and improvements | ||
|
||
- Added support for third-party starter templates via `wasp new -t github:<repo_owner>/<repo_name>[/dir/to/template]`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO: I should remove this if we decide to drop -t github:
support.
@@ -161,8 +161,7 @@ printUsage = | |||
title " GENERAL", | |||
cmd " new [<name>] [args] Creates a new Wasp project. Run it without arguments for interactive mode.", | |||
" OPTIONS:", | |||
" -t|--template <template-name>", | |||
" Check out the templates list here: https://github.com/wasp-lang/starters", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was pointing to a repo that contained only one or two starters, so I instead removed this, and you instead get more info on valid template names if you make a mistake while using -t
, which is more maintainable and less crowded here in the top level cli info.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just refactoring, before we had one big file, I split it into multiple files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also just refactoring of splitting into multiple files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also just refactoring of splitting into multiple files.
) | ||
|
||
{- HLINT ignore aiGeneratedStarterTemplate "Redundant $" -} | ||
waspAiGeneratedStarterTemplate :: ST.StarterTemplate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wasp AI generator is also here now, and has its own normal entry which is better. Refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also just refactoring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this file I added the notion of github:...
. So removing it would mostly come down to delegint big part of this file.
TODO: I should remove github:
support from there if we end up not going with it.
| IdTypeGhRepoTemplateUri | ||
deriving (Enum, Bounded) | ||
|
||
-- | This function serves its purpose just by being defined, even if not used anywhere, because it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sodic you might find this interesting as a type/compiler trick, we discussed sometihng similar some time ago, and I ended up using it here.
So when I wrote this PR I also wrote 9 comments for the reviewers to make reviewing easier, but they stayed on "pending"! Too bad, I pushed them now. |
Yeah @Martinsos I agree it's not really useful. What could be cool though is to have a section on our docs or webpage that features community templates to give those creators some recognition and perhaps inspire others to make their own. |
|
||
|
||
## Community templates #{community-templates} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This id in #{} got rendered in docs! See what is with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean? How does it look like?
TODO:
-t github:
feature?I started this PR with the idea to add support for external starter templates to Wasp CLI. I imagined that we would allow users to use them in the similar fashion as right now we do for our official templates, it is just that they would specify them with sometihng like
github:<repo_owner>/<repo_name>[/template/dir]
and we would pull the template from there.I implemented ability to this via
wasp new -t <repo_owner>/<repo_name>[/template/dir]
, and also ended up refactoring a bit bigger parts of the starter templates logic in CLI while at it, both to support it and to improve the code in general.However, I then at some point realized that I am not sure if this is useful at all! When you think about it, what do they get this way compared to just going to a github repo of that starter template and cloning that or using github's "clone as a template" feature? For official templates, we want to make sure they can be discovered and easily used from the CLI, and that makes sense, and we also insert name of the app into them and correct Wasp version. But for community tempaltes, that isn't that important I think -> We would expected users to go out of Wasp CLI and check out that template anyway, read the instrutions there, ... . They probably found out about it in some other fashion also. And I think maintainers of these community templates are not likely to be interested in using the rules that come with how our CLI pulls in the tempaltes -> I don't think they will use the template placeholders for wasp version and app name, nor can I see them updating templates immediately on every wasp version (which wasp CLI expects from official tempaltes, since it pulls them by specific version tag). I expect community templates will instead on their
main
be at the latest wasp version that they managed to update to and that is it, and they will be late a bit after each Wasp release, that is good enough and simple enough, I would actually recommend doing it that way.So, I concluded that having this ability to pull in the repo from our CLI via
github:...
is actually not useful! What do you think, do you agree?However, while implementing this PR, it turned out that most work was other stuff, which is improvments to the rest of the code / docs. Everything taht I implmented in this PR:
wasp new -t github:...
.wasp new
that is called "community template" that informs users about existence of community templates, to help with discovery.As it turns out, (1) is actually only a small part of it.
So, what I did at the end is create this PR that contains all the changes from above, although I would suggest that I remove (1) (which is mostly changes in TemplateId.hs), but I would merge the rest.
What I would like you to do:
github:
functionality or not. I vote for not, and will kick it out if you agree.Additional option in interactive menu:
Addition to docs: