Last active
September 9, 2018 01:29
-
-
Save belchior/83754cb2bb63fb74c87590526102336f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
main() { | |
local dirPath=$1 | |
local files=$(find "$dirPath" -name '*.ts' -type f) | |
while read filePath; do | |
countInjectedsFromFile "$filePath" | |
done <<< "$files" | |
} | |
countInjectedsFromFile() { | |
local filePath=$1 | |
local injectedNames=$(extractInjectedFromFile "$filePath") | |
if [[ $injectedNames != '' ]]; then | |
while read name; do | |
local num="$(countTerm "$name" "$filePath")" | |
if [[ $num = 1 ]]; then | |
printf '%s %s\n' "$name" "$filePath" | |
fi | |
done <<< "$injectedNames" | |
fi | |
} | |
extractInjectedFromFile() { | |
local filePath=$1 | |
# grep ... # extract constructor signature with parameters from file | |
# sed -e ... # remove comments | |
# sed -e ... # separating all statements by line break | |
# sed -e ... # removing empty line | |
# sed -e ... # removing know terms | |
# sed -e ... # geting only injected names | |
# sed -e ... # removing end line | |
grep --null-data --only-matching --extended-regexp 'constructor\s*\([^)]+)' "$filePath" | \ | |
sed --regexp-extended \ | |
-e 's/\/\/.*|\/\*.*\*\///' \ | |
-e 's/,/\n/g' | \ | |
sed --regexp-extended \ | |
-e 's/\(|\)|\?|constructor|private|public|protected//g' \ | |
-e '/^\s*$/d' \ | |
-e 's/\s*([^:]+):.*/\1/' \ | |
-e '/^\s+/d' | |
} | |
countTerm() { | |
local name=$1 | |
local filePath=$2 | |
local terms=$(grep --only-matching "$name" "$filePath" | wc --lines) | |
printf '%s\n' "$terms" | |
} | |
main $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment