From 9cd0f93f8a0a68a81e6be72115a082c559d8a9c5 Mon Sep 17 00:00:00 2001 From: cpojer Date: Fri, 1 Dec 2023 11:07:06 +0900 Subject: [PATCH] Add a pre-commit hook to run prettier. --- git-hooks/pre-commit | 7 +++++++ package.json | 1 + 2 files changed, 8 insertions(+) create mode 100755 git-hooks/pre-commit diff --git a/git-hooks/pre-commit b/git-hooks/pre-commit new file mode 100755 index 0000000..8763404 --- /dev/null +++ b/git-hooks/pre-commit @@ -0,0 +1,7 @@ +#!/bin/sh +FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') +[ -z "$FILES" ] && exit 0 +echo "$FILES" | xargs pnpm prettier --ignore-unknown --write +echo "$FILES" | xargs git add + +exit 0 diff --git a/package.json b/package.json index ee4f9a4..dbeb266 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "vitest": "^0.34.6" }, "scripts": { + "preinstall": "command -v git >/dev/null 2>&1 && git config core.hooksPath git-hooks || true", "build": "vite build", "dev:update-deps": "rm -rf pnpm-lock.yaml node_modules/ **/node_modules && pnpm install", "dev": "vite dev",