Skip to content

Commit

Permalink
refactored code in the skin support section under getBundleMetadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Nalseaf committed Sep 5, 2024
1 parent 4918a5a commit 1b16fc8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
Binary file modified dump.rdb
Binary file not shown.
42 changes: 29 additions & 13 deletions src/meta/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,10 @@ async function copyFontAwesomeFiles() {
);
}
}

await Promise.all(copyOperations);
}

async function filterMissingFiles(filepaths) {
const exists = await Promise.all(
filepaths.map(async (filepath) => {
Expand Down Expand Up @@ -204,24 +206,38 @@ async function getBundleMetadata(target) {
path.join(utils.getFontawesomePath(), 'scss'),
];

// Low complexitity skin support
let skin;
// Skin support
let skin = '';
let isCustomSkin = false;

if (target.startsWith('client-')) {
skin = target.split('-').slice(1).join('-');
const isBootswatchSkin = CSS.supportedSkins.includes(skin);
isCustomSkin = !isBootswatchSkin && await CSS.isCustomSkin(skin);
const targetSkin = target.split('-').slice(1).join('-');
const isBootswatchSkin = CSS.supportedSkins.includes(targetSkin);

isCustomSkin = !isBootswatchSkin && await CSS.isCustomSkin(targetSkin);
skin = (isBootswatchSkin || isCustomSkin) ? targetSkin : ''; // if it's not a valid skin, don't set it

target = 'client';
if (!isBootswatchSkin && !isCustomSkin) {
skin = ''; // invalid skin or deleted use default
}
}

let themeData = null;
if (target === 'client') {
themeData = await fetchThemeData(skin, isCustomSkin);
addThemePaths(paths, themeData);
}

let themeData = {};

if (target === 'client') {
themeData = await db.getObjectFields('config', ['theme:type', 'theme:id', 'useBSVariables', 'bsVariables']);
const themeId = (themeData['theme:id'] || 'nodebb-theme-harmony');
const baseThemePath = path.join(
nconf.get('themes_path'),
(themeData['theme:type'] && themeData['theme:type'] === 'local' ? themeId : 'nodebb-theme-harmony')
);
paths.unshift(baseThemePath);
paths.unshift(`${baseThemePath}/node_modules`);
themeData.bsVariables = parseInt(themeData.useBSVariables, 10) === 1 ? (themeData.bsVariables || '') : '';
themeData.bootswatchSkin = skin;
themeData.isCustomSkin = isCustomSkin;
const customSkin = isCustomSkin ? await CSS.getCustomSkin(skin) : null;
themeData._variables = customSkin && customSkin._variables;
}

const [scssImports, cssImports, acpScssImports] = await Promise.all([
filterGetImports(plugins.scssFiles, '.scss'),
Expand Down

0 comments on commit 1b16fc8

Please sign in to comment.