Skip to content

Commit bf0612b

Browse files
committed
Init.
0 parents  commit bf0612b

File tree

148 files changed

+33938
-0
lines changed

Some content is hidden

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

148 files changed

+33938
-0
lines changed

.config/.eslintrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
"extends": ["@grafana/eslint-config"],
8+
"root": true,
9+
"rules": {
10+
"react/prop-types": "off"
11+
}
12+
}

.config/.prettierrc.js

Lines changed: 16 additions & 0 deletions
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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ARG grafana_version=latest
2+
3+
FROM grafana/grafana:9.5.1
4+
5+
# Make it as simple as possible to access the grafana instance for development purposes
6+
# Do NOT enable these settings in a public facing / production grafana instance
7+
ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin"
8+
ENV GF_AUTH_ANONYMOUS_ENABLED "true"
9+
ENV GF_AUTH_BASIC_ENABLED "false"
10+
# Set development mode so plugins can be loaded without the need to sign
11+
ENV GF_DEFAULT_APP_MODE "development"
12+
13+
# Inject livereload script into grafana index.html
14+
USER root
15+
RUN sed -i 's/<\/body><\/html>/<script src=\"http:\/\/localhost:35729\/livereload.js\"><\/script><\/body><\/html>/g' /usr/share/grafana/public/views/index.html

.config/README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
```json
20+
{
21+
"extends": "./.config/.eslintrc",
22+
"rules": {
23+
"react/prop-types": "off"
24+
}
25+
}
26+
```
27+
28+
---
29+
30+
### Extending the Prettier config
31+
32+
Edit the `.prettierrc.js` file in the project root in order to extend the Prettier configuration.
33+
34+
**Example:**
35+
```javascript
36+
module.exports = {
37+
// Prettier configuration provided by Grafana scaffolding
38+
...require("./.config/.prettierrc.js"),
39+
40+
semi: false,
41+
};
42+
```
43+
44+
---
45+
46+
### Extending the Jest config
47+
48+
There are two configuration in the project root that belong to Jest: `jest-setup.js` and `jest.config.js`.
49+
50+
**`jest-setup.js`:** A file that is run before each test file in the suite is executed. We are using it to
51+
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))
52+
53+
**`jest.config.js`:** The main Jest configuration file that is extending our basic Grafana-tailored setup. ([link to Jest docs](https://jestjs.io/docs/configuration))
54+
55+
---
56+
57+
### Extending the TypeScript config
58+
59+
Edit the `tsconfig.json` file in the project root in order to extend the TypeScript configuration.
60+
61+
**Example:**
62+
```json
63+
{
64+
"extends": "./.config/tsconfig.json",
65+
"compilerOptions": {
66+
"preserveConstEnums": true
67+
}
68+
}
69+
```
70+
71+
---
72+
73+
### Extending the Webpack config
74+
75+
Follow these steps to extend the basic Webpack configuration that lives under `.config/`:
76+
77+
#### 1. Create a new Webpack configuration file
78+
79+
Create a new config file that is going to extend the basic one provided by Grafana.
80+
It can live in the project root, e.g. `webpack.config.ts`.
81+
82+
#### 2. Merge the basic config provided by Grafana and your custom setup
83+
We are going to use [`webpack-merge`](https://github.com/survivejs/webpack-merge) for this.
84+
85+
```typescript
86+
// webpack.config.ts
87+
import type { Configuration } from 'webpack';
88+
import { merge } from 'webpack-merge';
89+
import grafanaConfig from './.config/webpack/webpack.config';
90+
91+
const config = async (env): Promise<Configuration> => {
92+
const baseConfig = await grafanaConfig(env);
93+
94+
return merge(baseConfig, {
95+
// Add custom config here...
96+
output: {
97+
asyncChunks: true,
98+
},
99+
});
100+
};
101+
102+
export default config;
103+
104+
```
105+
106+
#### 3. Update the `package.json` to use the new Webpack config
107+
108+
We need to update the `scripts` in the `package.json` to use the extended Webpack configuration.
109+
110+
**Update for `build`:**
111+
```diff
112+
-"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",
113+
+"build": "webpack -c ./webpack.config.ts --env production",
114+
```
115+
116+
**Update for `dev`:**
117+
```diff
118+
-"dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development",
119+
+"dev": "webpack -w -c ./webpack.config.ts --env development",
120+
```

.config/jest-setup.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
import '@testing-library/jest-dom';
8+
9+
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
10+
Object.defineProperty(global, 'matchMedia', {
11+
writable: true,
12+
value: jest.fn().mockImplementation((query) => ({
13+
matches: false,
14+
media: query,
15+
onchange: null,
16+
addListener: jest.fn(), // deprecated
17+
removeListener: jest.fn(), // deprecated
18+
addEventListener: jest.fn(),
19+
removeEventListener: jest.fn(),
20+
dispatchEvent: jest.fn(),
21+
})),
22+
});
23+
24+
HTMLCanvasElement.prototype.getContext = () => {};

.config/jest.config.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
moduleNameMapper: {
9+
"\\.(css|scss|sass)$": "identity-obj-proxy",
10+
},
11+
modulePaths: ['<rootDir>/src'],
12+
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'],
13+
testEnvironment: 'jest-environment-jsdom',
14+
testMatch: [
15+
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
16+
'<rootDir>/src/**/*.{spec,test,jest}.{js,jsx,ts,tsx}',
17+
'<rootDir>/src/**/*.{spec,test,jest}.{js,jsx,ts,tsx}',
18+
],
19+
transform: {
20+
'^.+\\.(t|j)sx?$': [
21+
'@swc/jest',
22+
{
23+
sourceMaps: true,
24+
jsc: {
25+
parser: {
26+
syntax: 'typescript',
27+
tsx: true,
28+
decorators: false,
29+
dynamicImport: true,
30+
},
31+
},
32+
},
33+
],
34+
},
35+
transformIgnorePatterns: [],
36+
};

.config/tsconfig.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
"compilerOptions": {
8+
"alwaysStrict": true,
9+
"declaration": false,
10+
"rootDir": "../src",
11+
"baseUrl": "../src",
12+
"typeRoots": ["../node_modules/@types"],
13+
"resolveJsonModule": true
14+
},
15+
"ts-node": {
16+
"compilerOptions": {
17+
"module": "commonjs",
18+
"target": "es5",
19+
"esModuleInterop": true
20+
},
21+
"transpileOnly": true
22+
},
23+
"include": ["../src", "./types"],
24+
"extends": "@grafana/tsconfig"
25+
}

.config/types/custom.d.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Image declarations
2+
declare module '*.gif' {
3+
const src: string;
4+
export default src;
5+
}
6+
7+
declare module '*.jpg' {
8+
const src: string;
9+
export default src;
10+
}
11+
12+
declare module '*.jpeg' {
13+
const src: string;
14+
export default src;
15+
}
16+
17+
declare module '*.png' {
18+
const src: string;
19+
export default src;
20+
}
21+
22+
declare module '*.webp' {
23+
const src: string;
24+
export default src;
25+
}
26+
27+
declare module '*.svg' {
28+
const content: string;
29+
export default content;
30+
}
31+
32+
// Font declarations
33+
declare module '*.woff';
34+
declare module '*.woff2';
35+
declare module '*.eot';
36+
declare module '*.ttf';
37+
declare module '*.otf';

.config/webpack/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const SOURCE_DIR = 'src';
2+
export const DIST_DIR = 'dist';

.config/webpack/utils.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import fs from 'fs';
2+
import path from 'path';
3+
import util from 'util';
4+
import glob from 'glob';
5+
import { SOURCE_DIR } from './constants';
6+
7+
const globAsync = util.promisify(glob);
8+
9+
export function getPackageJson() {
10+
return require(path.resolve(process.cwd(), 'package.json'));
11+
}
12+
13+
export function getPluginId() {
14+
const { id } = require(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`));
15+
16+
return id;
17+
}
18+
19+
export function hasReadme() {
20+
return fs.existsSync(path.resolve(process.cwd(), SOURCE_DIR, 'README.md'));
21+
}
22+
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+
}));
31+
32+
return plugins.reduce((result, modules) => {
33+
return modules.reduce((result, module) => {
34+
const pluginPath = path.resolve(path.dirname(module), parent);
35+
const pluginName = path.basename(pluginPath);
36+
const entryName = plugins.length > 1 ? `${pluginName}/module` : 'module';
37+
38+
result[entryName] = path.join(parent, module);
39+
return result;
40+
}, result);
41+
}, {});
42+
}

0 commit comments

Comments
 (0)