doc-builder rewrites the former build-docs.sh workflow into a self-contained Go
CLI. It scans a project for prefixed markdown files, assembles a temporary VitePress
workspace, and produces a ready-to-ship dist directory without requiring any
manual steps.
- Discover markdown files whose names start with a configurable prefix (default
DOC_). - Merge additional markdown content that already lives inside the documentation directory, preserving hand-crafted guides.
- Generate a VitePress sidebar by replacing the
// SIDEBAR_ITEMS - will be replaced by build scriptplaceholder in.vitepress/base.config.js. - Run
npm install(only when needed) inside the temporary workspace and executenpm run docs:buildfor the chosen engine (currently VitePress). - Copy the produced
.vitepress/distoutput back into the documentation workspace. - Provide a
helpersubcommand that explains the complete workflow and expected repository layout.
- Go 1.22 or newer (for building the CLI).
- Node.js toolchain available on the system (
npmmust be onPATH). - A documentation workspace that contains:
.vitepress/base.config.jswith the sidebar placeholder comment.package.jsondefiningnpm run docs:build.
The command stops with a clear error message whenever a required file is missing.
go build -o bin/doc-builder ./cmd/docbuilderRun the unit test suite—covering front-matter parsing, sidebar generation, and filesystem helpers—with:
go test ./...Run the tool from your documentation directory (the directory that contains
.vitepress and package.json). Point --search to the project location you
want to scan for prefixed markdown files.
./bin/doc-builder \
--search ../ \
--doc-dir . \
--prefix DOC_ \
--engine vitepress--search(required): root folder where prefixed markdown files are discovered.--doc-dir(default: current directory): documentation workspace that holds.vitepressandpackage.json.--prefix(default:DOC_): filename prefix used to select markdown sources.--engine(default:vitepress): documentation engine. Onlyvitepressis implemented today; the flag keeps the interface forward compatible.--temp-dir(default:temp): name of the temporary build directory inside the documentation workspace.--verbose: prints detailed progress information.
To see a high-level overview of the pipeline, run:
./bin/doc-builder helperGenerate a sample markdown file (default DOC_this_is_example.md) to use as a
starting point:
./bin/doc-builder example-doc --doc-dir .Use --prefix if your project relies on a different filename prefix.
- The CLI deletes and recreates
./temp(or the configured temporary directory). - Markdown files that match the prefix are copied into the temp workspace with slugs derived from their filenames and categories read from YAML front matter.
- Existing markdown content inside the documentation workspace is merged so that curated guides remain available.
- The sidebar is regenerated based on the collected metadata and written both to
temp/.vitepress/config.jsand.vitepress/config.js. - Node dependencies are installed into the temp directory (unless
node_modulesalready exists there) andnpm run docs:buildis executed. - The freshly generated
temp/.vitepress/distdirectory replaces.vitepress/distin the documentation workspace.
If any of the steps fail (for example when package.json or the base config
cannot be found), the command stops immediately and reports the offending path in
English.
The original build-docs.sh script is no longer required. The new CLI provides the
same behaviour, adds structured error handling, and keeps the door open for
additional engines beyond VitePress.
This project is released under the Apache 2.0 License.