Skip to content

Commit 641e03f

Browse files
Merge pull request #98 from JsDaddy/feat/setup-hook
feat(ref: no-ref): add setup hook
2 parents d5e4a9d + 52bb9ba commit 641e03f

5 files changed

Lines changed: 47 additions & 4 deletions

File tree

.github/.hooks/commit-msg/check-commit-msg.sh renamed to .github/hooks/commit-msg

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#!/usr/bin
1+
#!/bin/bash
22

33
set -e
44

55
commit_msg=$(cat .git/COMMIT_EDITMSG)
6-
76
echo "$commit_msg" | npx commitlint
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin
1+
#!/bin/bash
22

33
set -e
44

.github/scripts/setup_hooks.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
3+
# Define the directory containing sample hooks
4+
SAMPLE_HOOKS_DIR=".github/hooks"
5+
6+
# Define the target directory for Git hooks
7+
GIT_HOOKS_DIR=".git/hooks"
8+
9+
# Function to copy or replace hooks
10+
copy_or_replace_hooks() {
11+
for hook in "$SAMPLE_HOOKS_DIR"/*; do
12+
hook_name=$(basename "$hook")
13+
target_hook="$GIT_HOOKS_DIR/$hook_name"
14+
if [ -f "$target_hook" ]; then
15+
echo "Replacing existing hook: $hook_name"
16+
else
17+
echo "Copying new hook: $hook_name"
18+
fi
19+
cp "$hook" "$target_hook"
20+
chmod ug+x "$target_hook" # Ensure executable permission is set
21+
done
22+
}
23+
24+
# Main function
25+
main() {
26+
# Check if .git/hooks directory exists
27+
if [ ! -d "$GIT_HOOKS_DIR" ]; then
28+
echo "Error: .git/hooks directory not found. Are you in a Git repository?"
29+
exit 1
30+
fi
31+
32+
# Copy or replace hooks
33+
copy_or_replace_hooks
34+
35+
echo "Git hooks setup complete."
36+
}
37+
38+
# Run the main function
39+
main

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ You can also try our NGX COPYPASTE [check](https://www.npmjs.com/package/ngx-cop
2525
$ npm install --save ngx-loader-indicator
2626
```
2727

28+
## Setup hooks
29+
```bash
30+
$ npm run init:hooks
31+
```
2832

2933
## Quickstart if ngx-loader-indicator version >= 15.0.0
3034

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"lint:fix": "ng lint --fix && npm run lint:scss:fix",
2828
"prettier:fix": "npx prettier --write .",
2929
"type-coverage-report": "typescript-coverage-report",
30-
"type-coverage": "type-coverage"
30+
"type-coverage": "type-coverage",
31+
"init:git:hooks": ".github/scripts/setup_hooks.sh"
3132
},
3233
"repository": {
3334
"type": "git",

0 commit comments

Comments
 (0)