diff --git a/dump.rdb b/dump.rdb index 4bcc9750d6..1d958f4808 100644 Binary files a/dump.rdb and b/dump.rdb differ diff --git a/src/meta/css.js b/src/meta/css.js index 18c3f665e0..8cef8d6da5 100644 --- a/src/meta/css.js +++ b/src/meta/css.js @@ -1,27 +1,22 @@ 'use strict'; - const _ = require('lodash'); const winston = require('winston'); const nconf = require('nconf'); const fs = require('fs'); const path = require('path'); const { mkdirp } = require('mkdirp'); - const plugins = require('../plugins'); const db = require('../database'); const file = require('../file'); const minifier = require('./minifier'); const utils = require('../utils'); - const CSS = module.exports; - CSS.supportedSkins = [ 'cerulean', 'cosmo', 'cyborg', 'darkly', 'flatly', 'journal', 'litera', 'lumen', 'lux', 'materia', 'minty', 'morph', 'pulse', 'quartz', 'sandstone', 'simplex', 'sketchy', 'slate', 'solar', 'spacelab', 'superhero', 'united', 'vapor', 'yeti', 'zephyr', ]; - const buildImports = { client: function (source, themeData) { return [ @@ -48,7 +43,6 @@ const buildImports = { ].join('\n'); }, }; - function boostrapImport(themeData) { // see https://getbootstrap.com/docs/5.0/customize/sass/#variable-defaults // for an explanation of this order and https://bootswatch.com/help/ @@ -62,25 +56,21 @@ function boostrapImport(themeData) { } return bsVariables; } - return [ bsvariables(), '@import "bootstrap/scss/mixins/banner";', '@include bsBanner("");', // functions must be included first '@import "bootstrap/scss/functions";', - // overrides for bs5 variables '@import "./scss/overrides";', // this file is in the themes scss folder '@import "overrides.scss";', // core scss overrides - // bs files '@import "bootstrap/scss/variables";', '@import "bootstrap/scss/variables-dark";', '@import "bootstrap/scss/maps";', '@import "bootstrap/scss/mixins";', '@import "bootstrap/scss/utilities";', - // Layout & components '@import "bootstrap/scss/root";', '@import "bootstrap/scss/reboot";', @@ -113,19 +103,14 @@ function boostrapImport(themeData) { '@import "bootstrap/scss/spinners";', '@import "bootstrap/scss/offcanvas";', '@import "bootstrap/scss/placeholders";', - // Helpers '@import "bootstrap/scss/helpers";', - '@import "responsive-utilities";', - // Utilities '@import "bootstrap/scss/utilities/api";', // scss-docs-end import-stack - '@import "fontawesome/loader";', getFontawesomeStyle(), - '@import "mixins";', // core mixins '@import "generics";', '@import "client";', // core page styles @@ -133,13 +118,10 @@ function boostrapImport(themeData) { bootswatchSkin && !isCustomSkin ? `@import "bootswatch/dist/${bootswatchSkin}/bootswatch";` : '', ].join('\n'); } - - function getFontawesomeStyle() { const styles = utils.getFontawesomeStyles(); return styles.map(style => `@import "fontawesome/style-${style}";`).join('\n'); } - async function copyFontAwesomeFiles() { await mkdirp(path.join(__dirname, '../../build/public/fontawesome/webfonts')); const fonts = await fs.promises.opendir(path.join(utils.getFontawesomePath(), '/webfonts')); @@ -151,10 +133,8 @@ async function copyFontAwesomeFiles() { ); } } - await Promise.all(copyOperations); } - async function filterMissingFiles(filepaths) { const exists = await Promise.all( filepaths.map(async (filepath) => { @@ -167,11 +147,9 @@ async function filterMissingFiles(filepaths) { ); return filepaths.filter((filePath, i) => exists[i]); } - async function getImports(files, extension) { const pluginDirectories = []; let source = ''; - function pathToImport(file) { if (!file) { return ''; @@ -181,7 +159,6 @@ async function getImports(files, extension) { const newFile = path.join(parsed.dir, parsed.name); return `\n@import "${newFile.replace(/\\/g, '/')}";`; } - files.forEach((styleFile) => { if (styleFile.endsWith(extension)) { source += pathToImport(styleFile); @@ -197,7 +174,6 @@ async function getImports(files, extension) { })); return source; } - async function getBundleMetadata(target) { const paths = [ path.join(__dirname, '../../node_modules'), @@ -205,7 +181,6 @@ async function getBundleMetadata(target) { path.join(__dirname, '../../public/fontawesome/scss'), path.join(utils.getFontawesomePath(), 'scss'), ]; - // Skin support let skin; let isCustomSkin = false; @@ -218,7 +193,6 @@ async function getBundleMetadata(target) { skin = ''; // invalid skin or deleted use default } } - let themeData = null; if (target === 'client') { themeData = await db.getObjectFields('config', ['theme:type', 'theme:id', 'useBSVariables', 'bsVariables']); @@ -235,24 +209,19 @@ async function getBundleMetadata(target) { const customSkin = isCustomSkin ? await CSS.getCustomSkin(skin) : null; themeData._variables = customSkin && customSkin._variables; } - const [scssImports, cssImports, acpScssImports] = await Promise.all([ filterGetImports(plugins.scssFiles, '.scss'), filterGetImports(plugins.cssFiles, '.css'), target === 'client' ? '' : filterGetImports(plugins.acpScssFiles, '.scss'), ]); - async function filterGetImports(files, extension) { const filteredFiles = await filterMissingFiles(files); return await getImports(filteredFiles, extension); } - let imports = `${cssImports}\n${scssImports}\n${acpScssImports}`; imports = buildImports[target](imports, themeData); - return { paths: paths, imports: imports }; } - CSS.getSkinSwitcherOptions = async function (uid) { const user = require('../user'); const meta = require('./index'); @@ -260,12 +229,10 @@ CSS.getSkinSwitcherOptions = async function (uid) { user.getSettings(uid), CSS.getCustomSkins(), ]); - const foundCustom = customSkins.find(skin => skin.value === meta.config.bootswatchSkin); const defaultSkin = foundCustom ? foundCustom.name : _.capitalize(meta.config.bootswatchSkin) || '[[user:no-skin]]'; - const defaultSkins = [ { name: `[[user:default, ${defaultSkin}]]`, value: '', selected: userSettings.bootswatchSkin === '' }, { name: '[[user:no-skin]]', value: 'noskin', selected: userSettings.bootswatchSkin === 'noskin' }, @@ -295,7 +262,6 @@ CSS.getSkinSwitcherOptions = async function (uid) { dark: parseSkins(darkSkins), }); }; - CSS.getCustomSkins = async function (opts = {}) { const meta = require('./index'); const slugify = require('../slugify'); @@ -315,36 +281,30 @@ CSS.getCustomSkins = async function (opts = {}) { } return returnSkins; }; - CSS.isSkinValid = async function (skin) { return CSS.supportedSkins.includes(skin) || await CSS.isCustomSkin(skin); }; - CSS.isCustomSkin = async function (skin) { const skins = await CSS.getCustomSkins(); return !!skins.find(s => s.value === skin); }; - CSS.getCustomSkin = async function (skin) { const skins = await CSS.getCustomSkins({ loadVariables: true }); return skins.find(s => s.value === skin); }; - CSS.buildBundle = async function (target, fork) { if (target === 'client') { let files = await fs.promises.readdir(path.join(__dirname, '../../build/public')); files = files.filter(f => f.match(/^client.*\.css$/)); await Promise.all(files.map(f => fs.promises.unlink(path.join(__dirname, '../../build/public', f)))); } - const data = await getBundleMetadata(target); const minify = process.env.NODE_ENV !== 'development'; const { ltr, rtl } = await minifier.css.bundle(data.imports, data.paths, minify, fork); - await Promise.all([ fs.promises.writeFile(path.join(__dirname, '../../build/public', `${target}.css`), ltr.code), fs.promises.writeFile(path.join(__dirname, '../../build/public', `${target}-rtl.css`), rtl.code), copyFontAwesomeFiles(), ]); return [ltr.code, rtl.code]; -}; +}; \ No newline at end of file