diff --git a/.github/.hooks/commit-msg/check-commit-msg.sh b/.github/hooks/commit-msg old mode 100644 new mode 100755 similarity index 87% rename from .github/.hooks/commit-msg/check-commit-msg.sh rename to .github/hooks/commit-msg index 8e4a168..70db84b --- a/.github/.hooks/commit-msg/check-commit-msg.sh +++ b/.github/hooks/commit-msg @@ -1,7 +1,6 @@ -#!/usr/bin +#!/bin/bash set -e commit_msg=$(cat .git/COMMIT_EDITMSG) - echo "$commit_msg" | npx commitlint diff --git a/.github/.hooks/pre-commit/quality.sh b/.github/hooks/pre-commit old mode 100644 new mode 100755 similarity index 95% rename from .github/.hooks/pre-commit/quality.sh rename to .github/hooks/pre-commit index 34d19b4..071b0ea --- a/.github/.hooks/pre-commit/quality.sh +++ b/.github/hooks/pre-commit @@ -1,4 +1,4 @@ -#!/usr/bin +#!/bin/bash set -e diff --git a/.github/scripts/setup_hooks.sh b/.github/scripts/setup_hooks.sh new file mode 100755 index 0000000..23c8312 --- /dev/null +++ b/.github/scripts/setup_hooks.sh @@ -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 diff --git a/README.md b/README.md index 2c652a1..9fe8ba1 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index 04bf6ce..77d73a2 100644 --- a/package.json +++ b/package.json @@ -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",