-
Notifications
You must be signed in to change notification settings - Fork 2
/
ts-utils.sh
executable file
·49 lines (40 loc) · 983 Bytes
/
ts-utils.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
49
# !/usr/bin/bash
function main {
while [ -n "$1" ]
do
case "$1" in
-fix-require) rewrite_require $2 ;;
esac
shift
done
}
function rewrite_require {
local data=$(cat $1);
IFS=$'\n'
for line in $data
do
local conforms=$(
node -e "
\`$line\`.match(/^const (\w+) = require/g)
" -p
);
if [ "$conforms" != 'null' ]
then
local line=$(
node -e "
let d = \`
$line
\`;
d = d.replace(/const/, 'import');
d = d.replace(/\= require\((.+)/, (res) => {
res = res.slice(10, res.length - 2);
return ' from ' + res + ';';
});
console.log(d.trim());
"
);
echo $line;
fi
done
}
main $@