Refactor compile-time glitch-soc theme handling

This commit is contained in:
Claire 2022-02-11 23:06:37 +01:00
parent 59b7ba451b
commit 9f763b5b79
2 changed files with 30 additions and 38 deletions

View File

@ -21,8 +21,7 @@ const core = function () {
return data.pack ? data : {}; return data.pack ? data : {};
}(); }();
for (let i = 0; i < flavourFiles.length; i++) { flavourFiles.forEach((flavourFile) => {
const flavourFile = flavourFiles[i];
const data = load(readFileSync(flavourFile), 'utf8'); const data = load(readFileSync(flavourFile), 'utf8');
data.name = basename(dirname(flavourFile)); data.name = basename(dirname(flavourFile));
data.skin = {}; data.skin = {};
@ -35,27 +34,25 @@ for (let i = 0; i < flavourFiles.length; i++) {
if (data.pack && typeof data.pack === 'object') { if (data.pack && typeof data.pack === 'object') {
flavours[data.name] = data; flavours[data.name] = data;
} }
} });
for (let i = 0; i < skinFiles.length; i++) { skinFiles.forEach((skinFile) => {
const skinFile = skinFiles[i];
let skin = basename(skinFile); let skin = basename(skinFile);
const name = basename(dirname(skinFile)); const name = basename(dirname(skinFile));
if (!flavours[name]) { if (!flavours[name]) {
continue; return;
} }
const data = flavours[name].skin; const data = flavours[name].skin;
if (lstatSync(skinFile).isDirectory()) { if (lstatSync(skinFile).isDirectory()) {
data[skin] = {}; data[skin] = {};
const skinPacks = glob.sync(join(skinFile, '*.{css,scss}')); const skinPacks = glob.sync(join(skinFile, '*.{css,scss}'));
for (let j = 0; j < skinPacks.length; j++) { skinPacks.forEach((pack) => {
const pack = skinPacks[j];
data[skin][basename(pack, extname(pack))] = pack; data[skin][basename(pack, extname(pack))] = pack;
} });
} else if ((skin = skin.match(/^(.*)\.s?css$/i))) { } else if ((skin = skin.match(/^(.*)\.s?css$/i))) {
data[skin[1]] = { common: skinFile }; data[skin[1]] = { common: skinFile };
} }
} });
const output = { const output = {
path: resolve('public', settings.public_output_path), path: resolve('public', settings.public_output_path),

View File

@ -10,38 +10,33 @@ const rules = require('./rules');
const localePacks = require('./generateLocalePacks'); const localePacks = require('./generateLocalePacks');
function reducePacks (data, into = {}) { function reducePacks (data, into = {}) {
if (!data.pack) { if (!data.pack) return into;
return into;
} for (const entry in data.pack) {
Object.keys(data.pack).reduce((map, entry) => {
const pack = data.pack[entry]; const pack = data.pack[entry];
if (!pack) { if (!pack) continue;
return map;
}
const packFile = typeof pack === 'string' ? pack : pack.filename; const packFile = typeof pack === 'string' ? pack : pack.filename;
if (packFile) { if (packFile) {
map[data.name ? `flavours/${data.name}/${entry}` : `core/${entry}`] = resolve(data.pack_directory, packFile); into[data.name ? `flavours/${data.name}/${entry}` : `core/${entry}`] = resolve(data.pack_directory, packFile);
} }
return map;
}, into);
if (data.name) {
Object.keys(data.skin).reduce((map, entry) => {
const skin = data.skin[entry];
const skinName = entry;
if (!skin) {
return map;
} }
Object.keys(skin).reduce((map, entry) => {
if (!data.name) return into;
for (const skinName in data.skin) {
const skin = data.skin[skinName];
if (!skin) continue;
for (const entry in skin) {
const packFile = skin[entry]; const packFile = skin[entry];
if (!packFile) { if (!packFile) continue;
return map;
into[`skins/${data.name}/${skinName}/${entry}`] = resolve(packFile);
} }
map[`skins/${data.name}/${skinName}/${entry}`] = resolve(packFile);
return map;
}, into);
return map;
}, into);
} }
return into; return into;
} }
@ -49,7 +44,7 @@ const entries = Object.assign(
{ locales: resolve('app', 'javascript', 'locales') }, { locales: resolve('app', 'javascript', 'locales') },
localePacks, localePacks,
reducePacks(core), reducePacks(core),
Object.keys(flavours).reduce((map, entry) => reducePacks(flavours[entry], map), {}) Object.values(flavours).reduce((map, data) => reducePacks(data, map), {})
); );