Croot Blog

Home About Tech Hobby Archive

⚠️

이 블로그의 모든 포스트는 Notion 데이터베이스를 자동 변환하여 작성 되었습니다.
따라서 문서에 따라 깨져 보일 수 있습니다.
더 많은 내용이 궁금하시다면 👀 Notion 보러가기

husky script

git commit 대상 ts, tsx 파일들의 console을 제거하는 스크립트

#!/usr/bin/env sh

# Function to remove console.log statements from a file
remove_console() {
  file=$1
  tmp_file="$file.tmp"

  # Use sed to remove console.log statements
  sed '/console\.[debug|log|error|info|trace]/d' "$file" > "$tmp_file"

  # Replace the original file with the temporary file
  mv "$tmp_file" "$file"
}

# Get the list of modified files in the commit range
files=$(git diff --staged --name-only --diff-filter=d)

for file in $files; do
  # Process only TypeScript files
  if [[ "$file" == *.ts || "$file" == *.tsx ]]; then
    echo "Processing $file"
    git show "$commit_range:$file" | remove_console "$file"
    git add "$file"
  fi
done

echo "Console removal complete."