or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

index.mddocs/

Grafana Toolkit

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.

Package Information

  • Package Name: @grafana/toolkit
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @grafana/toolkit
  • Status: DEPRECATED - All functionality migrated to newer tools

Core Imports

As 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.

Basic Usage

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:sign

For 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);

Architecture

Grafana Toolkit is structured as a command-line interface built around several core components:

  • CLI Entry Point: bin/grafana-toolkit.js detects development vs production mode and delegates to the TypeScript CLI handler
  • Command Parser: Uses Commander.js to define and parse CLI commands with support for options and arguments
  • Task Execution Framework: Modular system for running tasks with error handling, logging, and lifecycle management
  • Mode Detection: Automatic detection of linked/development mode vs production mode for appropriate execution context
  • Migration Layer: All plugin commands are deprecated and redirect users to new tooling with helpful migration messages

The execution flow:

  1. Binary entry point detects execution mode (linked/production)
  2. Uses ts-node for TypeScript execution in development mode, compiled JavaScript in production
  3. CLI handler registers commands and parses arguments
  4. Commands either show version info or display migration messages for deprecated functionality
  5. Task framework handles execution with comprehensive error handling and console output grouping

Migration Information

All plugin functionality has been migrated to newer tools:

  • Plugin Creation: Use grafana create-plugin from https://github.com/grafana/plugin-tools/tree/main/packages/create-plugin/
  • Plugin Signing: Use grafana sign-plugin from https://github.com/grafana/plugin-tools/tree/main/packages/sign-plugin
  • Plugin Building: Use tools from the plugin-tools repository

Capabilities

CLI Interface

Main 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;

Version Command

Display the toolkit version.

grafana-toolkit --version
grafana-toolkit -v

This is the only actively working command that returns version information.

Deprecated Plugin Commands

All plugin-related commands are deprecated and redirect users to new tools:

Plugin Creation (Deprecated)

grafana-toolkit plugin:create [name]

Status: Removed - redirects to grafana create-plugin

Plugin Building (Deprecated)

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

Plugin Signing (Deprecated)

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

Internal Utilities

These are internal utility functions used by the CLI but available for programmatic access:

Version Utility

/**
 * 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

Task Execution Framework

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

Internal Commands

When includeInternalScripts is enabled, additional debug commands are available:

grafana-toolkit debug:template

This is used for internal testing and development.

Types

/**
 * 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>;
}

Binary Entry Point

The package provides a CLI binary at bin/grafana-toolkit.js that:

  1. Detects if running in linked/development mode vs production mode
  2. Uses ts-node for TypeScript execution in development mode
  3. Uses compiled JavaScript in production mode
  4. Delegates to the main CLI handler in src/cli/index.ts

Error Handling

All deprecated commands will:

  1. Display appropriate migration messages
  2. Exit with status code 1
  3. Direct users to the correct replacement tools

The task execution framework includes comprehensive error handling with:

  • Console tracing for debugging
  • Automatic process exit on task failures
  • Grouped console output for better readability

Dependencies

Runtime Dependencies:

  • @grafana/tsconfig: ^1.2.0-rc1
  • @types/node: 16.11.26
  • chalk: ^4.1.2 (for colored console output)
  • commander: ^9.2.0 (for CLI command parsing)
  • ts-node: ^9.1.0 (for TypeScript execution)
  • tslib: 2.5.0
  • typescript: 4.8.2

The toolkit uses Commander.js for CLI functionality and Chalk for colored terminal output. TypeScript compilation is handled via ts-node in development mode.