The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/packages/grafana-plugin-configs/utils.ts

42 lines
1.2 KiB

import fs from 'fs';
import { glob } from 'glob';
import path from 'path';
import process from 'process';
export function getPackageJson() {
return require(path.resolve(process.cwd(), 'package.json'));
}
export function getPluginJson() {
return require(path.resolve(process.cwd(), 'plugin.json'));
}
export async function getEntries(): Promise<Record<string, string>> {
const pluginsJson = await glob(path.resolve(process.cwd(), '**/plugin.json'), {
ignore: ['**/dist/**'],
absolute: true,
});
const plugins = await Promise.all(
pluginsJson.map((pluginJson) => {
const folder = path.dirname(pluginJson);
return glob(`${folder}/module.{ts,tsx,js,jsx}`, { absolute: true });
})
);
let result: Record<string, string> = {};
return plugins.reduce((result, modules) => {
return modules.reduce((result, module) => {
const pluginPath = path.dirname(module);
const pluginName = path.relative(process.cwd(), pluginPath).replace(/src\/?/i, '');
const entryName = pluginName === '' ? 'module' : `${pluginName}/module`;
result[entryName] = module;
return result;
}, result);
}, result);
}
export function hasLicense() {
return fs.existsSync(path.resolve(process.cwd(), 'LICENSE'));
}