Husky

Husky is a tool that allows you to easily manage Git hooks. Git hooks are scripts that run automatically every time a particular event occurs in a Git repository.

Husky Official Docs

Installation

Install Husky using the ServerCN CLI:

npx servercn-cli add tooling husky

Scripts

{
  "scripts": {
    "prepare": "husky"
  }
}

Usage

Husky is commonly used to run tasks like linting, testing, or formatting before code is committed. This ensures that only valid, well-formatted code enters your repository.

Pre-commit Hook

By default, this setup configures a pre-commit Git hook that runs npm test.

File: .husky/pre-commit

npx lint-staged

This hook executes automatically every time you attempt to create a commit.

Benefits

  • Enforce Quality: Prevents bad code from being committed.
  • Automate Workflows: Link Git events to your development scripts.
  • Team Consistency: Ensures all contributors follow the same Git hook rules.

Add More Tooling

npx servercn-cli add tooling commitlint husky eslint prettier lint-staged typescript 

Installation

npx servercn-cli add tooling husky