/** * Composes the final multi-theme `unity.css` by concatenating the formatted * outputs from three SD instances into a single file. */ import fs from 'fs' import path from 'path' import prettier from 'prettier' export interface ComposeInput { /** css/variables output for legacy (:root selector) */ legacyCss: string /** css/variables output for rebrand ([data-uy-theme="rebrand"] selector) */ rebrandCss: string /** css/unity-theme output (@theme block + grid/typography utilities) */ themeCss: string /** File header + imports */ header: string /** Custom variant declarations */ customVariants: string /** Output path for the composed CSS */ outputPath: string } export async function composeMultiThemeCss(input: ComposeInput): Promise { const { legacyCss, rebrandCss, themeCss, header, customVariants, outputPath, } = input const css = `${header} @layer base { ${legacyCss} ${rebrandCss} } ${themeCss} ${customVariants} ` console.log(' \x1b[2m→\x1b[0m Formatting with Prettier...') const formatted = await prettier.format(css, { parser: 'css', printWidth: 120, tabWidth: 2, useTabs: false, }) fs.mkdirSync(path.dirname(outputPath), { recursive: true }) fs.writeFileSync(outputPath, formatted) console.log(` \x1b[2m→\x1b[0m Written to \x1b[33m${outputPath}\x1b[0m`) }