Skip to content

Commit 9e9128f

Browse files
authored
chore: add husky pre-push script (#3061)
* chore: add husky pre-push script * skip pre-push on windows * change to node script * add inquirer as devdependency * add inquirer as devdependency
1 parent 3dbaa33 commit 9e9128f

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

.husky/pre-push

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
BRANCH=`git rev-parse --abbrev-ref HEAD`
5+
PROTECTED_BRANCH="main"
6+
7+
if [ "$BRANCH" = $PROTECTED_BRANCH ]; then
8+
node .husky/pre-push.js < /dev/tty
9+
fi

.husky/pre-push.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const inquirer = require('inquirer');
2+
3+
const question = [
4+
{
5+
type: 'confirm',
6+
name: 'continuePush',
7+
message: '[pre-push hook] Warning: this is a protected branch. Continue?',
8+
},
9+
];
10+
11+
inquirer.prompt(question).then((answer) => {
12+
if (!answer.continuePush) process.exit(1);
13+
process.exit(0);
14+
});

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
"fork-ts-checker-webpack-plugin": "^7.2.13",
124124
"generate-changelog": "^1.8.0",
125125
"husky": "^7.0.1",
126+
"inquirer": "^8.0.0",
126127
"lerna": "^6.0.1",
127128
"lint-staged": "^12.1.7",
128129
"listr2": "^4.0.4",

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7106,7 +7106,7 @@ inquirer@^6.2.0:
71067106
strip-ansi "^5.1.0"
71077107
through "^2.3.6"
71087108

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

0 commit comments

Comments
 (0)