Skip to content

POC: codegen from plugin.json #1563

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
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

hugohaggmark
Copy link
Contributor

@hugohaggmark hugohaggmark commented Feb 21, 2025

What this PR does / why we need it:
Initial POC that illustrates how we could generate Typescript files from the plugin.json file.

Kapture.2025-02-21.at.08.27.36.mp4
  • The code generation should be made more extendable but I left that part out for now.
  • Naming and placement of the files is something we should discuss if moving forward with this solution
  • This could be extended to enforce rules in the plugin.json, for example For data source plugins, if the plugin supports alerting. Requires backend to be set to true. Those types of rules could be added here
  • Need to add the code generation to the webpack build pipeline too
  • Do I dare to mention this could be made for backend go files as well if any of the props in plugin.json have immediate impact on the backend that is

Which issue(s) this PR fixes:

Fixes #grafana/grafana#100898

Special notes for your reviewer:

@hugohaggmark hugohaggmark self-assigned this Feb 21, 2025
Copy link
Contributor

github-actions bot commented Feb 21, 2025

Hello! 👋 This repository uses Auto for releasing packages using PR labels.

✨ This PR can be merged. It will not be considered when calculating future versions of the npm packages and will not appear in the changelogs.

@hugohaggmark hugohaggmark added the no-changelog Don't include in changelog and version calculations label Feb 21, 2025
@hugohaggmark hugohaggmark requested a review from sunker February 21, 2025 07:42
@hugohaggmark hugohaggmark removed their assignment Feb 25, 2025
Copy link
Collaborator

@leventebalogh leventebalogh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one @hugohaggmark, this looks like a good direction to me! 🚀

I guess one of the main benefits of an auto-generated type file for these metadata would be the following: (over just importing the plugin.json, which is what plugins are usually doing now)

  • easier to discover available properties without looking at the JSON
  • better type safety during development (now the code actually "knows" what includes are available)

Obviously not part of the POC, but if we take this further we could probably somehow "generalise" the generation methods, so it's easy to introduce a new type?

@hugohaggmark
Copy link
Contributor Author

One thing that I haven't added to this POC yet is that we need to run the code generation before we build too, otherwise the build could potentially break if someone was using the code generated classes/functions/enums.

@hugohaggmark hugohaggmark self-assigned this Apr 9, 2025
@tolzhabayev
Copy link
Collaborator

tolzhabayev commented May 9, 2025

@hugohaggmark closing due to #1770

my bad, has nothing to do with the generation of the generic schema docs

@tolzhabayev tolzhabayev closed this May 9, 2025
@github-project-automation github-project-automation bot moved this from 🔬 In review to 🚀 Shipped in Plugins Platform / Grafana Community May 9, 2025
@tolzhabayev tolzhabayev reopened this May 19, 2025
@github-project-automation github-project-automation bot moved this from 🚀 Shipped to 💡 Ideation in Plugins Platform / Grafana Community May 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog Don't include in changelog and version calculations
Projects
Status: 💡 Ideation
Development

Successfully merging this pull request may close these issues.

3 participants