@mihairo/cmt 1.1.4 → 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.
Files changed (2) hide show
  1. package/cmt +20 -23
  2. 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.4" # x-release-please-version
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,51 +699,49 @@ 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
- local _cmt_path="$1"
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 "\${2:-}" ] && exit 0
708
- for _p in "${_cmt_path}" "\$HOME/.local/bin/cmt" "/usr/local/bin/cmt" "/opt/homebrew/bin/cmt"; do
709
- [ -x "\$_p" ] && { "\$_p" commit --write-only > "\$1"; exit 0; }
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
708
+ exit 0
711
709
  # <<< cmt
712
710
  SNIPPET
713
711
  }
714
712
 
715
713
  # lint snippet (commit-msg hook)
716
714
  _lint_snippet() {
717
- local _cmt_path="$1"
718
- cat << SNIPPET
715
+ cat << 'SNIPPET'
719
716
  # >>> cmt-lint — Conventional Commits CLI
720
- for _p in "${_cmt_path}" "\$HOME/.local/bin/cmt" "/usr/local/bin/cmt" "/opt/homebrew/bin/cmt"; do
721
- [ -x "\$_p" ] && { "\$_p" lint "\$1"; exit \$?; }
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 $?; }
722
719
  done
720
+ exit 0
723
721
  # <<< cmt-lint
724
722
  SNIPPET
725
723
  }
726
724
 
727
725
  # install or append cmt block to a hook file
728
- # usage: _install_hook <path> <needs_shebang> <cmt_path> [snippet_fn]
726
+ # usage: _install_hook <path> <needs_shebang> [snippet_fn]
729
727
  _install_hook() {
730
- local path="$1" shebang="${2:-1}" cmt_path="$3" snippet_fn="${4:-_hook_snippet}"
728
+ local path="$1" shebang="${2:-1}" snippet_fn="${3:-_hook_snippet}"
731
729
  local marker; [[ "$snippet_fn" == "_lint_snippet" ]] && marker="cmt-lint" || marker="cmt"
732
730
 
733
731
  if [[ -f "$path" ]]; then
734
732
  if grep -q ">>> ${marker}" "$path" 2>/dev/null; then
735
733
  local tmp; tmp=$(mktemp)
736
734
  awk "/# >>> ${marker}/{skip=1} !skip{print} /# <<< ${marker}/{skip=0}" "$path" > "$tmp"
737
- "$snippet_fn" "$cmt_path" >> "$tmp"
735
+ "$snippet_fn" >> "$tmp"
738
736
  mv "$tmp" "$path"
739
737
  success "Updated ${marker} block in $(basename "$(dirname "$path")")/$(basename "$path")"
740
738
  else
741
- "$snippet_fn" "$cmt_path" >> "$path"
739
+ "$snippet_fn" >> "$path"
742
740
  success "Appended to $(basename "$(dirname "$path")")/$(basename "$path")"
743
741
  fi
744
742
  else
745
743
  [[ "$shebang" == "1" ]] && printf '#!/usr/bin/env bash\n' > "$path"
746
- "$snippet_fn" "$cmt_path" >> "$path"
744
+ "$snippet_fn" >> "$path"
747
745
  chmod +x "$path"
748
746
  success "Created $(basename "$(dirname "$path")")/$(basename "$path")"
749
747
  fi
@@ -814,9 +812,8 @@ cmd_types() {
814
812
  cmd_init() {
815
813
  git rev-parse --git-dir > /dev/null 2>&1 || die "Not inside a git repository"
816
814
 
817
- local git_root cmt_path
815
+ local git_root
818
816
  git_root=$(git rev-parse --show-toplevel)
819
- cmt_path=$(realpath "$0")
820
817
 
821
818
  # .cmt.json
822
819
  if [[ ! -f "${git_root}/${CMT_CONFIG_FILE}" ]]; then
@@ -847,15 +844,15 @@ JSONEOF
847
844
 
848
845
  if [[ $use_husky -eq 1 ]]; then
849
846
  mkdir -p "${git_root}/.husky"
850
- _install_hook "${git_root}/.husky/prepare-commit-msg" 0 "$cmt_path"
847
+ _install_hook "${git_root}/.husky/prepare-commit-msg" 0
851
848
  if [[ $use_lint -eq 1 ]]; then
852
- _install_hook "${git_root}/.husky/commit-msg" 0 "$cmt_path" _lint_snippet
849
+ _install_hook "${git_root}/.husky/commit-msg" 0 _lint_snippet
853
850
  fi
854
851
  printf " ${DIM}Commit .husky/ hooks to share with your team.${RESET}\n"
855
852
  else
856
- _install_hook "${git_root}/.git/hooks/prepare-commit-msg" 1 "$cmt_path"
853
+ _install_hook "${git_root}/.git/hooks/prepare-commit-msg" 1
857
854
  if [[ $use_lint -eq 1 ]]; then
858
- _install_hook "${git_root}/.git/hooks/commit-msg" 1 "$cmt_path" _lint_snippet
855
+ _install_hook "${git_root}/.git/hooks/commit-msg" 1 _lint_snippet
859
856
  fi
860
857
  fi
861
858
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mihairo/cmt",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Zero-dependency conventional commits CLI — interactive picker, linter, and git hook installer. One bash script, works in any repo.",
5
5
  "keywords": [
6
6
  "conventional-commits",