Skip to content

Commit

Permalink
refactor: husky를 개선한다 (#886)
Browse files Browse the repository at this point in the history
* refactor: husky 개선

[#885]

* fix: 커밋 메시지 postfix 사라지는 문제 개선

[#885]

* fix: husky script 변경

[#885]

* chore: window용 husky 스크립트 추가

[#885]

* docs: 문서 설명 개선

[#885]
  • Loading branch information
feb-dain authored Oct 23, 2023
1 parent 2ca3a44 commit bc59856
Show file tree
Hide file tree
Showing 6 changed files with 171 additions and 122 deletions.
1 change: 0 additions & 1 deletion frontend/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/node_modules/
/dist/
.env
.husky
yarn-error.log
/storybook-static/
17 changes: 17 additions & 0 deletions frontend/.husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

COMMIT_MESSAGE_FILE_PATH=$1
MESSAGE=$(cat "$COMMIT_MESSAGE_FILE_PATH")

if [[ $(head -1 "$COMMIT_MESSAGE_FILE_PATH") == '' ]]; then
exit 0
fi

POSTFIX=$(git branch | grep '\*' | sed 's/* //' | sed 's/^.*\///' | sed 's/^\([^-]*-[^-]*\).*/\1/')

COMMIT_SOURCE=$2
CURRENT_BRANCH=$(git branch --show-current)

if [[ "$CURRENT_BRANCH" != "$POSTFIX" ]] && [ "$COMMIT_SOURCE" != "merge" ] && [[ "$MESSAGE" != *"[#$POSTFIX]"* ]]; then
printf "%s\n\n[#%s]" "$MESSAGE" "$POSTFIX" > "$COMMIT_MESSAGE_FILE_PATH"
fi
3 changes: 3 additions & 0 deletions frontend/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
cd frontend && yarn lint-staged
9 changes: 6 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"build": "webpack --config webpack.config.prod.js",
"build-dev": "webpack --config webpack.config.dev.js",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
"build-storybook": "storybook build",
"husky": "cd .. && husky install frontend/.husky && chmod +x frontend/.husky/*",
"husky:win": "cd .. && husky install frontend/.husky && cd frontend"
},
"author": "",
"license": "ISC",
Expand Down Expand Up @@ -63,9 +65,10 @@
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-storybook": "^0.6.12",
"fork-ts-checker-webpack-plugin": "^8.0.0",
"husky": "^8.0.3",
"jest": "^29.6.2",
"jest-environment-jsdom": "^29.6.2",
"lint-staged": "^13.2.3",
"lint-staged": "^15.0.1",
"msw": "^1.2.3",
"msw-storybook-addon": "^1.8.0",
"prettier": "^3.0.1",
Expand All @@ -80,7 +83,7 @@
"workerDirectory": "public"
},
"lint-staged": {
"**/*.{js,jsx,ts,tsx,json}": [
"**/*.{ts,tsx}": [
"eslint --fix",
"prettier --write"
]
Expand Down
23 changes: 21 additions & 2 deletions frontend/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,29 @@
yarn
```

### 컨벤션 자동화

- Mac

```bash
make // 2023-car-ffeine 폴더 에서

husky // frontend 폴더에서
```

- Window

```bash
git config core.hooksPath .githooks // 2023-car-ffeine 폴더 에서

husky:win // frontend 폴더에서
```

### 실행 모드

- development mode
- `yarn dev`

- `yarn dev`

- production mode
- `yarn start`
- `yarn start`
Loading

0 comments on commit bc59856

Please sign in to comment.