npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@arkweid/hookah

v0.2.2

Published

Simple git hooks manager

Downloads

2

Readme

Build Status

Hookah

Hookah it`s a simple manager of git hooks.

asciicast

Installation

Add Hookah to your system or build it from sources.

go

go get github.com/Arkweid/hookah

npm and yarn

npm i @arkweid/hookah-js --save-dev
# or yarn:
yarn add -D @arkweid/hookah-js

# Now you can call it:
npx hookah -h

NOTE: if you install it this way you should call it with npx for all listed examples below.

snap

sudo snap install --devmode hookah

brew

brew install Arkweid/hookah/hookah

Or take it from binaries and install manualy

Scenarios

First time user

Go to your project directory and run:

hookah install

It add for you configuration file hookah.yml with default directories for hooks sources. Now we ready to add hooks! For example we want to add pre commit hooks. Lets do that:

hookah add pre-commit

It will add a hook .git/hooks/pre-commit. So every time when you run git commit this file will be executed. That directories also will be created .hookah and .hookah-local. Use first one for project/team hooks. Second one for you personal hooks. Add it to .gitignore

Next fill the directory .hookah/pre-commit with executables you like

├───.hookah
│   └───pre-commit
│       ├─── fail_script
│       └─── ok_script

Example:

cat > .hookah/pre-commit/fail_script

#!/bin/sh
exit 1

cat > .hookah/pre-commit/ok_script

#!/bin/sh
exit 0

# Now we can commit:
git commit -am "It fail"

Done! Pretty simple, huh?

Complete example

hookah.yml

pre-commit:
  commands:
    eslint:
      glob: "*.{js,ts}"
      runner: yarn eslint {staged_files}  # hookah run it like "yarn eslint App.js Model.js ..."
    rubocop:
      tags: backend style
      glob: "*.{rb}"
      exclude: "application.rb|routes.rb" # simple regexp for more flexibility
      runner: bundle exec rubocop {all_files}
    govet:
      tags: backend style
      files: git ls-files -m # we can explicity define scope of files
      glob: "*.{go}"
      runner: go vet {files} # {files} will be replaced by matched files as arguments

  # If you have script files, you can specify parameters for them
  scripts:
    "hello.js":
      runner: node   # hookah run it like "node hello.js"
    "any.go":
      runner: go run # hookah run it like "go run any.go"

  # Not enough speed? Run all of them in parallel!
  # Default: false
  parallel: true

If your team have backend and frontend developers, you can skip unnsecesary hooks this way: hookah-local.yml

pre-commit:
  # I am fronted developer. Skip all this backend stuff!
  exclude_tags:
    - backend

  scripts:
    "any.go":
      runner: docker exec -it --rm <container_id_or_name> {cmd} # Wrap command from hookah.yml in docker
  commands:
    govet:
      skip: true # You can also skip command with this option

I want to run hook groups directly!

No problem, hookah have command for that:

hookah run pre-commit

# You will see the summary:
[ FAIL ] fail_script
[ OK ] ok_script

I want to use my own runner! And I dont want to change team/repository scripts.

Ok! For example you have any.go script. We can run it in this way:

Add hookah-local.yml

Add it to .gitignore. It your personal settings.

Next customize the any.go script:

pre-commit:
  "any.go":
    runner: "go run"

Done! Now our script will be executed like this:

go run any.go

I clone the existed repo which use hookah. How can I setup hooks?

We suppose repo already have the hookah structure. So all of you need it run install:

hookah install

Hookah wiil read existed hook groups and reproduce hooks in .git/hooks directory.

How can I can skip hoookah execution?

We have env HOOKAH=0 for that

HOOKAH=0 git commit -am "Hookah skipped"

How can I can skip some tags on the fly?

We have env HOOKAH_EXCLUDE=tag,tag for that

HOOKAH_EXCLUDE=ruby,security git commit -am "Skip some tag checks"

How can I run my linter against only modified files?

No problem. Lets take rubocop linter for ruby as example:

#!/bin/sh

git ls-files -m | xargs rubocop

I dont like bash. Give me working example for golang

Ok-ok! This is how any.go may looks like:

package main

import (
  "fmt"
  "os"
  "os/exec"
  "strings"
  
  "github.com/Arkweid/hookah/context"
)

func main() {
  files, _ := context.StagedFiles()
  files = context.FilterByExt(files, ".rb")

  cmd := exec.Command("rubocop", strings.Join(files, " "))

  outputBytes, err := cmd.CombinedOutput()

  fmt.Println(string(outputBytes))

  if err != nil {
    os.Exit(1)
  }
}

We include context package only for convenience. It`s just few useful functions.

Some hooks proved ARGS from git. How can I capture it in my script?

For pure script you can do it like that:

Example for prepare-commit-msg hook:

COMMIT_MSG_FILE=$1
COMMIT_SOURCE=$2
SHA1=$3

# ...

Can I change directory for script files?

Yes. You can do this through this config keys: hookah.yml

source_dir: ".hookah"
source_dir_local: ".hookah-local"

Uninstall

hookah uninstall