# @see
# https://github.com/evilmartians/lefthook
#
# Run the command to test:
#   npx -y lefthook run [-v,--verbose] <hook-name>
#
# Examples:
#   npx -y lefthook run --verbose pre-commit
#   npx -y lefthook run --verbose commit-msg
#   npx -y lefthook run --verbose post-merge

pre-commit:
  parallel: true

  scripts:
    check-link-in-package-json:
      run: |
        if grep -q 'link:' package.json; then
          echo "ERROR: \"link:\" is included in package.json. Please remove it before committing."
          exit 1
        fi

commit-msg:
  parallel: true

  commands:
    commitlint:
      run: npx -y commitlint@latest --edit {1} --verbose

    # cspell:
    #   run: npx -y @nozomiishii/cspell-config@latest {1}

post-merge:
  parallel: true

  commands:
    delete-merged-branches:
      run: git branch --merged | grep -Ev '\*|master|main|dev|develop|development|stag|staging|prod|production' | xargs git branch -d; git fetch --prune;

    install-packages:
      env:
        LEFTHOOK_VERBOSE: true
      interactive: true
      files: git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD
      glob: '**/{package.json,pnpm-lock.yaml,yarn.lock,package-lock.json}'
      run: |
        if [ -f "pnpm-lock.yaml" ]; then
          echo "🥊 Installing dependencies with pnpm..."
          yes | pnpm install
          exit 0
        fi

        if [ -f "yarn.lock" ]; then
          echo "🥊 Installing dependencies with yarn..."
          yarn install
          exit 0
        fi

        if [ -f "package-lock.json" ]; then
          echo "🥊 Installing dependencies with npm..."
          npm install
          exit 0
        fi
