Skip to content

Commit

Permalink
🔨 Added a just install script
Browse files Browse the repository at this point in the history
  • Loading branch information
BattleCh1cken committed Jan 7, 2024
1 parent 82edf8c commit d300292
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 20 deletions.
35 changes: 15 additions & 20 deletions docs.typ
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,30 @@
The best way to install the Notebookinator is as a local package. Make sure you
have the following software installed on your computer:

- Typst
- Git
- VSCode
- #link("https://github.com/casey/just#installation")[Typst]
- #link("https://github.com/casey/just#installation")[Git]
- #link("https://code.visualstudio.com/")[VSCode]
- #link("https://github.com/casey/just#installation")[just]

Once you have those, find the matching command for you operating system, and
then run it:
Once you've installed everything, simply run the following commands:

*Linux:*
```bash
git clone https://github.com/BattleCh1cken/notebookinator \
~/.local/share/typst/packages/local/
```

*MacOS:*
```zsh
git clone https://github.com/BattleCh1cken/notebookinator \
~/Library/Application Support/typst/packages/local/
```

*Windows:*
// FIXME: find the correct syntax highlighting for powershell
```pwsh
git clone https://github.com/BattleCh1cken/notebookinator %APPDATA%\typst\packages\local\
git clone https://github.com/BattleCh1cken/notebookinator
cd notebookinator
just install
```

= Basic Usage

Once the template is installed, you can import it into your project like this:

#raw(
block: true,
lang: "typ",
"#import \"@local/notebookinator:"+ version + "\": *"
)


```typ
#import "@local/notebookinator": *
```
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
typstfmt.packages.${system}.default
pkgs.act
pkgs.nodePackages_latest.prettier
pkgs.just
];
};

Expand Down
8 changes: 8 additions & 0 deletions justfile
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.
77 changes: 77 additions & 0 deletions scripts/package
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"

0 comments on commit d300292

Please sign in to comment.