Skip to content
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

Refactor recipes + add nextjs recipe #815

Merged
merged 7 commits into from
Jan 3, 2024
Merged

Refactor recipes + add nextjs recipe #815

merged 7 commits into from
Jan 3, 2024

Conversation

jaclarke
Copy link
Member

No description provided.

Comment on lines +14 to +19
recipeOptions.push(await recipe.getOptions?.(baseOptions));
}

await baseRecipe.apply(baseOptions);
for (let i = 0; i < recipes.length; i++) {
await recipes[i].apply(baseOptions, recipeOptions[i]);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about unwinding these changes and requiring that recipes are encapsulated again given that they can create their own prompts and can encode their own "skipping" logic in the function itself?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the aim to keep the recipes encapsulated, but I did split the prompts part into a separate step of each recipe, as I think it's preferable to do all the prompts before we start actually copying any files. I don't mind if we drop the skipping bit, that was just so we didn't have to duplicate that logic for the prompts and apply step for every recipe, but I think it's fine either way.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the aim to keep the recipes encapsulated, but I did split the prompts part into a separate step of each recipe, as I think it's preferable to do all the prompts before we start actually copying any files.

In general, I think I prefer the recipe to be completely opaque to the caller: pass the base options and let the recipe know how to do everything else. I'm not sure having the prompts happen upfront is objectively better: Imagine there was an issue in one recipe, but you answered the questions for all of the recipes. It seems just as valid to answer some questions then do the related work, answer more questions, do more work. The one possible advantage is being able to cancel before you do any changes, but I also see that as a possible disadvantage when trying to debug or troubleshoot an issue (e.g. you run through the changes until just before the issue and you can inspect the state of the filesystem or running recipe while the prompt is waiting for input).

It's also possible that there are prompts that are only relevant after some other side-effects have run, which is fine: even with the proposed changes you can continue to prompt the user, but then I think the whole case for hoisting the prompts up becomes weaker still.

To summarize, my case for keeping recipes fully opaque is:

  • The mechanism for running the recipes is trivial (for recipe of recipes { await recipe(opts); })
  • Reading a recipe is a complete description of the runtime behavior (rather than having to know about what each method does)
  • Failing faster might mean troubleshooting issues is easier/quicker as we add more recipes
  • More flexible: prompts are not special—they're just side effects

@jaclarke jaclarke marked this pull request as ready for review January 3, 2024 17:06
Base automatically changed from 807-edgedb-create to master January 3, 2024 17:23
@jaclarke jaclarke merged commit 5eabf23 into master Jan 3, 2024
7 checks passed
@jaclarke jaclarke deleted the create-nextjs branch January 3, 2024 21:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants