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