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

View file

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