Fix formatting

This commit is contained in:
RMidhunSuresh 2022-04-10 14:52:26 +05:30
parent ff98ef4465
commit 0a95eb0940

View File

@ -187,64 +187,64 @@ module.exports = function buildThemes(options) {
} }
return null; return null;
} }
}, },
transformIndexHtml(_, ctx) { transformIndexHtml(_, ctx) {
if (isDevelopment) { if (isDevelopment) {
// Don't add default stylesheets to index.html on dev // Don't add default stylesheets to index.html on dev
return; return;
}
let darkThemeLocation, lightThemeLocation;
for (const [, bundle] of Object.entries(ctx.bundle)) {
if (bundle.name === defaultDark) {
darkThemeLocation = bundle.fileName;
} }
if (bundle.name === defaultLight) { let darkThemeLocation, lightThemeLocation;
lightThemeLocation = bundle.fileName; for (const [, bundle] of Object.entries(ctx.bundle)) {
if (bundle.name === defaultDark) {
darkThemeLocation = bundle.fileName;
}
if (bundle.name === defaultLight) {
lightThemeLocation = bundle.fileName;
}
} }
} return [
return [ {
{ tag: "link",
tag: "link", attrs: {
attrs: { rel: "stylesheet",
rel: "stylesheet", type: "text/css",
type: "text/css", media: "(prefers-color-scheme: dark)",
media: "(prefers-color-scheme: dark)", href: `./${darkThemeLocation}`,
href: `./${darkThemeLocation}`, }
} },
}, {
{ tag: "link",
tag: "link", attrs: {
attrs: { rel: "stylesheet",
rel: "stylesheet", type: "text/css",
type: "text/css", media: "(prefers-color-scheme: light)",
media: "(prefers-color-scheme: light)", href: `./${lightThemeLocation}`,
href: `./${lightThemeLocation}`, }
} },
}, ];
]; },
},
generateBundle(_, bundle) { generateBundle(_, bundle) {
const { assetMap, chunkMap, runtimeThemeChunk } = parseBundle(bundle); const { assetMap, chunkMap, runtimeThemeChunk } = parseBundle(bundle);
for (const [location, chunkArray] of chunkMap) { for (const [location, chunkArray] of chunkMap) {
const manifest = require(`${location}/manifest.json`); const manifest = require(`${location}/manifest.json`);
const compiledVariables = options.compiledVariables.get(location); const compiledVariables = options.compiledVariables.get(location);
const derivedVariables = compiledVariables["derived-variables"]; const derivedVariables = compiledVariables["derived-variables"];
const icon = compiledVariables["icon"]; const icon = compiledVariables["icon"];
manifest.source = { manifest.source = {
"built-asset": chunkArray.map(chunk => assetMap.get(chunk.fileName).fileName), "built-asset": chunkArray.map(chunk => assetMap.get(chunk.fileName).fileName),
"runtime-asset": assetMap.get(runtimeThemeChunk.fileName).fileName, "runtime-asset": assetMap.get(runtimeThemeChunk.fileName).fileName,
"derived-variables": derivedVariables, "derived-variables": derivedVariables,
"icon": icon "icon": icon
}; };
const name = `theme-${manifest.name}.json`; const name = `theme-${manifest.name}.json`;
this.emitFile({ this.emitFile({
type: "asset", type: "asset",
name, name,
source: JSON.stringify(manifest), source: JSON.stringify(manifest),
}); });
} }
} },
} }
} }