mirror of
https://github.com/nexu-io/open-design.git
synced 2026-06-01 03:14:35 +07:00
* refactor(web): split global CSS by ownership * test(web): expand CSS imports in style checks * fix(web): keep privacy consent banner above modals
23 lines
786 B
TypeScript
23 lines
786 B
TypeScript
import { readFileSync } from 'node:fs';
|
|
import { dirname, join } from 'node:path';
|
|
|
|
function expandCssFile(filePath: string, seen = new Set<string>()): string {
|
|
const key = filePath;
|
|
if (seen.has(key)) {
|
|
return '';
|
|
}
|
|
seen.add(key);
|
|
|
|
const css = readFileSync(filePath, 'utf8');
|
|
return css.replace(/@import\s+(?:url\(([^)]+)\)|(['"])([^'"]+)\2);/g, (_match, urlImport, _quote, quotedImport) => {
|
|
const specifier = (quotedImport ?? urlImport ?? '').trim().replace(/^['"]|['"]$/g, '');
|
|
if (!specifier.startsWith('./') && !specifier.startsWith('../')) {
|
|
return '';
|
|
}
|
|
return expandCssFile(join(dirname(filePath), specifier), seen);
|
|
});
|
|
}
|
|
|
|
export function readExpandedIndexCss(): string {
|
|
return expandCssFile(join(process.cwd(), 'src/index.css'));
|
|
}
|