Skip to content

Latest commit

 

History

History

typescript

Folders and files

README.md

TypeScript example

acme is a small Bun app built with Prelude's TypeScript API (ts/). It has a command menu, a welcome banner (MOTD), and a docs page. Each command is declared next to the code it runs.

File Shows
server.ts a module that exports its API and a command wrapping it
db.ts a TypeScript command with a flag, and a shell command
main.ts the app: commands mounted under names, MOTD, docs
package.json scripts the app's menu imports as commands
guide.md the docs page, bundled into the app as text
standalone.ts the entry point for a single-file executable

Run it

Inside nix develop, which sets PRELUDE_LIB to the Go library:

./examples/typescript/main.ts                      # pick a command
./examples/typescript/main.ts dev --port 8080      # run one directly
./examples/typescript/main.ts db migrate --dry-run
./examples/typescript/main.ts motd                 # built in: the banner
./examples/typescript/main.ts docs                 # built in: the docs viewer
./examples/typescript/main.ts --list

The / in db/migrate makes migrate a subcommand of db: you type db migrate, and the menu shows one db row that opens migrate and seed. The build and clean scripts in package.json show up under scripts. Each runs exactly as written, from this folder, wherever you start the app.

One executable

./examples/typescript/main.ts build     # the package.json script
./examples/typescript/acme

The build script copies the Go library next to standalone.ts and compiles the app with bun build --compile.

acme carries Bun, the app, the docs page, and the Go library, so it runs where none of them are installed. nix run .#example-typescript -- --list builds and runs it the same way.

In your own project

Install the package with bun add @drkmttr/prelude and import it the same way. This example's tsconfig.json resolves @drkmttr/prelude to ../../ts instead, so it runs from a checkout without installing anything; see ts/README.md.