Skip to content

Commit

Permalink
Release 0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Apr 12, 2024
1 parent 3204a02 commit 150b85d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
57 changes: 57 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!-- deno-fmt-ignore-file -->

deno-task-hooks
===============

[![JSR][JSR badge]][JSR]
[![GitHub Actions][GitHub Actions badge]][GitHub Actions]

This package provides a simple way to run [Deno tasks] as [Git hooks]. You can
define Git hooks in your *deno.json* file and share them with your team.

[JSR]: https://jsr.io/@hongminhee/deno-task-hooks
[JSR badge]: https://jsr.io/badges/@hongminhee/deno-task-hooks
[GitHub Actions]: https://github.com/dahlia/deno-task-hooks/actions/workflows/main.yaml
[GitHub Actions badge]: https://github.com/dahlia/deno-task-hooks/actions/workflows/main.yaml/badge.svg


How to set up
-------------

First of all, you need to add `hooks:install` task to your *deno.json* file:

~~~~ json
{
"tasks": {
"hooks:install": "deno run --allow-read=deno.json,.git/hooks/ --allow-write=.git/hooks/ jsr:@hongminhee/deno-task-hooks"
}
}
~~~~

This `hooks:install` task will install the hooks defined in your *deno.json*
file to your *.git/hooks* directory. Let your team members run this task
immediately after cloning your repository.

Then, you can define your Git hooks in your *deno.json* file. All hooks are
prefixed with `hook:` and followed by the hook name (which is kebab-cased).
For example, to define a `pre-commit` hook, you can add the following task:

~~~~ json
{
"tasks": {
"hook:pre-commit": "deno check *.ts && deno lint"
}
}
~~~~

Then, install the hooks by running the following command:

~~~~ sh
deno task hooks:install
~~~~

Now, the `pre-commit` hook is installed to your *.git/hooks* directory. That's
it! You can now run `git commit` and see your `pre-commit` hook in action.

[Deno tasks]: https://docs.deno.com/runtime/manual/tools/task_runner
[Git hooks]: https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@std/path": "jsr:@std/path@^0.222.1"
},
"tasks": {
"check": "deno check *.ts && deno publish --dry-run --allow-dirty",
"check": "deno check *.ts && deno lint && deno publish --dry-run --allow-dirty",
"hooks:install": "deno run --allow-read=deno.json,.git/hooks/ --allow-write=.git/hooks/ install.ts",
"hooks:pre-commit": "deno task check"
}
Expand Down
2 changes: 1 addition & 1 deletion install.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { parseArgs } from "@std/cli/parse-args";
import { bold, green, red, setColorEnabled, yellow } from "@std/fmt/colors";
import { ensureDir } from "@std/fs/ensure-dir";
import { JsonValue } from "@std/json/common";
import type { JsonValue } from "@std/json/common";
import { parse } from "@std/jsonc/parse";
import { join } from "@std/path/join";

Expand Down

0 comments on commit 150b85d

Please sign in to comment.