| 
									
										
										
										
											2019-06-28 20:11:12 +08:00
										 |  |  | import * as fs from 'fs'; | 
					
						
							| 
									
										
										
										
											2022-04-22 21:33:13 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import { createTheme } from '@grafana/data'; | 
					
						
							| 
									
										
										
										
											2019-02-13 04:54:20 +08:00
										 |  |  | import { darkThemeVarsTemplate } from '@grafana/ui/src/themes/_variables.dark.scss.tmpl'; | 
					
						
							|  |  |  | import { lightThemeVarsTemplate } from '@grafana/ui/src/themes/_variables.light.scss.tmpl'; | 
					
						
							| 
									
										
										
										
											2019-02-13 21:45:11 +08:00
										 |  |  | import { commonThemeVarsTemplate } from '@grafana/ui/src/themes/_variables.scss.tmpl'; | 
					
						
							| 
									
										
										
										
											2019-02-13 04:54:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 18:03:52 +08:00
										 |  |  | const darkThemeVariablesPath = __dirname + '/../../public/sass/_variables.dark.generated.scss'; | 
					
						
							|  |  |  | const lightThemeVariablesPath = __dirname + '/../../public/sass/_variables.light.generated.scss'; | 
					
						
							|  |  |  | const defaultThemeVariablesPath = __dirname + '/../../public/sass/_variables.generated.scss'; | 
					
						
							| 
									
										
										
										
											2019-02-13 04:54:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const writeVariablesFile = async (path: string, data: string) => { | 
					
						
							|  |  |  |   return new Promise((resolve, reject) => { | 
					
						
							| 
									
										
										
										
											2021-01-20 14:59:48 +08:00
										 |  |  |     fs.writeFile(path, data, (e) => { | 
					
						
							| 
									
										
										
										
											2019-02-13 04:54:20 +08:00
										 |  |  |       if (e) { | 
					
						
							|  |  |  |         reject(e); | 
					
						
							|  |  |  |       } else { | 
					
						
							|  |  |  |         resolve(data); | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const generateSassVariableFiles = async () => { | 
					
						
							| 
									
										
										
										
											2021-04-21 20:25:43 +08:00
										 |  |  |   const darkTheme = createTheme(); | 
					
						
							| 
									
										
										
										
											2021-04-21 21:34:08 +08:00
										 |  |  |   const lightTheme = createTheme({ colors: { mode: 'light' } }); | 
					
						
							| 
									
										
										
										
											2021-04-21 20:25:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-13 04:54:20 +08:00
										 |  |  |   try { | 
					
						
							|  |  |  |     await Promise.all([ | 
					
						
							|  |  |  |       writeVariablesFile(darkThemeVariablesPath, darkThemeVarsTemplate(darkTheme)), | 
					
						
							|  |  |  |       writeVariablesFile(lightThemeVariablesPath, lightThemeVarsTemplate(lightTheme)), | 
					
						
							| 
									
										
										
										
											2021-04-21 20:25:43 +08:00
										 |  |  |       writeVariablesFile(defaultThemeVariablesPath, commonThemeVarsTemplate(darkTheme)), | 
					
						
							| 
									
										
										
										
											2019-02-13 04:54:20 +08:00
										 |  |  |     ]); | 
					
						
							|  |  |  |     console.log('\nSASS variable files generated'); | 
					
						
							|  |  |  |   } catch (error) { | 
					
						
							|  |  |  |     console.error('\nWriting SASS variable files failed', error); | 
					
						
							|  |  |  |     process.exit(1); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | generateSassVariableFiles(); |