<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mohamed Sayed</title>
    <description>The latest articles on DEV Community by Mohamed Sayed (@m0hamedsayed).</description>
    <link>https://dev.to/m0hamedsayed</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1015088%2Fabe11f1b-0fbd-4383-8cc9-fd1c463381ac.jpeg</url>
      <title>DEV Community: Mohamed Sayed</title>
      <link>https://dev.to/m0hamedsayed</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/m0hamedsayed"/>
    <language>en</language>
    <item>
      <title>Auto Generate Conventional Commits with commitizen ,devmoji and husky for NodeJS💥</title>
      <dc:creator>Mohamed Sayed</dc:creator>
      <pubDate>Fri, 27 Jan 2023 20:54:58 +0000</pubDate>
      <link>https://dev.to/m0hamedsayed/auto-generate-conventional-commits-with-commitizen-devmoji-and-husky-for-nodejs-5d50</link>
      <guid>https://dev.to/m0hamedsayed/auto-generate-conventional-commits-with-commitizen-devmoji-and-husky-for-nodejs-5d50</guid>
      <description>&lt;h3&gt;
  
  
  Hi! 👽
&lt;/h3&gt;

&lt;p&gt;In this &lt;strong&gt;article&lt;/strong&gt;, I will discuss how to write awesome commits with conventional commits&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.npmjs.com/package/commitizen" rel="noopener noreferrer"&gt;  &lt;code&gt;commitizen&lt;/code&gt;&lt;/a&gt; , &lt;a href="https://www.npmjs.com/package/pnpm" rel="noopener noreferrer"&gt;&lt;code&gt;pnpm&lt;/code&gt;&lt;/a&gt; , &lt;a href="https://www.npmjs.com/package/cz-conventional-changelog" rel="noopener noreferrer"&gt;&lt;code&gt;cz-conventional-changelog&lt;/code&gt;&lt;/a&gt; , &lt;a href="https://www.npmjs.com/package/husky" rel="noopener noreferrer"&gt;&lt;code&gt;husky&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://www.npmjs.com/package/devmoji" rel="noopener noreferrer"&gt;&lt;code&gt;devmoji&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;🔀 Before start :&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;we need to understand what the conventional commits and why using it ?&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  What is conventional commits !
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It is a lightweight convention on top of &lt;strong&gt;commit messages&lt;/strong&gt;. It provides an easy set of &lt;strong&gt;rules&lt;/strong&gt; for creating an explicit commit history which makes it easier to write automated tools on top of.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Why we Use Conventional Commits !
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Automatically generating CHANGELOGs.&lt;/li&gt;
&lt;li&gt;Automatically determining a semantic version bump (based on the types of commits landed).&lt;/li&gt;
&lt;li&gt;Communicating the nature of changes to teammates, the public, and other stakeholders.&lt;/li&gt;
&lt;li&gt;Triggering build and publish processes.&lt;/li&gt;
&lt;li&gt;Making it easier for people to contribute to your projects, by allowing them to explore a more structured commit history.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;type&amp;gt;[optional scope]: &amp;lt;description&amp;gt;

[optional body]

[optional footer(s)]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;&lt;em&gt;To read more :&lt;/em&gt;&lt;/strong&gt;  &lt;a href="https://www.conventionalcommits.org/en/v1.0.0/" rel="noopener noreferrer"&gt;conventionalcommits&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;If you don't have &lt;strong&gt;pnpm&lt;/strong&gt; 📦&lt;/p&gt;

&lt;p&gt;🔀 you should &lt;strong&gt;install&lt;/strong&gt; it :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -g pnpm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🔀 or using &lt;strong&gt;npm&lt;/strong&gt; 📦&lt;/p&gt;




&lt;h2&gt;
  
  
  Content
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Step #1 : Dealing with Commitizen package&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Step #2 : Commitizen Adapter&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Step #3 : Dealing with husky&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Step #4 : Applying emojis with commits&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Results&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step #1 : Dealing with Commitizen package
&lt;/h2&gt;

&lt;p&gt;🔀 we need to install &lt;strong&gt;commitizen&lt;/strong&gt; inside the project (locally) or globally with pnpm package.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This example assumes that the project has been set up to &lt;strong&gt;use Commitizen locally&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#locally
pnpm add -D commitizen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#globally
pnpm add -g commitizen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ Create a &lt;code&gt;.czrc&lt;/code&gt; file in your &lt;code&gt;home&lt;/code&gt; directory 🔀 in the &lt;strong&gt;path&lt;/strong&gt; that will be refer to the globally or locally path installed &lt;strong&gt;commitizen adapter&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# .czrc
{
  "path":""
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;➕ Add pnpm scripts in your &lt;strong&gt;&lt;code&gt;package.json&lt;/code&gt;&lt;/strong&gt; file with &lt;strong&gt;git-cz&lt;/strong&gt; or &lt;strong&gt;cz&lt;/strong&gt; pointing to the local version of Commitizen:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# package.json
"scripts": {
  "commit":"git-cz"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🚩 Or Using&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pnpm pkg set scripts.commit="git-cz"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Installing and running Commitizen locally allows you to ensure that developers are running on the exact same version of Commitizen on all machines.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step #2 : Commitizen Adapter
&lt;/h2&gt;

&lt;p&gt;✅ install &lt;strong&gt;cz-conventional-changelog&lt;/strong&gt; and integrate it with the commitizen config inside &lt;strong&gt;.czrc&lt;/strong&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#locally
pnpm add -D cz-conventional-changelog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#globally
pnpm add -g cz-conventional-changelog
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;✅ update &lt;strong&gt;.czrc&lt;/strong&gt; file with commitizen adapter&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "path":"node_modules/cz-conventional-changelog"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note : if you install the package global , you don't need to apply cz-conventional-changelog with node_modules&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "path": "cz-conventional-changelog"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step #3 : Dealing with husky :
&lt;/h2&gt;

&lt;blockquote&gt;
&lt;p&gt;Husky improves your commits 🐶&lt;br&gt;
 -- You can use it to &lt;strong&gt;lint your commit messages&lt;/strong&gt;, &lt;strong&gt;run tests&lt;/strong&gt;, &lt;strong&gt;lint code&lt;/strong&gt;, etc... when you commit or push. Husky supports &lt;a href="https://git-scm.com/docs/githooks" rel="noopener noreferrer"&gt;all Git hooks&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;✅ we will use it to apply emoijs with commits 😄&lt;/p&gt;

&lt;h4&gt;
  
  
  🚩 let's start
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# install husky locally
pnpm add -D husky
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# update pakage.json file
# run these commands
&amp;gt; pnpm pkg set scripts.prepare="husky install"
&amp;gt; pnpm prepare
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Step #4 : Applying emojis with commits ✨
&lt;/h2&gt;

&lt;h4&gt;
  
  
  ✅ Install devmoji package
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pnpm add -D devmoji
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  ✅ Add commit-msg hook
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pnpx husky add .husky/commit-msg "head -1 $1 | pnpx devmoji --commit &amp;gt; $1"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;🚩 Note&lt;/strong&gt; :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;head -1 $1&lt;/code&gt; is the same with &lt;code&gt;head -n 1 $1&lt;/code&gt; to select the first line in the commit msg file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;- -commit :&lt;/strong&gt; is &lt;strong&gt;true&lt;/strong&gt; by default , you can ignore it&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;also you can use &lt;code&gt;pnpx devmoji -e&lt;/code&gt; in commit-msg hook to read last commit from &lt;code&gt;.git/COMMIT_EDITMSG&lt;/code&gt; in the git root.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;if &lt;strong&gt;devmoji&lt;/strong&gt; is installed globally you don't need to add &lt;code&gt;pnpx&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  ➕ Add some validations as a pro 🚀
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# update commit-msg hook
# validation with regex
if ! head -1 $1 | grep -E "^(feat|fix|chore|docs|test|style|refactor|perf|build|ci|revert)(\(.+?\))?: .{1,}$"; then
echo "Aborting commit with invalid message." &amp;gt;&amp;amp;2
exit 1
fi
# message length validation
if ! head -1 $1 | grep -E "^.{1,88}$"; then
echo "Aborting commit with too long message." &amp;gt;&amp;amp;2
exit 1
fi
pnpx devmoji -e
# Or using
# head -1 $1 | pnpx devmoji --commit &amp;gt; $1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;a&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  🔖 Results:
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# adds a change in the working directory to the staging area
git add .
# Run this command
pnpm commit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  There are some questions to follow ⬇️
&lt;/h4&gt;

&lt;p&gt;-- ❓ Select the type of change that you're committing: &lt;code&gt;(Use arrow keys)&lt;/code&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;feat:&lt;/td&gt;
&lt;td&gt;A new feature&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;fix:&lt;/td&gt;
&lt;td&gt;A bug fix&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;docs:&lt;/td&gt;
&lt;td&gt;Documentation only changes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;style:&lt;/td&gt;
&lt;td&gt;Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;refactor:&lt;/td&gt;
&lt;td&gt;A code change that neither fixes a bug nor adds a feature&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;perf:&lt;/td&gt;
&lt;td&gt;A code change that improves performance&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;test:&lt;/td&gt;
&lt;td&gt;Adding missing tests or correcting existing tests&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;build:&lt;/td&gt;
&lt;td&gt;Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;ci:&lt;/td&gt;
&lt;td&gt;Changes to our CI configuration files and scripts Travis, Circle, BrowserStack, SauceLabs)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;chore:&lt;/td&gt;
&lt;td&gt;Other changes that don't modify src or test files&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;revert:&lt;/td&gt;
&lt;td&gt;Reverts a previous commit&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;-- ❓ What is the scope of this change (e.g. component or file name):&lt;code&gt;(press enter to skip)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;-- ❓ Write a short, imperative tense description of the change &lt;code&gt;(max 94 chars)&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;-- ❓ Provide a longer description of the change: &lt;code&gt;(press enter to skip)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;-- ❓ Are there any breaking changes? &lt;code&gt;(y/N)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;-- ❓ Does this change affect any open issues? &lt;code&gt;(y/N)&lt;/code&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;For more example&lt;/strong&gt;, You can access &lt;a href="https://github.com/M0hamedSayed/conventional-commits-with-emojis" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt; &lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>typescript</category>
      <category>python</category>
      <category>buildinpublic</category>
    </item>
  </channel>
</rss>
