mirror of https://github.com/grafana/grafana.git
Toolkit: Copy config files to dist for plugin use/Fix circleci build errors (#23575)
* replaced run * consolidated dist and toolkit * Solved a few more issues 1. Need to explicitly copy circleci config to dist so that it's published 2. Detect build directory, and use "local" or "linked" mode for local builds. * Reverted change used only for testing * grafana-toolkit.js always required now. Copy to dist * removed grafana-toolkit.dist.js, no longer required * feedback from code review * Code review comments 2.
This commit is contained in:
parent
0652671443
commit
52575ff03f
|
|
@ -1,3 +0,0 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
require(`${__dirname}/grafana-toolkit.js`);
|
||||
|
|
@ -5,26 +5,38 @@ const path = require('path');
|
|||
|
||||
let includeInternalScripts = false;
|
||||
|
||||
const isLinkedMode = () => {
|
||||
// In circleci we are in linked mode. Detect by using the circle working directory,
|
||||
// rather than the present working directory.
|
||||
const pwd = process.env.CIRCLE_WORKING_DIRECTORY || process.env.PWD;
|
||||
|
||||
if (path.basename(pwd) === 'grafana-toolkit') {
|
||||
return true;
|
||||
}
|
||||
|
||||
try {
|
||||
return fs.lstatSync(`${pwd}/node_modules/@grafana/toolkit`.replace('~', process.env.HOME)).isSymbolicLink();
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const entrypoint = () => {
|
||||
const defaultEntryPoint = '../src/cli/index.js';
|
||||
const toolkitDirectory = `${process.env['PWD']}/node_modules/@grafana/toolkit`;
|
||||
const defaultEntryPoint = `${__dirname}/../src/cli/index.js`;
|
||||
|
||||
// IF we have a toolkit directory AND linked grafana toolkit AND the toolkit dir is a symbolic lik
|
||||
// THEN run everything in linked mode
|
||||
if (fs.existsSync(toolkitDirectory)) {
|
||||
const tkStat = fs.lstatSync(toolkitDirectory);
|
||||
if (tkStat.isSymbolicLink()) {
|
||||
console.log('Running in linked mode');
|
||||
// This bin is used for cli executed internally
|
||||
var tsProjectPath = path.resolve(__dirname, '../tsconfig.json');
|
||||
require('ts-node').register({
|
||||
project: tsProjectPath,
|
||||
transpileOnly: true,
|
||||
});
|
||||
if (isLinkedMode()) {
|
||||
console.log('Running in local/linked mode');
|
||||
// This bin is used for cli executed internally
|
||||
var tsProjectPath = path.resolve(__dirname, '../tsconfig.json');
|
||||
require('ts-node').register({
|
||||
project: tsProjectPath,
|
||||
transpileOnly: true,
|
||||
});
|
||||
|
||||
includeInternalScripts = true;
|
||||
return '../src/cli/index.ts';
|
||||
}
|
||||
includeInternalScripts = true;
|
||||
return '../src/cli/index.ts';
|
||||
}
|
||||
|
||||
// We are using npx, and a relative path does not find index.js
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ export const savePackage = useSpinner<{
|
|||
|
||||
const preparePackage = async (pkg: any) => {
|
||||
pkg.bin = {
|
||||
'grafana-toolkit': './bin/grafana-toolkit.dist.js',
|
||||
'grafana-toolkit': './bin/grafana-toolkit.js',
|
||||
};
|
||||
|
||||
await savePackage({
|
||||
|
|
@ -53,7 +53,8 @@ const copyFiles = () => {
|
|||
const files = [
|
||||
'README.md',
|
||||
'CHANGELOG.md',
|
||||
'bin/grafana-toolkit.dist.js',
|
||||
'config/circleci/config.yml',
|
||||
'bin/grafana-toolkit.js',
|
||||
'src/config/prettier.plugin.config.json',
|
||||
'src/config/prettier.plugin.rc.js',
|
||||
'src/config/tsconfig.plugin.json',
|
||||
|
|
@ -66,6 +67,10 @@ const copyFiles = () => {
|
|||
return useSpinner<void>(`Moving ${files.join(', ')} files`, async () => {
|
||||
const promises = files.map(file => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const basedir = path.dirname(`${distDir}/${file}`);
|
||||
if (!fs.existsSync(basedir)) {
|
||||
fs.mkdirSync(basedir, { recursive: true });
|
||||
}
|
||||
fs.copyFile(`${cwd}/${file}`, `${distDir}/${file}`, err => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
|
|
|
|||
Loading…
Reference in New Issue