CLI
Overview of the zpress CLI -- commands, the dev server, file watching, and the build pipeline.
Overview
zpress uses yargs for command routing and @clack/prompts for styled terminal output. The CLI entry point is in packages/cli/src/, which registers all commands. Each command is a standalone module that orchestrates the core sync engine and Rspress build APIs.
Commands
zpress has eight commands:
sync
Runs the sync engine once. Loads the config, resolves all entries, writes content to .zpress/content/, generates sidebar/nav JSON, and reports write/skip/remove counts.
This is the core operation that all other commands build on.
dev
The primary development workflow. Combines three operations:
- Initial sync -- Full sync to populate
.zpress/content/ - File watcher -- Monitors source directories for changes
- Rspress dev server -- Starts on
http://localhost:6174with hot module replacement
The --clean flag removes cache, content, and dist before starting.
File Watching
The watcher (packages/cli/src/watcher.ts) monitors:
- Glob entries -- Parent directories of glob patterns (chokidar handles recursion)
- Single-file entries -- Individual source files
- Config file --
zpress.config.ts(triggers config reload on next sync) - Planning directory -- Optional
.planning/directory
Watch behavior:
- Markdown file changes (add, change, remove) trigger a debounced re-sync (150ms)
- Config file changes reload the config object for the next sync cycle
- Duplicate watch paths are deduplicated (child paths under a watched parent are skipped)
- Concurrent syncs are prevented -- if a sync is running, the next change queues a pending resync
build
Produces a static site:
- Optional clean step
- Full sync
- Rspress build (generates optimized HTML/CSS/JS in
.zpress/dist/)
serve
Starts a static file server pointing at .zpress/dist/ on http://localhost:6174. The browser opens automatically; use --no-open to disable.
clean
Removes .zpress/cache/, content/, and dist/. Safe to run at any time -- all content is regenerated by sync/build.
setup
Creates a starter zpress.config.ts in the current directory if one does not already exist.
dump
Resolves the full entry tree from the config and prints it as JSON. Useful for debugging config resolution and glob patterns.
generate
Generates branded banner and logo SVG assets from the project title. Reads title and optional tagline from zpress.config.ts, generates SVGs, and writes them to .zpress/public/. Skips generation when no title is configured. Does not overwrite files that have been manually customized.
Rspress Integration
The CLI communicates with Rspress through packages/cli/src/rspress.ts:
All functions receive a Rspress config object built by createRspressConfig() from @zpress/ui. This config loads the generated JSON files (sidebar, nav, workspaces) from .zpress/content/.generated/ and wires up the zpress theme.
Command Lifecycle
zpress dev (detailed)
zpress build (detailed)
Error Handling
CLI errors are handled at the command boundary:
- Config errors --
defineConfig()exits with a descriptive message viaprocess.exit(1) - Sync errors -- Result tuples propagate up; the CLI reports them via
@clack/prompts - Rspress errors -- Build/dev failures are caught and reported
No command calls process.exit directly except through the config validation boundary. All user-facing error formatting is centralized in the CLI layer.