Configuration

Each task in task-runner.json is a JSON object with the following properties:

nameoptionaltypedefaultdescription
commandfalsestring-path to the executable file or script or executable name
argstrue[string array]-command arguments
includetrue[array of glob]**/*glob pattern to select files
nametruestringcommandname of the task (recommended)
grouptruestring-group of the task (usually it should be the hook name)
branchtruestring (regex)-run task on specific branches only
pathModetrue[absolute, relative]relativefile path style (relative or absolute)
cwdtruestringproject root directorycurrent working directory for the command, can be relative or absolute
outputtrue[always, verbose, never]alwaysoutput log level
excludetrue[array of glob]-glob pattern to exclude files
windowstrueobject-overrides all the above settings for windows

Glob patterns

Husky.Net supports the standard dotnet FileSystemGlobbing patterns for include or exclude task configurations. The patterns that are specified in the include and exclude can use the following formats to match multiple files or directories.

  • Exact directory or file name
    • some-file.txt
    • path/to/file.txt
  • Wildcards * in file and directory names that represent zero to many characters not including separator characters.
ValueDescription
*.txtAll files with .txt file extension.
.All files with an extension.
*All files in top-level directory.
.*File names beginning with '.'.
wordAll files with 'word' in the filename.
readme.*All files named 'readme' with any file extension.
styles/*.cssAll files with extension '.css' in the directory 'styles/'.
scripts//All files in 'scripts/' or one level of subdirectory under 'scripts/'.
images*/*All files in a folder with name that is or begins with 'images'.
  • Arbitrary directory depth (/**/).
ValueDescription
*/All files in any subdirectory.
dir/**/*All files in any subdirectory under 'dir/'.
  • Relative paths.

To match all files in a directory named "shared" at the sibling level to the base directory use ../shared/*.

Read more hereopen in new window

Variables

There are some variables that you can use in your task arguments (args).

  • ${staged}
    • returns the list of currently staged files
  • ${last-commit}
    • returns last commit changed files
  • ${git-files}
    • returns the output of (git ls-files)
  • ${all-files}
    • returns the list of matched files using include/exclude, be careful with this variable, it will return all the files if you don't specify include or exclude
  • ${args}
    • returns the arguments passed directly to the husky run command using --args option

e.g.

"args": [ "${staged}" ]

Custom variables

You can define your own variables by adding a task to the variables section in task-runner.json.

e.g.

defining custom ${root-dir-files} variable to access root directory files

{
   "variables": [
      {
         "name": "root-dir-files",
         "command": "cmd",
         "args": ["/c", "dir", "/b"]
      }
   ],
   "tasks": [
      {
         "command": "cmd",
         "args": ["/c", "echo", "${root-dir-files}"]
      }
   ]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15