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,17 @@
const asyncWrapper = require('../../middleware/asyncWrapper');
const File = require('../../utils/File');
// @desc Get themes file
// @route GET /api/themes
// @access Public
const getThemes = asyncWrapper(async (req, res, next) => {
const file = new File('data/themes.json');
const content = JSON.parse(file.read());
res.status(200).json({
success: true,
data: content.themes,
});
});
module.exports = getThemes;

View file

@ -0,0 +1,3 @@
module.exports = {
getThemes: require('./getThemes'),
};

View file

@ -1,11 +1,13 @@
const initConfig = require('./initConfig');
const initFiles = require('./initFiles');
const initDockerSecrets = require('./initDockerSecrets');
const normalizeTheme = require('./normalizeTheme');
const initApp = async () => {
initDockerSecrets();
await initFiles();
await initConfig();
await normalizeTheme();
};
module.exports = initApp;

View file

@ -27,6 +27,142 @@
"queries": []
},
"isJSON": true
},
{
"name": "themes.json",
"msg": {
"created": "Created default theme file",
"found": "Found theme file"
},
"paths": {
"src": "../../data",
"dest": "../../data"
},
"template": {
"themes": [
{
"name": "blackboard",
"colors": {
"background": "#1a1a1a",
"primary": "#FFFDEA",
"accent": "#5c5c5c"
}
},
{
"name": "gazette",
"colors": {
"background": "#F2F7FF",
"primary": "#000000",
"accent": "#5c5c5c"
}
},
{
"name": "espresso",
"colors": {
"background": "#21211F",
"primary": "#D1B59A",
"accent": "#4E4E4E"
}
},
{
"name": "cab",
"colors": {
"background": "#F6D305",
"primary": "#1F1F1F",
"accent": "#424242"
}
},
{
"name": "cloud",
"colors": {
"background": "#f1f2f0",
"primary": "#35342f",
"accent": "#37bbe4"
}
},
{
"name": "lime",
"colors": {
"background": "#263238",
"primary": "#AABBC3",
"accent": "#aeea00"
}
},
{
"name": "white",
"colors": {
"background": "#ffffff",
"primary": "#222222",
"accent": "#dddddd"
}
},
{
"name": "tron",
"colors": {
"background": "#242B33",
"primary": "#EFFBFF",
"accent": "#6EE2FF"
}
},
{
"name": "blues",
"colors": {
"background": "#2B2C56",
"primary": "#EFF1FC",
"accent": "#6677EB"
}
},
{
"name": "passion",
"colors": {
"background": "#f5f5f5",
"primary": "#12005e",
"accent": "#8e24aa"
}
},
{
"name": "chalk",
"colors": {
"background": "#263238",
"primary": "#AABBC3",
"accent": "#FF869A"
}
},
{
"name": "paper",
"colors": {
"background": "#F8F6F1",
"primary": "#4C432E",
"accent": "#AA9A73"
}
},
{
"name": "neon",
"colors": {
"background": "#091833",
"primary": "#EFFBFF",
"accent": "#ea00d9"
}
},
{
"name": "pumpkin",
"colors": {
"background": "#2d3436",
"primary": "#EFFBFF",
"accent": "#ffa500"
}
},
{
"name": "onedark",
"colors": {
"background": "#282c34",
"primary": "#dfd9d6",
"accent": "#98c379"
}
}
]
},
"isJSON": true
}
]
}

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;

124
utils/init/themes.json Normal file
View file

@ -0,0 +1,124 @@
{
"themes": [
{
"name": "blackboard",
"colors": {
"background": "#1a1a1a",
"primary": "#FFFDEA",
"accent": "#5c5c5c"
}
},
{
"name": "gazette",
"colors": {
"background": "#F2F7FF",
"primary": "#000000",
"accent": "#5c5c5c"
}
},
{
"name": "espresso",
"colors": {
"background": "#21211F",
"primary": "#D1B59A",
"accent": "#4E4E4E"
}
},
{
"name": "cab",
"colors": {
"background": "#F6D305",
"primary": "#1F1F1F",
"accent": "#424242"
}
},
{
"name": "cloud",
"colors": {
"background": "#f1f2f0",
"primary": "#35342f",
"accent": "#37bbe4"
}
},
{
"name": "lime",
"colors": {
"background": "#263238",
"primary": "#AABBC3",
"accent": "#aeea00"
}
},
{
"name": "white",
"colors": {
"background": "#ffffff",
"primary": "#222222",
"accent": "#dddddd"
}
},
{
"name": "tron",
"colors": {
"background": "#242B33",
"primary": "#EFFBFF",
"accent": "#6EE2FF"
}
},
{
"name": "blues",
"colors": {
"background": "#2B2C56",
"primary": "#EFF1FC",
"accent": "#6677EB"
}
},
{
"name": "passion",
"colors": {
"background": "#f5f5f5",
"primary": "#12005e",
"accent": "#8e24aa"
}
},
{
"name": "chalk",
"colors": {
"background": "#263238",
"primary": "#AABBC3",
"accent": "#FF869A"
}
},
{
"name": "paper",
"colors": {
"background": "#F8F6F1",
"primary": "#4C432E",
"accent": "#AA9A73"
}
},
{
"name": "neon",
"colors": {
"background": "#091833",
"primary": "#EFFBFF",
"accent": "#ea00d9"
}
},
{
"name": "pumpkin",
"colors": {
"background": "#2d3436",
"primary": "#EFFBFF",
"accent": "#ffa500"
}
},
{
"name": "onedark",
"colors": {
"background": "#282c34",
"primary": "#dfd9d6",
"accent": "#98c379"
}
}
]
}