mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Regenerating variabless sas on theme edit v1
This commit is contained in:
35
scripts/cli/generateSassVariableFiles.ts
Normal file
35
scripts/cli/generateSassVariableFiles.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import fs from 'fs';
|
||||
import darkTheme from '@grafana/ui/src/themes/dark';
|
||||
import lightTheme from '@grafana/ui/src/themes/light';
|
||||
import { darkThemeVarsTemplate } from '@grafana/ui/src/themes/_variables.dark.scss.tmpl';
|
||||
import { lightThemeVarsTemplate } from '@grafana/ui/src/themes/_variables.light.scss.tmpl';
|
||||
|
||||
const darkThemeVariablesPath = __dirname + '/../../public/sass/_variables.dark.scss';
|
||||
const lightThemeVariablesPath = __dirname + '/../../public/sass/_variables.light.scss';
|
||||
|
||||
const writeVariablesFile = async (path: string, data: string) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.writeFile(path, data, e => {
|
||||
if (e) {
|
||||
reject(e);
|
||||
} else {
|
||||
resolve(data);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const generateSassVariableFiles = async () => {
|
||||
try {
|
||||
await Promise.all([
|
||||
writeVariablesFile(darkThemeVariablesPath, darkThemeVarsTemplate(darkTheme)),
|
||||
writeVariablesFile(lightThemeVariablesPath, lightThemeVarsTemplate(lightTheme)),
|
||||
]);
|
||||
console.log('\nSASS variable files generated');
|
||||
} catch (error) {
|
||||
console.error('\nWriting SASS variable files failed', error);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
generateSassVariableFiles();
|
||||
@@ -1,7 +0,0 @@
|
||||
|
||||
{
|
||||
"watch": ["packages/grafana-ui/src/themes"],
|
||||
"ext": "ts",
|
||||
"ignore": ["src/**/*.spec.ts"],
|
||||
"exec": "ts-node ./src/index.ts"
|
||||
}
|
||||
23
scripts/cli/start.js
Normal file
23
scripts/cli/start.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const concurrently = require('concurrently');
|
||||
|
||||
const startTask = async () => {
|
||||
try {
|
||||
const res = await concurrently([
|
||||
{
|
||||
command: 'nodemon -e ts -w ./packages/grafana-ui/src/themes -x yarn run themes:generate',
|
||||
name: 'SASS variables generator',
|
||||
},
|
||||
{
|
||||
command: 'webpack-dev-server --progress --colors --mode development --config scripts/webpack/webpack.hot.js',
|
||||
name: 'Dev server',
|
||||
},
|
||||
], {
|
||||
killOthers: ['failure', 'failure'],
|
||||
});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
}
|
||||
};
|
||||
|
||||
startTask();
|
||||
@@ -1,24 +0,0 @@
|
||||
// import chokidar from 'chokidar';
|
||||
import darkTheme from '@grafana/ui/src/themes/dark';
|
||||
import { darkThemeVarsTemplate } from '@grafana/ui/src/themes/_variables.dark.scss.tmpl';
|
||||
import fs from 'fs';
|
||||
|
||||
console.log(__dirname + '../../packages/grafana-ui/src/themes/dark.ts');
|
||||
|
||||
const fileToWatch = [
|
||||
__dirname + '/../../packages/grafana-ui/src/themes/dark.ts',
|
||||
__dirname + '/../../packages/grafana-ui/src/themes/light.ts',
|
||||
];
|
||||
// const watchService = chokidar.watch(fileToWatch);
|
||||
console.log(`Watching for file changes on ${fileToWatch}`);
|
||||
|
||||
// watchService.on('change', path => {
|
||||
|
||||
const result = darkThemeVarsTemplate(darkTheme);
|
||||
console.log(result);
|
||||
|
||||
fs.writeFile(__dirname + '/../../public/sass/_variables.dark.scss', result, e => {
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
// });
|
||||
Reference in New Issue
Block a user