-
Notifications
You must be signed in to change notification settings - Fork 35
/
convert.sh
executable file
·48 lines (39 loc) · 1.31 KB
/
convert.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
set -e
for x in $(find src test -name '*.js' | grep -v index.flow.js); do
echo Converting $x
tsname=$(echo $x | sed s/js$/ts/)
cat $x |
# Change `+x` to `readonly x`:
sed -E 's/^ *[+](\[?[_a-zA-Z0-9]+)/readonly \1/' |
# Fix exact types:
sed -e 's/{|/{/' |
sed -e 's/|}/}/' |
# Fix differently-named types:
sed -e 's/mixed/unknown/g' |
sed -e 's/\| void/| undefined/g' |
sed -e 's/ Iterator</ IterableIterator</g' |
sed -e 's/TimeoutID/ReturnType<typeof setTimeout>/g' |
sed -e 's/React\.Node/React.ReactNode/g' |
# Fix utility types:
sed -E 's/\$Call<([^,]*)[^>]*>/ReturnType<\1>/' |
sed -E 's/\$Keys<([^>]*)>/keyof \1/' |
sed -E 's/\$PropertyType<([^,]*),([^>]*)>/\1[\2]/' |
sed -e 's/$Shape</Partial</' |
# Specific problems:
sed -e "s/<Buttons: {/<Buttons extends {/" |
# Fix `import type` syntax:
sed -e 's/import type/import/' |
sed -E 's/type ([_a-zA-Z0-9]+)($|,| [^=])/\1\2/g' |
# We aren't JS anymore:
sed -e 's!// $FlowFixMe!// @ts-expect-error!' |
sed -e 's!// @flow!!' |
sed -e "s/[.]js'$/'/" > $tsname
if cat $x | grep -q -E '</|/>'; then
mv $tsname ${tsname}x
fi
rm $x
done
(cd ../../; yarn fix)
git add src
git rm convert.sh
git commit -m "x (cd packages/edge-login-ui-rn; ./convert.sh)" --no-verify