Skip to content

Commit f680945

Browse files
committed
updated lefthook config
1 parent cfef3fa commit f680945

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lefthook.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { chmod, exists, mkdir, writeFile } from "node:fs/promises";
2+
import { join } from "node:path";
3+
4+
const HOOKS_DIR = ".git/hooks";
5+
6+
if (!(await exists(".git"))) {
7+
console.error("Error: lefthook.ts script must be run from the root folder of git repo");
8+
process.exit(1);
9+
}
10+
11+
await mkdir(HOOKS_DIR, { recursive: true });
12+
13+
const preCommit = `#!/bin/sh
14+
export PATH="$PWD/node_modules/.bin:$PATH"
15+
lefthook run pre-commit`;
16+
17+
await writeFile(join(HOOKS_DIR, "pre-commit"), preCommit);
18+
19+
await chmod(join(HOOKS_DIR, "pre-commit"), 0o755);
20+
21+
console.log("lefthook hooks installed ✅");
22+
23+
process.exit(0);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"main": "src/index.ts",
44
"module": "src/index.ts",
55
"scripts": {
6-
"prepare": "lefthook install",
6+
"prepare": "bun run lefthook.ts",
77
"lint": "biome lint .",
88
"format": "biome format --write .",
99
"check": "biome check .",

0 commit comments

Comments
 (0)