1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-07-19 11:39:36 +02:00

Added theme string normalization to initial process. Added getThemes controller

This commit is contained in:
Paweł Malak 2022-03-23 14:13:14 +01:00
parent ee0b435493
commit e427fbf54c
6 changed files with 310 additions and 0 deletions

View file

@ -0,0 +1,28 @@
const { readFile, writeFile } = require('fs/promises');
const normalizeTheme = async () => {
// open main config file
const configFile = await readFile('data/config.json', 'utf8');
const config = JSON.parse(configFile);
// open default themes file
const themesFile = await readFile('utils/init/themes.json', 'utf8');
const { themes } = JSON.parse(themesFile);
// find theme
const theme = themes.find((t) => t.name === config.defaultTheme);
if (theme) {
// save theme in new format
// PAB - primary;accent;background
const { primary: p, accent: a, background: b } = theme.colors;
const normalizedTheme = `${p};${a};${b}`;
await writeFile(
'data/config.json',
JSON.stringify({ ...config, defaultTheme: normalizedTheme })
);
}
};
module.exports = normalizeTheme;