Skip to content

Automatically generate tutorial app from Markdown #2732

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

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from

Conversation

infomiho
Copy link
Contributor

@infomiho infomiho commented May 9, 2025

This PR implements running all the steps from the tutorial in the docs. We encode all the code changes into Git patches which we apply one by one.

We implement tooling for working with the patches when something breaks:

  • if there is a new step and a patch is missing - it prompts you to do the code change and it then creates a patch
  • if a patch fails, it prompts you to redo the code change and then it creates a new patch

This PR doesn't try to use git rebase to correct errors in patches because I felt fast enough with doing the changes manually. Maybe I'm too deep in the tutorial code?

}
```
</TabItem>
<TutorialAction step="8" action="diff">
Copy link
Member

@Martinsos Martinsos May 16, 2025

Choose a reason for hiding this comment

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

Just an idea, maybe not useful, but what we did for doc coderef checker is add this metadata directly tot he codeblock, via the "meta string", basically what follows in the line after three backticks and a language.

So you could do simlar, instead of having to add this extra copmonent around the code block, you could just have this, as part of the code block:

(three backticks)diff tutorial="#1"

you might not even need to supply any extra information at all, because based on the language you can figure out if you want to do diff or not. You can also obtain the file path from the title and for example if block is sh and has no title, you then execute it. That said, you can also be more explicit and just have a very simple dsl in the meta value string, something like tutorial="#<step>:<action>[:<action_param>]", for example tutorial="#1:write:src/main.wasp" or tutorial="#2:diff".

You will know the best if this is a good fit or not, maybe this kind of approach is not flexible enough, for example if you expect that there will be something that is not a code block that is also a part of the tutorial, but if all of it are code blocks, this might help with avoiding repeating some information + might make the DX a bit simpler / more integrated. Maybe it is worth doing this as the very last thing, once you have the system flushed out and have better idea what you need.

Copy link
Member

@cprecioso cprecioso left a comment

Choose a reason for hiding this comment

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

I think that, for consistency, I'd also have write actions take in a patch.

Copy link
Member

Choose a reason for hiding this comment

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

I'd rename this to step-08 so that it gets ordered better :D

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Martin had a good suggestion to keep the step IDs as unique strings and not really ordered numbers. If we add a new step between step 5 and 6 then that changes all the subsequent IDs.

Copy link
Member

Choose a reason for hiding this comment

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

Yes we concluded together it might be id that is also informative, so add-action or something. So path file's name would be "tutorial file name" + "step id".

Comment on lines 53 to 57
await waspNew(appDir)
// TODO: Maybe we should have a whitelist of files we want to keep in src?
await $`rm ${path.join(appDir, 'src/Main.css')}`
await $`rm ${path.join(appDir, 'src/waspLogo.png')}`
await $`rm ${path.join(appDir, 'src/MainPage.jsx')}`
Copy link
Member

Choose a reason for hiding this comment

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

I guess this should be the "minimal" starter?

Copy link
Member

Choose a reason for hiding this comment

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

Can't wait to move to npm workspaces, doing packages inside of packages inside of packages feels very brittle

Copy link
Member

Choose a reason for hiding this comment

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

Can we get a readme of what this script does?

Copy link
Member

@cprecioso cprecioso May 26, 2025

Choose a reason for hiding this comment

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

What would you think about this workflow? Using git rebase machinery, we take advantage of automatic conflict resolution whenever it's possible.


Example: There are 10 steps, I want to edit step 4

User: (no edits made yet) $ edit-tutorial --step 4

Program:

  • Create git repo, apply all 10 steps, one in each commit → (1)
  • git switch -c fixes $step4commitSHA

User: Makes changes as needed, tells program he's done

Program:

  • git commit -a --fixup=$step4commitSHA(2)
  • git switch main
  • git rebase fixes(3)

User: completes the rebase process if there are any conflicts. Most conflicts get automatically resolved by git

Program

  • git rebase --root --autosquash(4)
  • Convert back from commits to patches

Tldraw Whiteboard

Copy link

cloudflare-workers-and-pages bot commented Jul 16, 2025

Deploying wasp-docs-on-main with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3ea8530
Status: ✅  Deploy successful!
Preview URL: https://2ba2b52d.wasp-docs-on-main.pages.dev
Branch Preview URL: https://miho-tutorial-app-from-docs.wasp-docs-on-main.pages.dev

View logs

@infomiho infomiho changed the title Tutorial app from Markdown WIP Automatically generate tutorial app from Markdown Jul 16, 2025
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.

3 participants