generated from grafana/grafana-starter-datasource-backend
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into support-path
- Loading branch information
Showing
63 changed files
with
4,885 additions
and
2,321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,59 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import util from 'util' | ||
import glob from 'glob' | ||
import { SOURCE_DIR } from './constants' | ||
|
||
const globAsync = util.promisify(glob) | ||
import fs from 'fs'; | ||
import process from 'process'; | ||
import os from 'os'; | ||
import path from 'path'; | ||
import util from 'util'; | ||
import { glob } from 'glob'; | ||
import { SOURCE_DIR } from './constants'; | ||
|
||
|
||
export function isWSL() { | ||
if (process.platform !== 'linux') { | ||
return false; | ||
} | ||
|
||
if (os.release().toLowerCase().includes('microsoft')) { | ||
return true; | ||
} | ||
|
||
try { | ||
return fs.readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft'); | ||
} catch { | ||
return false; | ||
} | ||
} | ||
|
||
export function getPackageJson() { | ||
return require(path.resolve(process.cwd(), 'package.json')) | ||
return require(path.resolve(process.cwd(), 'package.json')); | ||
} | ||
|
||
export function getPluginJson() { | ||
return require(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`)) | ||
return require(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`)); | ||
} | ||
|
||
export function hasReadme() { | ||
return fs.existsSync(path.resolve(process.cwd(), SOURCE_DIR, 'README.md')) | ||
return fs.existsSync(path.resolve(process.cwd(), SOURCE_DIR, 'README.md')); | ||
} | ||
|
||
// Support bundling nested plugins by finding all plugin.json files in src directory | ||
// then checking for a sibling module.[jt]sx? file. | ||
export async function getEntries(): Promise<Record<string, string>> { | ||
const pluginsJson = await globAsync('**/src/**/plugin.json', { absolute: true }) | ||
const pluginsJson = await glob('**/src/**/plugin.json', { absolute: true }); | ||
|
||
const plugins = await Promise.all(pluginsJson.map((pluginJson) => { | ||
const folder = path.dirname(pluginJson) | ||
return globAsync(`${folder}/module.{ts,tsx,js,jsx}`, { absolute: true }) | ||
const folder = path.dirname(pluginJson); | ||
return glob(`${folder}/module.{ts,tsx,js,jsx}`, { absolute: true }); | ||
}) | ||
) | ||
); | ||
|
||
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) | ||
}, {}) | ||
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); | ||
}, {}); | ||
} |
Oops, something went wrong.