Skip to content

Commit

Permalink
replace husky and lint-staged with lefthook
Browse files Browse the repository at this point in the history
  • Loading branch information
arzafran committed Aug 6, 2024
1 parent a69c380 commit f3a64c3
Show file tree
Hide file tree
Showing 13 changed files with 971 additions and 544 deletions.
1 change: 0 additions & 1 deletion .husky/.gitignore

This file was deleted.

60 changes: 60 additions & 0 deletions .husky/_/post-merge
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh

if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then
set -x
fi

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

call_lefthook()
{
if test -n "$LEFTHOOK_BIN"
then
"$LEFTHOOK_BIN" "$@"
elif lefthook -h >/dev/null 2>&1
then
lefthook "$@"
else
dir="$(git rev-parse --show-toplevel)"
osArch=$(uname | tr '[:upper:]' '[:lower:]')
cpuArch=$(uname -m | sed 's/aarch64/arm64/;s/x86_64/x64/')
if test -f "$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook"
then
"$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook" "$@"
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"
then
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook" "$@"
elif test -f "$dir/node_modules/lefthook/bin/index.js"
then
"$dir/node_modules/lefthook/bin/index.js" "$@"

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 swift package plugin lefthook >/dev/null 2>&1
then
swift package --disable-sandbox plugin lefthook "$@"
elif command -v mint >/dev/null 2>&1
then
mint run csjones/lefthook-plugin "$@"
elif command -v npx >/dev/null 2>&1
then
npx lefthook "$@"
else
echo "Can't find lefthook in PATH"
fi
fi
}

call_lefthook run "post-merge" "$@"
60 changes: 60 additions & 0 deletions .husky/_/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh

if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then
set -x
fi

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

call_lefthook()
{
if test -n "$LEFTHOOK_BIN"
then
"$LEFTHOOK_BIN" "$@"
elif lefthook -h >/dev/null 2>&1
then
lefthook "$@"
else
dir="$(git rev-parse --show-toplevel)"
osArch=$(uname | tr '[:upper:]' '[:lower:]')
cpuArch=$(uname -m | sed 's/aarch64/arm64/;s/x86_64/x64/')
if test -f "$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook"
then
"$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook" "$@"
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"
then
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook" "$@"
elif test -f "$dir/node_modules/lefthook/bin/index.js"
then
"$dir/node_modules/lefthook/bin/index.js" "$@"

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 swift package plugin lefthook >/dev/null 2>&1
then
swift package --disable-sandbox plugin lefthook "$@"
elif command -v mint >/dev/null 2>&1
then
mint run csjones/lefthook-plugin "$@"
elif command -v npx >/dev/null 2>&1
then
npx lefthook "$@"
else
echo "Can't find lefthook in PATH"
fi
fi
}

call_lefthook run "pre-commit" "$@"
60 changes: 60 additions & 0 deletions .husky/_/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/sh

if [ "$LEFTHOOK_VERBOSE" = "1" -o "$LEFTHOOK_VERBOSE" = "true" ]; then
set -x
fi

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

call_lefthook()
{
if test -n "$LEFTHOOK_BIN"
then
"$LEFTHOOK_BIN" "$@"
elif lefthook -h >/dev/null 2>&1
then
lefthook "$@"
else
dir="$(git rev-parse --show-toplevel)"
osArch=$(uname | tr '[:upper:]' '[:lower:]')
cpuArch=$(uname -m | sed 's/aarch64/arm64/;s/x86_64/x64/')
if test -f "$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook"
then
"$dir/node_modules/lefthook-${osArch}-${cpuArch}/bin/lefthook" "$@"
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"
then
"$dir/node_modules/@evilmartians/lefthook-installer/bin/lefthook" "$@"
elif test -f "$dir/node_modules/lefthook/bin/index.js"
then
"$dir/node_modules/lefthook/bin/index.js" "$@"

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 swift package plugin lefthook >/dev/null 2>&1
then
swift package --disable-sandbox plugin lefthook "$@"
elif command -v mint >/dev/null 2>&1
then
mint run csjones/lefthook-plugin "$@"
elif command -v npx >/dev/null 2>&1
then
npx lefthook "$@"
else
echo "Can't find lefthook in PATH"
fi
fi
}

call_lefthook run "prepare-commit-msg" "$@"
1 change: 0 additions & 1 deletion .husky/post-merge

This file was deleted.

1 change: 0 additions & 1 deletion .husky/pre-commit

This file was deleted.

3 changes: 1 addition & 2 deletions PROD-README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ The usual process for Next.js based apps/websites:
- Sass (Modules)
- [Zustand](https://github.com/pmndrs/zustand)
- GraphQL (CMS API)
- [Next-Sitemap](https://github.com/iamvishnusankar/next-sitemap) (postbuild script)
- [@svgr/webpack](https://github.com/gregberge/svgr/tree/main) (SVG Imports in `next.config.js`)

## Code Style & Linting:
Expand All @@ -46,7 +45,7 @@ The usual process for Next.js based apps/websites:
"singleQuote": true
}
```
- [Husky + lint-staged precommit hooks](https://github.com/okonet/lint-staged)
- [Lefthook](https://github.com/evilmartians/lefthook)

## Third Party (optional tools):

Expand Down
39 changes: 39 additions & 0 deletions components/select/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {
Select as AriaSelect,
Button,
Label,
ListBox,
ListBoxItem,
Popover,
SelectValue,
} from 'react-aria-components'

export function Select({
className,
label,
options = [{ value: '1', label: 'Option 1' }],
icon,
}) {
return (
<AriaSelect className={className}>
{label && <Label>{label}</Label>}
<Button>
<SelectValue />
{icon ? icon : <span aria-hidden="true"></span>}
</Button>
<Popover>
<ListBox>
{options.map((props) => {
const { value, label } = props

return (
<ListBoxItem key={value} {...props}>
{label}
</ListBoxItem>
)
})}
</ListBox>
</Popover>
</AriaSelect>
)
}
Empty file.
34 changes: 34 additions & 0 deletions components/select/select.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { Select } from '.'

// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
export default {
title: 'Components/Select',
component: Select,
parameters: {
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
layout: 'centered',
},
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
tags: ['autodocs'],
// More on argTypes: https://storybook.js.org/docs/api/argtypes
argTypes: {},
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
args: {},
}

// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
export const Default = {
render: ({ children, ...props }) => <Select {...props}>{children}</Select>,
args: {
...Select.props,
label: 'Favorite Animal',
options: [
{ value: '1', label: 'Aardvark' },
{ value: '2', label: 'Cat' },
{ value: '3', label: 'Dog' },
{ value: '4', label: 'Kangaroo' },
{ value: '5', label: 'Panda' },
{ value: '6', label: 'Snake' },
],
},
}
50 changes: 50 additions & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# EXAMPLE USAGE:
#
# Refer for explanation to following link:
# https://github.com/evilmartians/lefthook/blob/master/docs/configuration.md
#
# pre-push:
# commands:
# packages-audit:
# tags: frontend security
# run: yarn audit
# gems-audit:
# tags: backend security
# run: bundle audit
#
# pre-commit:
# parallel: true
# commands:
# eslint:
# glob: "*.{js,ts,jsx,tsx}"
# run: yarn eslint {staged_files}
# rubocop:
# tags: backend style
# glob: "*.rb"
# exclude: '(^|/)(application|routes)\.rb$'
# run: bundle exec rubocop --force-exclusion {all_files}
# govet:
# tags: backend style
# files: git ls-files -m
# glob: "*.go"
# run: go vet {files}
# scripts:
# "hello.js":
# runner: node
# "any.go":
# runner: go run

pre-commit:
parallel: true
commands:
lint:
glob: '*.{js,ts,jsx,tsx}'
run: npx eslint --cache --fix {staged_files}
format:
glob: '*.{js,ts,jsx,tsx,css,scss,md}'
run: npx prettier --write {staged_files}

post-merge:
commands:
update-env:
run: npx vc env pull
Loading

1 comment on commit f3a64c3

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"⚡️ Lighthouse report for the changes in this commit:

🔴 Performance: 46
🟢 Accessibility: 91
🟢 Best practices: 96
🟢 SEO: 92
🔴 PWA: undefined

Lighthouse ran on https://vercel.com/login?next=%2Fsso-api%3Furl%3Dhttps%253A%252F%252Fsatus-storybook-i3bq9m3h9-darkroom-engineering.vercel.app%252F%26nonce%3Df0bf7ee054c9fef9b73d468100a7dc0193ba3b5bc272f04051afbd71359e901d"

Please sign in to comment.