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; | 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 entrypoint = () => { | ||||||
|   const defaultEntryPoint = '../src/cli/index.js'; |   const defaultEntryPoint = `${__dirname}/../src/cli/index.js`; | ||||||
|   const toolkitDirectory = `${process.env['PWD']}/node_modules/@grafana/toolkit`; |  | ||||||
| 
 | 
 | ||||||
|   // IF we have a toolkit directory AND linked grafana toolkit AND the toolkit dir is a symbolic lik
 |   // IF we have a toolkit directory AND linked grafana toolkit AND the toolkit dir is a symbolic lik
 | ||||||
|   // THEN run everything in linked mode
 |   // THEN run everything in linked mode
 | ||||||
|   if (fs.existsSync(toolkitDirectory)) { |   if (isLinkedMode()) { | ||||||
|     const tkStat = fs.lstatSync(toolkitDirectory); |     console.log('Running in local/linked mode'); | ||||||
|     if (tkStat.isSymbolicLink()) { |     // This bin is used for cli executed internally
 | ||||||
|       console.log('Running in linked mode'); |     var tsProjectPath = path.resolve(__dirname, '../tsconfig.json'); | ||||||
|       // This bin is used for cli executed internally
 |     require('ts-node').register({ | ||||||
|       var tsProjectPath = path.resolve(__dirname, '../tsconfig.json'); |       project: tsProjectPath, | ||||||
|       require('ts-node').register({ |       transpileOnly: true, | ||||||
|         project: tsProjectPath, |     }); | ||||||
|         transpileOnly: true, |  | ||||||
|       }); |  | ||||||
| 
 | 
 | ||||||
|       includeInternalScripts = true; |     includeInternalScripts = true; | ||||||
|       return '../src/cli/index.ts'; |     return '../src/cli/index.ts'; | ||||||
|     } |  | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|   // We are using npx, and a relative path does not find index.js
 |   // 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) => { | const preparePackage = async (pkg: any) => { | ||||||
|   pkg.bin = { |   pkg.bin = { | ||||||
|     'grafana-toolkit': './bin/grafana-toolkit.dist.js', |     'grafana-toolkit': './bin/grafana-toolkit.js', | ||||||
|   }; |   }; | ||||||
| 
 | 
 | ||||||
|   await savePackage({ |   await savePackage({ | ||||||
|  | @ -53,7 +53,8 @@ const copyFiles = () => { | ||||||
|   const files = [ |   const files = [ | ||||||
|     'README.md', |     'README.md', | ||||||
|     'CHANGELOG.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.config.json', | ||||||
|     'src/config/prettier.plugin.rc.js', |     'src/config/prettier.plugin.rc.js', | ||||||
|     'src/config/tsconfig.plugin.json', |     'src/config/tsconfig.plugin.json', | ||||||
|  | @ -66,6 +67,10 @@ const copyFiles = () => { | ||||||
|   return useSpinner<void>(`Moving ${files.join(', ')} files`, async () => { |   return useSpinner<void>(`Moving ${files.join(', ')} files`, async () => { | ||||||
|     const promises = files.map(file => { |     const promises = files.map(file => { | ||||||
|       return new Promise((resolve, reject) => { |       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 => { |         fs.copyFile(`${cwd}/${file}`, `${distDir}/${file}`, err => { | ||||||
|           if (err) { |           if (err) { | ||||||
|             reject(err); |             reject(err); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue