import { readdirSync, readFileSync, writeFileSync, statSync } from 'node:fs' import path from 'node:path' import { fileURLToPath } from 'node:url' const CLASS_ATTR = /className=(?:"[^"]*"|'[^']*'|\{"[^"]*"\}|\{'[^']*'\}|\{`(?:[^`\\]|\\.)*`\})/g const ROUNDED = /(? q + body.trim().replace(/ {2,}/g, ' ') + q) out = out.replace(/^(className=\{`)\s+/, '$1').replace(/\s+(`\})$/, '$1') return out } export function transformSource(src) { const next = src.replace(CLASS_ATTR, transformClassAttr) return next.replace(/ className=(?:""|''|\{""\}|\{''\}|\{``\})/g, '') } function walk(dir, files = []) { for (const name of readdirSync(dir)) { const full = path.join(dir, name) if (statSync(full).isDirectory()) walk(full, files) else if (full.endsWith('.tsx')) files.push(full) } return files } function main() { const dry = process.argv.includes('--dry') const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..') let changed = 0 for (const dir of ['app', 'components']) { for (const file of walk(path.join(root, dir))) { const before = readFileSync(file, 'utf8') const after = transformSource(before) if (after !== before) { changed++ if (!dry) writeFileSync(file, after) } } } console.log(`${dry ? 'would change' : 'changed'} ${changed} files`) } if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) main()