Git Hooks
This package is a command line interface (CLI) to enable users to create and configure commit hooks for the repository. This creates a directory structure like this:
- husky
- pre-commit
This folder structure is well suited to the needs of the majority of our projects which benefit from libraries and features being shared across multiple applications.
The GenesisX CLI uses the git-hooks command line interface to setup husky to add hooks for pre commit
Usage
To create a pre-commit git hook using GenesisX, you can follow the steps outlined below:
Pre-requisites
Make sure you are on correct version of Nodejs 18.x and Nx Version 16.6
node --version
nx --versionTo start with, create a new GenesisX workspace in an empty directory, run below command, of if you already have the workspace ready , please skip this step.
npx @genesisx/create-workspace
- Provide the requested parameters
- Provide name to your workspace like test-workspace
- Move to the created workspace -
cd test-workspace
- Install the packages
yarn install
Install Git Hooks package
yarn add @genesisx/git-hooks
Run this command inside the newly created project directory
npx @genesisx/git-hooks
When asked for these questions, then provide the following-
- Do you want to setup pre-commit hook for branch name validation? Y
- Please enter the branch name regex
Enter your regex string
- Do you want to setup pre-commit hook for linting? Y/N
- Do you want to setup pre-commit hook for unit test? Y/N
Now if you commit with a wrong branch name, then you would get his message with your branch name.
- Branch names in this project must adhere to this contract:
your regex string
- Your commit will be rejected.
- You should rename your branch to a valid name and try again.
- Branch names in this project must adhere to this contract:
Generators & Plugins
Nx provides a large number of generators and executors that can be used by installing plugins. There are a huge number of community maintained plugins which can be found in the Nx Plugin Directory and officially supported plugins for all major frameworks.
GenesisX Plugins
The goal of the GenesisX project is to accelerate development and increase quality by providing templates that encapsulate best practices through generators that can be useful for your project. GenesisX plugins are installed into the node_modules directory and can be run from the command line or from the Nx console in Visual Studio Code. You can also "eject" a plugin which will convert it into a workspace generator which you can customize as required.
Testing the app
To execute unit test cases run-
nx run git-hooks:test
Running build and lints
To build using the CLI, run-
nx run git-hooks:build
To execute lint checks, run-
nx run git-hooks:lint
More details & Troubleshooting
Visit the troubleshooting guide for common issues or refer to the readme.md file located within the package folder
<workspace-folder>/node_modules/@genesisx/git-hooks/README.md