ApiDoc provides a comprehensive command-line interface for generating API documentation from source files. The CLI offers extensive configuration options and can be used for both one-time generation and continuous development workflows.
# Generate documentation from source to output directory
apidoc -i src/ -o doc/
# Generate with verbose output
apidoc -i src/ -o doc/ --verbose
# Generate with custom template
apidoc -i src/ -o doc/ -t ./my-template/
# Generate single HTML file
apidoc -i src/ -o doc/api.html --single-i, --input <input...> Input/source dirname (default: ["./src"])
-o, --output <output> Output dirname (default: "doc/")
-c, --config <config> Path to config file (json or javascript)
-t, --template <template> Use template for output files-f, --file-filters <file-filters...> RegEx-Filter to select files that should be parsed
-e, --exclude-filters <exclude-filters...> RegEx-Filter to select files/dirs that should not be parsed
--filter-by <tag-filter=value> Filter documentation by tagDefault include filters:
.*\.(clj|cls|coffee|cpp|cs|dart|erl|exs?|go|groovy|ino?|java|js|jsx|kt|litcoffee|lua|p|php?|pl|pm|py|rb|scala|ts|tsx|vue)$Default exclude filters:
apidoc.config.jsnode_modules-n, --dry-run Parse source files but do not write any output files
-S, --single Output to single file
--write-json Will create api-data.json file with parsed API info
-p, --private Include private APIs in output-v, --verbose Verbose output
-q, --quiet Turn all output off
-d, --debug Show debug messages
--no-color Turn off log color
--log-format <format> Change log format (allowed: simple, json)
--warn-error Treat warnings as error and exit with error code--encoding <encoding> Set the encoding of the source code (default: "utf8")
--line-ending <line-ending> Turn off autodetect line-ending (allowed: LF, CR, CRLF)
--markdown [markdown] Turn off default markdown parser or set a file to a custom parser
--definitions Include definitions file rather than copying definitions--parse-filters <parse-filters...> Optional user defined filters (format: name=filename)
--parse-languages <parse-languages...> Optional user defined languages (format: name=filename)
--parse-parsers <parse-parsers...> Optional user defined parsers (format: name=filename)
--parse-workers <parse-workers...> Optional user defined workers (format: name=filename)-w, --watch Watch input files for changes to rebuild the docsApiDoc supports multiple configuration sources:
{
"name": "My API",
"version": "1.0.0",
"description": "My API Documentation",
"title": "Custom API Title",
"url": "https://api.example.com",
"sampleUrl": "https://api.example.com",
"input": ["./src"],
"output": "./docs",
"template": {
"showRequiredLabels": true,
"withCompare": true,
"withGenerator": true
},
"header": {
"title": "Custom Header",
"filename": "header.md"
},
"footer": {
"title": "Custom Footer",
"filename": "footer.md"
},
"order": ["User", "Authentication", "Posts"]
}module.exports = {
name: 'My API',
version: '1.0.0',
description: 'My API Documentation',
input: ['./src'],
output: './docs',
template: {
showRequiredLabels: true,
withCompare: true
}
};{
"name": "my-project",
"version": "1.0.0",
"apidoc": {
"name": "My API",
"version": "1.0.0",
"description": "My API Documentation"
}
}Watch mode automatically rebuilds documentation when source files change:
apidoc -i src/ -o doc/ --watchThis starts a file watcher that:
# Generate docs for JavaScript project
apidoc -i lib/ -o docs/
# Generate docs with custom config
apidoc -c apidoc.json
# Generate docs with verbose logging
apidoc -i src/ -o docs/ --verbose --debug# Only process TypeScript files
apidoc -i src/ -o docs/ -f ".*\.ts$"
# Exclude test files and node_modules
apidoc -i src/ -o docs/ -e "test" -e "spec" -e "node_modules"
# Filter by API group
apidoc -i src/ -o docs/ --filter-by "group=User"# Use custom template
apidoc -i src/ -o docs/ --template ./my-template/
# Generate single HTML file
apidoc -i src/ -o docs/api.html --single
# Include private APIs
apidoc -i src/ -o docs/ --private# Generate docs and JSON data file
apidoc -i src/ -o docs/ --write-json
# Dry run to validate source files
apidoc -i src/ -o docs/ --dry-run
# Treat warnings as errors for CI
apidoc -i src/ -o docs/ --warn-errorThe CLI exits with different codes based on the result:
Common error scenarios:
# Error: Cannot access input directory
apidoc -i nonexistent/ -o docs/# Error: Invalid config file
apidoc -c invalid-config.json# Error: Template directory not found
apidoc -i src/ -o docs/ --template ./nonexistent-template/The CLI supports custom plugins through command-line options:
# Custom language parser
apidoc -i src/ -o docs/ --parse-languages "myext=./my-language-parser.js"
# Custom API parser
apidoc -i src/ -o docs/ --parse-parsers "myapi=./my-api-parser.js"
# Custom filter
apidoc -i src/ -o docs/ --parse-filters "myfilter=./my-filter.js"
# Custom worker
apidoc -i src/ -o docs/ --parse-workers "myworker=./my-worker.js"Some CLI behavior can be controlled via environment variables:
# Disable colors in output
NO_COLOR=1 apidoc -i src/ -o docs/
# Set default encoding
APIDOC_ENCODING=utf16 apidoc -i src/ -o docs/Common patterns for package.json scripts:
{
"scripts": {
"docs": "apidoc -i lib/ -o docs/",
"docs:watch": "apidoc -i lib/ -o docs/ --watch",
"docs:single": "apidoc -i lib/ -o docs/api.html --single",
"docs:build": "apidoc -i lib/ -o docs/ --write-json",
"docs:validate": "apidoc -i lib/ -o docs/ --dry-run --warn-error"
}
}