[docs-utils] 2️⃣ Refactor build_api_docs_cli into modular tasks#247713
Merged
clintandrewhall merged 8 commits intoelastic:mainfrom Jan 15, 2026
Merged
[docs-utils] 2️⃣ Refactor build_api_docs_cli into modular tasks#247713clintandrewhall merged 8 commits intoelastic:mainfrom
clintandrewhall merged 8 commits intoelastic:mainfrom
Conversation
Decompose the monolithic build_api_docs_cli.ts into a modular, task-based architecture for improved testability and maintainability. Changes: - Extract CLI flag parsing into parse_cli_flags.ts with validation logic - Create discrete task modules in cli/tasks/: - setup_project - Plugin discovery, path resolution, TypeScript project setup - build_api_map - TypeScript analysis and API extraction - collect_stats - Plugin statistics gathering (ESLint disable counts, Enzyme imports, API stats) - report_metrics - CI stats reporting and validation result logging - write_docs - Documentation file generation and nav cleanup - Add shared type definitions in cli/types.ts (CliFlags, CliOptions, CliContext, task result interfaces) - Simplify main CLI runner to orchestrate tasks sequentially Testing: - Add unit tests for each task module - Add unit tests for CLI flag parsing and validation The main CLI file is reduced from ~450 lines to ~115 lines, with all business logic now isolated in testable, single-responsibility modules.
Contributor
|
Pinging @elastic/kibana-operations (Team:Operations) |
Contributor
|
Pinging @elastic/appex-sharedux (Team:SharedUX) |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the monolithic build_api_docs_cli.ts file into a modular, task-based architecture to improve testability and maintainability. The main CLI file is reduced from ~450 lines to ~115 lines by extracting business logic into discrete, testable modules.
Key changes:
- Extracted CLI flag parsing with validation into a dedicated module
- Created five distinct task modules with single responsibilities (setup, build, collect, report, write)
- Added comprehensive unit tests for all new modules
- Introduced shared type definitions for better type safety across the codebase
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
packages/kbn-docs-utils/src/cli/types.ts |
Defines shared TypeScript interfaces for CLI flags, options, context, and task results |
packages/kbn-docs-utils/src/cli/parse_cli_flags.ts |
Extracts and validates CLI flag parsing logic with proper error handling |
packages/kbn-docs-utils/src/cli/parse_cli_flags.test.ts |
Provides comprehensive test coverage for flag parsing validation |
packages/kbn-docs-utils/src/cli/tasks/setup_project.ts |
Isolates plugin discovery, path resolution, and TypeScript project setup |
packages/kbn-docs-utils/src/cli/tasks/setup_project.test.ts |
Tests setup task including plugin discovery and folder management |
packages/kbn-docs-utils/src/cli/tasks/build_api_map.ts |
Encapsulates TypeScript analysis and API extraction logic |
packages/kbn-docs-utils/src/cli/tasks/build_api_map.test.ts |
Tests API map building functionality |
packages/kbn-docs-utils/src/cli/tasks/collect_stats.ts |
Consolidates plugin statistics gathering (ESLint, Enzyme, API stats) |
packages/kbn-docs-utils/src/cli/tasks/collect_stats.test.ts |
Tests statistics collection for plugins |
packages/kbn-docs-utils/src/cli/tasks/report_metrics.ts |
Handles CI stats reporting and validation logging |
packages/kbn-docs-utils/src/cli/tasks/report_metrics.test.ts |
Tests metrics reporting functionality |
packages/kbn-docs-utils/src/cli/tasks/write_docs.ts |
Manages documentation file generation and nav cleanup |
packages/kbn-docs-utils/src/cli/tasks/write_docs.test.ts |
Tests documentation writing with proper mocking |
packages/kbn-docs-utils/src/cli/tasks/index.ts |
Provides clean exports for all task modules |
packages/kbn-docs-utils/src/cli/index.ts |
Exports CLI-related functions and types |
packages/kbn-docs-utils/src/build_api_docs_cli.ts |
Simplified main CLI runner orchestrating tasks sequentially |
Contributor
💛 Build succeeded, but was flaky
Failed CI Steps
Metrics [docs]Unknown metric groupsUnreferenced deprecated APIs
History
|
tylersmalley
approved these changes
Jan 15, 2026
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Decompose the monolithic
build_api_docs_cli.tsinto a modular, task-based architecture for improved testability and maintainability.Note
This PR is a subset of #247688 for ease of review.
This PR was written with Cursor and
claude-4.5-opus-high.Changes
parse_cli_flags.tswith validation logicsetup_project- Plugin discovery, path resolution, TypeScript project setupbuild_api_map- TypeScript analysis and API extractioncollect_stats- Plugin statistics gathering (ESLint disable counts, Enzyme imports, API stats)report_metrics- CI stats reporting and validation result loggingwrite_docs- Documentation file generation and nav cleanupcli/types.ts(CliFlags,CliOptions,CliContext, task result interfaces)Testing
The main CLI file is reduced from ~450 lines to ~115 lines, with all business logic now isolated in testable, single-responsibility modules.