@mihairo/cmt 1.1.5 → 1.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cmt +18 -23
- package/package.json +1 -1
package/cmt
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
# =============================================================================
|
|
7
7
|
set -euo pipefail
|
|
8
8
|
|
|
9
|
-
CMT_VERSION="1.1.
|
|
9
|
+
CMT_VERSION="1.1.6" # x-release-please-version
|
|
10
10
|
CMT_CONFIG_FILE=".cmt.json"
|
|
11
11
|
CMT_SCHEMA_URL="https://raw.githubusercontent.com/mihai-ro/cmt/main/schema/cmt.schema.json"
|
|
12
12
|
|
|
@@ -699,14 +699,11 @@ lint_message() {
|
|
|
699
699
|
# It intercepts plain `git commit`, runs the picker, writes the message.
|
|
700
700
|
# commit-msg is not needed — the message is already conventional when we write it.
|
|
701
701
|
_hook_snippet() {
|
|
702
|
-
|
|
703
|
-
# variables prefixed with \ are meant for the hook at runtime (not expanded now).
|
|
704
|
-
# _cmt_path IS expanded now; it records the install-time absolute path.
|
|
705
|
-
cat << SNIPPET
|
|
702
|
+
cat << 'SNIPPET'
|
|
706
703
|
# >>> cmt — Conventional Commits CLI
|
|
707
|
-
[ -n "
|
|
708
|
-
for _p in "
|
|
709
|
-
[ -x "
|
|
704
|
+
[ -n "${2:-}" ] && exit 0
|
|
705
|
+
for _p in "./node_modules/.bin/cmt" "$HOME/.local/bin/cmt" "/usr/local/bin/cmt" "/opt/homebrew/bin/cmt"; do
|
|
706
|
+
[ -x "$_p" ] && { "$_p" commit --write-only > "$1"; exit 0; }
|
|
710
707
|
done
|
|
711
708
|
exit 0
|
|
712
709
|
# <<< cmt
|
|
@@ -715,11 +712,10 @@ SNIPPET
|
|
|
715
712
|
|
|
716
713
|
# lint snippet (commit-msg hook)
|
|
717
714
|
_lint_snippet() {
|
|
718
|
-
|
|
719
|
-
cat << SNIPPET
|
|
715
|
+
cat << 'SNIPPET'
|
|
720
716
|
# >>> cmt-lint — Conventional Commits CLI
|
|
721
|
-
for _p in "
|
|
722
|
-
[ -x "
|
|
717
|
+
for _p in "./node_modules/.bin/cmt" "$HOME/.local/bin/cmt" "/usr/local/bin/cmt" "/opt/homebrew/bin/cmt"; do
|
|
718
|
+
[ -x "$_p" ] && { "$_p" lint "$1"; exit $?; }
|
|
723
719
|
done
|
|
724
720
|
exit 0
|
|
725
721
|
# <<< cmt-lint
|
|
@@ -727,25 +723,25 @@ SNIPPET
|
|
|
727
723
|
}
|
|
728
724
|
|
|
729
725
|
# install or append cmt block to a hook file
|
|
730
|
-
# usage: _install_hook <path> <needs_shebang>
|
|
726
|
+
# usage: _install_hook <path> <needs_shebang> [snippet_fn]
|
|
731
727
|
_install_hook() {
|
|
732
|
-
local path="$1" shebang="${2:-1}"
|
|
728
|
+
local path="$1" shebang="${2:-1}" snippet_fn="${3:-_hook_snippet}"
|
|
733
729
|
local marker; [[ "$snippet_fn" == "_lint_snippet" ]] && marker="cmt-lint" || marker="cmt"
|
|
734
730
|
|
|
735
731
|
if [[ -f "$path" ]]; then
|
|
736
732
|
if grep -q ">>> ${marker}" "$path" 2>/dev/null; then
|
|
737
733
|
local tmp; tmp=$(mktemp)
|
|
738
734
|
awk "/# >>> ${marker}/{skip=1} !skip{print} /# <<< ${marker}/{skip=0}" "$path" > "$tmp"
|
|
739
|
-
"$snippet_fn"
|
|
735
|
+
"$snippet_fn" >> "$tmp"
|
|
740
736
|
mv "$tmp" "$path"
|
|
741
737
|
success "Updated ${marker} block in $(basename "$(dirname "$path")")/$(basename "$path")"
|
|
742
738
|
else
|
|
743
|
-
"$snippet_fn"
|
|
739
|
+
"$snippet_fn" >> "$path"
|
|
744
740
|
success "Appended to $(basename "$(dirname "$path")")/$(basename "$path")"
|
|
745
741
|
fi
|
|
746
742
|
else
|
|
747
743
|
[[ "$shebang" == "1" ]] && printf '#!/usr/bin/env bash\n' > "$path"
|
|
748
|
-
"$snippet_fn"
|
|
744
|
+
"$snippet_fn" >> "$path"
|
|
749
745
|
chmod +x "$path"
|
|
750
746
|
success "Created $(basename "$(dirname "$path")")/$(basename "$path")"
|
|
751
747
|
fi
|
|
@@ -816,9 +812,8 @@ cmd_types() {
|
|
|
816
812
|
cmd_init() {
|
|
817
813
|
git rev-parse --git-dir > /dev/null 2>&1 || die "Not inside a git repository"
|
|
818
814
|
|
|
819
|
-
local git_root
|
|
815
|
+
local git_root
|
|
820
816
|
git_root=$(git rev-parse --show-toplevel)
|
|
821
|
-
cmt_path=$(realpath "$0")
|
|
822
817
|
|
|
823
818
|
# .cmt.json
|
|
824
819
|
if [[ ! -f "${git_root}/${CMT_CONFIG_FILE}" ]]; then
|
|
@@ -849,15 +844,15 @@ JSONEOF
|
|
|
849
844
|
|
|
850
845
|
if [[ $use_husky -eq 1 ]]; then
|
|
851
846
|
mkdir -p "${git_root}/.husky"
|
|
852
|
-
_install_hook "${git_root}/.husky/prepare-commit-msg" 0
|
|
847
|
+
_install_hook "${git_root}/.husky/prepare-commit-msg" 0
|
|
853
848
|
if [[ $use_lint -eq 1 ]]; then
|
|
854
|
-
_install_hook "${git_root}/.husky/commit-msg" 0
|
|
849
|
+
_install_hook "${git_root}/.husky/commit-msg" 0 _lint_snippet
|
|
855
850
|
fi
|
|
856
851
|
printf " ${DIM}Commit .husky/ hooks to share with your team.${RESET}\n"
|
|
857
852
|
else
|
|
858
|
-
_install_hook "${git_root}/.git/hooks/prepare-commit-msg" 1
|
|
853
|
+
_install_hook "${git_root}/.git/hooks/prepare-commit-msg" 1
|
|
859
854
|
if [[ $use_lint -eq 1 ]]; then
|
|
860
|
-
_install_hook "${git_root}/.git/hooks/commit-msg" 1
|
|
855
|
+
_install_hook "${git_root}/.git/hooks/commit-msg" 1 _lint_snippet
|
|
861
856
|
fi
|
|
862
857
|
fi
|
|
863
858
|
|
package/package.json
CHANGED