/** * Theme Style Analyzer * * Automatically analyzes existing Shopify theme styles and extracts them * for integration with Preliquify components. This prevents style conflicts * and ensures React components blend seamlessly with the existing theme. * * Features: * - Scans assets/*.css for theme styles * - Extracts :root CSS variables * - Extracts @keyframes animations * - Extracts important selectors (.shopify-*, etc.) * - Generates theme-extracted.css with scoped styles */ import { promises as fs } from "node:fs"; import { join, basename } from "node:path"; import fg from "fast-glob"; export interface ExtractedStyles { /** CSS custom properties from :root */ cssVariables: string[]; /** @keyframes definitions */ keyframes: string[]; /** Important theme selectors */ themeSelectors: string[]; /** Font-face declarations */ fontFaces: string[]; /** Media queries with theme settings */ mediaQueries: string[]; /** Raw combined CSS */ rawCSS: string; } export interface ThemeAnalyzerOptions { /** Directory containing theme assets (default: ./assets) */ assetsDir?: string; /** Directory containing Liquid files to scan for embedded CSS */ liquidDirs?: string[]; /** Selectors to always include */ includeSelectors?: string[]; /** Selectors to exclude */ excludeSelectors?: string[]; /** Whether to scope extracted styles */ scopeStyles?: boolean; /** Scope selector (default: [data-preliquify]) */ scopeSelector?: string; /** Enable verbose logging */ verbose?: boolean; } const DEFAULT_OPTIONS: Required = { assetsDir: "./assets", liquidDirs: ["./layout", "./sections", "./snippets", "./templates"], includeSelectors: [ ":root", ".shopify-", ".section-", ".page-", ".rte", ".product-", ".collection-", ".cart-", ".customer-", ".header", ".footer", ".drawer", ".modal", ".overlay", "[data-", ], excludeSelectors: [".preliquify-", "[data-preliquify]"], scopeStyles: true, scopeSelector: "[data-preliquify]", verbose: false, }; /** * Extracts CSS from a file content */ function extractCSSFromContent(content: string): string { // Extract inline