Skip to content
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

@grafana/toolkit - implement common tooling for plugin developers #17819

Closed
38 of 39 tasks
dprokop opened this issue Jun 28, 2019 · 10 comments
Closed
38 of 39 tasks

@grafana/toolkit - implement common tooling for plugin developers #17819

dprokop opened this issue Jun 28, 2019 · 10 comments

Comments

@dprokop
Copy link
Member

dprokop commented Jun 28, 2019

The work started in: #17445

TODO:

  • Enable building app/plugin using shared rollup config
  • If there is more than one module.ts entry then add manual chunks
  • Enable running tests on app/plugin
  • Introduce common tsconfig
  • Introduce common tslint config
  • Do not expose internal cli commands
  • Validate plugin name/org
    - OK for plugins in grafana repo to skip the org
  • Run typecheck before linting
  • Add watch option to enable easy development (rollup watch, plugin:[dev|watch])

Areas to cover

Plugin development tasks

  • grafana-toolkit plugin:test - performs tests for a given plugin
  • grafana-toolkit plugin:dev - runs plugin in development mode, meaning that Rollup is run in watch mode
  • grafana-toolkit plugin:build - prepares plugin distribution package
    • Runs linter
    • Runs tests
    • Bundles plugin
  • grafana-toolkit plugin:create - creates plugin seed from a template (grafana/toolkit: Introduce scaffolding task #18506)

Testing plugin

Linting / Prettier

Bundling plugin

### Documentation

  • generate docs from /docs folder
    a different task should do this

CircleCI helpers

package a plugin in circleci. this will be super helpful for backend plugins.

See: #17967

Plugin stylesheet (#17938)

  • Add support for common conventions:
    • Single css/scss file (used via import)
    • Separate files for themes (used via loadPluginCss)
    • Emotion
  • Enable PostCSS
  • Verify SASS setup

With new react panels, we should push for emotion. However we still need to support old/existing panels that tend to either just import a .css file, or use: loadPluginCss

loadPluginCss({
  dark: 'plugins/grafana-kubernetes-app/css/dark.css',
  light: 'plugins/grafana-kubernetes-app/css/light.css'
});

v2 backlog:

  • Make Enzyme a default test tool in toolkit
  • plugin:ci - gather stats from webpack task

Current (known) problems to be figured out

  1. How to handle imports from core? import XXX from 'app/plugins/sdk'
    This problem surfaced in k8s and ajax panel. Can't see any clear path how to fight this one. Problem is that those plugins import implementations from core (indirectyl, via pligins/sdk). It's not about interfaces anymore but about actual implementations being extended by apps/plugins. Thing is that we possibly could extract app/plugins/sdk to a separate package, i.e. @grafana/plugin-sdk, but it's super hard because of app/plugins/sdk referencing core modules.... Crap

Toolkit wishlist:

@dprokop
Copy link
Member Author

dprokop commented Jun 28, 2019

@ryantxu could you please update Check if plugin.json naming follows naming convention above? I remember you had an idea about plugin naming convention in regards to org name and plugin name

@ryantxu
Copy link
Member

ryantxu commented Jun 29, 2019

rollup vs webpack? so I originally though rollup was a good path because it makes nicer bundles... but having tried this with a bunch of plugins, I think it is going to be more difficult that in is worth :(

rollup seems to be much stricter about how it imports and packages libraries. This is likely more "correct", but I am struggling to find something that works.

I think we should consider webpack. @dprokop, could you take a stab a matching this webpack.config.js -- If you get close, I can poke on the details till it works with a few of the plugins

@dprokop
Copy link
Member Author

dprokop commented Jul 1, 2019

@ryantxu sure, as we talked on friday, we gonna try with webpack here.

@dprokop
Copy link
Member Author

dprokop commented Jul 1, 2019

@ryantxu webpack related work: #17850

@ryantxu
Copy link
Member

ryantxu commented Jul 6, 2019

Current Status:

https://github.com/ryantxu/ajax-panel
https://github.com/NatelEnergy/grafana-discrete-panel
https://github.com/grafana/kentik-app
https://github.com/grafana/kubernetes-app
grafana/simple-json-datasource#129
https://github.com/ryantxu/grafana-graphql-datasource: fails with:
image
https://medium.com/@gavin.blog/how-to-solve-ng-annotate-stringmap-expected-string-key-error-f0711c7c84db

I think the next priorities should be:

  1. prettier --fix?

    • yarn dev -- auto fix prettier and lint errors
    • yarn build -- failes if prettier or lint fails

    Alternativly we could add an explicit call with --fix, but I think fewer options is better

  2. @grafana/data build/publish?

@dprokop
Copy link
Member Author

dprokop commented Jul 8, 2019

@ryantxu me need to publish @grafana/data in order to make those ^^ problems disappear(grapgql ds and simple-json ds). Opened #17981 to see how we can improve the process there

@dprokop
Copy link
Member Author

dprokop commented Jul 9, 2019

@ryantxu the grafana-graphql-datasource plugin should build correctly with #18005 applied and @grafana/data added as dependency

dprokop added a commit that referenced this issue Jul 9, 2019
This fixes error caused by ng-annotate mentioned in #17819 (comment)
@briangann
Copy link
Contributor

Currently the toolkit doesn't watch .html files, which are common in plugins for the query editors/datasource configuration.

It would be great to have 'yarn dev --watch' detect changes to these files and drop them into dist, just like the rest of the process.

The "hack" i've used so far is to add htmlwebpackplugin, though it leaves an artifact 'index.html' that never gets used, but does detect and copy the partials/* correctly.

@torkelo
Copy link
Member

torkelo commented Oct 14, 2019

Anything left for this issue? Maybe close this and create an issue for remaining issues

@dprokop
Copy link
Member Author

dprokop commented Oct 16, 2019

@torkelo yup, closing this one. Other toolkit tasks are tracked in separate issues.

@dprokop dprokop closed this as completed Oct 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants