#!/bin/bash

# check if npm is installed
if !command -v npm &> /dev/null; then
  echo "npm is not found. Please install npm and try again."
  exit 1
fi

# Create git hooks folder
mkdir -p .git/hooks

# Install git hooks
if [[ (-a .git/hooks/commit-msg) || (-a .git/hooks/pre-commit) || (-a .git/hooks/pre-push) ]]; then
  echo "Git hooks already installed"
else
  echo "Installing git hooks"
  ln -s ../../.git-hooks/commit-msg .git/hooks/commit-msg
  ln -s ../../.git-hooks/pre-commit .git/hooks/pre-commit
  ln -s ../../.git-hooks/pre-push .git/hooks/pre-push
fi

# Install commitlint
npm install -g @commitlint/{cli,config-conventional}
