🪝 Astro Husky Git Hooks #
In this Astro Husky Git hooks video, we start by seeing what the Husky tooling is all about.
With that out of the way, we take an existing git repo and add three hooks.
Hooks are just code snippets which we want to run automatically just before a git operation. As an example, we see a pre-push
hook. In that one, we run the astro check
command (automatically)
every time we push code to our remote repo. This might catch a simple JavaScript error, stop the
commit and give you a chance to update. So the hooks help keep your remote repos clean. In fact,
they are fantastic if you are working in a team.
Anyway, you came here to see the short video, so hit play below! You can drop a comment below or reach out for a chat on Element as well as Twitter @mention if you have suggestions for improvements or questions.
📹 Video #
🗳 Poll #
🖥 Astro Husky Git Hooks: Code #
🔗 Links #
- Astro vanilla-extract post,
- MDN docs on URL JavaScript Web API ,
- Husky docs ,
- Conventional Commits site ,
- Commitizen repo ,
- Element chat: #Rodney matrix chat ,
- Twitter handle: @askRodney .
🏁 Astro Husky Git Hooks: Summary #
Can you use Husky git hook with Astro? #
- Certainly! To get going, install the Husky package with `pnpm add husky` then run `pnpm husky install` to initialize it. You can add all the popular hooks like commit-msg (e.g. with commitlint for conventional commits), pre-push and pre-commit.
What does astro check do? #
- Astro check, inspired by Svelte check lints your Astro files. It will point out if you stray from best practices, On top if you are using TypeScript in your project, it will spot additional errors. Running it before push code to your remote git repo is a fantastic idea as one final check to make sure your code is spotless!
How can you automatically check your Astro source code when you run git commit? #
- Husky git hooks work really well with Astro. If you install Husky, you can first add a prettier formatting script to your project package.json file. For example: `"prettier:check": "prettier --check --plugin=prettier-plugin-astro ."`. Then add a Husky pre-commit script, to run just before each commit: `pnpm husky add .husky/pre-commit "pnpm prettier:check"`. In this case, if formatting is not quite right, the commit will fail, giving you a chance to fix it before finally committing a pristine version!
🙏🏽 Feedback #
Have you found the post useful? Would you prefer to see posts on another topic instead? Get in touch with ideas for new posts. Also, if you like my writing style, get in touch if I can write some posts for your company site on a consultancy basis. Read on to find ways to get in touch, further below. If you want to support posts similar to this one and can spare a few dollars, euros or pounds, please consider supporting me through Buy me a Coffee.
Quick video on how to set up ✅ astro-check and other CLI tooling in your 🚀 Astro project continuous integration process using Husky.
— Rodney (@askRodney) January 30, 2023
Hope you find it useful!
#learnastro #JAMStackhttps://t.co/xQrTDdQnAl
Finally, feel free to share the post on your social media accounts for all your followers who will find it useful. As well as leaving a comment below, you can get in touch via @askRodney on Twitter, @rodney@toot.community on Mastodon and also the #rodney Element Matrix room. Also, see further ways to get in touch with Rodney Lab. I post regularly on Astro as well as SEO. Also, subscribe to the newsletter to keep up-to-date with our latest projects.