forked from Botanical/BotanJS
Migrate old externs 2/x
This commit is contained in:
Executable
+65
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "usage: $0 <TypeName>"
|
||||
echo "example: $0 System.utils.IKey"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
type_name="$1"
|
||||
from="type {$type_name}"
|
||||
to="type {typeof $type_name}"
|
||||
|
||||
mapfile -t files < <(git grep -l -F "$from" -- '*.js')
|
||||
|
||||
if [ "${#files[@]}" -eq 0 ]; then
|
||||
echo "No matches found for: $from"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Replacing:"
|
||||
echo " $from"
|
||||
echo "with:"
|
||||
echo " $to"
|
||||
echo
|
||||
|
||||
for file in "${files[@]}"; do
|
||||
echo "============================================================"
|
||||
echo "$file"
|
||||
echo "============================================================"
|
||||
|
||||
git grep -n -F "$from" -- "$file" || true
|
||||
echo
|
||||
|
||||
while true; do
|
||||
read -r -p "Replace in this file? [y/N/q/a] " ans
|
||||
case "$ans" in
|
||||
y|Y)
|
||||
perl -0pi -e 's/\Q'"$from"'\E/'"$to"'/g' "$file"
|
||||
echo "patched: $file"
|
||||
break
|
||||
;;
|
||||
a|A)
|
||||
for f in "${files[@]}"; do
|
||||
perl -0pi -e 's/\Q'"$from"'\E/'"$to"'/g' "$f"
|
||||
echo "patched: $f"
|
||||
done
|
||||
exit 0
|
||||
;;
|
||||
q|Q)
|
||||
echo "aborted"
|
||||
exit 0
|
||||
;;
|
||||
""|n|N)
|
||||
echo "skipped: $file"
|
||||
break
|
||||
;;
|
||||
*)
|
||||
echo "Use y, n, q, or a."
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
echo
|
||||
done
|
||||
Reference in New Issue
Block a user