|
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 | +. "$(dirname "${BASH_SOURCE[0]}")/setup" |
| 8 | + |
| 9 | +if (( $# < 1 )) || [[ "${1:-}" == "help" ]]; then |
| 10 | + echo "package TARGET" |
| 11 | + echo "" |
| 12 | + echo "Packages all relevant files into a directory named '<name>/<version>'" |
| 13 | + echo "at TARGET. If TARGET is set to @local or @preview, the local Typst package" |
| 14 | + echo "directory will be used so that the package gets installed for local use." |
| 15 | + echo "The name and version are read from 'typst.toml' in the project root." |
| 16 | + echo "" |
| 17 | + echo "Local package prefix: $DATA_DIR/typst/package/local" |
| 18 | + echo "Local preview package prefix: $DATA_DIR/typst/package/preview" |
| 19 | + exit 1 |
| 20 | +fi |
| 21 | + |
| 22 | +TARGET="$(resolve-target "${1:?Missing target path, @local or @preview}")" |
| 23 | +echo "Install dir: $TARGET" |
| 24 | + |
7 | 25 | # ignore rules
|
8 | 26 | readarray -t ignores < <(grep -v '^#' .typstignore | grep '[^[:blank:]]')
|
9 | 27 |
|
@@ -49,49 +67,6 @@ function enumerate {
|
49 | 67 | readarray -t files < <(enumerate ".")
|
50 | 68 | # declare -p files >&2
|
51 | 69 |
|
52 |
| -# Local package directories per platform |
53 |
| -if [[ "$OSTYPE" == "linux"* ]]; then |
54 |
| - DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}" |
55 |
| -elif [[ "$OSTYPE" == "darwin"* ]]; then |
56 |
| - DATA_DIR="$HOME/Library/Application Support" |
57 |
| -else |
58 |
| - DATA_DIR="${APPDATA}" |
59 |
| -fi |
60 |
| - |
61 |
| -if (( $# < 1 )) || [[ "${1:-}" == "help" ]]; then |
62 |
| - echo "package TARGET" |
63 |
| - echo "" |
64 |
| - echo "Packages all relevant files into a directory named '<name>/<version>'" |
65 |
| - echo "at TARGET. If TARGET is set to @local or @preview, the local Typst package" |
66 |
| - echo "directory will be used so that the package gets installed for local use." |
67 |
| - echo "The name and version are read from 'typst.toml' in the project root." |
68 |
| - echo "" |
69 |
| - echo "Local package prefix: $DATA_DIR/typst/package/local" |
70 |
| - echo "Local preview package prefix: $DATA_DIR/typst/package/preview" |
71 |
| - exit 1 |
72 |
| -fi |
73 |
| - |
74 |
| -function read-toml() { |
75 |
| - local file="$1" |
76 |
| - local key="$2" |
77 |
| - # Read a key value pair in the format: <key> = "<value>" |
78 |
| - # stripping surrounding quotes. |
79 |
| - perl -lne "print \"\$1\" if /^${key}\\s*=\\s*\"(.*)\"/" < "$file" |
80 |
| -} |
81 |
| - |
82 |
| -ROOT="$(cd "$(dirname "$0")"; pwd -P)/.." # macOS has no realpath |
83 |
| -TARGET="${1:?Missing target path, @local or @preview}" |
84 |
| -PKG_PREFIX="$(read-toml "$ROOT/typst.toml" "name")" |
85 |
| -VERSION="$(read-toml "$ROOT/typst.toml" "version")" |
86 |
| - |
87 |
| -if [[ "$TARGET" == "@local" ]]; then |
88 |
| - TARGET="${DATA_DIR}/typst/packages/local" |
89 |
| - echo "Install dir: $TARGET" |
90 |
| -elif [[ "$TARGET" == "@preview" ]]; then |
91 |
| - TARGET="${DATA_DIR}/typst/packages/preview" |
92 |
| - echo "Install dir: $TARGET" |
93 |
| -fi |
94 |
| - |
95 | 70 | TMP="$(mktemp -d)"
|
96 | 71 |
|
97 | 72 | for f in "${files[@]}"; do
|
|
0 commit comments