mirror of
https://github.com/infinilabs/coco-app.git
synced 2025-12-16 19:47:43 +01:00
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { readFileSync, writeFileSync } from "fs";
|
|
import { join, dirname } from "path";
|
|
import { fileURLToPath } from "url";
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = dirname(__filename);
|
|
|
|
const extractCssVars = () => {
|
|
const filePath = join(__dirname, "../out/search-chat/index.css");
|
|
|
|
const cssContent = readFileSync(filePath, "utf-8");
|
|
|
|
const vars: Record<string, string> = {};
|
|
|
|
const propertyBlockRegex = /@property\s+(--[\w-]+)\s*\{([\s\S]*?)\}/g;
|
|
|
|
let match: RegExpExecArray | null;
|
|
|
|
while ((match = propertyBlockRegex.exec(cssContent))) {
|
|
const [, varName, body] = match;
|
|
|
|
const initialValueMatch = /initial-value\s*:\s*([^;]+);/.exec(body);
|
|
|
|
if (initialValueMatch) {
|
|
vars[varName] = initialValueMatch[1].trim();
|
|
}
|
|
}
|
|
|
|
const cssVarsBlock =
|
|
`.coco-container {\n` +
|
|
Object.entries(vars)
|
|
.map(([k, v]) => ` ${k}: ${v};`)
|
|
.join("\n") +
|
|
`\n}\n`;
|
|
|
|
writeFileSync(filePath, `${cssContent}\n${cssVarsBlock}`, "utf-8");
|
|
};
|
|
|
|
extractCssVars();
|