@grafana/create-plugin 0.8.0 → 0.8.2-canary.182.820acd2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ # v0.8.1 (Tue Dec 13 2022)
2
+
3
+ :tada: This release contains work from a new contributor! :tada:
4
+
5
+ Thank you, Erik Sundell ([@sunker](https://github.com/sunker)), for all your work!
6
+
7
+ #### 🐛 Bug Fix
8
+
9
+ - Templates: Use getDefaultQuery method to set query default values [#173](https://github.com/grafana/plugin-tools/pull/173) ([@sunker](https://github.com/sunker))
10
+
11
+ #### Authors: 1
12
+
13
+ - Erik Sundell ([@sunker](https://github.com/sunker))
14
+
15
+ ---
16
+
1
17
  # v0.8.0 (Wed Nov 30 2022)
2
18
 
3
19
  #### 🚀 Enhancement
@@ -68,7 +68,7 @@ function default_1(plop) {
68
68
  name: 'pluginType',
69
69
  type: 'list',
70
70
  choices: [constants_1.PLUGIN_TYPES.app, constants_1.PLUGIN_TYPES.datasource, constants_1.PLUGIN_TYPES.panel],
71
- message: 'What kind of plugin would you like? '
71
+ message: 'What type of plugin would you like?'
72
72
  },
73
73
  {
74
74
  name: 'hasBackend',
@@ -196,6 +196,6 @@ function printSuccessMessage(answers) {
196
196
  ], (answers.hasBackend ? ['- `mage -v build:linux` to build the plugin backend code.'] : []), true), [
197
197
  '- Open http://localhost:3000 in your browser to create a dashboard to begin developing your plugin.',
198
198
  ], false);
199
- var msg = "\nCongratulations on scaffolding a Grafana ".concat(answers.pluginType, " plugin! \uD83D\uDE80\n\n## What's next?\n\nRun the following commands to get started:\n").concat(commands.map(function (command) { return command; }).join('\n'), "\n\n_Note: We strongly recommend creating a new Git repository by running `git init` in ./").concat(directory, " before continuing._\n\n- View ./").concat(directory, "/README.md\n- Learn more about Grafana Plugins at https://grafana.com/docs/grafana/latest/plugins/developing/development/\n");
199
+ var msg = "\nCongratulations on scaffolding a Grafana ".concat(answers.pluginType, " plugin! \uD83D\uDE80\n\n## What's next?\n\nRun the following commands to get started:\n").concat(commands.map(function (command) { return command; }).join('\n'), "\n\n_Note: We strongly recommend creating a new Git repository by running `git init` in ./").concat(directory, " before continuing._\n\n- View create-plugin documentation at https://grafana.github.io/plugin-tools/\n- Learn more about Grafana Plugins at https://grafana.com/docs/grafana/latest/plugins/developing/development/\n");
200
200
  return (0, utils_console_1.displayAsMarkdown)(msg);
201
201
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/create-plugin",
3
- "version": "0.8.0",
3
+ "version": "0.8.2-canary.182.820acd2.0",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "directory": "packages/create-plugin",
@@ -60,5 +60,5 @@
60
60
  "engines": {
61
61
  "node": ">=16"
62
62
  },
63
- "gitHead": "bb69dd167db675f1d90a1a31744b89bb0cd5ebc6"
63
+ "gitHead": "820acd28975420b9d0b38e143fa76c6e80e4cbe8"
64
64
  }
@@ -65,7 +65,7 @@ export default function (plop: NodePlopAPI) {
65
65
  name: 'pluginType',
66
66
  type: 'list',
67
67
  choices: [PLUGIN_TYPES.app, PLUGIN_TYPES.datasource, PLUGIN_TYPES.panel],
68
- message: 'What kind of plugin would you like? ',
68
+ message: 'What type of plugin would you like?',
69
69
  },
70
70
  {
71
71
  name: 'hasBackend',
@@ -268,7 +268,7 @@ ${commands.map((command) => command).join('\n')}
268
268
 
269
269
  _Note: We strongly recommend creating a new Git repository by running \`git init\` in ./${directory} before continuing._
270
270
 
271
- - View ./${directory}/README.md
271
+ - View create-plugin documentation at https://grafana.github.io/plugin-tools/
272
272
  - Learn more about Grafana Plugins at https://grafana.com/docs/grafana/latest/plugins/developing/development/
273
273
  `;
274
274
 
@@ -1,10 +1,14 @@
1
- import { DataSourceInstanceSettings } from '@grafana/data';
2
-
3
- import { MyQuery, MyDataSourceOptions } from './types';
1
+ import { DataSourceInstanceSettings, CoreApp } from '@grafana/data';
4
2
  import { DataSourceWithBackend } from '@grafana/runtime';
5
3
 
4
+ import { MyQuery, MyDataSourceOptions, DEFAULT_QUERY } from './types';
5
+
6
6
  export class DataSource extends DataSourceWithBackend<MyQuery, MyDataSourceOptions> {
7
7
  constructor(instanceSettings: DataSourceInstanceSettings<MyDataSourceOptions>) {
8
8
  super(instanceSettings);
9
9
  }
10
+
11
+ getDefaultQuery(_: CoreApp): Partial<MyQuery> {
12
+ return DEFAULT_QUERY
13
+ }
10
14
  }
@@ -21,21 +21,22 @@ export function hasReadme() {
21
21
  }
22
22
 
23
23
  export async function getEntries(): Promise<Record<string, string>> {
24
- const parent = '..';
25
- const pluginsJson = await globAsync('**/src/**/plugin.json');
26
-
27
- const plugins = await Promise.all(pluginsJson.map(pluginJson => {
28
- const folder = path.dirname(pluginJson);
29
- return globAsync(`${folder}/module.{ts,tsx,js}`);
30
- }));
24
+ const pluginsJson = await globAsync('**/src/**/plugin.json', { absolute: true });
25
+
26
+ const plugins = await Promise.all(pluginsJson.map((pluginJson) => {
27
+ const folder = path.dirname(pluginJson);
28
+ return globAsync(`${folder}/module.{ts,tsx,js}`, { absolute: true });
29
+ })
30
+ );
31
31
 
32
32
  return plugins.reduce((result, modules) => {
33
33
  return modules.reduce((result, module) => {
34
- const pluginPath = path.resolve(path.dirname(module), parent);
34
+ const pluginPath = path.dirname(module);
35
35
  const pluginName = path.basename(pluginPath);
36
- const entryName = plugins.length > 1 ? `${pluginName}/module` : 'module';
37
-
38
- result[entryName] = path.join(parent, module);
36
+ // support bundling nested plugins
37
+ const entryName = pluginName === 'src' ? 'module' : `${pluginName}/module`;
38
+
39
+ result[entryName] = module;
39
40
  return result;
40
41
  }, result);
41
42
  }, {});
@@ -1,10 +1,8 @@
1
- import defaults from 'lodash/defaults';
2
-
3
1
  import React, { ChangeEvent, PureComponent } from 'react';
4
2
  import { LegacyForms } from '@grafana/ui';
5
3
  import { QueryEditorProps } from '@grafana/data';
6
4
  import { DataSource } from '../datasource';
7
- import { defaultQuery, MyDataSourceOptions, MyQuery } from '../types';
5
+ import { MyDataSourceOptions, MyQuery } from '../types';
8
6
 
9
7
  const { FormField } = LegacyForms;
10
8
 
@@ -24,8 +22,7 @@ export class QueryEditor extends PureComponent<Props> {
24
22
  };
25
23
 
26
24
  render() {
27
- const query = defaults(this.props.query, defaultQuery);
28
- const { queryText, constant } = query;
25
+ const { queryText, constant } = this.props.query;
29
26
 
30
27
  return (
31
28
  <div className="gf-form">
@@ -1,5 +1,3 @@
1
- import defaults from 'lodash/defaults';
2
-
3
1
  import {
4
2
  DataQueryRequest,
5
3
  DataQueryResponse,
@@ -9,7 +7,7 @@ import {
9
7
  FieldType,
10
8
  } from '@grafana/data';
11
9
 
12
- import { MyQuery, MyDataSourceOptions, defaultQuery } from './types';
10
+ import { MyQuery, MyDataSourceOptions, DEFAULT_QUERY } from './types';
13
11
 
14
12
  export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
15
13
  constructor(instanceSettings: DataSourceInstanceSettings<MyDataSourceOptions>) {
@@ -23,12 +21,11 @@ export class DataSource extends DataSourceApi<MyQuery, MyDataSourceOptions> {
23
21
 
24
22
  // Return a constant for each query.
25
23
  const data = options.targets.map((target) => {
26
- const query = defaults(target, defaultQuery);
27
24
  return new MutableDataFrame({
28
- refId: query.refId,
25
+ refId: target.refId,
29
26
  fields: [
30
27
  { name: 'Time', values: [from, to], type: FieldType.time },
31
- { name: 'Value', values: [query.constant, query.constant], type: FieldType.number },
28
+ { name: 'Value', values: [target.constant, target.constant], type: FieldType.number },
32
29
  ],
33
30
  });
34
31
  });
@@ -5,7 +5,7 @@ export interface MyQuery extends DataQuery {
5
5
  constant: number;
6
6
  }
7
7
 
8
- export const defaultQuery: Partial<MyQuery> = {
8
+ export const DEFAULT_QUERY: Partial<MyQuery> = {
9
9
  constant: 6.5,
10
10
  };
11
11