-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82edf8c
commit d300292
Showing
5 changed files
with
101 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
typstfmt.packages.${system}.default | ||
pkgs.act | ||
pkgs.nodePackages_latest.prettier | ||
pkgs.just | ||
]; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package target: | ||
./scripts/package "{{target}}" | ||
|
||
install: | ||
./scripts/package "@local" | ||
|
||
docs: | ||
typst compile docs.typ docs.pdf |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/usr/bin/env bash | ||
set -eu | ||
|
||
# Credit to the Cetz package for this script | ||
# https://github.com/johannes-wolf/cetz/blob/master/scripts/package | ||
|
||
PKG_PREFIX="notebookinator" | ||
|
||
# List of all files that get packaged | ||
files=( | ||
lib.typ | ||
entries.typ | ||
glossary.typ | ||
utils.typ | ||
globals.typ | ||
internals.typ | ||
themes/ | ||
typst.toml | ||
LICENSE | ||
README.md | ||
docs.typ | ||
docs-template.typ | ||
docs.pdf | ||
) | ||
|
||
# Local package directories per platform | ||
if [[ "$OSTYPE" == "linux"* ]]; then | ||
DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}" | ||
elif [[ "$OSTYPE" == "darwin"* ]]; then | ||
DATA_DIR="$HOME/Library/Application Support" | ||
else | ||
DATA_DIR="${APPDATA}" | ||
fi | ||
|
||
if (( $# < 1 )) || [[ "${1:-}" == "help" ]]; then | ||
echo "package TARGET" | ||
echo "" | ||
echo "Packages all relevant files into a directory named '${PKG_PREFIX}/<version>'" | ||
echo "at TARGET. If TARGET is set to @local, the local Typst package directory" | ||
echo "will be used so that the package gets installed for local use." | ||
echo "The version is read from 'typst.toml' in the project root." | ||
echo "" | ||
echo "Local package prefix: $DATA_DIR/typst/package/local" | ||
exit 1 | ||
fi | ||
|
||
function read-toml() { | ||
local file="$1" | ||
local key="$2" | ||
# Read a key value pair in the format: <key> = "<value>" | ||
# stripping surrounding quotes. | ||
perl -lne "print \"\$1\" if /^${key}\\s*=\\s*\"(.*)\"/" < "$file" | ||
} | ||
|
||
SOURCE="$(cd "$(dirname "$0")"; pwd -P)/.." # macOS has no realpath | ||
TARGET="${1:?Missing target path or @local}" | ||
VERSION="$(read-toml "$SOURCE/typst.toml" "version")" | ||
|
||
if [[ "$TARGET" == "@local" ]] || [[ "$TARGET" == "install" ]]; then | ||
TARGET="${DATA_DIR}/typst/packages/local/" | ||
echo "Install dir: $TARGET" | ||
fi | ||
|
||
TMP="$(mktemp -d)" | ||
|
||
for f in "${files[@]}"; do | ||
mkdir -p "$TMP/$(dirname "$f")" 2>/dev/null | ||
cp -r "$SOURCE/$f" "$TMP/$f" | ||
done | ||
|
||
TARGET="${TARGET:?}/${PKG_PREFIX:?}/${VERSION:?}" | ||
echo "Packaged to: $TARGET" | ||
if rm -rf "${TARGET:?}" 2>/dev/null; then | ||
echo "Overwriting existing version." | ||
fi | ||
mkdir -p "$TARGET" | ||
mv "$TMP"/* "$TARGET" |