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:
parent
ee0b435493
commit
e427fbf54c
6 changed files with 310 additions and 0 deletions
28
utils/init/normalizeTheme.js
Normal file
28
utils/init/normalizeTheme.js
Normal 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;
|
Loading…
Add table
Add a link
Reference in a new issue