Skip to content

Commit

Permalink
reversed back to previous commit for better test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Nalseaf committed Sep 5, 2024
1 parent ee4550d commit 0558ef6
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 41 deletions.
Binary file modified dump.rdb
Binary file not shown.
42 changes: 1 addition & 41 deletions src/meta/css.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
'use strict';

Check failure on line 1 in src/meta/css.js

View workflow job for this annotation

GitHub Actions / test

Expected newline after "use strict" directive

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');

Check failure on line 12 in src/meta/css.js

View workflow job for this annotation

GitHub Actions / test

Expected 1 empty line after require statement not followed by another require

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 [
Expand All @@ -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/
Expand All @@ -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";',
Expand Down Expand Up @@ -113,33 +103,25 @@ 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
'@import "./theme";', // rest of the theme scss
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'));
Expand All @@ -151,10 +133,8 @@ async function copyFontAwesomeFiles() {
);
}
}

await Promise.all(copyOperations);
}

async function filterMissingFiles(filepaths) {
const exists = await Promise.all(
filepaths.map(async (filepath) => {
Expand All @@ -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 '';
Expand All @@ -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);
Expand All @@ -197,15 +174,13 @@ async function getImports(files, extension) {
}));
return source;
}

async function getBundleMetadata(target) {
const paths = [
path.join(__dirname, '../../node_modules'),
path.join(__dirname, '../../public/scss'),
path.join(__dirname, '../../public/fontawesome/scss'),
path.join(utils.getFontawesomePath(), 'scss'),
];

// Skin support
let skin;
let isCustomSkin = false;
Expand All @@ -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']);
Expand All @@ -235,37 +209,30 @@ 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');
const [userSettings, customSkins] = await Promise.all([
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' },
Expand Down Expand Up @@ -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');
Expand All @@ -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];
};
};

Check failure on line 310 in src/meta/css.js

View workflow job for this annotation

GitHub Actions / test

Newline required at end of file but not found

0 comments on commit 0558ef6

Please sign in to comment.