@grafana/toolkit
Grafana Toolkit
Last updated 6 days ago by dprokop .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @grafana/toolkit 
SYNC missed versions from official npm registry.

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

grafana-toolkit

grafana-toolkit is CLI that enables efficient development of Grafana plugins

Rationale

Historically, creating Grafana plugin was an exercise of reverse engineering and ceremony around testing, developing and eventually building the plugin. We want to help our community to focus on the core value of their plugins rather than all the setup required to develop them.

Getting started

Setup new plugin with grafana-toolkit plugin:create command:

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

Updating your plugin to use grafana-toolkit

In order to start using grafana-toolkit in your existing plugin you need to follow the steps below:

  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 put in your hands 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

Creating plugin

grafana-toolkit plugin:create plugin-name

Creates new Grafana plugin from template.

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

Developing plugin

grafana-toolkit plugin:dev

Creates 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

Testing plugin

grafana-toolkit plugin:test

Runs Jest against your codebase

Available options:

Building plugin

grafana-toolkit plugin:build

Creates production ready build of your plugin

FAQ

Which version should I use?

Please refer to Grafana packages versioning guide

What tools does grafana-toolkit use?

grafana-toolkit comes with Typescript, TSLint, 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, 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 setup 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 Jest config via package.json file. For more details please refer to Jest docs.

Currently we support following Jest config properties:

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, create dark.[css|scss] and light.[css|scss] files in src/styles directory of your plugin. grafana-toolkit will generate theme specific stylesheets that will end up in dist/styles directory.

In order for Grafana to pickup up you theme stylesheets you need to use loadPluginCss from @grafana/runtime package. Typically you would do that in the entrypoint 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 need to add @grafana/runtime to your plugin dependencies by running yarn add @grafana/runtime or npm instal @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 will get access to Grafana Theme variables.

To use start using Emotion you first need to add it to your plugin dependencies:

  yarn add "@emotion/core"@10.0.14

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 TSLint configuration to suit my needs?

grafana-toolkit comes with default config for TSLint. As for now there is now way to customise TSLint 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 pickup 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"),
};

Contributing to grafana-toolkit

Typically plugins should be developed using the @grafana/toolkit installed from npm. However, when working on the toolkit, you may want to use the local version. To do that follow the steps below:

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

Current Tags

  • 6.5.0-pre-0303aad98f                                ...           canary (an hour ago)
  • 6.4.3                                ...           latest (6 days ago)
  • 6.4.0-beta.2                                ...           next (a month ago)

136 Versions

  • 6.5.0-pre-0303aad98f                                ...           an hour ago
  • 6.4.3                                ...           6 days ago
  • 6.4.2                                ...           14 days ago
  • 6.4.0                                ...           21 days ago
  • 6.4.0-beta.2                                ...           a month ago
  • 6.5.0-pre-235a69527                                ...           a month ago
  • 6.4.0-beta.1                                ...           a month ago
  • 6.4.0-alpha.44-7ca77b8a9                                ...           a month ago
  • 6.4.0-alpha.44-0ba07720d                                ...           2 months ago
  • 6.4.0-alpha.44-93ecf63e7                                ...           2 months ago
  • 6.4.0-alpha.44-3ccc10f82                                ...           2 months ago
  • 6.4.0-alpha.44-4b3440325                                ...           2 months ago
  • 6.4.0-alpha.44-ab1701579                                ...           2 months ago
  • 6.3.2                                ...           2 months ago
  • 6.4.0-alpha.44-8b0bbb2c4                                ...           2 months ago
  • 6.4.0-alpha.44-72b0e9570                                ...           2 months ago
  • 6.4.0-alpha.44-c38804216                                ...           2 months ago
  • 6.4.0-alpha.44-151b40ee2                                ...           2 months ago
  • 6.4.0-alpha.44-054f908f2                                ...           2 months ago
  • 6.4.0-alpha.44-c55578d30                                ...           2 months ago
  • 6.4.0-alpha.44-66faedfb9                                ...           2 months ago
  • 6.4.0-alpha.44-760aec7d3                                ...           3 months ago
  • 6.4.0-alpha.44-b05afd7e4                                ...           3 months ago
  • 6.4.0-alpha.44-ead2d6e88                                ...           3 months ago
  • 6.4.0-alpha.44-541981c34                                ...           3 months ago
  • 6.4.0-alpha.44-d8f86834d                                ...           3 months ago
  • 6.4.0-alpha.22-6a870513a                                ...           3 months ago
  • 6.4.0-alpha.22-09e793849                                ...           3 months ago
  • 6.4.0-alpha.44                                ...           3 months ago
  • 6.4.0-alpha.22-202c13623                                ...           3 months ago
  • 6.4.0-alpha.22-50a043f58                                ...           3 months ago
  • 6.4.0-alpha.22-5f4b5dfec                                ...           3 months ago
  • 6.4.0-alpha.22-83da3660d                                ...           3 months ago
  • 6.4.0-alpha.43                                ...           3 months ago
  • 6.4.0-alpha.42                                ...           3 months ago
  • 6.4.0-alpha.22-294eabda5                                ...           3 months ago
  • 6.4.0-alpha.22-794932963                                ...           3 months ago
  • 6.4.0-alpha.22-4ce814ba9                                ...           3 months ago
  • 6.4.0-alpha.41                                ...           3 months ago
  • 6.4.0-alpha.22-9d8792398                                ...           3 months ago
  • 6.4.0-alpha.40                                ...           3 months ago
  • 6.4.0-alpha.39                                ...           3 months ago
  • 6.4.0-alpha.38                                ...           3 months ago
  • 6.4.0-alpha.22-6fa617efd                                ...           3 months ago
  • 6.4.0-alpha.37                                ...           3 months ago
  • 6.4.0-alpha.36                                ...           3 months ago
  • 6.4.0-alpha.35                                ...           3 months ago
  • 6.4.0-alpha.34                                ...           3 months ago
  • 6.4.0-alpha.33                                ...           3 months ago
  • 6.4.0-alpha.22-c01bbf205                                ...           3 months ago
  • 6.4.0-alpha.22-996567ac4                                ...           3 months ago
  • 6.4.0-alpha.22-3145a1dd2                                ...           3 months ago
  • 6.4.0-alpha.22-6144c0f51                                ...           3 months ago
  • 6.4.0-alpha.22-0752a09f9                                ...           3 months ago
  • 6.4.0-alpha.32                                ...           3 months ago
  • 6.4.0-alpha.31                                ...           3 months ago
  • 6.4.0-alpha.30                                ...           3 months ago
  • 6.4.0-alpha.29                                ...           3 months ago
  • 6.4.0-alpha.22-b5ad2ebe9                                ...           3 months ago
  • 6.4.0-alpha.22-eac145983                                ...           3 months ago
  • 6.4.0-alpha.28                                ...           3 months ago
  • 6.4.0-alpha.27                                ...           3 months ago
  • 6.4.0-alpha.26                                ...           3 months ago
  • 6.4.0-alpha.25                                ...           3 months ago
  • 6.4.0-alpha.24                                ...           3 months ago
  • 6.4.0-alpha.22-9f415e84b                                ...           3 months ago
  • 6.4.0-alpha.22-06b43f6d4                                ...           3 months ago
  • 6.4.0-alpha.23                                ...           3 months ago
  • 6.4.0-alpha.22-3e0625ff3                                ...           3 months ago
  • 6.4.0-alpha.22-2c8809d3c                                ...           3 months ago
  • 6.4.0-alpha.12-c8498461a                                ...           3 months ago
  • 6.4.0-alpha.22                                ...           3 months ago
  • 6.4.0-alpha.21                                ...           3 months ago
  • 6.4.0-alpha.19                                ...           3 months ago
  • 6.4.0-alpha.18                                ...           3 months ago
  • 6.4.0-alpha.17                                ...           3 months ago
  • 6.4.0-alpha.16                                ...           3 months ago
  • 6.4.0-alpha.15                                ...           3 months ago
  • 6.4.0-alpha.12-c194ae1ba                                ...           3 months ago
  • 6.4.0-alpha.14                                ...           3 months ago
  • 6.4.0-alpha.12-5151b8ce0                                ...           3 months ago
  • 6.4.0-alpha.12-e56f98f03                                ...           3 months ago
  • 6.4.0-alpha.12-29c89de14                                ...           3 months ago
  • 6.4.0-alpha.12-de705229b                                ...           3 months ago
  • 6.4.0-alpha.12-ceaa30d88                                ...           3 months ago
  • 6.4.0-alpha.12                                ...           3 months ago
  • 6.4.0-alpha.11                                ...           3 months ago
  • 6.4.0-alpha.10                                ...           3 months ago
  • 6.4.0-alpha.9                                ...           3 months ago
  • 6.4.0-alpha.8                                ...           3 months ago
  • 6.4.0-alpha.7                                ...           3 months ago
  • 6.4.0-alpha.6                                ...           3 months ago
  • 6.4.0-alpha.5                                ...           3 months ago
  • 6.4.0-alpha.4                                ...           3 months ago
  • 6.4.0-alpha.3                                ...           3 months ago
  • 6.4.0-alpha.2                                ...           3 months ago
  • 6.3.0-alpha.40                                ...           3 months ago
  • 6.3.0-alpha.39                                ...           3 months ago
  • 6.3.0-alpha.38                                ...           3 months ago
  • 6.3.0-alpha.36                                ...           3 months ago
  • 6.3.0-alpha.35                                ...           3 months ago
  • 6.3.0-alpha.34                                ...           3 months ago
  • 6.3.0-alpha.33                                ...           3 months ago
  • 6.3.0-alpha.32                                ...           3 months ago
  • 6.3.0-alpha.31                                ...           3 months ago
  • 6.3.0-alpha.30                                ...           3 months ago
  • 6.3.0-alpha.29                                ...           3 months ago
  • 6.3.0-alpha.28                                ...           4 months ago
  • 6.3.0-alpha.27                                ...           4 months ago
  • 6.3.0-alpha.26                                ...           4 months ago
  • 6.3.0-alpha.25                                ...           4 months ago
  • 6.3.0-alpha.24                                ...           4 months ago
  • 6.3.0-alpha.23                                ...           4 months ago
  • 6.3.0-alpha.22                                ...           4 months ago
  • 6.3.0-alpha.21                                ...           4 months ago
  • 6.3.0-alpha.20                                ...           4 months ago
  • 6.3.0-alpha.19                                ...           4 months ago
  • 6.3.0-alpha.18                                ...           4 months ago
  • 6.3.0-alpha.17                                ...           4 months ago
  • 6.3.0-alpha.16                                ...           4 months ago
  • 6.3.0-alpha.15                                ...           4 months ago
  • 6.3.0-alpha.14                                ...           4 months ago
  • 6.3.0-alpha.13                                ...           4 months ago
  • 6.3.0-alpha.12                                ...           4 months ago
  • 6.3.0-alpha.11                                ...           4 months ago
  • 6.3.0-alpha.10                                ...           4 months ago
  • 6.3.0-alpha.9                                ...           4 months ago
  • 6.3.0-alpha.8                                ...           4 months ago
  • 6.3.0-alpha.7                                ...           4 months ago
  • 6.3.0-alpha.6                                ...           4 months ago
  • 6.3.0-alpha.5                                ...           4 months ago
  • 6.3.0-alpha.4                                ...           4 months ago
  • 6.3.0-alpha.2                                ...           4 months ago
  • 6.3.0-alpha.3                                ...           4 months ago
  • 6.3.0-alpha.1                                ...           5 months ago
  • 6.3.0-alpha.0                                ...           5 months ago
Downloads
Today 41
This Week 74
This Month 616
Last Day 33
Last Week 271
Last Month 1,564
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |