Skip to content

Commit

Permalink
feat(husky): update husky and related workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jason-capsule42 authored and blackfalcon committed May 25, 2021
1 parent c3b334a commit 5d78271
Show file tree
Hide file tree
Showing 10 changed files with 95 additions and 129 deletions.
30 changes: 30 additions & 0 deletions .husky/_/husky.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
if [ -z "$husky_skip_init" ]; then
debug () {
[ "$HUSKY_DEBUG" = "1" ] && echo "husky (debug) - $1"
}

readonly hook_name="$(basename "$0")"
debug "starting $hook_name..."

if [ "$HUSKY" = "0" ]; then
debug "HUSKY env variable is set to 0, skipping hook"
exit 0
fi

if [ -f ~/.huskyrc ]; then
debug "sourcing ~/.huskyrc"
. ~/.huskyrc
fi

export readonly husky_skip_init=1
sh -e "$0" "$@"
exitCode="$?"

if [ $exitCode != 0 ]; then
echo "husky - $hook_name hook exited with code $exitCode (error)"
exit $exitCode
fi

exit 0
fi
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit "$1"
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npm test
13 changes: 13 additions & 0 deletions bin/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ Creating Web Components People Love.
let areDependenciesInstalled = false;
let isGitRepo = false;
let isMainBranch = false;
let isHuskyConfigured = false;
let isBuilt = false;
let assetsAreCommitted = false;

Expand All @@ -391,6 +392,18 @@ Creating Web Components People Love.
}
isMainBranch = true;

process.stdout.write(`\nConfiguring Husky scripts`);
loadingLoop(() => isHuskyConfigured);
try {
await exec('npx husky-init', { cwd: params.dir });
await exec('chmod ug+x .husky/*', { cwd: params.dir });
await exec('chmod ug+x .git/hooks/*', { cwd: params.dir });
log(chalk.green('\nHusky successfully configured!'));
} catch ({ message }) {
log(chalk.red(message));
}
isHuskyConfigured = true;

process.stdout.write(`\nInstalling dependencies`);
loadingLoop(() => areDependenciesInstalled);
try {
Expand Down
121 changes: 5 additions & 116 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,10 @@
"@semantic-release/changelog": "^3.0.6",
"@semantic-release/git": "^7.0.18",
"@semantic-release/npm": "^5.3.5",
"husky": "^4.3.8",
"husky": "^6.0.0",
"npm-run-all": "^4.1.5",
"semantic-release": "^17.4.1"
},
"husky": {
"hooks": {
"pre-commit": "npm test",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
Expand Down
30 changes: 30 additions & 0 deletions template/.husky/_/husky.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/sh
if [ -z "$husky_skip_init" ]; then
debug () {
[ "$HUSKY_DEBUG" = "1" ] && echo "husky (debug) - $1"
}

readonly hook_name="$(basename "$0")"
debug "starting $hook_name..."

if [ "$HUSKY" = "0" ]; then
debug "HUSKY env variable is set to 0, skipping hook"
exit 0
fi

if [ -f ~/.huskyrc ]; then
debug "sourcing ~/.huskyrc"
. ~/.huskyrc
fi

export readonly husky_skip_init=1
sh -e "$0" "$@"
exitCode="$?"

if [ $exitCode != 0 ]; then
echo "husky - $hook_name hook exited with code $exitCode (error)"
exit $exitCode
fi

exit 0
fi
4 changes: 4 additions & 0 deletions template/.husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx --no-install commitlint --edit "$1"
4 changes: 4 additions & 0 deletions template/.husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

./node_modules/.bin/npm-run-all test linters bundler postinstall
6 changes: 0 additions & 6 deletions template/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@
"nodemonConfig": {
"ignore": ["*-css.js", "*.css"]
},
"husky": {
"hooks": {
"pre-commit": "npm-run-all test linters bundler postinstall",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"release": {
"branches": [
"main"
Expand Down

0 comments on commit 5d78271

Please sign in to comment.