-
-
Save pimlie/666fbb1c8cd3959c930455a713efd1bb to your computer and use it in GitHub Desktop.
List component tag occurences in your project (eg to optimize bootstrap-vue components)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
extPattern="*.vue" | |
tagPattern="<b-[a-zA-Z\\\-]+" | |
srcFiles=($(find . -iname "$extPattern" ! -path '*node_modules*' ! -path '*.nuxt*' | sort)) | |
components=() | |
for file in ${srcFiles[@]}; do | |
components+=($(cat "$file" | awk '{split($0, a, "'$tagPattern'", sep); for (k in sep) print substr(sep[k], 2) }' | sort -u)); | |
done | |
# create unique array | |
components=($(echo ${components[@]} | tr ' ' '\n' | sort -u | tr '\n' ' ')) | |
for c in ${components[@]}; do | |
files=() | |
for file in ${srcFiles[@]}; do | |
if [ $(grep -c "<$c" "$file") -gt 0 ]; then | |
files+=("$file") | |
fi | |
done | |
echo $c": "${#files[@]} | |
if [ "$1" == "-v" ]; then | |
echo "${files[@]}" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment