-
Notifications
You must be signed in to change notification settings - Fork 340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: parse template name error #880
Conversation
WalkthroughThe changes in this pull request involve modifications to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (2)
packages/vue-generator/src/plugins/genTemplatePlugin.js (1)
Line range hint
1-34
: Consider documenting template resolution precedence.The plugin has multiple ways to resolve templates:
- Function from options.template
- String from options.template
- Default template
Consider adding JSDoc comments to document this precedence for better maintainability.
Example documentation:
+/** + * Generates template code based on the following precedence: + * 1. If options.template is a function, executes it with (schema, context) + * 2. If options.template is a string, looks up in templateMap + * 3. Falls back to 'default' template if none specified + * @param {Object} options Plugin options + * @param {string|Function} [options.template='default'] Template name or generator function + * @returns {Object} Plugin configuration + */ function genTemplatePlugin(options = {}) {packages/vue-generator/src/templates/vue-template/index.js (1)
Line range hint
76-173
: LGTM! Consider extracting template configuration.The restructuring with conditional favicon handling is a good improvement. However, the large array of static template files could be extracted for better maintainability.
Consider moving the template configuration to a separate file:
// templateConfig.js export const defaultTemplates = [ { fileType: 'md', fileName: 'README.md', path: '.', template: readmeFile }, // ... other templates ] // index.js import { defaultTemplates } from './templateConfig' export function generateTemplate(schema) { const res = defaultTemplates.map(({ template, ...config }) => ({ ...config, fileContent: template ? getTemplate(schema, template) : template })) const faviconData = base64ToBlob(logoImage) if (faviconData) { res.push({ fileType: 'image/x-icon', fileName: 'favicon.ico', path: './public', fileContent: faviconData }) } return res }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- packages/vue-generator/src/plugins/genTemplatePlugin.js (1 hunks)
- packages/vue-generator/src/templates/vue-template/index.js (3 hunks)
🔇 Additional comments (1)
packages/vue-generator/src/plugins/genTemplatePlugin.js (1)
21-21
: LGTM! Moving template configuration to options is more appropriate.The change from
context?.template
tooptions?.template
is architecturally sound as configuration values belong in options rather than context. This also maintains backward compatibility by falling back to 'default'.Let's verify if there are any direct uses of
context.template
that might be affected:✅ Verification successful
The change from
context.template
tooptions.template
is safe and architecturally soundThe verification confirms that:
- There are no direct references to
context.template
in the codebase- The template configuration is properly passed through
config.pluginConfig?.template
ingenerateApp.js
- The change maintains the plugin's contract while improving architectural clarity by moving configuration to options
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any direct references to context.template rg -l "context\.template" --type jsLength of output: 37
Script:
#!/bin/bash # Let's try a broader search to find any references to template property access rg "\.template" --type js -A 2 -B 2 # Also search for imports or requires of genTemplatePlugin to understand usage rg "genTemplatePlugin" --type jsLength of output: 4738
* fix: parse template name error * fix: add detection for test env
* fix: parse template name error * fix: add detection for test env
English | 简体中文
PR
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
Background and solution
What is the current behavior?
context.template
->options.template
。Issue Number: N/A
What is the new behavior?
Does this PR introduce a breaking change?
Other information
Summary by CodeRabbit
New Features
Bug Fixes
Refactor