typst-community / typst-package-template

The Unlicense
3 stars 2 forks source link

Add commands for packaging and local install/uninstall #8

Closed SillyFreak closed 3 weeks ago

SillyFreak commented 3 weeks ago

This PR adds two scripts adapted from CeTZ (Apache 2.0): https://github.com/johannes-wolf/cetz/blob/35c0868378cea5ad323cc0d9c2f76de8ed9ba5bd/scripts/package

# copies a selected set of files into the `out` directory
just package out

# locally installs under the name `@local/package`
just install
just uninstall

# locally installs under the name `@preview/package` (i.e. lets you test code that contains imports of the published package)
just install-preview
just uninstall-preview

The files that are included in packaging are those that are either necessary for the package, or are likely to be linked in the README, meaning links to them on Universe should work:

JamesxX commented 3 weeks ago

I think storing the list of directories and files in the script itself may unnecessarily complicate the process of adding more should the package author need to.

Would it be possible to set those in a dot file with a format like .gitignore?

SillyFreak commented 3 weeks ago

I was a bit hasty with submitting; now there's a bit more context in the original PR message.

The two factors that influenced my reasoning:

a dot file would probably be better, but I don't really look forward to implementing the filtering in bash...

JamesxX commented 3 weeks ago

I'll give it a go tomorrow when I have a moment, but yeah the reasoning behind my request was relating to some packages possibly needing to also ship a gallery folder (or whatever)

Edit: perhaps something like this? https://stackoverflow.com/a/73082137

SillyFreak commented 3 weeks ago

I'll try it out!

SillyFreak commented 3 weeks ago

some preliminary playing around indicates that that script doesn't work as intended; using -name for matching only uses the basename (last name in the path), so ignoring something like docs/*.typ wouldn't work. replacing with -path also doesn't just work because ignoring .github doesn't ignore the files in there. Also, -path can match foo/bar with f*, i.e. * also matches / which is not intuitive.

I'll try some more.

SillyFreak commented 3 weeks ago

ok, I managed to do something. I called the ignore file .typstignore, not sure if that's a good name. The file contains a short description what is supported. I tested the script superficially; the negated patterns seem to work and file names/patterns with spaces don't seem to make problems. Even file names with asterisks, and patterns with escaped asterisks seem to work!

A second pair of eyes that properly looks at the code would definitely be a good idea, though.

JamesxX commented 3 weeks ago

<3