Build step for the css themes continued

This commit is contained in:
Ariadna 2025-05-15 01:36:19 -04:00
parent e49ce63db9
commit 0a6279823e
Signed by: ari
SSH key fingerprint: SHA256:j4xpQafvRcIH4rwZqM5aREIogWsCjyYohia7vH0+uZY
2 changed files with 119 additions and 0 deletions

30
theming.ts Normal file
View file

@ -0,0 +1,30 @@
import { Plugin } from 'vite';
import { Config } from './config';
// Replaces app.css with the contents of the file specified in the
// config file.
export const themePlugin = (): Plugin => {
const themeFile = Config.THEME;
console.log(`Using theme file: ${themeFile}`);
return {
name: 'theme-generator',
transform(code, id) {
if (id.endsWith('app.css')) {
// Read the theme file and replace the contents of app.css with it
// Needs full path to the file
const themeCode = Deno.readTextFileSync(Deno.cwd() + '/src/themes/' + themeFile);
// Replace the contents of app.css with the theme code
// and add a comment at the top
const themeComment = `/* Generated from ${themeFile} */\n`;
const themeCodeWithComment = themeComment + themeCode;
// Return the theme code as the new contents of app.css
return {
code: themeCodeWithComment,
map: null,
};
}
return null;
}
};
};