Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Simplify Your Workflow 📈: A Guide to Standardizing Commit Messages with Husky 🐶 in Monorepos 📦

Posted on Aug 7 You have a project. But, its a monorepo. Along the way, you start to have many people onboard in the project. But, you want people to follow a certain standard when committing a message for the changes that they have make. You are thinking about the future. The clarity of what have been done. The maintenance effort and so on.How to implement a standard Commit Message across your team? Well, one of the ways is by using git hooks, and Husky 🐶 can help you with that!To read more about why and what’s the benefit of standardizing commit message? You can read it here.Today, I’ll give you step by step, on how to setup husky on monorepo to standardize the commit message across your teams.Let’s just say you have your folder structure like below, where you’re building for your Frontend project.There's a multiple folder that you create for your admin website and public website. Or maybe you have project for mobile and another one is for desktop. Anything. As long as you have multiple projects in a repository.It's recommended to add husky in root package.json. But in this tutorial, we’ll just install husky in one of the folder in your repo and just use our existing package.json. It’s totally okay and fine.Meaning, you will not have package.json and package-lock.json at your root folder.Install husky by running below command.Update your package.json manually. You can update the prepare scripts in package.json according to your preferences. In this case, we change directory to the root folder (as husky install must be run in the same directory as .git) and put husky config inside the user-public folder. Or you can just let husky install in your root folder. Just your husky modules will be inside user-public folder.In our case, our .git is the same level with our user-public and admin-internal . Hence we will need to do some manual configuring on our package.json by ourself before running the command. That is what we do in step 3, where we amend our package.json a bit to cater with our folder structure and point out to husky that we are using current folder to install husky. Incase you wondering and don’t understand where is your .git folder is and what it is, click here for explanation. Then, what you need to do, is just run the command below.This is what you will get, once you have run the above command and you can see the .husky config folder under your user-public folder.Before we add our Git Hooks, we need to add the “Scripts” that will check for your commit message. In this case, you can just get the template that I have make here. It is in Javascript (Please don’t judge me hahah). You can make your own in bash or any language you like, but for me, I prefer and comfortable with Javascript, hence I use Javascript. The template might be not really complete or perfect, but hey, it get the jobs done for me! :pOnce you have download/copy the template or make your own checking, put the template inside .husky config folder, and your folder will look something like this now.Now we are ready to start adding our git hooks! Husky supports all Git hooks. For us, because we want to standardize the commit message only, let’s use commit-msg hooks. Run below command to add the hooks. Click here for explanation on command below.Once you run the above command, you will get the result below. Now, your .husky config folder will contain commit-msg file. This file is automatically create by husky once you run the above command.Once you start to commit your changes with your message, and if the commit is not according to your checking and validation, it will show something like this. Husky will prevent you from committing your commit. You’re good to go now! That’s all you need :)Of course, if you don’t like how’s the message looks like or you want different kind of checking, feel free to update or change the content inside commit-msg-linter.js. Like I was saying in step number 6, you can use whatever language that you comfortable with!Hope you able to improve and standardize the commit message across your team! Goodluck and have fun with the commit message.Stay hungry, stay foolish, and keep learning!Psstt pstt :pDo consider to love this article ❤️ and follow me! Why not right? It's FREE~I would really appreciate it 👨🏻‍💻Will be posting more on things related to AWS, JavaScript, Serverless and more!The .git folder is a hidden folder that is created when you initialize a Git repository or clone a project from somewhere else. It contains all the necessary information for your project in version control, including the history of commits, remote repository address, and more. It will be in your root folder in your project.Here is some key information about the .git folder:It's important to note that the .git folder should not be modified or deleted manually unless you have a good understanding of Git and its implications.Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well Confirm For further actions, you may consider blocking this person and/or reporting abuse christine - Jul 26 Suraj Vishwakarma - Jul 31 Retiago Drago - Jul 3 Retiago Drago - Jul 7 Once suspended, harithzainudin will not be able to comment or publish posts until their suspension is removed. Once unsuspended, harithzainudin will be able to comment and publish posts again. Once unpublished, all posts by harithzainudin will become hidden and only accessible to themselves. If harithzainudin is not suspended, they can still re-publish their posts from their dashboard. Note: Once unpublished, this post will become invisible to the public and only accessible to Muhammad Harith Zainudin. They can still re-publish the post if they are not suspended. Thanks for keeping DEV Community safe. Here is what you can do to flag harithzainudin: harithzainudin consistently posts content that violates DEV Community's code of conduct because it is harassing, offensive or spammy. Unflagging harithzainudin will restore default visibility to their posts. DEV Community — A constructive and inclusive social network for software developers. With you every step of your journey. Built on Forem — the open source software that powers DEV and other inclusive communities.Made with love and Ruby on Rails. DEV Community © 2016 - 2023. We're a place where coders share, stay up-to-date and grow their careers.



This post first appeared on VedVyas Articles, please read the originial post: here

Share the post

Simplify Your Workflow 📈: A Guide to Standardizing Commit Messages with Husky 🐶 in Monorepos 📦

×

Subscribe to Vedvyas Articles

Get updates delivered right to your inbox!

Thank you for your subscription

×