Skip to content

Commit

Permalink
test lefthook
Browse files Browse the repository at this point in the history
  • Loading branch information
moinulmoin committed Jul 29, 2023
1 parent e03adfa commit df3d95c
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 20 deletions.
8 changes: 0 additions & 8 deletions .husky/pre-commit

This file was deleted.

42 changes: 42 additions & 0 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh

if [ "$LEFTHOOK" = "0" ]; then
exit 0
fi

call_lefthook()
{
dir="$(git rev-parse --show-toplevel)"
osArch=$(uname | tr '[:upper:]' '[:lower:]')
cpuArch=$(uname -m | sed 's/aarch64/arm64/')

if lefthook -h >/dev/null 2>&1
then
lefthook "$@"
elif test -f "$dir/node_modules/lefthook/bin/index.js"
then
"$dir/node_modules/lefthook/bin/index.js" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"
elif test -f "$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook"
then
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook_${osArch}_${cpuArch}/lefthook" "$@"
elif bundle exec lefthook -h >/dev/null 2>&1
then
bundle exec lefthook "$@"
elif yarn lefthook -h >/dev/null 2>&1
then
yarn lefthook "$@"
elif pnpm lefthook -h >/dev/null 2>&1
then
pnpm lefthook "$@"
elif command -v npx >/dev/null 2>&1
then
npx @evilmartians/lefthook "$@"
else
echo "Can't find lefthook in PATH"
fi
}

call_lefthook run "prepare-commit-msg" "$@"
14 changes: 14 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# EXAMPLE USAGE:
#
# Refer for explanation to following link:
# https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md
#

pre-commit:
commands:
lint:
glob: "src/**/*.{ts,tsx,js,jsx}"
run: npx eslint {staged_files} --fix && git add {staged_files}
format:
glob: "src/**/*.{ts,tsx,js,jsx}"
run: npx prettier --write {staged_files} && git add {staged_files}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"lint": "next lint",
"format": "prettier --write ./src/**/*.{ts,tsx,js,jsx}",
"lint:fix": "eslint src/**/*.{js,jsx,ts,tsx} --fix",
"prepare": "husky install"
"postinstall": "lefthook install"
},
"dependencies": {
"@ducanh2912/next-pwa": "^9.2.1",
Expand Down Expand Up @@ -62,7 +62,7 @@
"@typescript-eslint/parser": "^5.59.7",
"eslint": "8.43.0",
"eslint-config-next": "13.4.7",
"husky": "^8.0.3",
"lefthook": "^1.4.7",
"prettier": "2.8.8",
"prettier-plugin-tailwindcss": "^0.3.0"
}
Expand Down
91 changes: 82 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Metadata } from "next";
import { Metadata } from "next";

export const metadata: Metadata = {
title: "Overview",
Expand Down

0 comments on commit df3d95c

Please sign in to comment.