From 9f763b5b79a8e6c61407943615038bafa499bd22 Mon Sep 17 00:00:00 2001 From: Claire Date: Fri, 11 Feb 2022 23:06:37 +0100 Subject: Refactor compile-time glitch-soc theme handling --- config/webpack/shared.js | 51 ++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) (limited to 'config/webpack/shared.js') diff --git a/config/webpack/shared.js b/config/webpack/shared.js index ce08ac206..de347fa88 100644 --- a/config/webpack/shared.js +++ b/config/webpack/shared.js @@ -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); + } + } + + 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) continue; + + into[`skins/${data.name}/${skinName}/${entry}`] = resolve(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) => { - const packFile = skin[entry]; - if (!packFile) { - return map; - } - 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), {}) ); -- cgit From f3b9a2b590147c8b383b9db7e46684e89d74ad69 Mon Sep 17 00:00:00 2001 From: Claire Date: Fri, 11 Feb 2022 23:52:42 +0100 Subject: Add support for multiple source files per pack --- app/controllers/concerns/theming_concern.rb | 2 +- config/webpack/shared.js | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'config/webpack/shared.js') diff --git a/app/controllers/concerns/theming_concern.rb b/app/controllers/concerns/theming_concern.rb index 425554072..f993a81d7 100644 --- a/app/controllers/concerns/theming_concern.rb +++ b/app/controllers/concerns/theming_concern.rb @@ -20,7 +20,7 @@ module ThemingConcern end def valid_pack_data?(data, pack_name) - data['pack'].is_a?(Hash) && [String, Hash].any? { |c| data['pack'][pack_name].is_a?(c) } + data['pack'].is_a?(Hash) && data['pack'][pack_name].present? end def nil_pack(data) diff --git a/config/webpack/shared.js b/config/webpack/shared.js index de347fa88..c2a108a89 100644 --- a/config/webpack/shared.js +++ b/config/webpack/shared.js @@ -16,10 +16,16 @@ function reducePacks (data, into = {}) { const pack = data.pack[entry]; if (!pack) continue; - const packFile = typeof pack === 'string' ? pack : pack.filename; - - if (packFile) { - into[data.name ? `flavours/${data.name}/${entry}` : `core/${entry}`] = resolve(data.pack_directory, packFile); + let packFiles = []; + if (typeof pack === 'string') + packFiles = [pack]; + else if (Array.isArray(pack)) + packFiles = pack; + else + packFiles = [pack.filename]; + + if (packFiles) { + into[data.name ? `flavours/${data.name}/${entry}` : `core/${entry}`] = packFiles.map(packFile => resolve(data.pack_directory, packFile)); } } -- cgit