-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtsort-modules.orig
executable file
·71 lines (59 loc) · 1.4 KB
/
tsort-modules.orig
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
#
# Originally written by Greg in 2018-11, in the `tools/` directory
# of github:zulip/zulip-mobile . Motivation in these commits:
# https://github.com/zulip/zulip-mobile/commit/fa1b8a85c
# https://github.com/zulip/zulip-mobile/commit/063a3a134
#
# For our purposes, the interesting bit is the many shell functions,
# and their use in pipelines for other functions.
shopt -s globstar
this_file=$(readlink -f "$0")
rootdir=${this_file%/*/*}
bindir=$rootdir/node_modules/.bin
import_pairs()
{
"$bindir"/flow get-imports --json "$rootdir"/src/**/*.js \
| jq '.[] | .requirements[] | [.import, .path]
| map(ltrimstr("'"$rootdir"'/")) | join(" ") ' \
-r \
# | sort -u
}
sorted_files()
{
import_pairs | tsort 2>/dev/null
}
sorted_ourfiles()
{
grep -l '@flow' -- $(sorted_files | grep ^src/.*js$)
}
with_flow()
{
grep '@flow' -- $(sorted_files | grep ^src/.*js$)
}
todo()
{
with_flow | number_lines | grep -Ev '@flow strict(\s|$)'
}
depends()
{
local f="$1";
import_pairs | perl -lane 'print $F[0] if (m( '"$f"'$))'
}
rdepends()
{
local f="$1";
import_pairs | perl -lane 'print $F[1] if (m(^'"$f"' ))'
}
number_lines()
{
nl -ba -nln -w3 -s' '
}
case "$1" in
pairs) import_pairs;;
''|list) sorted_ourfiles;;
flow) with_flow | number_lines;;
todo) todo;;
depends) depends "$2";;
rdepends) rdepends "$2";;
esac