Skip to content

Commit 6de8745

Browse files
init
0 parents  commit 6de8745

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+17585
-0
lines changed

.config/.cprc.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"version": "5.14.0"
3+
}

.config/.eslintrc

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
3+
*
4+
* In order to extend the configuration follow the steps in
5+
* https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment#extend-the-eslint-config
6+
*/
7+
{
8+
"extends": ["@grafana/eslint-config"],
9+
"root": true,
10+
"rules": {
11+
"react/prop-types": "off"
12+
},
13+
"overrides": [
14+
{
15+
"plugins": ["deprecation"],
16+
"files": ["src/**/*.{ts,tsx}"],
17+
"rules": {
18+
"deprecation/deprecation": "warn"
19+
},
20+
"parserOptions": {
21+
"project": "./tsconfig.json"
22+
}
23+
},
24+
{
25+
"files": ["./tests/**/*"],
26+
"rules": {
27+
"react-hooks/rules-of-hooks": "off"
28+
}
29+
}
30+
]
31+
}

.config/.prettierrc.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
3+
*
4+
* In order to extend the configuration follow the steps in .config/README.md
5+
*/
6+
7+
module.exports = {
8+
endOfLine: 'auto',
9+
printWidth: 120,
10+
trailingComma: 'es5',
11+
semi: true,
12+
jsxSingleQuote: false,
13+
singleQuote: true,
14+
useTabs: false,
15+
tabWidth: 2,
16+
};

.config/Dockerfile

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
ARG grafana_version=latest
2+
3+
FROM grafana/grafana:${grafana_version}
4+
5+
ARG anonymous_auth_enabled=true
6+
ARG development=false
7+
ARG TARGETARCH
8+
9+
10+
ENV DEV "${development}"
11+
12+
# Make it as simple as possible to access the grafana instance for development purposes
13+
# Do NOT enable these settings in a public facing / production grafana instance
14+
ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin"
15+
ENV GF_AUTH_ANONYMOUS_ENABLED "${anonymous_auth_enabled}"
16+
ENV GF_AUTH_BASIC_ENABLED "false"
17+
# Set development mode so plugins can be loaded without the need to sign
18+
ENV GF_DEFAULT_APP_MODE "development"
19+
20+
21+
LABEL maintainer="Grafana Labs <[email protected]>"
22+
23+
ENV GF_PATHS_HOME="/usr/share/grafana"
24+
WORKDIR $GF_PATHS_HOME
25+
26+
USER root
27+
28+
# Installing supervisor and inotify-tools
29+
RUN if [ "${development}" = "true" ]; then \
30+
if grep -i -q alpine /etc/issue; then \
31+
apk add supervisor inotify-tools git; \
32+
elif grep -i -q ubuntu /etc/issue; then \
33+
DEBIAN_FRONTEND=noninteractive && \
34+
apt-get update && \
35+
apt-get install -y supervisor inotify-tools git && \
36+
rm -rf /var/lib/apt/lists/*; \
37+
else \
38+
echo 'ERROR: Unsupported base image' && /bin/false; \
39+
fi \
40+
fi
41+
42+
COPY supervisord/supervisord.conf /etc/supervisor.d/supervisord.ini
43+
COPY supervisord/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
44+
45+
46+
47+
# Inject livereload script into grafana index.html
48+
RUN sed -i 's|</body>|<script src="http://localhost:35729/livereload.js"></script></body>|g' /usr/share/grafana/public/views/index.html
49+
50+
51+
COPY entrypoint.sh /entrypoint.sh
52+
RUN chmod +x /entrypoint.sh
53+
ENTRYPOINT ["/entrypoint.sh"]

.config/README.md

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Default build configuration by Grafana
2+
3+
**This is an auto-generated directory and is not intended to be changed! ⚠️**
4+
5+
The `.config/` directory holds basic configuration for the different tools
6+
that are used to develop, test and build the project. In order to make it updates easier we ask you to
7+
not edit files in this folder to extend configuration.
8+
9+
## How to extend the basic configs?
10+
11+
Bear in mind that you are doing it at your own risk, and that extending any of the basic configuration can lead
12+
to issues around working with the project.
13+
14+
### Extending the ESLint config
15+
16+
Edit the `.eslintrc` file in the project root in order to extend the ESLint configuration.
17+
18+
**Example:**
19+
20+
```json
21+
{
22+
"extends": "./.config/.eslintrc",
23+
"rules": {
24+
"react/prop-types": "off"
25+
}
26+
}
27+
```
28+
29+
---
30+
31+
### Extending the Prettier config
32+
33+
Edit the `.prettierrc.js` file in the project root in order to extend the Prettier configuration.
34+
35+
**Example:**
36+
37+
```javascript
38+
module.exports = {
39+
// Prettier configuration provided by Grafana scaffolding
40+
...require('./.config/.prettierrc.js'),
41+
42+
semi: false,
43+
};
44+
```
45+
46+
---
47+
48+
### Extending the Jest config
49+
50+
There are two configuration in the project root that belong to Jest: `jest-setup.js` and `jest.config.js`.
51+
52+
**`jest-setup.js`:** A file that is run before each test file in the suite is executed. We are using it to
53+
set up the Jest DOM for the testing library and to apply some polyfills. ([link to Jest docs](https://jestjs.io/docs/configuration#setupfilesafterenv-array))
54+
55+
**`jest.config.js`:** The main Jest configuration file that extends the Grafana recommended setup. ([link to Jest docs](https://jestjs.io/docs/configuration))
56+
57+
#### ESM errors with Jest
58+
59+
A common issue with the current jest config involves importing an npm package that only offers an ESM build. These packages cause jest to error with `SyntaxError: Cannot use import statement outside a module`. To work around this, we provide a list of known packages to pass to the `[transformIgnorePatterns](https://jestjs.io/docs/configuration#transformignorepatterns-arraystring)` jest configuration property. If need be, this can be extended in the following way:
60+
61+
```javascript
62+
process.env.TZ = 'UTC';
63+
const { grafanaESModules, nodeModulesToTransform } = require('./config/jest/utils');
64+
65+
module.exports = {
66+
// Jest configuration provided by Grafana
67+
...require('./.config/jest.config'),
68+
// Inform jest to only transform specific node_module packages.
69+
transformIgnorePatterns: [nodeModulesToTransform([...grafanaESModules, 'packageName'])],
70+
};
71+
```
72+
73+
---
74+
75+
### Extending the TypeScript config
76+
77+
Edit the `tsconfig.json` file in the project root in order to extend the TypeScript configuration.
78+
79+
**Example:**
80+
81+
```json
82+
{
83+
"extends": "./.config/tsconfig.json",
84+
"compilerOptions": {
85+
"preserveConstEnums": true
86+
}
87+
}
88+
```
89+
90+
---
91+
92+
### Extending the Webpack config
93+
94+
Follow these steps to extend the basic Webpack configuration that lives under `.config/`:
95+
96+
#### 1. Create a new Webpack configuration file
97+
98+
Create a new config file that is going to extend the basic one provided by Grafana.
99+
It can live in the project root, e.g. `webpack.config.ts`.
100+
101+
#### 2. Merge the basic config provided by Grafana and your custom setup
102+
103+
We are going to use [`webpack-merge`](https://github.com/survivejs/webpack-merge) for this.
104+
105+
```typescript
106+
// webpack.config.ts
107+
import type { Configuration } from 'webpack';
108+
import { merge } from 'webpack-merge';
109+
import grafanaConfig from './.config/webpack/webpack.config';
110+
111+
const config = async (env): Promise<Configuration> => {
112+
const baseConfig = await grafanaConfig(env);
113+
114+
return merge(baseConfig, {
115+
// Add custom config here...
116+
output: {
117+
asyncChunks: true,
118+
},
119+
});
120+
};
121+
122+
export default config;
123+
```
124+
125+
#### 3. Update the `package.json` to use the new Webpack config
126+
127+
We need to update the `scripts` in the `package.json` to use the extended Webpack configuration.
128+
129+
**Update for `build`:**
130+
131+
```diff
132+
-"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",
133+
+"build": "webpack -c ./webpack.config.ts --env production",
134+
```
135+
136+
**Update for `dev`:**
137+
138+
```diff
139+
-"dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development",
140+
+"dev": "webpack -w -c ./webpack.config.ts --env development",
141+
```
142+
143+
### Configure grafana image to use when running docker
144+
145+
By default, `grafana-enterprise` will be used as the docker image for all docker related commands. If you want to override this behavior, simply alter the `docker-compose.yaml` by adding the following build arg `grafana_image`.
146+
147+
**Example:**
148+
149+
```yaml
150+
version: '3.7'
151+
152+
services:
153+
grafana:
154+
extends:
155+
file: .config/docker-compose-base.yaml
156+
service: grafana
157+
build:
158+
args:
159+
grafana_version: ${GRAFANA_VERSION:-9.1.2}
160+
grafana_image: ${GRAFANA_IMAGE:-grafana}
161+
```
162+
163+
In this example, we assign the environment variable `GRAFANA_IMAGE` to the build arg `grafana_image` with a default value of `grafana`. This will allow you to set the value while running the docker compose commands, which might be convenient in some scenarios.
164+
165+
---

.config/docker-compose-base.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
services:
2+
grafana:
3+
user: root
4+
container_name: 'target-dashboardtabs-panel'
5+
6+
build:
7+
context: .
8+
args:
9+
grafana_version: ${GRAFANA_VERSION:-9.2.5}
10+
development: ${DEVELOPMENT:-false}
11+
anonymous_auth_enabled: ${ANONYMOUS_AUTH_ENABLED:-true}
12+
ports:
13+
- 3001:3000/tcp
14+
volumes:
15+
- ../dist:/var/lib/grafana/plugins/target-dashboardtabs-panel
16+
- ../provisioning:/etc/grafana/provisioning
17+
- ..:/root/target-dashboardtabs-panel
18+
19+
environment:
20+
NODE_ENV: development
21+
GF_LOG_FILTERS: plugin.target-dashboardtabs-panel:debug
22+
GF_LOG_LEVEL: debug
23+
GF_DATAPROXY_LOGGING: 1
24+
GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS: target-dashboardtabs-panel

.config/entrypoint.sh

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
if [ "${DEV}" = "false" ]; then
4+
echo "Starting test mode"
5+
exec /run.sh
6+
fi
7+
8+
echo "Starting development mode"
9+
10+
if grep -i -q alpine /etc/issue; then
11+
exec /usr/bin/supervisord -c /etc/supervisord.conf
12+
elif grep -i -q ubuntu /etc/issue; then
13+
exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf
14+
else
15+
echo 'ERROR: Unsupported base image'
16+
exit 1
17+
fi
18+

.config/jest-setup.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
3+
*
4+
* In order to extend the configuration follow the steps in
5+
* https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment#extend-the-jest-config
6+
*/
7+
8+
import '@testing-library/jest-dom';
9+
import { TextEncoder, TextDecoder } from 'util';
10+
11+
Object.assign(global, { TextDecoder, TextEncoder });
12+
13+
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
14+
Object.defineProperty(global, 'matchMedia', {
15+
writable: true,
16+
value: (query) => ({
17+
matches: false,
18+
media: query,
19+
onchange: null,
20+
addListener: jest.fn(), // deprecated
21+
removeListener: jest.fn(), // deprecated
22+
addEventListener: jest.fn(),
23+
removeEventListener: jest.fn(),
24+
dispatchEvent: jest.fn(),
25+
}),
26+
});
27+
28+
HTMLCanvasElement.prototype.getContext = () => {};

.config/jest.config.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
3+
*
4+
* In order to extend the configuration follow the steps in
5+
* https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment#extend-the-jest-config
6+
*/
7+
8+
const path = require('path');
9+
const { grafanaESModules, nodeModulesToTransform } = require('./jest/utils');
10+
11+
module.exports = {
12+
moduleNameMapper: {
13+
'\\.(css|scss|sass)$': 'identity-obj-proxy',
14+
'react-inlinesvg': path.resolve(__dirname, 'jest', 'mocks', 'react-inlinesvg.tsx'),
15+
},
16+
modulePaths: ['<rootDir>/src'],
17+
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'],
18+
testEnvironment: 'jest-environment-jsdom',
19+
testMatch: [
20+
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
21+
'<rootDir>/src/**/*.{spec,test,jest}.{js,jsx,ts,tsx}',
22+
'<rootDir>/src/**/*.{spec,test,jest}.{js,jsx,ts,tsx}',
23+
],
24+
transform: {
25+
'^.+\\.(t|j)sx?$': [
26+
'@swc/jest',
27+
{
28+
sourceMaps: 'inline',
29+
jsc: {
30+
parser: {
31+
syntax: 'typescript',
32+
tsx: true,
33+
decorators: false,
34+
dynamicImport: true,
35+
},
36+
},
37+
},
38+
],
39+
},
40+
// Jest will throw `Cannot use import statement outside module` if it tries to load an
41+
// ES module without it being transformed first. ./config/README.md#esm-errors-with-jest
42+
transformIgnorePatterns: [nodeModulesToTransform(grafanaESModules)],
43+
};

0 commit comments

Comments
 (0)