feat: add generateOnly filtering on final paths and new test template
Description
Add generateOnly filtering on final output paths for all template writes/copies, with negated globs supported and copy paths filtered.
- Added centralized filtering helpers (writeFileWithFiltering/copyFileWithFiltering) applying generateOnly (with negation) and noOverwriteGlobs on final output paths for all template writes and copies.
- React rendering now filters after metadata.fileName renames via the shared helper; Nunjucks writes use the helper, copy path is filtered.
Known
Hooks/conditional dirs remain ungated by generateOnly (extra files like asyncapi.yaml still appear) needs to be worked
Test are failing and needs to be fixed
Summary by CodeRabbit
Release Notes
- New Features
- Added
--generate-onlyCLI option (short form-g) to selectively generate files matching glob patterns - Supports negation patterns (prefixed with
!) for excluding specific files - Integrates with existing file protection options for combined filtering control
- Displays warning when specified patterns match no files
- Added
✏️ Tip: You can customize this high-level summary in your review settings.
⚠️ No Changeset found
Latest commit: e4d9a09643afba2df4faef863d1faf93599594dd
Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.
This PR includes no changesets
When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types
Click here to learn what changesets are, and how to add one.
Click here if you're a maintainer who wants to add a changeset to this PR
Walkthrough
This PR introduces a --generate-only CLI option that accepts glob patterns to limit code generation to specific files. It adds filtering utilities, updates the generator constructor to accept and process generateOnly patterns, modifies file writing operations to respect the filter, and includes logging messages and test coverage for the new feature.
Changes
| Cohort / File(s) | Summary |
|---|---|
CLI Interface apps/generator/cli.js |
Added --generate-only (alias -g) CLI option that accepts glob patterns; creates accumulator and parser to collect patterns into an array passed to Generator configuration. |
Core Generator Logic apps/generator/lib/generator.js |
Updated constructor to accept generateOnly parameter; added generatedFilesCount property to track file generation; replaced direct file writes with filtered equivalents; added warnIfNoGenerateOnlyMatches() method to alert when no files match patterns. |
Logging Messages apps/generator/lib/logMessages.js |
Added two new log message helpers: skipGenerateOnly(filePath) for skipped files and generateOnlyNoMatches(patterns) for unmatched patterns. |
File Filtering Utilities apps/generator/lib/utils.js |
Added minimatch dependency; introduced isAllowedByGenerateOnly() helper supporting negation patterns; added shouldSkipOverwrite() helper; created writeFileWithFiltering() and copyFileWithFiltering() public functions that gate operations by generateOnly whitelist then noOverwriteGlobs blacklist. |
React Renderer apps/generator/lib/renderer/react.js |
Updated saveRenderedReactContent() and saveContentToFile() signatures to accept generateOnly and targetDir parameters; replaced direct file writes with writeFileWithFiltering() calls; changed return value to numeric count of written files. |
Unit & Integration Tests apps/generator/test/generator.test.js, apps/generator/test/integration.test.js, apps/generator/test/renderer.test.js, apps/generator/test/utils.test.js |
Added tests for generateOnly property and warnIfNoGenerateOnlyMatches() method; added integration tests for exact file matching, glob patterns, and combined generateOnly/noOverwriteGlobs scenarios; updated renderer tests to mock writeFileWithFiltering; added comprehensive filtering utility tests. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
- Filtering logic in
apps/generator/lib/utils.js: Verify negation pattern handling (patterns prefixed with!), minimatch integration, and correct precedence (generateOnly applied before noOverwriteGlobs). - Integration across layers: Confirm parameter propagation from CLI → Generator → utilities → renderer and that relative path calculations are consistent.
- File writing flow changes: Review all
writeFileWithFiltering()andcopyFileWithFiltering()call sites to ensure proper targetDir context and option passing. - Test coverage completeness: Validate that new integration tests cover edge cases like empty generateOnly arrays, conflicting patterns, and interaction with existing noOverwriteGlobs.
Possibly related PRs
- asyncapi/generator#1515: Modifies the same generator.js file and generation lifecycle (generateFile handling) to add conditional generation rules, which could overlap with or be affected by the new generateOnly feature at the code level.
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 42.86% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Title check | ✅ Passed | The title clearly and specifically describes the main change: adding generateOnly filtering on final paths with support for a new test template feature. |
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
✨ Finishing touches
- [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
- [ ] Create PR with unit tests
- [ ] Post copyable unit tests in a comment
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
What reviewer looks at during PR review
The following are ideal points maintainers look for during review. Reviewing these points yourself beforehand can help streamline the review process and reduce time to merge.
-
PR Title: Use a concise title that follows our Conventional Commits guidelines and clearly summarizes the change using imperative mood (it means
spoken or written as if giving a command or instruction, like "add new helper for listing operations")Note - In Generator, prepend
feat:orfix:in PR title only when PATCH/MINOR release must be triggered. -
PR Description: Clearly explain the issue being solved, summarize the changes made, and mention the related issue.
Note - In Generator, we use Maintainers Work board to track progress. Ensure the PR Description includes
Resolves #<issue-number>orFixes #<issue-number>this will automatically close the linked issue when the PR is merged and helps automate the maintainers workflow. -
Documentation: Update the relevant Generator documentation to accurately reflect the changes introduced in the PR, ensuring users and contributors have up-to-date guidance.
-
Comments and JSDoc: Write clear and consistent JSDoc comments for functions, including parameter types, return values, and error conditions, so others can easily understand and use the code.
-
DRY Code: Ensure the code follows the Don't Repeat Yourself principle. Look out for duplicate logic that can be reused.
-
Test Coverage: Ensure the new code is well-tested with meaningful test cases that pass consistently and cover all relevant edge cases.
-
Commit History: Contributors should avoid force-pushing as much as possible. It makes it harder to track incremental changes and review the latest updates.
-
Template Design Principles Alignment: While reviewing template-related changes in the
packages/directory, ensure they align with the Assumptions and Principles. If any principle feels outdated or no longer applicable, start a discussion these principles are meant to evolve with the project. -
Reduce Scope When Needed: If an issue or PR feels too large or complex, consider splitting it and creating follow-up issues. Smaller, focused PRs are easier to review and merge.
-
Bot Comments: As reviewers, check that contributors have appropriately addressed comments or suggestions made by automated bots. If there are bot comments the reviewer disagrees with, react to them or mark them as resolved, so the review history remains clear and accurate.
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code