Skip to content

Instantly share code, notes, and snippets.

@pimlie
Created February 18, 2019 17:19
Show Gist options
  • Save pimlie/666fbb1c8cd3959c930455a713efd1bb to your computer and use it in GitHub Desktop.
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)
#!/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