diff --git a/.config/.cprc.json b/.config/.cprc.json index 7f76f04..783393a 100644 --- a/.config/.cprc.json +++ b/.config/.cprc.json @@ -1,3 +1,3 @@ { - "version": "4.11.4" + "version": "5.22.4" } diff --git a/.config/.eslintrc b/.config/.eslintrc index 1486ed2..88ffdf0 100644 --- a/.config/.eslintrc +++ b/.config/.eslintrc @@ -2,7 +2,7 @@ * ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️ * * In order to extend the configuration follow the steps in - * https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-eslint-config + * https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment#extend-the-eslint-config */ { "extends": ["@grafana/eslint-config"], @@ -20,6 +20,12 @@ "parserOptions": { "project": "./tsconfig.json" } + }, + { + "files": ["./tests/**/*"], + "rules": { + "react-hooks/rules-of-hooks": "off", + }, } ] } diff --git a/.config/Dockerfile b/.config/Dockerfile index 2a8a2b1..0c5e6e8 100644 --- a/.config/Dockerfile +++ b/.config/Dockerfile @@ -3,17 +3,19 @@ ARG grafana_image=grafana-enterprise FROM grafana/${grafana_image}:${grafana_version} +ARG anonymous_auth_enabled=true ARG development=false +ARG TARGETARCH ARG GO_VERSION=1.21.6 -ARG GO_ARCH=amd64 +ARG GO_ARCH=${TARGETARCH:-amd64} ENV DEV "${development}" # Make it as simple as possible to access the grafana instance for development purposes # Do NOT enable these settings in a public facing / production grafana instance ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin" -ENV GF_AUTH_ANONYMOUS_ENABLED "true" +ENV GF_AUTH_ANONYMOUS_ENABLED "${anonymous_auth_enabled}" ENV GF_AUTH_BASIC_ENABLED "false" # Set development mode so plugins can be loaded without the need to sign ENV GF_DEFAULT_APP_MODE "development" @@ -29,14 +31,14 @@ USER root # Installing supervisor and inotify-tools RUN if [ "${development}" = "true" ]; then \ if grep -i -q alpine /etc/issue; then \ - apk add supervisor inotify-tools git; \ + apk add supervisor inotify-tools git; \ elif grep -i -q ubuntu /etc/issue; then \ - DEBIAN_FRONTEND=noninteractive && \ - apt-get update && \ - apt-get install -y supervisor inotify-tools git && \ - rm -rf /var/lib/apt/lists/*; \ + DEBIAN_FRONTEND=noninteractive && \ + apt-get update && \ + apt-get install -y supervisor inotify-tools git && \ + rm -rf /var/lib/apt/lists/*; \ else \ - echo 'ERROR: Unsupported base image' && /bin/false; \ + echo 'ERROR: Unsupported base image' && /bin/false; \ fi \ fi diff --git a/.config/README.md b/.config/README.md index a23b6d1..5ba3186 100644 --- a/.config/README.md +++ b/.config/README.md @@ -106,9 +106,9 @@ We are going to use [`webpack-merge`](https://github.com/survivejs/webpack-merge // webpack.config.ts import type { Configuration } from 'webpack'; import { merge } from 'webpack-merge'; -import grafanaConfig from './.config/webpack/webpack.config'; +import grafanaConfig, { type Env } from './.config/webpack/webpack.config'; -const config = async (env): Promise => { +const config = async (env: Env): Promise => { const baseConfig = await grafanaConfig(env); return merge(baseConfig, { @@ -151,14 +151,15 @@ version: '3.7' services: grafana: - container_name: 'myorg-basic-app' + extends: + file: .config/docker-compose-base.yaml + service: grafana build: - context: ./.config args: grafana_version: ${GRAFANA_VERSION:-9.1.2} grafana_image: ${GRAFANA_IMAGE:-grafana} ``` -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. +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. --- diff --git a/.config/docker-compose-base.yaml b/.config/docker-compose-base.yaml new file mode 100644 index 0000000..2b3d2f3 --- /dev/null +++ b/.config/docker-compose-base.yaml @@ -0,0 +1,31 @@ +services: + grafana: + user: root + container_name: 'grafana-mqtt-datasource' + + build: + context: . + args: + grafana_image: ${GRAFANA_IMAGE:-grafana-enterprise} + grafana_version: ${GRAFANA_VERSION:-12.0.1} + development: ${DEVELOPMENT:-false} + anonymous_auth_enabled: ${ANONYMOUS_AUTH_ENABLED:-true} + ports: + - 3000:3000/tcp + - 2345:2345/tcp # delve + security_opt: + - 'apparmor:unconfined' + - 'seccomp:unconfined' + cap_add: + - SYS_PTRACE + volumes: + - ../dist:/var/lib/grafana/plugins/grafana-mqtt-datasource + - ../provisioning:/etc/grafana/provisioning + - ..:/root/grafana-mqtt-datasource + + environment: + NODE_ENV: development + GF_LOG_FILTERS: plugin.grafana-mqtt-datasource:debug + GF_LOG_LEVEL: debug + GF_DATAPROXY_LOGGING: 1 + GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS: grafana-mqtt-datasource diff --git a/.config/jest-setup.js b/.config/jest-setup.js index 27d6420..74832e3 100644 --- a/.config/jest-setup.js +++ b/.config/jest-setup.js @@ -2,18 +2,18 @@ * ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️ * * In order to extend the configuration follow the steps in - * https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-jest-config + * https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment#extend-the-jest-config */ import '@testing-library/jest-dom'; import { TextEncoder, TextDecoder } from 'util'; - + Object.assign(global, { TextDecoder, TextEncoder }); // https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom Object.defineProperty(global, 'matchMedia', { writable: true, - value: jest.fn().mockImplementation((query) => ({ + value: (query) => ({ matches: false, media: query, onchange: null, @@ -22,7 +22,7 @@ Object.defineProperty(global, 'matchMedia', { addEventListener: jest.fn(), removeEventListener: jest.fn(), dispatchEvent: jest.fn(), - })), + }), }); HTMLCanvasElement.prototype.getContext = () => {}; diff --git a/.config/jest.config.js b/.config/jest.config.js index 94489cb..09704b4 100644 --- a/.config/jest.config.js +++ b/.config/jest.config.js @@ -2,7 +2,7 @@ * ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️ * * In order to extend the configuration follow the steps in - * https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-jest-config + * https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment#extend-the-jest-config */ const path = require('path'); diff --git a/.config/tsconfig.json b/.config/tsconfig.json index 207b28f..15e64ac 100644 --- a/.config/tsconfig.json +++ b/.config/tsconfig.json @@ -2,7 +2,7 @@ * ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️ * * In order to extend the configuration follow the steps in - * https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-typescript-config + * https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment#extend-the-typescript-config */ { "compilerOptions": { diff --git a/.config/types/bundler-rules.d.ts b/.config/types/bundler-rules.d.ts new file mode 100644 index 0000000..e67197c --- /dev/null +++ b/.config/types/bundler-rules.d.ts @@ -0,0 +1,37 @@ +// Image declarations +declare module '*.gif' { + const src: string; + export default src; +} + +declare module '*.jpg' { + const src: string; + export default src; +} + +declare module '*.jpeg' { + const src: string; + export default src; +} + +declare module '*.png' { + const src: string; + export default src; +} + +declare module '*.webp' { + const src: string; + export default src; +} + +declare module '*.svg' { + const src: string; + export default src; +} + +// Font declarations +declare module '*.woff'; +declare module '*.woff2'; +declare module '*.eot'; +declare module '*.ttf'; +declare module '*.otf'; diff --git a/.config/types/webpack-plugins.d.ts b/.config/types/webpack-plugins.d.ts new file mode 100644 index 0000000..6dbab10 --- /dev/null +++ b/.config/types/webpack-plugins.d.ts @@ -0,0 +1,83 @@ +declare module 'replace-in-file-webpack-plugin' { + import { Compiler, Plugin } from 'webpack'; + + interface ReplaceRule { + search: string | RegExp; + replace: string | ((match: string) => string); + } + + interface ReplaceOption { + dir?: string; + files?: string[]; + test?: RegExp | RegExp[]; + rules: ReplaceRule[]; + } + + class ReplaceInFilePlugin extends Plugin { + constructor(options?: ReplaceOption[]); + options: ReplaceOption[]; + apply(compiler: Compiler): void; + } + + export = ReplaceInFilePlugin; +} + +declare module 'webpack-livereload-plugin' { + import { ServerOptions } from 'https'; + import { Compiler, Plugin, Stats, Compilation } from 'webpack'; + + interface Options extends Pick { + /** + * protocol for livereload `