@grafana/toolkit
Grafana Toolkit
Last updated 2 months ago by ryantxu .
Apache-2.0 · Original npm · Tarball · package.json
$ cnpm install @grafana/toolkit 
SYNC missed versions from official npm registry.

Grafana Toolkit

Make sure to run yarn install before trying anything! Otherwise you may see unknown command grafana-toolkit and spend a while tracking that down.

Internal development

Typically plugins should be developed using the @grafana/toolkit import from npm. However, when working on the toolkit, you may want to use the local version while underdevelopment. This works, but is a little flakey.

  1. navigate to packages/grafana-toolkit and run yarn link.
  2. in your plugin, run npx grafana-toolkit plugin:dev --yarnlink

Step 2 will add all the same dependencies to your development plugin as the toolkit. These are typically used from the node_modules folder

TODO: Experiment with yalc for linking packages

Publishing to npm

The publish process is now manual. Follow the steps to publish @grafana/toolkit to npm

  1. From Grafana root dir: ./node_modules/.bin/grafana-toolkit toolkit:build
  2. cd packages/grafana-toolkit/dist
  3. Open package.json, change version according to current version on npm (https://www.npmjs.com/package/@grafana/toolkit)
  4. Run npm publish --tag next - for dev purposes we now publish on next channel

Note, that for publishing you need to be part of Grafana npm org and you need to be logged in to npm in your terminal (npm login).

Grafana extensions development with grafana-toolkit overview

Available tasks

grafana-toolkit plugin:test

Runs Jest against your codebase. See Tests for more details.

Available options:

  • -u, --updateSnapshot - performs snapshots update
  • --coverage - reports code coverage

grafana-toolkit plugin:dev

Compiles plugin in development mode.

Available options:

  • -w, --watch - runs plugin:dev task in watch mode

grafana-toolkit plugin:build

Compiles plugin in production mode

Typescript

To configure Typescript create tsconfig.json file in the root dir of your app. grafana-toolkit comes with default tsconfig located in packages/grafana-toolkit/src/config/tsconfig.plugin.ts. In order for Typescript to be able to pickup your source files you need to extend that config as follows:

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

TSLint

grafana-toolkit comes with default config for TSLint, that's located in packages/grafana-toolkit/src/config/tslint.plugin.ts. As for now there is now way to customise TSLint config.

Tests

grafana-toolkit comes with Jest as a test runner. It runs tests according to common config locted in packages/grafana-toolkit/src/config/jest.plugin.config.ts.

For now the config is not extendable, but our goal is to enable custom jest config via jest.config or package.json file. This might be required in the future if you want to use i.e. enzyme-to-json snapshots serializer. For that particular serializer we can also utilise it's API and add initialisation in the setup files (https://github.com/adriantoine/enzyme-to-json#serializer-in-unit-tests). We need to test that approach first.

Jest setup

We are not opinionated about tool used for implmenting tests. Internally at Grafana we use Enzyme. If you want to configure Enzyme as a testing utility, you need to configure enzyme-adapter-react. To do so, you need to create [YOUR_APP]/config/jest-setup.ts file that will provide React/Enzyme setup. Simply copy 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() });

grafana-toolkit will use that file as Jest's setup file. You can also setup Jest with shims of your needs by creating jest-shim.ts file in the same directory: [YOUR_APP]/config/jest-shim.ts

Adidtionaly, you can also provide additional Jest config via package.json file. For more details please refer to Jest docs. Currently we support following properties:

Working with CSS & static assets

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

  1. Single css/sass file Create your css/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 a subject of change in the future!

  1. Theme specific css/sass files 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. Based on that we will generate stylesheets that will end up in dist/styles directory.

TODO: add note about loadPluginCss

Note that 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.

  1. Emotion Starting from Grafana 6.2 our suggested way of styling plugins is by using Emotion. It's a css-in-js library that we use internaly 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'

And start implementing your styles:

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

Using themes: TODO, for now please refer to internal guide

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

Prettier

When plugin:build task is performed we run Prettier check. In order for your IDE to pickup our Prettier config we suggest creating .prettierrc.js file in the root directory of your plugin with following contents:

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

Development mode [todo]

grafana-toolkit plugin:dev [--watch] TODO

  • Enable rollup watch on extension sources

Current Tags

  • 6.5.0-pre-2c9577fcc                                ...           canary (2 hours ago)
  • 6.3.2                                ...           latest (a month ago)
  • 6.4.0-beta.1                                ...           next (7 days ago)

131 Versions

  • 6.5.0-pre-2c9577fcc                                ...           2 hours ago
  • 6.4.0-beta.1                                ...           7 days ago
  • 6.4.0-alpha.44-7ca77b8a9                                ...           13 days ago
  • 6.4.0-alpha.44-0ba07720d                                ...           a month ago
  • 6.4.0-alpha.44-93ecf63e7                                ...           a month ago
  • 6.4.0-alpha.44-3ccc10f82                                ...           a month ago
  • 6.4.0-alpha.44-4b3440325                                ...           a month ago
  • 6.4.0-alpha.44-ab1701579                                ...           a month ago
  • 6.3.2                                ...           a month ago
  • 6.4.0-alpha.44-8b0bbb2c4                                ...           a month ago
  • 6.4.0-alpha.44-72b0e9570                                ...           a month 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                                ...           2 months ago
  • 6.4.0-alpha.44-b05afd7e4                                ...           2 months ago
  • 6.4.0-alpha.44-ead2d6e88                                ...           2 months ago
  • 6.4.0-alpha.44-541981c34                                ...           2 months ago
  • 6.4.0-alpha.44-d8f86834d                                ...           2 months ago
  • 6.4.0-alpha.22-6a870513a                                ...           2 months ago
  • 6.4.0-alpha.22-09e793849                                ...           2 months ago
  • 6.4.0-alpha.44                                ...           2 months ago
  • 6.4.0-alpha.22-202c13623                                ...           2 months ago
  • 6.4.0-alpha.22-50a043f58                                ...           2 months ago
  • 6.4.0-alpha.22-5f4b5dfec                                ...           2 months ago
  • 6.4.0-alpha.22-83da3660d                                ...           2 months ago
  • 6.4.0-alpha.43                                ...           2 months ago
  • 6.4.0-alpha.42                                ...           2 months ago
  • 6.4.0-alpha.22-294eabda5                                ...           2 months ago
  • 6.4.0-alpha.22-794932963                                ...           2 months ago
  • 6.4.0-alpha.22-4ce814ba9                                ...           2 months ago
  • 6.4.0-alpha.41                                ...           2 months ago
  • 6.4.0-alpha.22-9d8792398                                ...           2 months ago
  • 6.4.0-alpha.40                                ...           2 months ago
  • 6.4.0-alpha.39                                ...           2 months ago
  • 6.4.0-alpha.38                                ...           2 months ago
  • 6.4.0-alpha.22-6fa617efd                                ...           2 months ago
  • 6.4.0-alpha.37                                ...           2 months ago
  • 6.4.0-alpha.36                                ...           2 months ago
  • 6.4.0-alpha.35                                ...           2 months ago
  • 6.4.0-alpha.34                                ...           2 months ago
  • 6.4.0-alpha.33                                ...           2 months ago
  • 6.4.0-alpha.22-c01bbf205                                ...           2 months ago
  • 6.4.0-alpha.22-996567ac4                                ...           2 months ago
  • 6.4.0-alpha.22-3145a1dd2                                ...           2 months ago
  • 6.4.0-alpha.22-6144c0f51                                ...           2 months ago
  • 6.4.0-alpha.22-0752a09f9                                ...           2 months ago
  • 6.4.0-alpha.32                                ...           2 months ago
  • 6.4.0-alpha.31                                ...           2 months ago
  • 6.4.0-alpha.30                                ...           2 months ago
  • 6.4.0-alpha.29                                ...           2 months ago
  • 6.4.0-alpha.22-b5ad2ebe9                                ...           2 months ago
  • 6.4.0-alpha.22-eac145983                                ...           2 months ago
  • 6.4.0-alpha.28                                ...           2 months ago
  • 6.4.0-alpha.27                                ...           2 months ago
  • 6.4.0-alpha.26                                ...           2 months ago
  • 6.4.0-alpha.25                                ...           2 months ago
  • 6.4.0-alpha.24                                ...           2 months ago
  • 6.4.0-alpha.22-9f415e84b                                ...           2 months ago
  • 6.4.0-alpha.22-06b43f6d4                                ...           2 months ago
  • 6.4.0-alpha.23                                ...           2 months ago
  • 6.4.0-alpha.22-3e0625ff3                                ...           2 months ago
  • 6.4.0-alpha.22-2c8809d3c                                ...           2 months ago
  • 6.4.0-alpha.12-c8498461a                                ...           2 months ago
  • 6.4.0-alpha.22                                ...           2 months ago
  • 6.4.0-alpha.21                                ...           2 months ago
  • 6.4.0-alpha.19                                ...           2 months ago
  • 6.4.0-alpha.18                                ...           2 months ago
  • 6.4.0-alpha.17                                ...           2 months ago
  • 6.4.0-alpha.16                                ...           2 months ago
  • 6.4.0-alpha.15                                ...           2 months ago
  • 6.4.0-alpha.12-c194ae1ba                                ...           2 months ago
  • 6.4.0-alpha.14                                ...           2 months ago
  • 6.4.0-alpha.12-5151b8ce0                                ...           2 months ago
  • 6.4.0-alpha.12-e56f98f03                                ...           2 months ago
  • 6.4.0-alpha.12-29c89de14                                ...           2 months ago
  • 6.4.0-alpha.12-de705229b                                ...           2 months ago
  • 6.4.0-alpha.12-ceaa30d88                                ...           2 months ago
  • 6.4.0-alpha.12                                ...           2 months ago
  • 6.4.0-alpha.11                                ...           2 months ago
  • 6.4.0-alpha.10                                ...           2 months ago
  • 6.4.0-alpha.9                                ...           2 months ago
  • 6.4.0-alpha.8                                ...           2 months ago
  • 6.4.0-alpha.7                                ...           2 months ago
  • 6.4.0-alpha.6                                ...           2 months ago
  • 6.4.0-alpha.5                                ...           2 months ago
  • 6.4.0-alpha.4                                ...           2 months ago
  • 6.4.0-alpha.3                                ...           2 months ago
  • 6.4.0-alpha.2                                ...           2 months ago
  • 6.3.0-alpha.40                                ...           2 months ago
  • 6.3.0-alpha.39                                ...           2 months ago
  • 6.3.0-alpha.38                                ...           2 months ago
  • 6.3.0-alpha.36                                ...           2 months ago
  • 6.3.0-alpha.35                                ...           2 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                                ...           3 months ago
  • 6.3.0-alpha.27                                ...           3 months ago
  • 6.3.0-alpha.26                                ...           3 months ago
  • 6.3.0-alpha.25                                ...           3 months ago
  • 6.3.0-alpha.24                                ...           3 months ago
  • 6.3.0-alpha.23                                ...           3 months ago
  • 6.3.0-alpha.22                                ...           3 months ago
  • 6.3.0-alpha.21                                ...           3 months ago
  • 6.3.0-alpha.20                                ...           3 months ago
  • 6.3.0-alpha.19                                ...           3 months ago
  • 6.3.0-alpha.18                                ...           3 months ago
  • 6.3.0-alpha.17                                ...           3 months ago
  • 6.3.0-alpha.16                                ...           3 months ago
  • 6.3.0-alpha.15                                ...           3 months ago
  • 6.3.0-alpha.14                                ...           3 months ago
  • 6.3.0-alpha.13                                ...           3 months ago
  • 6.3.0-alpha.12                                ...           3 months ago
  • 6.3.0-alpha.11                                ...           3 months ago
  • 6.3.0-alpha.10                                ...           3 months ago
  • 6.3.0-alpha.9                                ...           3 months ago
  • 6.3.0-alpha.8                                ...           3 months ago
  • 6.3.0-alpha.7                                ...           3 months ago
  • 6.3.0-alpha.6                                ...           3 months ago
  • 6.3.0-alpha.5                                ...           3 months ago
  • 6.3.0-alpha.4                                ...           3 months ago
  • 6.3.0-alpha.2                                ...           3 months ago
  • 6.3.0-alpha.3                                ...           3 months ago
  • 6.3.0-alpha.1                                ...           4 months ago
  • 6.3.0-alpha.0                                ...           4 months ago
Downloads
Today 21
This Week 76
This Month 1,224
Last Day 55
Last Week 342
Last Month 988
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |