Skip to content

Commit

Permalink
[skip travis] npm distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
A.A.Abroskin committed Mar 7, 2019
1 parent c51bea7 commit 3f980b4
Show file tree
Hide file tree
Showing 9 changed files with 330 additions and 62 deletions.
18 changes: 9 additions & 9 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ builds:
- darwin
- windows
archive:
# replacements:
# windows: Windows
# darwin: MacOS
# linux: Linux
# 386: i386
# amd64: x86_64
# format_overrides:
# - goos: windows
# format: zip
replacements:
windows: Windows
darwin: MacOS
linux: Linux
386: i386
amd64: x86_64
format_overrides:
- goos: windows
format: zip
checksum:
name_template: '{{ .ProjectName }}_checksums.txt'
snapshot:
Expand Down
265 changes: 265 additions & 0 deletions .npm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
![Build Status](https://api.travis-ci.org/Arkweid/hookah.svg?branch=master)

# Hookah

Hookah it`s a simple manager of git hooks.

<a href="https://evilmartians.com/?utm_source=hookah">
<img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>

[![asciicast](https://asciinema.org/a/rupBzaCqin2n3qGlNFM9Agm7f.svg)](https://asciinema.org/a/rupBzaCqin2n3qGlNFM9Agm7f)

## Installation

Add Hookah to your system or build it from sources.

### go
```bash
go get github.com/Arkweid/hookah
```

### npm and yarn
```bash
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
```bash
sudo snap install --devmode hookah
```

### brew
```bash
brew install Arkweid/hookah/hookah
```

Or take it from [binaries](https://github.com/Arkweid/hookah/releases) and install manualy

## Scenarios

### First time user

Go to your project directory and run:


```bash
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:


```bash
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:
```bash
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`
```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`
```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:

```bash
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:

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

Done! Now our script will be executed like this:
```bash
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:

```bash
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

```bash
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

```bash
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:

```bash
#!/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:

```go
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:
```bash
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`
```yml
source_dir: ".hookah"
source_dir_local: ".hookah-local"
```

### Uninstall

```bash
hookah uninstall
```
Binary file added .npm/bin/hookah-linux
Binary file not shown.
Binary file added .npm/bin/hookah-mac
Binary file not shown.
Binary file added .npm/bin/hookah-win.exe
Binary file not shown.
30 changes: 30 additions & 0 deletions .npm/bin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env node

var spawn = require('child_process').spawn;
var path = require('path');

var command_args = process.argv.slice(2);

function spawnCommand(binaryExecutable) {
var child = spawn(
path.join(__dirname, binaryExecutable),
command_args,
{ stdio: [process.stdin, process.stdout, process.stderr] });

child.on('close', function (code) {
if (code !== 0) {
process.exit(1);
}
});
}

if (process.platform === 'darwin') {
spawnCommand('hookah-mac');
} else if (process.platform === 'linux') {
spawnCommand('hookah-linux');
} else if (process.platform === 'win32') {
spawnCommand('hookah-win.exe');
} else {
console.log("Unsupported OS");
process.exit(1);
}
26 changes: 26 additions & 0 deletions .npm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@arkweid/hookah-js",
"version": "0.2.1",
"description": "Simple git hooks manager",
"main": "index.js",
"bin": {
"hookah": "./bin/index.js"
},
"repository": "https://github.com/Arkweid/hookah",
"keywords": [
"git",
"hook",
"manager"
],
"author": "Arkweid",
"license": "MIT",
"bugs": {
"url": "https://github.com/Arkweid/hookah-js/issues"
},
"homepage": "https://github.com/Arkweid/hookah-js#readme",
"os": [
"darwin",
"linux",
"win32"
]
}
19 changes: 0 additions & 19 deletions .npmignore

This file was deleted.

Loading

0 comments on commit 3f980b4

Please sign in to comment.