Skip to content

Commit

Permalink
Merge pull request #98 from JsDaddy/feat/setup-hook
Browse files Browse the repository at this point in the history
feat(ref: no-ref): add setup hook
  • Loading branch information
NepipenkoIgor authored Mar 29, 2024
2 parents d5e4a9d + 52bb9ba commit 641e03f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
3 changes: 1 addition & 2 deletions ...hub/.hooks/commit-msg/check-commit-msg.sh → .github/hooks/commit-msg
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin
#!/bin/bash

set -e

commit_msg=$(cat .git/COMMIT_EDITMSG)

echo "$commit_msg" | npx commitlint
2 changes: 1 addition & 1 deletion .github/.hooks/pre-commit/quality.sh → .github/hooks/pre-commit
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin
#!/bin/bash

set -e

Expand Down
39 changes: 39 additions & 0 deletions .github/scripts/setup_hooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

# Define the directory containing sample hooks
SAMPLE_HOOKS_DIR=".github/hooks"

# Define the target directory for Git hooks
GIT_HOOKS_DIR=".git/hooks"

# Function to copy or replace hooks
copy_or_replace_hooks() {
for hook in "$SAMPLE_HOOKS_DIR"/*; do
hook_name=$(basename "$hook")
target_hook="$GIT_HOOKS_DIR/$hook_name"
if [ -f "$target_hook" ]; then
echo "Replacing existing hook: $hook_name"
else
echo "Copying new hook: $hook_name"
fi
cp "$hook" "$target_hook"
chmod ug+x "$target_hook" # Ensure executable permission is set
done
}

# Main function
main() {
# Check if .git/hooks directory exists
if [ ! -d "$GIT_HOOKS_DIR" ]; then
echo "Error: .git/hooks directory not found. Are you in a Git repository?"
exit 1
fi

# Copy or replace hooks
copy_or_replace_hooks

echo "Git hooks setup complete."
}

# Run the main function
main
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ You can also try our NGX COPYPASTE [check](https://www.npmjs.com/package/ngx-cop
$ npm install --save ngx-loader-indicator
```

## Setup hooks
```bash
$ npm run init:hooks
```

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

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"lint:fix": "ng lint --fix && npm run lint:scss:fix",
"prettier:fix": "npx prettier --write .",
"type-coverage-report": "typescript-coverage-report",
"type-coverage": "type-coverage"
"type-coverage": "type-coverage",
"init:git:hooks": ".github/scripts/setup_hooks.sh"
},
"repository": {
"type": "git",
Expand Down

0 comments on commit 641e03f

Please sign in to comment.