@@ -4,15 +4,50 @@ set -eu
4
4
# adapted from https://github.com/johannes-wolf/cetz/blob/35c0868378cea5ad323cc0d9c2f76de8ed9ba5bd/scripts/package
5
5
# licensed under Apache License 2.0
6
6
7
+ # ignore rules
8
+ readarray -t ignores < <( grep -v ' ^#' .typstignore | grep ' [^[:blank:]]' )
9
+
10
+ # recursively print all files that are not excluded via .typstignore
11
+ function enumerate {
12
+ local root=" $1 "
13
+ if [[ -f " $root " ]]; then
14
+ echo " $root "
15
+ else
16
+ local files
17
+ readarray -t files < <( find " $root " \
18
+ -mindepth 1 -maxdepth 1 \
19
+ -not -name .git \
20
+ -not -name .typstignore)
21
+ # declare -p files >&2
22
+
23
+ local f
24
+ for f in " ${files[@]} " ; do
25
+ local include
26
+ include=1
27
+
28
+ local ignore
29
+ for ignore in " ${ignores[@]} " ; do
30
+ if [[ " $ignore " =~ ^! ]]; then
31
+ ignore=" ${ignore: 1} "
32
+ if [[ " $f " == ./$ignore ]]; then
33
+ # echo "\"$f\" matched \"!$ignore\"" >&2
34
+ include=1
35
+ fi
36
+ elif [[ " $f " == ./$ignore ]]; then
37
+ # echo "\"$f\" matched \"$ignore\"" >&2
38
+ include=0
39
+ fi
40
+ done
41
+ if [[ " $include " == 1 ]]; then
42
+ enumerate " $f "
43
+ fi
44
+ done
45
+ fi
46
+ }
47
+
7
48
# List of all files that get packaged
8
- files=(
9
- docs/manual.pdf
10
- src/
11
- CHANGELOG.md
12
- LICENSE
13
- README.md
14
- typst.toml
15
- )
49
+ readarray -t files < <( enumerate " ." )
50
+ # declare -p files >&2
16
51
17
52
# Local package directories per platform
18
53
if [[ " $OSTYPE " == " linux" * ]]; then
60
95
TMP=" $( mktemp -d) "
61
96
62
97
for f in " ${files[@]} " ; do
63
- if [[ -e " $f " ]]; then
64
- mkdir -p " $TMP /$( dirname " $f " ) " 2> /dev/null
65
- cp -r " $ROOT /$f " " $TMP /$f "
66
- fi
98
+ mkdir -p " $TMP /$( dirname " $f " ) " 2> /dev/null
99
+ cp -r " $ROOT /$f " " $TMP /$f "
67
100
done
68
101
69
102
TARGET=" ${TARGET:? } /${PKG_PREFIX:? } /${VERSION:? } "
0 commit comments