grafana/packages/grafana-toolkit
Stephanie Closson 6310aaff55
Toolkit: docker image for plugin CI process (#22790)
* Adding dockerfile for builds

* Adding standardized bashrc

* Updated dockerfile

* removed bashrc. Not required

* WIP: Updates to dockerfile for e2e and readme

* Storybook: Add relative logo url (#22786)

* DevEnv: update frontend dependencies - rollup (#22794)

* DevEnv: updates rollup 1.6.0 -> 2.0.6 in grafana-data package

* DevEnv: updates rollup 1.6.0 -> 2.0.6 in grafana-e2e package

* DevEnv: updates rollup 1.6.0 -> 2.0.6 in grafana-runtime package

* DevEnv: updates rollup 1.6.0 -> 2.0.6 in grafana-ui package

* DevEnv: updates rollup-plugin-sourcemaps 0.4.2 -> 0.5.0 in grafana-data package

* DevEnv: updates rollup-plugin-sourcemaps 0.4.2 -> 0.5.0 in grafana-e2e package

* DevEnv: updates rollup-plugin-sourcemaps 0.4.2 -> 0.5.0 in grafana-runtime package

* DevEnv: updates rollup-plugin-sourcemaps 0.4.2 -> 0.5.0 in grafana-ui package

* DevEnv: updates rollup-plugin-terser 4.0.4 -> 5.3.0 in grafana-data package

* DevEnv: updates rollup-plugin-terser 4.0.4 -> 5.3.0 in grafana-e2e package

* DevEnv: updates rollup-plugin-terser 4.0.4 -> 5.3.0 in grafana-runtime package

* DevEnv: updates rollup-plugin-terser 4.0.4 -> 5.3.0 in grafana-ui package

* DevEnv: updates rollup-plugin-typescript2 0.19.3 -> 0.26.0 in grafana-data package

* DevEnv: updates rollup-plugin-typescript2 0.19.3 -> 0.26.0 in grafana-e2e package

* DevEnv: updates rollup-plugin-typescript2 0.19.3 -> 0.26.0 in grafana-runtime package

* DevEnv: updates rollup-plugin-typescript2 0.19.3 -> 0.26.0 in grafana-ui package

* DevEnv: updates @rollup/plugin-commonjs 9.2.1 -> 11.0.2 in grafana-data package

* DevEnv: updates @rollup/plugin-commonjs 9.2.1 -> 11.0.2 in grafana-e2e package

* DevEnv: updates @rollup/plugin-commonjs 9.2.1 -> 11.0.2 in grafana-runtime package

* DevEnv: updates @rollup/plugin-commonjs 9.2.1 -> 11.0.2 in grafana-ui package

* DevEnv: updates rollup config import in grafana-data package

* DevEnv: updates rollup config import in grafana-e2e package

* DevEnv: updates rollup config import in grafana-ui package

* DevEnv: updates rollup config import in grafana-runtime package

* DevEnv: updates @rollup/plugin-node-resolve 4.0.1 -> 7.1.1 in grafana-data package

* DevEnv: updates @rollup/plugin-node-resolve 4.0.1 -> 7.1.1 in grafana-e2e package

* DevEnv: updates @rollup/plugin-node-resolve 4.0.1 -> 7.1.1 in grafana-runtime package

* DevEnv: updates @rollup/plugin-node-resolve 4.0.1 -> 7.1.1 in grafana-ui package

* DevEnv: updates lockfile

* DevEnv: updates rollup config plugin-node-resolve import in grafana-data package

* DevEnv: updates rollup config plugin-node-resolve import in grafana-ui package

* DevEnv: updates rollup config plugin-node-resolve import in grafana-e2e package

* DevEnv: updates rollup config plugin-node-resolve import in grafana-runtime package

* DevEnv: updates rollup-plugin-visualizer 0.9.2 -> 3.3.1 in grafana-data package

* DevEnv: updates rollup-plugin-visualizer 0.9.2 -> 3.3.1 in grafana-e2e package

* DevEnv: updates rollup-plugin-visualizer 0.9.2 -> 3.3.1 in grafana-runtime package

* DevEnv: updates rollup-plugin-visualizer 0.9.2 -> 3.3.1 in grafana-ui package

* Fronted: Fixed webpack chunk syntax error

* Fix: fixes issue with headers property with different casing (#22778)

Fixes #22756

* Variables: migrates data source variable type to React/Redux (#22770)

* Refactor: moves all the newVariables part to features/variables directory

* Feature: adds datasource type

* Tests: adds reducer tests

* Tests: covers data source actions with tests

* Chore: reduces strict null errors

* AngularPanels: Fixed inner height calculation (#22796)

* Chore: migrate admin/users from angular to react + redux (#22759)

* Start adding admin users list page to redux/react.

* removed unused code.

* added pagination.

* changed so we use the new form styles.

* added tooltip.

* using tagbadge for authlabels.

* remove unused code.

* removed old code.

* Fixed the last feedback on PR.

* DevEnv: update frontend dependencies - webpack (#22144)

* DevEnv: updates webpack 4.29.6 -> 4.41.5

* DevEnv: updates webpack-cli 3.2.3 -> 3.3.10

* DevEnv: updates webpack-dev-server 3.2.1 -> 3.10.3

* DevEnv: updates terser-webpack-plugin 1.2.3 -> 2.3.4

* DevEnv: updates webpack-bundle-analyzer 3.3.2 -> 3.6.0

* DevEnv updates webpack-merge 4.2.1 -> 4.2.2

* DevEnv: updates clean-webpack-plugin 2.0.0 -> 3.0.0

* DevEnv: updates file-loader 3.0.1 -> 5.0.2

* DevEnv: updates css-loader 2.1.1 -> 3.4.2

* DevEnv: updates sass-loader 7.1.0 -> 8.0.2

* DevEnv: updates style-loader 0.23.1 -> 1.1.3

* DevEnv: updates fork-ts-checker-webpack-plugin 1.0.0 -> 4.0.3

* DevEnv: updates optimize-css-assets-webpack-plugin 5.0.1 -> 5.0.3

* DevEnv: updates mini-css-extract-plugin 0.5.0 -> 0.9.0

* DevEnv: updates @cypress/webpack-preprocessor 4.1.1 -> 4.1.3 in grafana-e2e package

* DevEnv: updates @types/webpack 4.4.34 -> 4.41.7 in grafana-toolkit package

* DevEnv: updates copy-webpack-plugin 5.0.3 -> 5.1.1 in grafana-toolkit package

* DevEnv: updates terser-webpack-plugin 1.3.0 -> 2.3.4 in grafana-toolkit package

* DevEnv: updates webpack 4.35.0 -> 4.41.5 in grafana-toolkit package

* DevEnv: updates import of CleanWebpackPlugin to named import (#22800)

* Build: Migrate PR pipeline (#22788)

Implement new PR pipeline

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>

* DevEnv: update frontend dependencies - mixed 1/2 (#22147)

* DevEnv: updates @emotion/core 10.0.10 -> 10.0.27

* DevEnv: updates autoprefixer 9.5.0 -> 9.7.4

* DevEnv: updates axios 0.19.0 -> 0.19.2

* DevEnv: updates es6-promise 3.3.1 -> 4.2.8

* DevEnv: updates glob 7.1.3 -> 7.1.6

* DevEnv: updates husky 1.3.1 -> 4.2.1

* DevEnv: updates lerna 3.15.0 -> 3.20.2

* DevEnv: updates lint-staged 8.1.5 -> 10.0.7

* DevEnv: updates module-alias 2.2.0 -> 2.2.2

* DevEnv: updates monaco-editor 0.15.6 -> 0.19.3

* DevEnv: updates postcss-browser-reporter 0.5.0 -> 0.6.0

* DevEnv: updates rimraf 2.6.3 -> 3.0.1

* Revert "DevEnv: updates monaco-editor 0.15.6 -> 0.19.3"

* DevEnv: updates axios 0.19.0 -> 0.19.2 in grafana-toolkit package

* DevEnv: updates lockfile

* DevEnv: update frontend dependencies - mixed 2/2 (#22148)

* DevEnv: updates sinon 1.17.6 -> 8.1.1

* DevEnv: updates zone.js 0.7.8 -> 0.10.2

* DevEnv: updates brace 0.10.0 -> 0.11.1

* DevEnv: updates eventemitter3 2.0.3 -> 4.0.0

* DevEnv: updates file-saver 1.3.8 -> 2.0.2

* DevEnv: updates is-hotkey 0.1.4 -> 0.1.6

* DevEnv: updates mousetrap 1.6.3 -> 1.6.5

* DevEnv: updates prismjs 1.16.0 -> 1.19.0

* DevEnv: updates search-query-parser 1.5.2 -> 1.5.4

* DevEnv: updates tether 1.4.5 -> 1.4.7

* DevEnv: updates xss 1.0.3 -> 1.0.6

* Revert "DevEnv: updates zone.js 0.7.8 -> 0.10.2"

* DevEnv: updates sinon 1.17.6 -> 8.1.1 in grafana-data package

* DevEnv: updates @types/sinon 7.0.11 -> 7.5.2 in grafana-data package

* DevEnv: updates eventemitter import

* DevEnv: updates lockfile

* Variables: migrates interval variable type to React/Redux  (#22797)

* Feature: migrates interval variable type to React/Redux

* Forms: Fix input suffix position (#22780)

* Forms: Fix input suffix position

* Update

* FieldOverrides: Apply field overrides in PanelQueryRunner (#22439)

* Apply field overrides in PanelChrome

* Move applyFieldOverrides to panel query runner

* Review updates

* Make sure overrides are applied back on souce panel when exiting the new edit mode

* TS ignores in est

* Make field display work in viz repeater

* Review updates

* Review and test updates

* Change the way overrides and trransformations are retrieved in PQR

* Minor updates after review

* Fix null checks

* E2E: Add new run modes for e2e tests (#22795)

* WIP: started e2e tests for bar gauge

* Updated

* Updated

* Updated cypress from 3.7 -> 4.1

* reverted cypress upgrade

* Updated test

* Update e2e docs

* Updated docs

* DevEnv: update frontend dependencies - npm, nodemon, typescript (#22145)

* DevEnv: updates npm 6.13.4 -> 6.13.7

* DevEnv: updates nodemon 1.18.10 -> 2.0.2

* DevEnv: updates typescript 3.7.2 -> 3.7.5

* DevEnv: removes npm from dev dependencies

* DevEnv: updates typescript 3.7.2 -> 3.7.5 in grafana-data package

* DevEnv: updates typescript 3.7.2 -> 3.7.5 in grafana-e2e package

* DevEnv: updates typescript 3.7.2 -> 3.7.5 in grafana-toolkit package

* DevEnv: updates typescript 3.7.2 -> 3.7.5 in grafana-ui package

* DevEnv: updates typescript 3.7.2 -> 3.7.5 in grafana-runtime package

* SaveDashboard: Updated modal design/layout a bit (#22810)

* DevEnv: updates build-ci-deploy dockerfile and CI config to include yarn (#22809)

* DevEnv: updates build-ci-deploy dockerfile

* DevEnv: updates build-ci-deploy dockerfile version in circleci config

* Plugins: Hide plugins page from viewers, and limit /api/plugins to only core plugins when called by viewer role  (#21901)

* Hide plugins list from viewers

* Made /api/plugins only return core plugins for users with viewer role

Co-authored-by: Torkel Ödegaard <torkel@grafana.com>

* Webpack: Add relative node_modules path (#22806)

* DevEnv: updates lockfile to fix breaking builds on CI (#22811)

* DevEnv: updates lockfile

* DevEnv: updates lockfile

* Added readme, and review feedback

* Renamed README

* fixed error in path for docs

* Added updatedb

* Set grafana checkout to latest stable

* Variables: fixes so single value picker closes dropdown on select (#22823)

* FieldOverrides: Remove console warn from processFieldConfigValue (#22824)

* Grafana-UI: Add invalid state to Forms.Textarea (#22775)

* Storybook: Bring back theme switch (#22826)

* TestData: New dashboard that tests variables that update on time range change (#22829)

* CircleCI: Download grabpl from GCS (#22828)

* CircleCI: Download grabpl from GCS

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>

* CircleCI: Fix installation of grabpl

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>

* Fix dashboard picker's props (#22815)

* TablePanel: Enable new units picker (#22833)

* CircleCI: Install build pipeline tool from GitHub repo (#22837)

* Variables: fixes so order in list is preserved after save (#22805)

* Storybook: Deploy on PR, master and release (#22827)

* Update CircleCI deployment

* Add GCP auth

* Change master to latest dir

* Variables: adds onTimeRangeUpdated to newVariables (#22821)

* Feature: adds onTimeRangeUpdated to newVariables

* Refactor: removes VariableWithRefresh and unused func

* Refactor: adds console output when something throws as well

* Storybook: add canary deploy from master (#22843)

* Canary from master latest from release

* Fix logo URL

* Adding dockerfile for builds

* Adding standardized bashrc

* Updated dockerfile

* removed bashrc. Not required

* WIP: Updates to dockerfile for e2e and readme

* Added readme, and review feedback

* Renamed README

* fixed error in path for docs

* Added updatedb

* Set grafana checkout to latest stable

* Feedback from code review

* Update packages/grafana-toolkit/docker/grafana-plugin-ci/README.md

Co-Authored-By: Arve Knudsen <arve.knudsen@gmail.com>

* recommended changes from code review

Co-authored-by: Tobias Skarhed <1438972+tskarhed@users.noreply.github.com>
Co-authored-by: Lukas Siatka <lukasz.siatka@grafana.com>
Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
Co-authored-by: Hugo Häggmark <hugo.haggmark@grafana.com>
Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>
Co-authored-by: Arve Knudsen <arve.knudsen@gmail.com>
Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
Co-authored-by: Andrej Ocenas <mr.ocenas@gmail.com>
Co-authored-by: Alex Khomenko <Clarity-89@users.noreply.github.com>
2020-03-17 13:36:35 -06:00
..
bin grafana/toolkit: Add plugin scaffolding (#19207) 2019-09-20 09:47:49 +02:00
docker/grafana-plugin-ci Toolkit: docker image for plugin CI process (#22790) 2020-03-17 13:36:35 -06:00
src Toolkit: use fs-extra instead of fs (#22723) 2020-03-11 07:37:31 -07:00
.eslintrc TSLint → ESLint (#21006) 2020-02-08 02:40:04 +01:00
CHANGELOG.md Changelog: v6.6.0-beta1 (#21619) 2020-01-21 10:10:16 +01:00
package.json DevEnv: update frontend dependencies - npm, nodemon, typescript (#22145) 2020-03-16 15:04:02 +01:00
README.md canary 404 previous versions (#22495) 2020-02-28 11:27:45 -05:00
tsconfig.json TSLint → ESLint (#21006) 2020-02-08 02:40:04 +01:00

WARNING: @grafana/toolkit is currently in ALPHA. The core API is unstable and can be a subject of breaking changes!

grafana-toolkit

grafana-toolkit is a CLI that enables efficient development of Grafana plugins. We want to help our community focus on the core value of their plugins rather than all the setup required to develop them.

Getting started

Set up a new plugin with grafana-toolkit plugin:create command:

npx @grafana/toolkit plugin:create my-grafana-plugin
cd my-grafana-plugin
yarn install
yarn dev

Update your plugin to use grafana-toolkit

Follow the steps below to start using grafana-toolkit in your existing plugin.

  1. Add @grafana/toolkit package to your project by running yarn add @grafana/toolkit or npm install @grafana/toolkit.
  2. Create tsconfig.json file in the root dir of your plugin and paste the code below:
{
  "extends": "./node_modules/@grafana/toolkit/src/config/tsconfig.plugin.json",
  "include": ["src", "types"],
  "compilerOptions": {
    "rootDir": "./src",
    "baseUrl": "./src",
    "typeRoots": ["./node_modules/@types"]
  }
}
  1. Create .prettierrc.js file in the root dir of your plugin and paste the code below:
module.exports = {
  ...require("./node_modules/@grafana/toolkit/src/config/prettier.plugin.config.json"),
};
  1. In your package.json file add following scripts:
"scripts": {
  "build": "grafana-toolkit plugin:build",
  "test": "grafana-toolkit plugin:test",
  "dev": "grafana-toolkit plugin:dev",
  "watch": "grafana-toolkit plugin:dev --watch"
},

Usage

With grafana-toolkit, we give you a CLI that addresses common tasks performed when working on Grafana plugin:

  • grafana-toolkit plugin:create
  • grafana-toolkit plugin:dev
  • grafana-toolkit plugin:test
  • grafana-toolkit plugin:build

Create your plugin

grafana-toolkit plugin:create plugin-name

This command creates a new Grafana plugin from template.

If plugin-name is provided, then the template is downloaded to ./plugin-name directory. Otherwise, it will be downloaded to the current directory.

Develop your plugin

grafana-toolkit plugin:dev

This command creates a development build that's easy to play with and debug using common browser tooling.

Available options:

  • -w, --watch - run development task in a watch mode

Test your plugin

grafana-toolkit plugin:test

This command runs Jest against your codebase.

Available options:

Build your plugin

grafana-toolkit plugin:build

This command creates a production-ready build of your plugin.

FAQ

Which version of grafana-toolkit should I use?

See Grafana packages versioning guide.

What tools does grafana-toolkit use?

grafana-toolkit comes with TypeScript, ESLint, Prettier, Jest, CSS and SASS support.

How to start using grafana-toolkit in my plugin?

See Updating your plugin to use grafana-toolkit.

Can I use TypeScript to develop Grafana plugins?

Yes! grafana-toolkit supports TypeScript by default.

How can I test my plugin?

grafana-toolkit comes with Jest as a test runner.

Internally at Grafana we use Enzyme. If you are developing React plugin and you want to configure Enzyme as a testing utility, then you need to configure enzyme-adapter-react. To do so, create <YOUR_PLUGIN_DIR>/config/jest-setup.ts file that will provide necessary setup. Copy the following code into that file to get Enzyme working with React:

import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });

You can also set up Jest with shims of your needs by creating jest-shim.ts file in the same directory: <YOUR_PLUGIN_DIR_>/config/jest-shim.ts

Can I provide custom setup for Jest?

You can provide custom Jest configuration with a package.json file. For more details, see Jest docs.

Currently we support following Jest configuration properties:

How can I customize Webpack rules or plugins?

You can provide your own webpack.config.js file that exports a getWebpackConfig function. We recommend that you extend the standard configuration, but you are free to create your own:

const CustomPlugin = require('custom-plugin');

module.exports.getWebpackConfig = (config, options) => ({
  ...config,
  plugins: [
    ...config.plugins,
    new CustomPlugin()
  ]
});

How can I style my plugin?

We support pure CSS, SASS, and CSS-in-JS approach (via Emotion).

Single CSS or SASS file

Create your CSS or SASS file and import it in your plugin entry point (typically module.ts):

import 'path/to/your/css_or_sass'

The styles will be injected via style tag during runtime.

Note that imported static assets will be inlined as base64 URIs. This can be subject of change in the future!

Theme-specific stylesheets

If you want to provide different stylesheets for dark/light theme, then create dark.[css|scss] and light.[css|scss] files in the src/styles directory of your plugin. grafana-toolkit generates theme-specific stylesheets that are stored in dist/styles directory.

In order for Grafana to pick up your theme stylesheets, you need to use loadPluginCss from @grafana/runtime package. Typically you would do that in the entry point of your plugin:

import { loadPluginCss } from '@grafana/runtime';

loadPluginCss({
  dark: 'plugins/<YOUR-PLUGIN-ID>/styles/dark.css',
  light: 'plugins/<YOUR-PLUGIN-ID>/styles/light.css',
});

You must add @grafana/runtime to your plugin dependencies by running yarn add @grafana/runtime or npm install @grafana/runtime.

Note that in this case static files (png, svg, json, html) are all copied to dist directory when the plugin is bundled. Relative paths to those files does not change!

Emotion

Starting from Grafana 6.2 our suggested way for styling plugins is by using Emotion. It's a CSS-in-JS library that we use internally at Grafana. The biggest advantage of using Emotion is that you can access Grafana Theme variables.

To start using Emotion, you first must add it to your plugin dependencies:

  yarn add "emotion"@10.0.27

Then, import css function from Emotion:

import { css } from 'emotion'

Now you are ready to implement your styles:

const MyComponent = () => {
  return <div className={css`background: red;`} />
}

To learn more about using Grafana theme please refer to Theme usage guide

We do not support Emotion's css prop. Use className instead!

Can I adjust TypeScript configuration to suit my needs?

Yes! However, it's important that your tsconfig.json file contains the following lines:

{
  "extends": "./node_modules/@grafana/toolkit/src/config/tsconfig.plugin.json",
  "include": ["src"],
  "compilerOptions": {
    "rootDir": "./src",
    "typeRoots": ["./node_modules/@types"]
  }
}

Can I adjust ESLint configuration to suit my needs?

grafana-toolkit comes with default config for ESLint. For now, there is now way to customise ESLint config.

How is Prettier integrated into grafana-toolkit workflow?

When building plugin with grafana-toolkit plugin:build task, grafana-toolkit performs Prettier check. If the check detects any Prettier issues, the build will not pass. To avoid such situation we suggest developing plugin with grafana-toolkit plugin:dev --watch task running. This task tries to fix Prettier issues automatically.

My editor does not respect Prettier config, what should I do?

In order for your editor to pick up our Prettier config you need to create .prettierrc.js file in the root directory of your plugin with following content:

module.exports = {
  ...require("./node_modules/@grafana/toolkit/src/config/prettier.plugin.config.json"),
};

How do I add third-party dependencies that are not npm packages?

Put them in the static directory in the root of your project. The static directory is copied when the plugin is built.

I am getting this message when I run yarn install: Request failed \"404 Not Found\"

If you are using version canary, this error occurs because a canary release unpublishes previous versions leaving yarn.lock outdated. Remove yarn.lock and run yarn install again.

I am getting this message when I run my plugin: Unable to dynamically transpile ES module A loader plugin needs to be configured via SystemJS.config({ transpiler: 'transpiler-module' }).

This error occurs when you bundle your plugin using the grafana-toolkit plugin:dev task and your code comments include ES2016 code.

There are two issues at play:

  • The grafana-toolkit plugin:dev task does not remove comments from your bundled package.
  • Grafana does not support ES modules.

If your comments include ES2016 code, then SystemJS v0.20.19, which Grafana uses internally to load plugins, interprets your code as an ESM and fails.

To fix this error, remove the ES2016 code from your comments.

Contribute to grafana-toolkit

You can contribute to grafana-toolkit by helping develop it or by debugging it.

Develop grafana-toolkit

Typically plugins should be developed using the @grafana/toolkit installed from npm. However, when working on the toolkit, you might want to use the local version. Follow the steps below to develop with a local version:

  1. Clone Grafana repository.
  2. Navigate to the directory you have cloned Grafana repo to and then run yarn install --pure-lockfile.
  3. Navigate to <GRAFANA_DIR>/packages/grafana-toolkit and then run yarn link.
  4. Navigate to the directory where your plugin code is and then run npx grafana-toolkit plugin:dev --yarnlink. This adds all dependencies required by grafana-toolkit to your project, as well as link your local grafana-toolkit version to be used by the plugin.

Debug grafana-toolkit

To debug grafana-toolkit you can use standard NodeJS debugging methods (node --inspect, node --inspect-brk).

To run grafana-toolkit in a debugging session use the following command in the toolkit's directory:

node --inspect-brk ./bin/grafana-toolkit.js [task]

To run linked grafana-toolkit in a debugging session use the following command in the plugin's directory:

node --inspect-brk ./node_modules/@grafana/toolkit/bin/grafana-toolkit.js [task]