2023-01-26 06:02:22 -06:00
|
|
|
import { writeFile } from 'node:fs/promises';
|
|
|
|
import { resolve } from 'path';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
|
|
|
import { createTheme } from '@grafana/data';
|
2019-02-12 14:54:20 -06: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 07:45:11 -06:00
|
|
|
import { commonThemeVarsTemplate } from '@grafana/ui/src/themes/_variables.scss.tmpl';
|
2019-02-12 14:54:20 -06:00
|
|
|
|
2023-01-26 06:02:22 -06:00
|
|
|
const darkThemeVariablesPath = resolve(__dirname, 'public', 'sass', '_variables.dark.generated.scss');
|
|
|
|
const lightThemeVariablesPath = resolve(__dirname, 'public', 'sass', '_variables.light.generated.scss');
|
|
|
|
const defaultThemeVariablesPath = resolve(__dirname, 'public', 'sass', '_variables.generated.scss');
|
2019-02-12 14:54:20 -06:00
|
|
|
|
2023-01-26 06:02:22 -06:00
|
|
|
async function writeVariablesFile(path: string, data: string) {
|
|
|
|
try {
|
|
|
|
await writeFile(path, data);
|
|
|
|
} catch (error) {
|
|
|
|
console.error('\nWriting SASS variable files failed', error);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
}
|
2019-02-12 14:54:20 -06:00
|
|
|
|
2023-01-26 06:02:22 -06:00
|
|
|
async function generateSassVariableFiles() {
|
2021-04-21 07:25:43 -05:00
|
|
|
const darkTheme = createTheme();
|
2021-04-21 08:34:08 -05:00
|
|
|
const lightTheme = createTheme({ colors: { mode: 'light' } });
|
2019-02-12 14:54:20 -06:00
|
|
|
try {
|
2023-01-26 06:02:22 -06:00
|
|
|
await writeVariablesFile(darkThemeVariablesPath, darkThemeVarsTemplate(darkTheme));
|
|
|
|
await writeVariablesFile(lightThemeVariablesPath, lightThemeVarsTemplate(lightTheme));
|
|
|
|
await writeVariablesFile(defaultThemeVariablesPath, commonThemeVarsTemplate(darkTheme));
|
2019-02-12 14:54:20 -06:00
|
|
|
} catch (error) {
|
|
|
|
console.error('\nWriting SASS variable files failed', error);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2023-01-26 06:02:22 -06:00
|
|
|
}
|
2019-02-12 14:54:20 -06:00
|
|
|
|
|
|
|
generateSassVariableFiles();
|