Skip to content

Commit

Permalink
add .typstignore and adapt package script to use it
Browse files Browse the repository at this point in the history
  • Loading branch information
SillyFreak committed Jun 5, 2024
1 parent c70c957 commit fe4f791
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 12 deletions.
16 changes: 16 additions & 0 deletions .typstignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# this is not a "standard" ignore file, it's specific to this template's `scripts/package` script
# list any files here that should not be uploaded to Universe when releasing this package

# if you are used to ignore files, be aware that .typstignore is a bit more limited:
# - only this file is used; .typstignore files in subdirectories are not considered
# - patterns must match file/directory names from the beginning: `x.typ` will not match `src/x.typ`
# - `*` in patterns works, but also matches directory separators: `*.typ` _will_ match `src/x.typ`
# .git and .typstignore are excluded automatically

.github
scripts
tests
Justfile
# PDF manuals should be included so that they can be linked, but not their sources
docs/*
!docs/*.pdf
57 changes: 45 additions & 12 deletions scripts/package
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,50 @@ set -eu
# adapted from https://github.com/johannes-wolf/cetz/blob/35c0868378cea5ad323cc0d9c2f76de8ed9ba5bd/scripts/package
# licensed under Apache License 2.0

# ignore rules
readarray -t ignores < <(grep -v '^#' .typstignore | grep '[^[:blank:]]')

# recursively print all files that are not excluded via .typstignore
function enumerate {
local root="$1"
if [[ -f "$root" ]]; then
echo "$root"
else
local files
readarray -t files < <(find "$root" \
-mindepth 1 -maxdepth 1 \
-not -name .git \
-not -name .typstignore)
# declare -p files >&2

local f
for f in "${files[@]}"; do
local include
include=1

local ignore
for ignore in "${ignores[@]}"; do
if [[ "$ignore" =~ ^! ]]; then
ignore="${ignore:1}"
if [[ "$f" == ./$ignore ]]; then
# echo "\"$f\" matched \"!$ignore\"" >&2
include=1
fi
elif [[ "$f" == ./$ignore ]]; then
# echo "\"$f\" matched \"$ignore\"" >&2
include=0
fi
done
if [[ "$include" == 1 ]]; then
enumerate "$f"
fi
done
fi
}

# List of all files that get packaged
files=(
docs/manual.pdf
src/
CHANGELOG.md
LICENSE
README.md
typst.toml
)
readarray -t files < <(enumerate ".")
# declare -p files >&2

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

for f in "${files[@]}"; do
if [[ -e "$f" ]]; then
mkdir -p "$TMP/$(dirname "$f")" 2>/dev/null
cp -r "$ROOT/$f" "$TMP/$f"
fi
mkdir -p "$TMP/$(dirname "$f")" 2>/dev/null
cp -r "$ROOT/$f" "$TMP/$f"
done

TARGET="${TARGET:?}/${PKG_PREFIX:?}/${VERSION:?}"
Expand Down

0 comments on commit fe4f791

Please sign in to comment.