Skip to content

Commit

Permalink
chore: add husky pre-push script (#3061)
Browse files Browse the repository at this point in the history
* chore: add husky pre-push script

* skip pre-push on windows

* change to node script

* add inquirer as devdependency

* add inquirer as devdependency
  • Loading branch information
georgexu99 committed Nov 21, 2022
1 parent 3dbaa33 commit 9e9128f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
9 changes: 9 additions & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

BRANCH=`git rev-parse --abbrev-ref HEAD`
PROTECTED_BRANCH="main"

if [ "$BRANCH" = $PROTECTED_BRANCH ]; then
node .husky/pre-push.js < /dev/tty
fi
14 changes: 14 additions & 0 deletions .husky/pre-push.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const inquirer = require('inquirer');

const question = [
{
type: 'confirm',
name: 'continuePush',
message: '[pre-push hook] Warning: this is a protected branch. Continue?',
},
];

inquirer.prompt(question).then((answer) => {
if (!answer.continuePush) process.exit(1);
process.exit(0);
});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
"fork-ts-checker-webpack-plugin": "^7.2.13",
"generate-changelog": "^1.8.0",
"husky": "^7.0.1",
"inquirer": "^8.0.0",
"lerna": "^6.0.1",
"lint-staged": "^12.1.7",
"listr2": "^4.0.4",
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7106,7 +7106,7 @@ inquirer@^6.2.0:
strip-ansi "^5.1.0"
through "^2.3.6"

inquirer@^8.2.4:
inquirer@^8.0.0, inquirer@^8.2.4:
version "8.2.5"
resolved "https://registry.yarnpkg.com/inquirer/-/inquirer-8.2.5.tgz#d8654a7542c35a9b9e069d27e2df4858784d54f8"
integrity sha512-QAgPDQMEgrDssk1XiwwHoOGYF9BAbUcc1+j+FhEvaOt8/cKRqyLn0U5qA6F74fGhTMGxf92pOvPBeh29jQJDTQ==
Expand Down

0 comments on commit 9e9128f

Please sign in to comment.