Coder Social home page Coder Social logo

alirezaseif28 / husky.net Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alirezanet/husky.net

1.0 1.0 0.0 145 KB

Git hooks made easy with Husky.Net internal task runner!๐Ÿถ woof! (inspired by husky and lint-staged libraries)

License: MIT License

C# 94.21% Shell 5.05% Batchfile 0.74%

husky.net's Introduction

Husky.Net

Introduction

Husky improves your commits and more ๐Ÿถ woof!

You can use it to lint your commit messages, run tests, lint code, etc... when you commit or push.

Features

  • Supports all Git hooks
  • Powered by modern new Git feature (core.hooksPath)
  • User-friendly messages
  • Supports macOS, Linux and Windows
  • Git GUIs
  • Custom directories
  • Monorepo
  • ๐Ÿ”ฅ Internal task runner! ๐Ÿ†•
  • ๐Ÿ”ฅ Multiple file states (staged, lastCommit, glob) ๐Ÿ†•
  • ๐Ÿ”ฅ Compatible with dotnet-format ๐Ÿ†•
  • ๐Ÿ”ฅ Customizable tasks ๐Ÿ†•

next

  • โŒ› Task for specific branch or tags (soon)
  • โŒ› User-defined file states (soon)
  • โŒ› Internal commit-msg linter (soon)

If you already know what is the lint-staged or Husky (npm packages), this is very similar but you can use Husky.Net without having node, yarn, etc.. installed, with a lot of more features! ๐Ÿš€๐Ÿš€

A lot of features are coming soon, stay tuned! ๐Ÿ‘๏ธโ€๐Ÿ—จ๏ธ๐Ÿ‘€

Installation

# local installation (recommended)
cd <Your project root directory>
dotnet new tool-manifest
dotnet tool install Husky

# global installation
dotnet tool install --global Husky

Note: With the global installation, you don't need to add the dotnet prefix to the commands.

Setup husky for your project

cd <Your project root directory>
dotnet husky install

Add your first hook

dotnet husky add .husky/pre-commit "echo 'Husky is awesome!'"
git add .husky/pre-commit

Make a commit

git commit -m "Keep calm and commit"
# `echo 'Husky is awesome!'` will run every time you commit

Automate husky installation for other contributors

If you installed husky locally, just add the below code to one of your projects (*.csproj *.vbproj).

Important: Just make sure to update the working directory depending on your folder structure.

<Target Name="husky" BeforeTargets="Restore;CollectPackageReferences">
   <Exec Command="dotnet tool restore"  StandardOutputImportance="Low" StandardErrorImportance="High"/>
   <Exec Command="dotnet husky install" StandardOutputImportance="Low" StandardErrorImportance="High"
         WorkingDirectory="../../" />  <!--Update this to the releative path to your project root dir -->
</Target>

If you have only one multiple target project (TargetFrameworks) add the bellow condition IsCrossTargetingBuild to the target tag to prevent multiple execution

<Target Name="husky" BeforeTargets="Restore;CollectPackageReferences" Condition="'$(IsCrossTargetingBuild)' == 'true'">
   ...

Or If you are using the npm, add the below code to your package.json file to automatically install husky after the installation process:

 "scripts": {
    "prepare": "dotnet tool restore && dotnet husky install"
 }

Task runner

After installation, you must have task-runner.json file in your .husky directory that you can use to define your tasks.

you can run and test your tasks with husky run command. Once you are sure that your tasks are working properly, you can add it to the hook.

e.g.

dotnet husky add .husky/pre-commit "dotnet husky run"
A simple real-world example task-runner.json

{
   "tasks": [
      {
         "command": "dotnet",
         "group": "backend",
         "output": "verbose",
         "args": ["dotnet-format", "--include", "${staged}"],
         "include": ["**/*.cs", "**/*.vb"]
      },
      {
         "name": "eslint",
         "group": "frontend",
         "command": "npm",
         "pathMode": "absolute",
         "cwd": "Client",
         "args": ["run", "lint", "${staged}"],
         "include": ["**/*.ts", "**/*.vue", "**/*.js"]
      },
      {
         "name": "prettier",
         "group": "frontend",
         "command": "npx",
         "pathMode": "absolute",
         "cwd": "Client",
         "args": ["prettier", "--write", "--ignore-unknown", "${staged}"],
         "include": [
            "**/*.ts",
            "**/*.vue",
            "**/*.js",
            "**/*.json",
            "**/*.yml",
            "**/*.css",
            "**/*.scss"
         ]
      },
      {
         "name": "Welcome",
         "output": "always",
         "command": "bash",
         "args": ["-c", "echo  ๐ŸŒˆ Nice work! ๐Ÿฅ‚"],
         "windows": {
            "command": "cmd",
            "args": ["/c", "echo  ๐ŸŒˆ Nice work! ๐Ÿฅ‚"]
         }
      }
   ]
}


Task supported configurations

Using bellow configuration you can define your task with a lot of options.


name optional type default description
command false string - path to the executable file or script or executable name
args true [string array] - command arguments
include true [array of glob] ** glob pattern to select files
name true string - name of the task (recomended)
group true string - group of the task
pathMode true [absolute, relative] relative file path style (releative or absolute)
cwd true string project root directory current working directory for the command, can be relative or absolute
output true [always, error, verbose, never] error output log level
exclude true [array of glob] - glob pattern to exclude files
windows true object - ovverides all the above settings for windows

Glob patterns

Husky.Net supports the standard dotnet FileSystemGlobbing patterns for include or exclude task configurations. read more here


Notes

  • I've added two sample task to the task-runner.json file, make sure to read the comments before removing them until we complete the documentation. any help appreciated!

  • Consider all bellow 1.x versions as beta. ( we need a lot of tests before major release )

  • Don't forget to give a โญ on GitHub

  • This library inspired and is a combination of husky & lint-staged & VsCode Task runner!, for DotNet, so make sure to support them too!

Known issues

  • husky run command doesn't have color when executed from hooks.
  • Task output not showing errors correctly with default values. workaround -> setting output to always

husky.net's People

Contributors

alirezanet avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.