-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
167 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/bin/sh | ||
[ -z "$LOG_PREFIX" ] && LOG_PREFIX="[.husky/???]" | ||
|
||
log() { | ||
echo "${LOG_PREFIX} $1" | ||
} | ||
|
||
error() { | ||
echo >&2 "${LOG_PREFIX} $1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
LOG_PREFIX="[.husky/post-checkout]" | ||
|
||
. "$(dirname "$0")/hook-utils.sh" | ||
|
||
HEAD_PREV="$1" | ||
HEAD_NEW="$2" | ||
CKOUT_TYPE_FLAG="$3" # 0 = retrieve file from index, 1 = changing branches | ||
|
||
# check if this is a post-checkout after a `git clone` | ||
IS_CLONING=$( [ -z "$HEAD_PREV" ] && echo true || echo false ) | ||
|
||
update_npm_dependencies() { | ||
# Only run if chaning branches and not performing the initial `git clone` | ||
if [ $CKOUT_TYPE_FLAG == 1 ] && [ $IS_CLONING == false ]; then | ||
local changed_files="" | ||
# derived from https://gist.github.com/taurus227/28960de89e6c43bb3d492125368f1224 | ||
changed_files="$(git diff-tree -r --name-only --no-commit-id $HEAD_PREV $HEAD_NEW)" | ||
|
||
if echo "$changed_files" | grep --quiet "package-lock.json"; then | ||
log "CHANGE DETECTED: 'package-lock.json'" | ||
log "Dependency requirements changed! This will take a few seconds..." | ||
|
||
local cmd="npm install --prefer-offline" | ||
if ! command -v npm &>/dev/null; then | ||
log "NPM not found on \$PATH, however '$cmd' is desired. Please accomplish manually." | ||
return | ||
fi | ||
log "$> $cmd" | ||
eval "$cmd" | ||
fi | ||
fi | ||
} | ||
|
||
update_npm_dependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
[ -z "$LOG_PREFIX" ] && LOG_PREFIX="[.husky/post-merge]" | ||
|
||
. "$(dirname "$0")/hook-utils.sh" | ||
|
||
update_npm_dependencies() { | ||
# derived from https://gist.github.com/taurus227/28960de89e6c43bb3d492125368f1224 | ||
local changed_files="" | ||
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)" | ||
|
||
local NEEDS_INSTALL=true | ||
|
||
if echo -e "$changed_files" | grep --quiet "package-lock.json"; then | ||
log "CHANGE DETECTED: 'package-lock.json'" | ||
log "Lock files rarely merge properly. Deleting and re-generating it..." | ||
|
||
local output="$changed_files" | ||
output="$(echo -e "$output" | grep "package-lock.json")" | ||
local lockfiles=("$output") # make array of filepaths | ||
rm ${lockfiles[@]} | ||
|
||
elif echo -e "$changed_files" | grep --quiet "package.json"; then | ||
log "CHANGE DETECTED: 'package.json'" | ||
log "Dependencies might of changed, lets make sure we are g2g!" | ||
else | ||
NEEDS_INSTALL=false | ||
fi | ||
|
||
if [ "$NEEDS_INSTALL" == true ]; then | ||
cmd="npm install" | ||
if ! command -v npm &>/dev/null; then | ||
log "NPM not found on \$PATH, however '$cmd' is desired. Please accomplish manually." | ||
return | ||
fi | ||
log "$> $cmd" | ||
eval "$cmd" | ||
|
||
changed_files="$(git diff --name-only --diff-filter=d)" | ||
if echo -e "$changed_files" | grep --quiet "package-lock.json"; then | ||
log "ALL FIXED! package-lock.json needed a refresh." | ||
|
||
local lockfiles=($(echo -e "$changed_files" | grep "package-lock.json")) | ||
git add -- "${lockfiles[@]}" | ||
|
||
for lockfile in "${lockfiles[@]}"; do | ||
log "STAGED: $lockfile" | ||
done | ||
|
||
local filenoun="file" | ||
if [ "${#lockfiles[@]}" -gt 1 ]; then | ||
filenoun="${filenoun}s" | ||
fi | ||
log "Please commit the newly generated $filenoun for the team!" | ||
fi | ||
fi | ||
} | ||
|
||
update_npm_dependencies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
CALLER_CMD="$1" # rebase || amend | ||
export LOG_PREFIX="[.husky/post-rewrite]" | ||
|
||
. "$(dirname "$0")/hook-utils.sh" | ||
|
||
# derived from https://gist.github.com/taurus227/28960de89e6c43bb3d492125368f1224 | ||
if [ "$CALLER_CMD" == "rebase" ]; then | ||
log "DETECTED: git-rebase."; | ||
$(dirname "$0")/post-merge | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/sh | ||
. "$(dirname "$0")/_/husky.sh" | ||
|
||
export NODE_ENV=production | ||
|
||
LOG_PREFIX="[.husky/pre-commit]" | ||
|
||
. "$(dirname "$0")/hook-utils.sh" | ||
|
||
if command -v npm &>/dev/null; then | ||
log "$> npm run lint" | ||
if ! npm run lint; then | ||
error "ERROR: Dirty code detected!" | ||
error "Fix the lint errors before committing to the repository." | ||
exit -1 | ||
fi | ||
else | ||
error "NPM not found on \$PATH, unable to run pre-commit lint hook." | ||
exit -1 | ||
fi |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters