@grafana/create-plugin 0.3.1 → 0.4.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.
@@ -86,10 +86,10 @@ var migrate = function () { return __awaiter(void 0, void 0, void 0, function ()
86
86
  _a.label = 5;
87
87
  case 5:
88
88
  if (!(0, utils_npm_1.hasNpmDependenciesToUpdate)()) return [3, 7];
89
- return [4, (0, utils_console_1.confirmPrompt)(constants_1.TEXT.updateNpmDependenciesPrompt + (0, utils_npm_1.getPackageJsonUpdatesAsText)())];
89
+ return [4, (0, utils_console_1.confirmPrompt)(constants_1.TEXT.updateNpmDependenciesPrompt + (0, utils_npm_1.getPackageJsonUpdatesAsText)({ ignoreGrafanaDependencies: true }))];
90
90
  case 6:
91
91
  if (_a.sent()) {
92
- (0, utils_npm_1.updatePackageJson)();
92
+ (0, utils_npm_1.updatePackageJson)({ ignoreGrafanaDependencies: true });
93
93
  (0, utils_console_1.printSuccessMessage)(constants_1.TEXT.updateNpmDependenciesSuccess);
94
94
  }
95
95
  else {
package/dist/constants.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  exports.__esModule = true;
6
- exports.TEXT = exports.UDPATE_CONFIG = exports.MIGRATION_CONFIG = exports.EXTRA_TEMPLATE_VARIABLES = exports.PLUGIN_TYPES = exports.TEMPLATE_PATHS = exports.FIXTURES_PATH = exports.PARTIALS_DIR = exports.TEMPLATES_DIR = exports.DIST_DIR = exports.EXPORT_PATH_PREFIX = exports.DEV_EXPORT_DIR = exports.IS_DEV = void 0;
6
+ exports.TEXT = exports.UDPATE_CONFIG = exports.MIGRATION_CONFIG = exports.GRAFANA_FE_PACKAGES = exports.EXTRA_TEMPLATE_VARIABLES = exports.PLUGIN_TYPES = exports.TEMPLATE_PATHS = exports.FIXTURES_PATH = exports.PARTIALS_DIR = exports.TEMPLATES_DIR = exports.DIST_DIR = exports.EXPORT_PATH_PREFIX = exports.DEV_EXPORT_DIR = exports.IS_DEV = void 0;
7
7
  var path_1 = __importDefault(require("path"));
8
8
  exports.IS_DEV = process.env.CREATE_PLUGIN_DEV !== undefined;
9
9
  exports.DEV_EXPORT_DIR = path_1["default"].join(__dirname, '..', 'generated');
@@ -31,6 +31,14 @@ var PLUGIN_TYPES;
31
31
  exports.EXTRA_TEMPLATE_VARIABLES = {
32
32
  grafanaVersion: '9.1.2'
33
33
  };
34
+ exports.GRAFANA_FE_PACKAGES = [
35
+ '@grafana/data',
36
+ '@grafana/e2e-selectors',
37
+ '@grafana/e2e',
38
+ '@grafana/runtime',
39
+ '@grafana/schema',
40
+ '@grafana/ui',
41
+ ];
34
42
  exports.MIGRATION_CONFIG = {
35
43
  filesToOverride: [
36
44
  '.config/',
@@ -37,12 +37,16 @@ function writePackageJson(json) {
37
37
  exports.writePackageJson = writePackageJson;
38
38
  function getNpmDependencyUpdatesAsText(dependencyUpdates) {
39
39
  return Object.entries(dependencyUpdates)
40
+ .filter(function (_a) {
41
+ var packageName = _a[0], _b = _a[1], prev = _b.prev, next = _b.next;
42
+ return prev !== next;
43
+ })
40
44
  .map(function (_a) {
41
45
  var packageName = _a[0], _b = _a[1], prev = _b.prev, next = _b.next;
42
46
  if (!prev) {
43
47
  return "`".concat(packageName, "` - `").concat(next, "` (new)");
44
48
  }
45
- return "`".concat(packageName, "` - `").concat(prev, "` -> `").concat(next, "`");
49
+ return "`".concat(packageName, "` - `").concat(prev, "` -> `").concat(next, "` (updated)");
46
50
  })
47
51
  .join('\n ');
48
52
  }
@@ -94,12 +98,42 @@ function getPackageJsonUpdates(options) {
94
98
  var newDevDependencies = newPackageJson.devDependencies || {};
95
99
  var dependencyUpdates = getUpdatableNpmDependencies(dependencies, newDependencies, options);
96
100
  var devDependencyUpdates = getUpdatableNpmDependencies(devDependencies, newDevDependencies, options);
101
+ if (options.ignoreGrafanaDependencies) {
102
+ var prevGrafanaDependencies = Object.entries(__assign(__assign({}, dependencies), devDependencies)).reduce(function (acc, _a) {
103
+ var key = _a[0], value = _a[1];
104
+ if (constants_1.GRAFANA_FE_PACKAGES.includes(key)) {
105
+ acc[key] = value;
106
+ }
107
+ return acc;
108
+ }, {});
109
+ return {
110
+ dependencyUpdates: ignoreGrafanaDependencies(dependencyUpdates, prevGrafanaDependencies),
111
+ devDependencyUpdates: ignoreGrafanaDependencies(devDependencyUpdates, prevGrafanaDependencies)
112
+ };
113
+ }
97
114
  return {
98
115
  dependencyUpdates: dependencyUpdates,
99
116
  devDependencyUpdates: devDependencyUpdates
100
117
  };
101
118
  }
102
119
  exports.getPackageJsonUpdates = getPackageJsonUpdates;
120
+ function ignoreGrafanaDependencies(dependencyUpdates, prevGrafanaDependencies) {
121
+ var whatever = Object.keys(prevGrafanaDependencies);
122
+ var result = Object.entries(dependencyUpdates).reduce(function (acc, _a) {
123
+ var packageName = _a[0], value = _a[1];
124
+ if (whatever.includes(packageName)) {
125
+ acc[packageName] = {
126
+ prev: prevGrafanaDependencies[packageName],
127
+ next: prevGrafanaDependencies[packageName]
128
+ };
129
+ }
130
+ else {
131
+ acc[packageName] = value;
132
+ }
133
+ return acc;
134
+ }, {});
135
+ return result;
136
+ }
103
137
  function getUpdatableNpmDependencies(prevDeps, nextDeps, options) {
104
138
  if (options === void 0) { options = {}; }
105
139
  var updateSummary = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/create-plugin",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "directory": "packages/create-plugin",
@@ -58,8 +58,12 @@ export const migrate = async () => {
58
58
  // (skipped automatically if there is nothing to update)
59
59
  // ------------------------------------------------
60
60
  if (hasNpmDependenciesToUpdate()) {
61
- if (await confirmPrompt(TEXT.updateNpmDependenciesPrompt + getPackageJsonUpdatesAsText())) {
62
- updatePackageJson();
61
+ if (
62
+ await confirmPrompt(
63
+ TEXT.updateNpmDependenciesPrompt + getPackageJsonUpdatesAsText({ ignoreGrafanaDependencies: true })
64
+ )
65
+ ) {
66
+ updatePackageJson({ ignoreGrafanaDependencies: true });
63
67
  printSuccessMessage(TEXT.updateNpmDependenciesSuccess);
64
68
  } else {
65
69
  printMessage(TEXT.updateNpmDependenciesAborted);
package/src/constants.ts CHANGED
@@ -40,6 +40,15 @@ export const EXTRA_TEMPLATE_VARIABLES = {
40
40
  grafanaVersion: '9.1.2',
41
41
  };
42
42
 
43
+ export const GRAFANA_FE_PACKAGES = [
44
+ '@grafana/data',
45
+ '@grafana/e2e-selectors',
46
+ '@grafana/e2e',
47
+ '@grafana/runtime',
48
+ '@grafana/schema',
49
+ '@grafana/ui',
50
+ ];
51
+
43
52
  export const MIGRATION_CONFIG = {
44
53
  // Files that should be overriden during a migration.
45
54
  // (paths are relative to the scaffolded projects root)
@@ -3,12 +3,13 @@ import fs from 'fs';
3
3
  import semver from 'semver';
4
4
  import { readJsonFile } from './utils.files';
5
5
  import { renderTemplateFromFile, getTemplateData } from './utils.templates';
6
- import { TEMPLATE_PATHS } from '../constants';
6
+ import { GRAFANA_FE_PACKAGES, TEMPLATE_PATHS } from '../constants';
7
7
 
8
8
  type UpdateSummary = Record<string, { prev: string | null; next: string | null }>;
9
9
 
10
10
  type UpdateOptions = {
11
11
  onlyOutdated?: Boolean;
12
+ ignoreGrafanaDependencies?: boolean;
12
13
  };
13
14
 
14
15
  type PackageJson = {
@@ -35,6 +36,7 @@ export function writePackageJson(json: PackageJson) {
35
36
 
36
37
  export function getNpmDependencyUpdatesAsText(dependencyUpdates: UpdateSummary) {
37
38
  return Object.entries(dependencyUpdates)
39
+ .filter(([packageName, { prev, next }]) => prev !== next)
38
40
  .map(([packageName, { prev, next }]) => {
39
41
  // New package
40
42
  if (!prev) {
@@ -42,7 +44,7 @@ export function getNpmDependencyUpdatesAsText(dependencyUpdates: UpdateSummary)
42
44
  }
43
45
 
44
46
  // Updated package
45
- return `\`${packageName}\` - \`${prev}\` -> \`${next}\``;
47
+ return `\`${packageName}\` - \`${prev}\` -> \`${next}\` (updated)`;
46
48
  })
47
49
  .join('\n ');
48
50
  }
@@ -100,12 +102,44 @@ export function getPackageJsonUpdates(options: UpdateOptions = {}) {
100
102
  const dependencyUpdates = getUpdatableNpmDependencies(dependencies, newDependencies, options);
101
103
  const devDependencyUpdates = getUpdatableNpmDependencies(devDependencies, newDevDependencies, options);
102
104
 
105
+ if (options.ignoreGrafanaDependencies) {
106
+ const prevGrafanaDependencies = Object.entries({ ...dependencies, ...devDependencies }).reduce<
107
+ Record<string, string>
108
+ >((acc, [key, value]) => {
109
+ if (GRAFANA_FE_PACKAGES.includes(key)) {
110
+ acc[key] = value;
111
+ }
112
+ return acc;
113
+ }, {});
114
+ return {
115
+ dependencyUpdates: ignoreGrafanaDependencies(dependencyUpdates, prevGrafanaDependencies),
116
+ devDependencyUpdates: ignoreGrafanaDependencies(devDependencyUpdates, prevGrafanaDependencies),
117
+ };
118
+ }
119
+
103
120
  return {
104
121
  dependencyUpdates,
105
122
  devDependencyUpdates,
106
123
  };
107
124
  }
108
125
 
126
+ function ignoreGrafanaDependencies(dependencyUpdates: UpdateSummary, prevGrafanaDependencies: Record<string, string>) {
127
+ const whatever = Object.keys(prevGrafanaDependencies);
128
+ const result = Object.entries(dependencyUpdates).reduce<UpdateSummary>((acc, [packageName, value]) => {
129
+ if (whatever.includes(packageName)) {
130
+ acc[packageName] = {
131
+ prev: prevGrafanaDependencies[packageName],
132
+ next: prevGrafanaDependencies[packageName],
133
+ };
134
+ } else {
135
+ acc[packageName] = value;
136
+ }
137
+ return acc;
138
+ }, {});
139
+
140
+ return result;
141
+ }
142
+
109
143
  export function getUpdatableNpmDependencies(
110
144
  prevDeps: Record<string, string>,
111
145
  nextDeps: Record<string, string>,
@@ -4,7 +4,7 @@ import { AppConfig } from './components/AppConfig';
4
4
 
5
5
  export const plugin = new AppPlugin<{}>().setRootPage(App).addConfigPage({
6
6
  title: 'Configuration',
7
- icon: 'fa fa-cog',
7
+ icon: 'cog',
8
8
  // @ts-ignore - Would expect a Class component, however works absolutely fine with a functional one
9
9
  // Implementation: https://github.com/grafana/grafana/blob/fd44c01675e54973370969dfb9e78f173aff7910/public/app/features/plugins/PluginPage.tsx#L157
10
10
  body: AppConfig,
@@ -4,9 +4,12 @@
4
4
  * In order to extend the configuration follow the steps in .config/README.md
5
5
  */
6
6
 
7
+ const path = require('path');
8
+
7
9
  module.exports = {
8
10
  moduleNameMapper: {
9
11
  "\\.(css|scss|sass)$": "identity-obj-proxy",
12
+ "react-inlinesvg": path.resolve(__dirname, "mocks", "react-inlinesvg.tsx"),
10
13
  },
11
14
  modulePaths: ['<rootDir>/src'],
12
15
  setupFilesAfterEnv: ['<rootDir>/jest-setup.js'],
@@ -32,7 +35,5 @@ module.exports = {
32
35
  },
33
36
  ],
34
37
  },
35
- transformIgnorePatterns: [
36
- 'node_modules/(?!(ol)/)', // <- exclude the open layers library
37
- ],
38
+ transformIgnorePatterns: [],
38
39
  };
@@ -0,0 +1,25 @@
1
+ // Due to the grafana/ui Icon component making fetch requests to
2
+ // `/public/img/icon/<icon_name>.svg` we need to mock react-inlinesvg to prevent
3
+ // the failed fetch requests from displaying errors in console.
4
+
5
+ import React from 'react';
6
+
7
+ type Callback = (...args: any[]) => void;
8
+
9
+ export interface StorageItem {
10
+ content: string;
11
+ queue: Callback[];
12
+ status: string;
13
+ }
14
+
15
+ export const cacheStore: { [key: string]: StorageItem } = Object.create(null);
16
+
17
+ const SVG_FILE_NAME_REGEX = /(.+)\/(.+)\.svg$/;
18
+
19
+ const InlineSVG = ({ src }: { src: string }) => {
20
+ // testId will be the file name without extension (e.g. `public/img/icons/angle-double-down.svg` -> `angle-double-down`)
21
+ const testId = src.replace(SVG_FILE_NAME_REGEX, '$2');
22
+ return <svg xmlns="http://www.w3.org/2000/svg" data-testid={testId} viewBox="0 0 24 24" />;
23
+ };
24
+
25
+ export default InlineSVG;
@@ -5,26 +5,28 @@ on:
5
5
  push:
6
6
  branches:
7
7
  - master
8
+ - main
8
9
  pull_request:
9
10
  branches:
10
11
  - master
12
+ - main
11
13
  jobs:
12
14
  build:
13
15
  runs-on: ubuntu-latest
14
16
  steps:
15
- - uses: actions/checkout@v2
17
+ - uses: actions/checkout@v3
16
18
 
17
19
  - name: Setup Node.js environment
18
- uses: actions/setup-node@v2.1.2
20
+ uses: actions/setup-node@v3
19
21
  with:
20
22
  node-version: '16.x'
21
23
 
22
24
  - name: Get yarn cache directory path
23
25
  id: yarn-cache-dir-path
24
- run: echo "::set-output name=dir::$(yarn cache dir)"
26
+ run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
25
27
 
26
28
  - name: Cache yarn cache
27
- uses: actions/cache@v2
29
+ uses: actions/cache@v3
28
30
  id: cache-yarn-cache
29
31
  with:
30
32
  path: $\{{ steps.yarn-cache-dir-path.outputs.dir }}
@@ -34,7 +36,7 @@ jobs:
34
36
 
35
37
  - name: Cache node_modules
36
38
  id: cache-node-modules
37
- uses: actions/cache@v2
39
+ uses: actions/cache@v3
38
40
  with:
39
41
  path: node_modules
40
42
  key: $\{{ runner.os }}-$\{{ matrix.node-version }}-nodemodules-$\{{ hashFiles('**/yarn.lock') }}
@@ -61,12 +63,12 @@ jobs:
61
63
  run: |
62
64
  if [ -f "Magefile.go" ]
63
65
  then
64
- echo "::set-output name=has-backend::true"
66
+ echo "has-backend=true" >> $GITHUB_OUTPUT
65
67
  fi
66
68
 
67
69
  - name: Setup Go environment
68
70
  if: steps.check-for-backend.outputs.has-backend == 'true'
69
- uses: actions/setup-go@v2
71
+ uses: actions/setup-go@v3
70
72
  with:
71
73
  go-version: '1.19'
72
74
 
@@ -11,24 +11,24 @@ jobs:
11
11
  runs-on: ubuntu-latest
12
12
 
13
13
  steps:
14
- - uses: actions/checkout@v2
14
+ - uses: actions/checkout@v3
15
15
 
16
16
  - name: Setup Node.js environment
17
- uses: actions/setup-node@v2.1.2
17
+ uses: actions/setup-node@v3
18
18
  with:
19
19
  node-version: '16.x'
20
20
 
21
21
  - name: Setup Go environment
22
- uses: actions/setup-go@v2
22
+ uses: actions/setup-go@v3
23
23
  with:
24
- go-version: '1.15'
24
+ go-version: '1.19'
25
25
 
26
26
  - name: Get yarn cache directory path
27
27
  id: yarn-cache-dir-path
28
- run: echo "::set-output name=dir::$(yarn cache dir)"
28
+ run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
29
29
 
30
30
  - name: Cache yarn cache
31
- uses: actions/cache@v2
31
+ uses: actions/cache@v3
32
32
  id: cache-yarn-cache
33
33
  with:
34
34
  path: $\{{ steps.yarn-cache-dir-path.outputs.dir }}
@@ -38,7 +38,7 @@ jobs:
38
38
 
39
39
  - name: Cache node_modules
40
40
  id: cache-node-modules
41
- uses: actions/cache@v2
41
+ uses: actions/cache@v3
42
42
  with:
43
43
  path: node_modules
44
44
  key: $\{{ runner.os }}-$\{{ matrix.node-version }}-nodemodules-$\{{ hashFiles('**/yarn.lock') }}
@@ -59,7 +59,7 @@ jobs:
59
59
  run: |
60
60
  if [ -f "Magefile.go" ]
61
61
  then
62
- echo "::set-output name=has-backend::true"
62
+ echo "has-backend=true" >> $GITHUB_OUTPUT
63
63
  fi
64
64
 
65
65
  - name: Test backend
@@ -92,19 +92,19 @@ jobs:
92
92
  export GRAFANA_PLUGIN_ARTIFACT=${GRAFANA_PLUGIN_ID}-${GRAFANA_PLUGIN_VERSION}.zip
93
93
  export GRAFANA_PLUGIN_ARTIFACT_CHECKSUM=${GRAFANA_PLUGIN_ARTIFACT}.md5
94
94
 
95
- echo "::set-output name=plugin-id::${GRAFANA_PLUGIN_ID}"
96
- echo "::set-output name=plugin-version::${GRAFANA_PLUGIN_VERSION}"
97
- echo "::set-output name=plugin-type::${GRAFANA_PLUGIN_TYPE}"
98
- echo "::set-output name=archive::${GRAFANA_PLUGIN_ARTIFACT}"
99
- echo "::set-output name=archive-checksum::${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}"
95
+ echo "plugin-id=${GRAFANA_PLUGIN_ID}" >> $GITHUB_OUTPUT
96
+ echo "plugin-version=${GRAFANA_PLUGIN_VERSION}" >> $GITHUB_OUTPUT
97
+ echo "plugin-type=${GRAFANA_PLUGIN_TYPE}" >> $GITHUB_OUTPUT
98
+ echo "archive=${GRAFANA_PLUGIN_ARTIFACT}" >> $GITHUB_OUTPUT
99
+ echo "archive-checksum=${GRAFANA_PLUGIN_ARTIFACT_CHECKSUM}" >> $GITHUB_OUTPUT
100
100
 
101
- echo ::set-output name=github-tag::${GITHUB_REF#refs/*/}
101
+ echo "github-tag=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
102
102
 
103
103
  - name: Read changelog
104
104
  id: changelog
105
105
  run: |
106
106
  awk '/^## / {s++} s == 1 {print}' CHANGELOG.md > release_notes.md
107
- echo "::set-output name=path::release_notes.md"
107
+ echo "path=release_notes.md" >> $GITHUB_OUTPUT
108
108
 
109
109
  - name: Check package version
110
110
  run: if [ "v$\{{ steps.metadata.outputs.plugin-version }}" != "$\{{ steps.metadata.outputs.github-tag }}" ]; then printf "\033[0;31mPlugin version doesn't match tag name\033[0m\n"; exit 1; fi
@@ -115,7 +115,7 @@ jobs:
115
115
  mv dist $\{{ steps.metadata.outputs.plugin-id }}
116
116
  zip $\{{ steps.metadata.outputs.archive }} $\{{ steps.metadata.outputs.plugin-id }} -r
117
117
  md5sum $\{{ steps.metadata.outputs.archive }} > $\{{ steps.metadata.outputs.archive-checksum }}
118
- echo "::set-output name=checksum::$(cat ./$\{{ steps.metadata.outputs.archive-checksum }} | cut -d' ' -f1)"
118
+ echo "checksum=$(cat ./$\{{ steps.metadata.outputs.archive-checksum }} | cut -d' ' -f1)" >> $GITHUB_OUTPUT
119
119
 
120
120
  - name: Lint plugin
121
121
  run: |