-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathbuild-problem-list
More file actions
executable file
·60 lines (47 loc) · 1.21 KB
/
build-problem-list
File metadata and controls
executable file
·60 lines (47 loc) · 1.21 KB
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
#!/usr/bin/env bash
set -euo pipefail
echo -e "\nbuilding problems.js..."
OUTFILE="problems.js"
TMPFILE="$(mktemp).js"
write(){ echo "$@" >> "$TMPFILE"; }
load_name(){ jq -r .meta.name "$1/problem.json"; }
load_category() { jq -r .meta.category "$1/problem.json"; }
is_enabled(){
local name="$1"
local category="$2"
if [[ -f enabled-problems ]]; then
grep -qx "$name" enabled-problems && return 0
grep -qx "$category" enabled-problems && return 0
return 1
else
return 0
fi
}
declare -A dir_for_name
for dir in */*/; do
[[ -f "${dir}problem.json" ]] || continue
d=${dir%/}
name=$(load_name "$d")
category=$(load_category "$d")
if is_enabled "$name" "$category"; then
dir_for_name["$name"]="$d"
fi
done
IFS=$'\n' sorted_names=($(printf "%s\n" "${!dir_for_name[@]}" | sort))
unset IFS
write "// THIS FILE IS AUTOGENERATED. DO NOT EDIT MANUALLY."
write ""
for name in "${sorted_names[@]}"; do
dir=${dir_for_name[$name]}
write "import $name from './$dir/problem.json';"
done
write ""
write "const problems = ["
for name in "${sorted_names[@]}"; do
write " $name,"
done
write "];"
write ""
write "export default problems;"
mv "$TMPFILE" "$OUTFILE"
echo "Build succeeded: $OUTFILE"