Grafana Toolkit is a deprecated CLI tool that was designed to enable efficient development of Grafana plugins. Originally created to help the Grafana community focus on the core value of their plugins rather than the setup required to develop them, it provided commands for plugin creation, building, and signing. However, all functionality has been migrated to newer tools in the Grafana plugin ecosystem.
npm install @grafana/toolkitAs a CLI tool, @grafana/toolkit is primarily used via command line interface rather than programmatic imports. Due to the package structure, the programmatic API would need to be imported directly from the CLI module:
import { run } from "@grafana/toolkit/src/cli/index";For CommonJS:
const { run } = require("@grafana/toolkit/src/cli/index");Note: The package.json specifies "main": "src/index.ts" but this file does not exist. The primary interface is the CLI binary.
The tool is typically used as a CLI binary:
# Check version (only working command)
npx @grafana/toolkit --version
# All other commands are deprecated and will display migration instructions
npx @grafana/toolkit plugin:create my-plugin
npx @grafana/toolkit plugin:build
npx @grafana/toolkit plugin:signFor programmatic usage (if needed):
import { run } from "@grafana/toolkit/src/cli/index";
// Run with external scripts disabled (default)
run();
// Run with internal scripts enabled (development mode)
run(true);Grafana Toolkit is structured as a command-line interface built around several core components:
bin/grafana-toolkit.js detects development vs production mode and delegates to the TypeScript CLI handlerThe execution flow:
All plugin functionality has been migrated to newer tools:
grafana create-plugin from https://github.com/grafana/plugin-tools/tree/main/packages/create-plugin/grafana sign-plugin from https://github.com/grafana/plugin-tools/tree/main/packages/sign-pluginMain CLI entry point that sets up and handles all command-line operations.
/**
* Main CLI entry point that sets up and parses commands
* @param includeInternalScripts - Whether to include internal/debug scripts
*/
function run(includeInternalScripts?: boolean): void;Display the toolkit version.
grafana-toolkit --version
grafana-toolkit -vThis is the only actively working command that returns version information.
All plugin-related commands are deprecated and redirect users to new tools:
grafana-toolkit plugin:create [name]Status: Removed - redirects to grafana create-plugin
grafana-toolkit plugin:build [options]Options:
--maxJestWorkers <num>|<string>: Limit number of Jest workers spawned--coverage: Run code coverage (default: false)--skipTest: Skip running tests for pipelines that run it separately (default: false)--skipLint: Skip running lint for pipelines that run it separately (default: false)--preserveConsole: Preserves console calls (default: false)Status: Removed - redirects to grafana create-plugin
grafana-toolkit plugin:sign [options]Options:
--signatureType <type>: Signature Type--rootUrls <urls...>: Root URLs (accepts multiple values or comma-separated string)Status: Removed - redirects to grafana sign-plugin
These are internal utility functions used by the CLI but available for programmatic access:
/**
* Reads and returns toolkit version from package.json
* @returns The version string from package.json
* @throws string - "Could not find the toolkit version" if version not found
*/
function getToolkitVersion(): string;Import from: @grafana/toolkit/src/cli/tasks/plugin.utils
The toolkit includes a task execution framework for internal operations:
/**
* Generic task runner function type
*/
type TaskRunner<T> = (options: T) => Promise<any>;
/**
* Task execution class for managing task lifecycle
*/
class Task<TOptions> {
options: TOptions;
name: string;
runner: TaskRunner<TOptions>;
constructor(name: string, runner: TaskRunner<TOptions>);
/** Set the task name */
setName(name: string): void;
/** Set the task runner function */
setRunner(runner: TaskRunner<TOptions>): void;
/** Set task options */
setOptions(options: TOptions): void;
/** Execute the task with current options */
exec(): Promise<any>;
}
/**
* Execute a task with error handling and logging
*/
function execTask<TOptions>(task: Task<TOptions>):
(options: TOptions & TaskBasicOptions) => Promise<void>;
/**
* Basic options for task execution
*/
interface TaskBasicOptions {
/** Don't print task details when running */
silent?: boolean;
}Import Task and TaskRunner from: @grafana/toolkit/src/cli/tasks/task
Import execTask from: @grafana/toolkit/src/cli/utils/execTask
Import TaskBasicOptions from: @grafana/toolkit/src/cli/utils/execTask
When includeInternalScripts is enabled, additional debug commands are available:
grafana-toolkit debug:templateThis is used for internal testing and development.
/**
* Legacy task function type for backward compatibility
* Note: This type is defined in src/cli/index.d.ts for compatibility
* but is separate from the current Task execution framework
*/
type Task<T> = (options: T) => Promise<void>;
/**
* Task runner function type for the current execution framework
*/
type TaskRunner<T> = (options: T) => Promise<any>;
/**
* Options interface for template tasks
*/
interface TemplateOptions {}
/**
* Basic options available for all task executions
*/
interface TaskBasicOptions {
/** Don't print task details when running */
silent?: boolean;
}
/**
* Task execution class for managing task lifecycle
* This is the current implementation used by the task framework
*/
class Task<TOptions> {
options: TOptions;
name: string;
runner: TaskRunner<TOptions>;
}The package provides a CLI binary at bin/grafana-toolkit.js that:
src/cli/index.tsAll deprecated commands will:
The task execution framework includes comprehensive error handling with:
Runtime Dependencies:
The toolkit uses Commander.js for CLI functionality and Chalk for colored terminal output. TypeScript compilation is handled via ts-node in development mode.