Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 4x 4x 4x 1x 2x 2x 2x | /**
* @fds-uif/core - CSS Node.js Utilities
*
* File system operations for CSS metadata extraction.
* These functions require Node.js and are NOT available in browser builds.
*
* @see RFC: uif-styling-layer.md
*/
import { readFile } from 'node:fs/promises';
import { resolve, dirname, relative } from 'node:path';
import type { CssMetadata, ParseCssOptions } from './types.js';
import { generateCssMetadata } from './metadata-generator.js';
import { inferSystemFromFilename } from './metadata-queries.js';
/**
* Parse a CSS file from disk and generate metadata.
*
* @param cssPath - Path to the CSS file
* @param options - Parser options
* @returns Complete CSS metadata
*/
export async function parseCssSource(
cssPath: string,
options: ParseCssOptions = {},
): Promise<CssMetadata> {
const cssContent = await readFile(cssPath, 'utf-8');
const relativePath = relative(process.cwd(), cssPath);
return generateCssMetadata(cssContent, relativePath, options);
}
/**
* Extract CSS metadata from a UIF system definition.
*
* @param uif - UIF object with optional cssSource property
* @param uifFilePath - Path to the UIF file (for resolving relative cssSource)
* @returns CSS metadata or null if no cssSource
*/
export async function extractCssMetadata(
uif: { name?: string; cssSource?: string },
uifFilePath: string,
): Promise<CssMetadata | null> {
if (!uif.cssSource) {
return null;
}
const cssPath = resolve(dirname(uifFilePath), uif.cssSource);
const system = inferSystemFromFilename(uifFilePath);
return parseCssSource(cssPath, {
componentName: uif.name,
system,
});
}
|