@hyperfrontend/workspace/generators/hookshooks
Installs the Git hooks a workspace configures into the clone: one POSIX sh stub per hook that has steps in hooks.config.ts, written into the repository's hooks directory and starting hf hooks run <hook>. A workspace without a configuration gets a first one, with a format step before a commit and the affected checks before a push, and .gitignore gains the line that keeps a clone's hooks.local.config.ts out of the repository.
npx hf generate hooks
| Option | What it sets |
|---|---|
--force | Replace a hook file that neither this generator nor Lefthook wrote |
--skipFormat | Leave the first configuration unformatted |
Running it again is how a change to the configured hooks reaches the clone: it rewrites its own stubs, takes the place of Lefthook's, and removes the stubs of hooks that no longer have steps. A repository installs its hooks on every install by naming the generator in the prepare script of its root manifest; where the CI variable is set or there is no repository it writes nothing and succeeds, so the script is harmless in a deploy build.
It writes nothing, and says why, where the workspace is not the root of its repository or Git reads the hooks from a directory outside the workspace. The steps, the skips and the commands are described under /git-hooks.
API Reference§
ƒ Functions
hooksGenerator( tree: Tree, options: HooksGeneratorOptions, env: Readonly< Record< string, string | undefined>>): Promise< void>
sh stub per configured hook in the repository's hooks directory, each starting hf hooks run <hook>. A workspace without a hooks.config.ts gets a first one. It writes nothing and succeeds where CI is set or there is no repository, so a root prepare script may run it in every install; it says why and writes nothing where the workspace is not the root of its repository or Git reads the hooks from a directory outside it.Parameters
Returns
Promise< void>Examples
Installing the hooks of a clone
npx hf generate hooksOn every install of the repository, from its root manifest
{ "scripts": { "prepare": "hf generate hooks" } }Parameters
Returns
stringExample
Writing stubs only where a clone can take them
import { DEFAULT_HOOKS, stubDirectory, writeStubs } from '@hyperfrontend/workspace/generators/hooks'
const directory = stubDirectory(tree, process.env) // => '.git/hooks' in a clone, null in a deploy build
if (directory !== null) writeStubs(tree, { directory, hooks: DEFAULT_HOOKS, force: false })Example
Giving a workspace of your own generator its hooks
import { writeHooksSetup } from '@hyperfrontend/workspace/generators/hooks'
writeHooksSetup(tree) // writes hooks.config.ts when missing, and adds hooks.local.config.ts to .gitignoreParameters
| Name | Type | Description |
|---|---|---|
§tree | Tree | The tree, rooted at the workspace |
§request | StubRequest | The directory, the hooks and whether to replace a foreign file |
Example
Installing two hooks into the repository of the tree
import { writeStubs } from '@hyperfrontend/workspace/generators/hooks'
writeStubs(tree, { directory: '.git/hooks', hooks: ['pre-commit', 'pre-push'], force: false })◈ Interfaces
hooks generator takes.