snipbuild
v0.3.1
Published
HyperSnips snippets bundler
Readme
snipbuild - HyperSnips snippets bundler
snipbuild is a build tool that provides an easier way to develop HyperSnips snippets.
- You can develop Global block JavaScript using TypeScript.
- Each
src/globals/[LANGUAGE].tsexports what will be included in the global block of the corresponding snippet file (Note: only named exports are allowed, i.e., do not useexport default). - Because snipbuild uses a bundler (Rolldown) under the hood, you can split your source code in several files.
- You can use your favorite tools for normal JS/TS development, for example, Vitest for unit-testing. It makes maintainance far easier.
- Each
- The snippet blocks for each language is located at
src/snippets/[LANGUAGE].hsnips. It is in the exact same format as normal.hsnipsfiles except:- It does not have the
global ... endglobalblock at the top. - It allows you to include common snippets shared by several (but not necessarily all) languages using
#include "...".
- It does not have the
- When running
npx snipbuild, Rolldown generates the global JavaScript fromsrc/globals/[LANGUAGE.ts], and the output is concatenated with the snippet blocks fromsrc/snippets/[LANGUAGE].hsnips.
How to use
Install Node.js
Run
npx snipbuildto generate snippet files under thedist/directory.- Alternatively, you can install
snipbuildas a dependency (e.g.npm install -D snipbuildorpnpm add -D snipbuild), add"build": "snipbuild"script topackage.json, and then runpnpm build.
- Alternatively, you can install
Install the generated snippet files. For example, you can use the following script on macOS (assuming you've installed both VSCode and Cursor):
#!/usr/bin/env bash set -euo pipefail for app in Code Cursor; do dir="$HOME/Library/Application Support/$app/User/globalStorage/draivin.hsnips" mkdir -p "$dir" ln -sf $(realpath dist) "$dir/hsnips" doneMake sure you execute the
HyperSnips: Reload Snippetscommand after updating the snippet files.
Once you install the snippets using symbolic links (as shown above), all you have to do after making edit to the source code is npx snipbuild & HyperSnips: Reload Snippets.
Examples
You can refer to https://github.com/RyotaUshio/hsnips-dev for example usages.
