bookcover-node
v0.10.0
Published
Generate print-ready book covers. Part of the [bookcover](https://github.com/gracious-tech/bookcover) generation system.
Readme
bookcover-node
Generate print-ready book covers. Part of the bookcover generation system.
npm install bookcover-nodeThis is a Node.js wrapper for the book cover generator. Writes files to a temp directory, spawns the typst CLI binary, and reads back the compiled output.
Requires typst on $PATH.
See the schema reference which is passed as an argument and is what actually configures the cover design.
import {generate} from 'bookcover-node'generate(options): Promise<GenerateResult>
interface GenerateOptions {
schema: unknown // raw schema (see above)
input_path: string // directory to search for background image
output_path: string // where to write the output file
format?: 'pdf'|'svg'|'png' // default: 'pdf'
ppi?: number // PNG resolution, default: 144
split?: boolean // also write front/back/spine panel files
assets_dir?: string // root of the assets tree (see "Assets" below)
fonts_dir?: string // fonts tree if kept elsewhere, default: <assets_dir>/fonts
typst_path?: string // typst CLI binary, default: 'typst' from $PATH
custom_fonts?: CustomFont[] // user-uploaded font families (from typst-fonts)
}
interface GenerateResult {
output_path: string
split_paths?: {front: string, back: string, spine?: string}
}Assets
The Typst templates are bundled inside bookcover-core itself (tied to the exact installed
version — no setup needed). Generating still requires a local fonts collection, which does not
ship inside the npm packages. Set it up once and pass its path as assets_dir
(or fonts_dir directly):
# Fonts — download the curated families + Noto fallbacks named by the repo's font config
curl -O https://raw.githubusercontent.com/gracious-tech/bookcover/main/font_config.json
npx typst-fonts-download --fonts assets/fonts --config font_config.jsonThat produces the expected layout:
assets/
fonts/ manifest.json, <family>/, _noto/<family>/Inside the bookcover repo itself assets_dir
can be omitted — it defaults to the repo's own assets/ dir.
Example
import {generate} from 'bookcover-node'
await generate({
schema: {
title1: 'My Book',
author: 'Jane Doe',
page_count: 200,
printer: {service: 'kdp', binding_type: 'paperback', ink_type: 'bw', paper_type: 'white'},
size_id: 'us_trade',
},
input_path: '.',
output_path: './cover.pdf',
assets_dir: './assets',
})