CLI 命令
下方是 @grafana/create-plugin
中可用的命令。
create-plugin
使用 create-plugin
命令来搭建插件骨架。
- npm
- Yarn
- pnpm
npx @grafana/create-plugin@latest
yarn dlx @grafana/create-plugin@latest
pnpm dlx @grafana/create-plugin@latest
运行 create-plugin
命令时,会出现以下提示
选择插件类型
? Select a plugin type …
❯ App (add custom pages, UI extensions and bundle other plugins)
Data source (query data from a custom source)
Panel (add a visualization for data or a widget)
App with Scenes (create dynamic dashboards in app pages)
要了解不同类型的插件,请参阅Grafana 插件类型和用法。
有关 Scenes 如何让您在应用程序插件中创建类似仪表盘的体验的更多信息,请参阅Scenes 文档。
添加后端以支持服务器端功能?(y/N)
如果您正在创建应用程序或数据源插件,系统会询问您是否额外添加后端组件。
后端插件提供强大的功能,例如
- 为数据源启用Grafana 告警。
- 连接到浏览器通常无法连接的非 HTTP 服务。例如,SQL 数据库服务器。
- 在用户之间保持状态。例如,数据源的查询缓存。
- 使用 Grafana 不支持的自定义认证方法和/或授权检查。
- 使用自定义数据源请求代理。
要了解更多信息,请参阅后端插件。
输入插件名称
为您的插件命名,以便更容易识别其用途。
输入您的组织名称(通常是您的 Grafana Cloud 组织)
输入您的组织名称。这必须是您的Grafana Cloud 组织。使用组织名称,您可以签署插件,并可选择将其发布到Grafana 插件目录。
跳过提示
您可以使用 create-plugin
CLI 参数跳过所有前面的提示。要使用 CLI 参数搭建插件骨架,请将它们传递给 create-plugin
命令,如下所示
npx @grafana/create-plugin \
--plugin-type="app" \
--plugin-name="myPlugin" \
--org-name="myorg" \
--backend
您可以使用 CLI 参数搭建插件骨架,以便更快地开始。使用参数还允许您在非交互式环境(例如 CI)中运行该工具,或使用其他工具搭建插件骨架。
请参阅下表,了解完整的提示跳过选项列表
提示 | 等效参数名称 | 值 |
---|---|---|
插件类型 | --plugin-type | app 、datasource 、panel 或 scenesapp 之一 |
后端 | --backend / --no-backend | 布尔值 |
名称 | --plugin-name | 字符串 |
组织 | --org-name | 字符串 |
update
要将现有插件更新到最新版本的 create-plugin
工具,请从插件的根目录运行以下命令
- npm
- Yarn
- pnpm
npx @grafana/create-plugin@latest update
yarn dlx @grafana/create-plugin@latest update
pnpm dlx @grafana/create-plugin@latest update
此命令更新以下内容
/.config
- 用于构建插件的配置文件- NPM 依赖项 - 依赖项(主要用于支持最新的 Grafana 版本和构建更新)
- NPM 脚本 - 构建相关脚本的任何更新
update --force
默认情况下,如果仓库中有任何未提交的更改,update
命令将停止。如果要强制更新,可以使用 --force
标志
- npm
- Yarn
- pnpm
npx @grafana/create-plugin@latest update --force
yarn dlx @grafana/create-plugin@latest update --force
pnpm dlx @grafana/create-plugin@latest update --force