forked from coding-cat-official/coding-cat-public
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-problem-list
More file actions
executable file
·47 lines (35 loc) · 930 Bytes
/
build-problem-list
File metadata and controls
executable file
·47 lines (35 loc) · 930 Bytes
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
#!/bin/bash
set -e
OUTFILE="problems.js"
TMPFILE="$(mktemp).js"
echo "Building problem list in $TMPFILE ... "
write() {
echo "$@" >> "$TMPFILE"
}
load-problem-name() {
jq -r .meta.name "$1/problem.json"
}
is-problem-enabled() {
if [ -f enabled-problems ] ; then
grep -q "$1" enabled-problems
else
return 0 # all problems are enabled if there's no list
fi
}
write "// THIS FILE IS AUTOGENERATED. DO NOT EDIT MANUALLY."
write ""
for f in * ; do
[ ! -d "$f" ] && continue
name="$(load-problem-name "$f")"
is-problem-enabled "$name" && write "import" "$name" "from './$f/problem.json';"
done
write "const problems = ["
for f in * ; do
[ ! -d "$f" ] && continue
name="$(load-problem-name "$f")"
is-problem-enabled "$name" && write " $name,"
done
write "];"
write "export default problems;"
echo "Build succeeded. Overwriting $OUTFILE"
mv "$TMPFILE" "$OUTFILE"