-
Notifications
You must be signed in to change notification settings - Fork 35
Create Plugin (poc): Support new add cmd #2233
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
Draft
sunker
wants to merge
6
commits into
main
Choose a base branch
from
create-plugin/add-cmd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Conversation
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
Contributor
- Create additions registry for managing optional feature additions - Implement additions manager with runAddition, executeAddition - Add utilities that reuse migration infrastructure (Context, formatFiles, etc.) - Support for version-agnostic, idempotent additions - Designed to be extensible for future additions beyond i18n
- Add new 'add' command to CLI (npx @grafana/create-plugin add <feature>) - Implement pre-flight checks (git directory, clean working tree, plugin directory) - Add interactive prompts for i18n locale selection using enquirer - Support for multiple locale selection with multiselect UI - Allow custom locale codes to be entered manually - Register command in CLI entry point and command index
Implements complete i18n setup automation: - Updates docker-compose.yaml with localizationForPlugins feature toggle - Updates plugin.json with languages array and grafanaDependency >= 12.1.0 - Creates locale folders and translation files for selected locales - Adds @grafana/i18n dependency to package.json - Adds i18next-cli dev dependency and i18n-extract script - Creates i18next.config.ts with proper extraction configuration - Updates eslint.config.mjs with i18n linting rules - Adds i18n imports to module.ts/tsx automatically - Idempotent: safely runs multiple times without breaking - Comprehensive test suite with 8 passing tests covering: * Idempotency verification * Single and multiple locale support * Skipping when already configured * Handling existing feature toggles * Support for both .ts and .tsx modules * Version-aware dependency updates * Edge cases (missing scripts, etc.) This automates all manual steps shown in grafana/grafana-plugin-examples#588
- Add comprehensive documentation for the new 'add' command - Document 'add i18n' usage with interactive prompts - List all actions performed by the i18n addition - Provide examples of common locales that can be selected - Link to plugin internationalization documentation - Explain the automated setup process
- Add additions scripts to rollup input alongside migrations - Ensures add-i18n.js is compiled and available in dist/ - Fixes module resolution error when running npx @grafana/create-plugin add i18n
…lity This commit enhances the add i18n command to better support plugins targeting different Grafana versions: Key improvements: 1. **Backward compatibility for Grafana 11+**: Automatically detects if a plugin targets Grafana < 12.1.0 and applies the appropriate configuration: - Sets grafanaDependency to >=11.0.0 (instead of >=12.1.0) - Creates loadResources.ts file for manual resource loading - Adds conditional loader logic in module initialization - Adds semver as a regular dependency (not just dev) - Skips docker-compose.yaml feature toggle (not needed for < 12.1.0) 2. **Updated dependency versions**: - @grafana/i18n: 12.2.2 (was ^1.0.0) - Added semver: ^7.6.0 and @types/semver: ^7.5.0 for version checks 3. **Example translations**: Generated locale JSON files now include example translation structure (components and config sections) to help users understand the format 4. **Build configuration**: Updated rollup.config.ts to properly bundle addition scripts from src/additions/scripts directory The implementation follows the official Grafana documentation for i18n support in plugins before Grafana 12.1.0, including: - loadResources.ts for resource loading - Conditional loaders based on Grafana version - Proper import setup for semver and config from @grafana/runtime Tests updated to cover both backward compatibility mode (Grafana 11+) and modern mode (Grafana 12.1.0+).
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.
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
📦 Published PR as canary version:
Canary Versions✨ Test out this PR locally via: