File: /var/www/design.system/src/icons/utils/fixSvgColor.ts
import fs from 'fs/promises';
import path from 'path';
const sizes = ['16', '20', '24'];
const baseDir = './src/icons';
const replaceColors = async (filePath: string) => {
const content = await fs.readFile(filePath, 'utf-8');
const result = content
.replace(/stroke="(?!none)([^"]+)"/g, 'stroke="currentColor"')
.replace(/fill="(?!none)([^"]+)"/g, 'fill="currentColor"')
.replace(/color="(?!none)([^"]+)"/g, 'color="currentColor"');
if (result !== content) {
await fs.writeFile(filePath, result, 'utf-8');
}
};
const run = async () => {
for (const size of sizes) {
const dir = path.join(baseDir, size);
const files = await fs.readdir(dir);
await Promise.all(
files.filter((f) => f.endsWith('.svg')).map((file) => replaceColors(path.join(dir, file)))
);
}
};
run();