Skip to content

Commit 5879540

Browse files
author
Thomas G.
committed
feat: ✨ improve plugin install
1 parent 3a0ead1 commit 5879540

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

src/githooks/_commit-msg.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ if [ -t 1 ]; then
66
exec >/dev/tty 2>&1
77
fi
88

9+
# Install commitizen plugins
10+
git hook run install-plugins -- '.commitlint.extends//""'
11+
912
# Apply commitlint rules to the latest commit message
1013
zz_log i "Applying commitlint rules to the latest commit..."
11-
PLUGINS=$(cat package.json | npx --yes jqn '.commitlint.extends' | tr -d "'[]:")
12-
npm list $PLUGINS 2>/dev/null 1>&2 || npm install --no-save $PLUGINS 2>/dev/null 1>&2 && npx --yes commitlint --edit "$1" && npx --yes devmoji -e
14+
npx --yes commitlint --edit "$1" && npx --yes devmoji -e

src/githooks/_install-plugins.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
json_key=$1
4+
json_file=${2:-package.json}
5+
6+
plugins=$(cat $json_file | npx --yes jqn "$1" | tr -d "'[]:,\"\n")
7+
8+
if [ -z "$plugins" ]; then
9+
zz_log w "No plugins found at key {B $json_key} in {U $json_file}"
10+
elif npm list $plugins 2>/dev/null 1>&2; then
11+
zz_log s "Plugins {B $plugins} already installed!"
12+
else
13+
zz_log i "Installing plugins {B $plugins} ..."
14+
npm install --no-save $plugins 2>/dev/null 1>&2
15+
zz_log s "Plugins {B $plugins} installed successfully!"
16+
fi

src/githooks/_pre-commit.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ if git diff --name-only ${@:---cached} | grep -q "composer.json"; then
5858
fi
5959
fi
6060

61-
# Install Prettier & Commitlint plugins if they are not already installed
62-
npm install --no-save $(cat package.json | npx --yes jqn '.prettier.plugins//"",.commitlint.extend//""' | tr -d "'[]:,\"\n") 2>/dev/null 1>&2
61+
# Install Prettier plugins if they are not already installed
62+
git hook run install-plugins -- '.prettier.plugins//""'
6363

6464
# Run pre-commit checks
6565
npx --yes git-precommit-checks

src/githooks/_prepare-commit-msg.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if [ -t 1 ]; then
88
fi
99

1010
# Install commitizen plugins
11-
npm install --no-save $(cat package.json | npx --yes jqn '.config.commitizen.path//""' | tr -d "'[]:,\"\n") 2>/dev/null 1>&2
11+
git hook run install-plugins -- '.config.commitizen.path//""'
1212

1313
# Edit commit message
1414
if [ $(grep -cv -e '^#' -e '^$' .git/COMMIT_EDITMSG) -eq 0 ]; then

0 commit comments

Comments
 (0)