From fe4f791f9f7965f4b46b4ed1199c40faadba2967 Mon Sep 17 00:00:00 2001 From: Clemens Koza Date: Wed, 5 Jun 2024 22:00:10 +0200 Subject: [PATCH] add .typstignore and adapt package script to use it --- .typstignore | 16 ++++++++++++++ scripts/package | 57 ++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 61 insertions(+), 12 deletions(-) create mode 100644 .typstignore diff --git a/.typstignore b/.typstignore new file mode 100644 index 0000000..ba2d170 --- /dev/null +++ b/.typstignore @@ -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 diff --git a/scripts/package b/scripts/package index 61cd9e3..0bf9f17 100755 --- a/scripts/package +++ b/scripts/package @@ -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 @@ -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:?}"