pds dash for shimaenaga.veryroundbird.house (based off of pds.witchcraft.systems)
1import { Plugin } from 'vite';
2import { Config } from './config';
3
4
5// Replaces app.css with the contents of the file specified in the
6// config file.
7export const themePlugin = (): Plugin => {
8 const themeFolder = Config.THEME;
9 console.log(`Using theme folder: ${themeFolder}`);
10 return {
11 name: 'theme-generator',
12 enforce: 'pre', // Ensure this plugin runs first
13 transform(code, id) {
14 if (id.endsWith('app.css')) {
15 // Read the theme file and replace the contents of app.css with it
16 // Needs full path to the file
17 const themeCode = Deno.readTextFileSync(Deno.cwd() + '/themes/' + themeFolder + '/theme.css');
18 // Replace the contents of app.css with the theme code
19
20 // and add a comment at the top
21 const themeComment = `/* Generated from ${themeFolder} */\n`;
22 const themeCodeWithComment = themeComment + themeCode;
23 // Return the theme code as the new contents of app.css
24 return {
25 code: themeCodeWithComment,
26 map: null,
27 };
28 }
29 return null;
30 }
31 };
32};