build theme css bundles

This commit is contained in:
Bruno Windels 2020-08-12 16:39:35 +02:00
parent c3dc01283d
commit fc8d2efaf2

View File

@ -84,11 +84,10 @@ async function build() {
await buildHtml(doc, version, bundleName); await buildHtml(doc, version, bundleName);
if (legacy) { if (legacy) {
await buildJsLegacy(bundleName); await buildJsLegacy(bundleName);
await buildCssLegacy();
} else { } else {
await buildJs(bundleName); await buildJs(bundleName);
await buildCss();
} }
await buildCssBundles(legacy ? buildCssLegacy : buildCss, themes);
if (offline) { if (offline) {
await buildOffline(version, bundleName); await buildOffline(version, bundleName);
} }
@ -231,22 +230,29 @@ async function buildOffline(version, bundleName) {
await fs.writeFile(path.join(targetDir, "icon-192.png"), icon); await fs.writeFile(path.join(targetDir, "icon-192.png"), icon);
} }
async function buildCss() { async function buildCssBundles(buildFn, themes) {
// create css bundle const cssMainFile = path.join(cssDir, "main.css");
const cssMainFile = path.join(projectDir, "src/ui/web/css/main.css"); await buildFn(cssMainFile, path.join(targetDir, `${PROJECT_ID}.css`));
const preCss = await fs.readFile(cssMainFile, "utf8"); for (const theme of themes) {
const cssBundler = postcss([postcssImport]); await buildFn(
const result = await cssBundler.process(preCss, {from: cssMainFile}); path.join(cssDir, `themes/${theme}/theme.css`),
await fs.writeFile(path.join(targetDir, `${PROJECT_ID}.css`), result.css, "utf8"); path.join(targetDir, `themes/${theme}/bundle.css`)
);
}
} }
async function buildCssLegacy() { async function buildCss(entryPath, bundlePath) {
// create css bundle const preCss = await fs.readFile(entryPath, "utf8");
const cssMainFile = path.join(projectDir, "src/ui/web/css/main.css"); const cssBundler = postcss([postcssImport]);
const preCss = await fs.readFile(cssMainFile, "utf8"); const result = await cssBundler.process(preCss, {from: entryPath});
await fs.writeFile(bundlePath, result.css, "utf8");
}
async function buildCssLegacy(entryPath, bundlePath) {
const preCss = await fs.readFile(entryPath, "utf8");
const cssBundler = postcss([postcssImport, cssvariables(), flexbugsFixes()]); const cssBundler = postcss([postcssImport, cssvariables(), flexbugsFixes()]);
const result = await cssBundler.process(preCss, {from: cssMainFile}); const result = await cssBundler.process(preCss, {from: entryPath});
await fs.writeFile(path.join(targetDir, `${PROJECT_ID}.css`), result.css, "utf8"); await fs.writeFile(bundlePath, result.css, "utf8");
} }
function removeOrEnableScript(scriptNode, enable) { function removeOrEnableScript(scriptNode, enable) {