import fs from 'fs' import path from 'path' import type { Config, Dictionary, PlatformConfig } from 'style-dictionary/types' export function appendAnimations( dictionary: Dictionary, config: PlatformConfig, options: Config, ) { if (!config.animationsPath) { console.warn('No animationsPath specified in config') return } if (!config.files || config.files.length === 0) { console.warn('No output files specified in config') return } if (!config.buildPath) { console.warn('No buildPath specified in config') return } const animationsDir = config.animationsPath as string const outputFile = config.files[0]?.destination ?? '' const cssPath = path.join(config.buildPath, outputFile) if (!fs.existsSync(animationsDir)) { console.warn(`Animations directory not found: ${animationsDir}`) return } const animationFiles = fs .readdirSync(animationsDir) .filter(file => file.endsWith('.css')) const animations = animationFiles .map(file => fs.readFileSync(path.join(animationsDir, file), 'utf8')) .join('\n\n') const css = fs.readFileSync(cssPath, 'utf8') const finalCSS = `${css}\n\n${animations}` fs.writeFileSync(cssPath, finalCSS) } export function removeAnimations( dictionary: Dictionary, config: PlatformConfig, options: Config, ) { if (!config.animationsPath) { console.warn('No animationsPath specified in config') return } if (!config.files || config.files.length === 0) { console.warn('No output files specified in config') return } if (!config.buildPath) { console.warn('No buildPath specified in config') return } const outputFile = config.files[0]?.destination ?? '' const cssPath = path.join(config.buildPath, outputFile) // erase animations from the file const css = fs.readFileSync(cssPath, 'utf8') const finalCSS = css.replace(/@keyframes\s+\w+\s*\{[\s\S]*?\}/g, '') fs.writeFileSync(cssPath, finalCSS) }