const fs = require('fs');
const path = require('path');
const chunk = fs.readFileSync(path.join(__dirname, 'chunk.js'), 'utf8');
function extractStyle(id) {
const pattern = id + ':{paletteStrategy:';
const idx = chunk.indexOf(pattern);
if (idx === -1) return null;
let start = idx + id.length + 1;
let depth = 0;
let end = start;
for (let j = start; j < chunk.length; j++) {
if (chunk[j] === '{') depth++;
if (chunk[j] === '}') depth--;
if (depth === 0) { end = j + 1; break; }
}
const raw = chunk.substring(start, end);
const name = raw.match(/style_name:\s*"([^"]+)"/)?.[1] || '';
const industry = raw.match(/industry:\s*"([^"]+)"/)?.[1] || '';
const palette = raw.match(/paletteStrategy:"((?:[^"\\]|\\.)*)"/)?.[1] || '';
const typo = raw.match(/typography:"((?:[^"\\]|\\.)*)"/)?.[1] || '';
const radius = raw.match(/radiusPolicy:"((?:[^"\\]|\\.)*)"/)?.[1] || '';
const shadow = raw.match(/shadowPolicy:"((?:[^"\\]|\\.)*)"/)?.[1] || '';
const border = raw.match(/borderLanguage:"((?:[^"\\]|\\.)*)"/)?.[1] || '';
const patterns = raw.match(/patterns:"((?:[^"\\]|\\.)*)"/)?.[1] || '';
const motion = raw.match(/motion:"((?:[^"\\]|\\.)*)"/)?.[1] || '';
const dosM = raw.match(/dos:\[((?:[^\]]|\n)*)\]/);
const dos = dosM ? dosM[1].match(/"((?:[^"\\]|\\.)*)"/g)?.map(s => s.slice(1, -1)) || [] : [];
const dontsM = raw.match(/donts:\[((?:[^\]]|\n)*)\]/);
const donts = dontsM ? dontsM[1].match(/"((?:[^"\\]|\\.)*)"/g)?.map(s => s.slice(1, -1)) || [] : [];
// Extract tokens (YAML block inside template literal)
const tStart = raw.indexOf('tokens:`') + 8;
const tEnd = raw.lastIndexOf('`');
let tokens = '';
if (tStart > 7 && tEnd > tStart) {
tokens = raw.substring(tStart, tEnd)
.replace(/^\\`\\`\\`yaml\n/, '')
.replace(/\\`\\`\\`$/, '')
.trim();
}
return {
id, name, industry,
styleDNA: { palette, typo, radius, shadow, border, patterns, motion },
dos, donts, tokens,
rawLength: raw.length
};
}
// Extract all 100 styles
const styles = {};
const promptsDir = path.join(__dirname, 'prompts');
fs.mkdirSync(promptsDir, { recursive: true });
for (let n = 1; n <= 100; n++) {
const id = 'S' + String(n).padStart(2, '0');
const style = extractStyle(id);
if (style) {
styles[id] = style;
// Save individual prompt file
const md = `# ${id} — ${style.name}
## Industry: ${style.industry}
## Style DNA
- **Palette:** ${style.styleDNA.palette}
- **Typography:** ${style.styleDNA.typo}
- **Radius:** ${style.styleDNA.radius}
- **Shadow:** ${style.styleDNA.shadow}
- **Border:** ${style.styleDNA.border}
- **Patterns:** ${style.styleDNA.patterns}
- **Motion:** ${style.styleDNA.motion}
## Do's
${style.dos.map(d => '- ' + d).join('\n')}
## Don'ts
${style.donts.map(d => '- ' + d).join('\n')}
## Design Tokens
\`\`\`yaml
${style.tokens}
\`\`\`
`;
fs.writeFileSync(path.join(promptsDir, `${id}.md`), md);
}
}
// Save complete JSON
fs.writeFileSync(
path.join(__dirname, 'styles-complete.json'),
JSON.stringify(styles, null, 2)
);
// Save index
const index = Object.values(styles).map(s => ({
id: s.id,
name: s.name,
industry: s.industry,
palette_summary: s.styleDNA.palette.substring(0, 80),
prompt_file: `prompts/${s.id}.md`,
raw_length: s.rawLength
}));
fs.writeFileSync(
path.join(__dirname, 'styles-index.json'),
JSON.stringify(index, null, 2)
);
console.log(`Extracted ${Object.keys(styles).length} styles`);
console.log(`Files saved to: ${promptsDir}`);
console.log(`Index: styles-index.json`);
console.log(`Complete: styles-complete.json`);