Skip to content

Commit fe4f791

Browse files
committed
add .typstignore and adapt package script to use it
1 parent c70c957 commit fe4f791

File tree

2 files changed

+61
-12
lines changed

2 files changed

+61
-12
lines changed

.typstignore

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# this is not a "standard" ignore file, it's specific to this template's `scripts/package` script
2+
# list any files here that should not be uploaded to Universe when releasing this package
3+
4+
# if you are used to ignore files, be aware that .typstignore is a bit more limited:
5+
# - only this file is used; .typstignore files in subdirectories are not considered
6+
# - patterns must match file/directory names from the beginning: `x.typ` will not match `src/x.typ`
7+
# - `*` in patterns works, but also matches directory separators: `*.typ` _will_ match `src/x.typ`
8+
# .git and .typstignore are excluded automatically
9+
10+
.github
11+
scripts
12+
tests
13+
Justfile
14+
# PDF manuals should be included so that they can be linked, but not their sources
15+
docs/*
16+
!docs/*.pdf

scripts/package

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,50 @@ set -eu
44
# adapted from https://github.com/johannes-wolf/cetz/blob/35c0868378cea5ad323cc0d9c2f76de8ed9ba5bd/scripts/package
55
# licensed under Apache License 2.0
66

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+
748
# 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
1651

1752
# Local package directories per platform
1853
if [[ "$OSTYPE" == "linux"* ]]; then
@@ -60,10 +95,8 @@ fi
6095
TMP="$(mktemp -d)"
6196

6297
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"
67100
done
68101

69102
TARGET="${TARGET:?}/${PKG_PREFIX:?}/${VERSION:?}"

0 commit comments

Comments
 (0)