- Ported Minimalist templates to JSON (Swiss Grid, Brutalist, etc.) - Ported Tech templates to JSON (SaaS, Terminal, Cyberpunk, etc.) - Ported Creative templates to JSON (Art Gallery, Zine, Pop Art, etc.) - Ported Industrial templates to JSON (Blueprint, Factory, Schematic, etc.) - Ported Nature templates to JSON (Botanical, Ocean, Mountain, etc.) - Ported Lifestyle templates to JSON (Cookbook, Travel, Coffee House, etc.) - Ported Vintage templates to JSON (Art Deco, Medieval, Retro 80s, etc.) - Updated README.md to reflect the new JSON-based style system (example configuration and contribution workflow) - Completed migration of over 150 styles to the new architecture
50 lines
2.1 KiB
JavaScript
50 lines
2.1 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const rootDir = 'd:\\gdfhbfgdbnbdfbdf\\typogenie\\src-tauri\\templates';
|
|
|
|
function walk(dir) {
|
|
const files = fs.readdirSync(dir, { withFileTypes: true });
|
|
files.forEach(dirent => {
|
|
const fullPath = path.join(dir, dirent.name);
|
|
if (dirent.isDirectory()) {
|
|
walk(fullPath);
|
|
} else if (dirent.name.endsWith('.json')) {
|
|
let content = fs.readFileSync(fullPath, 'utf8');
|
|
let changed = false;
|
|
|
|
// 1. Fix double quotes artifact from previous failed regex
|
|
if (content.includes('""border')) {
|
|
content = content.replace(/""border/g, '"border');
|
|
changed = true;
|
|
}
|
|
|
|
// 2. Fix the swallowed element braces for common elements
|
|
// We look for a border property followed by a new key without a closing/opening sequence
|
|
// e.g. "borderBottom": { ... }, "h3": {
|
|
// needs a closing brace: "borderBottom": { ... } }, "h3": {
|
|
|
|
// This regex matches a border property at the end of an element.
|
|
// It tries to insert a closing brace if it's missing.
|
|
const keys = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'blockquote', 'code', 'pre', 'ul', 'ol', 'table', 'hr', 'img', 'mark', 'footnote', 'page'];
|
|
keys.forEach(key => {
|
|
// If we see a border property followed by a comma and then a key,
|
|
// it means the element itself was never closed.
|
|
const brokenSequenceRegex = new RegExp(`("border(?:Top|Bottom|Left|Right)":\\s*{[^}]*}\\s*),\\s*"(${key})":`, 'g');
|
|
if (brokenSequenceRegex.test(content)) {
|
|
content = content.replace(brokenSequenceRegex, '$1\n },\n "$2":');
|
|
changed = true;
|
|
}
|
|
});
|
|
|
|
if (changed) {
|
|
fs.writeFileSync(fullPath, content, { encoding: 'utf8' });
|
|
console.log(`Surgery Performed: ${fullPath}`);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
walk(rootDir);
|
|
console.log('Finished template surgery.');
|