|
| 1 | +import fs from 'fs-extra' |
| 2 | +import { themes as allThemes } from 'tm-themes' |
| 3 | + |
| 4 | +async function main() { |
| 5 | + // if a theme doesn't define bracket colors, it falls back to these |
| 6 | + // from vscode /src/vs/editor/common/core/editorColorRegistry.ts |
| 7 | + const vsCodeBaseThemes: Record<string, Record<string, string>> = { |
| 8 | + light: { |
| 9 | + 'editorBracketHighlight.foreground1': '#0431FA', |
| 10 | + 'editorBracketHighlight.foreground2': '#319331', |
| 11 | + 'editorBracketHighlight.foreground3': '#7B3814', |
| 12 | + 'editorBracketHighlight.unexpectedBracket.foreground': |
| 13 | + 'rgba(255, 18, 18, 0.8)', |
| 14 | + }, |
| 15 | + dark: { |
| 16 | + 'editorBracketHighlight.foreground1': '#FFD700', |
| 17 | + 'editorBracketHighlight.foreground2': '#DA70D6', |
| 18 | + 'editorBracketHighlight.foreground3': '#179FFF', |
| 19 | + 'editorBracketHighlight.unexpectedBracket.foreground': |
| 20 | + 'rgba(255, 18, 18, 0.8)', |
| 21 | + }, |
| 22 | + lightHighContrast: { |
| 23 | + 'editorBracketHighlight.foreground1': '#0431FA', |
| 24 | + 'editorBracketHighlight.foreground2': '#319331', |
| 25 | + 'editorBracketHighlight.foreground3': '#7B3814', |
| 26 | + 'editorBracketHighlight.unexpectedBracket.foreground': '#B5200D', |
| 27 | + }, |
| 28 | + darkHighContrast: { |
| 29 | + 'editorBracketHighlight.foreground1': '#FFD700', |
| 30 | + 'editorBracketHighlight.foreground2': '#DA70D6', |
| 31 | + 'editorBracketHighlight.foreground3': '#87CEFA', |
| 32 | + 'editorBracketHighlight.unexpectedBracket.foreground': |
| 33 | + 'rgba(255, 50, 50, 1)', |
| 34 | + }, |
| 35 | + } |
| 36 | + |
| 37 | + const themes: Record<string, string[]> = {} |
| 38 | + for (const t of allThemes) { |
| 39 | + const theme = await fs.readJSON(`./node_modules/shiki/node_modules/tm-themes/themes/${t.name}.json`) |
| 40 | + const isHighContrast = t.name.includes('high-contrast') |
| 41 | + const themeType = theme.type ?? 'dark' |
| 42 | + const baseTheme = isHighContrast ? `${themeType}HighContrast` : themeType |
| 43 | + const colors: Record<string, string> = { |
| 44 | + ...vsCodeBaseThemes[baseTheme], |
| 45 | + ...theme.colors, |
| 46 | + } |
| 47 | + const bracketTheme = [ |
| 48 | + colors['editorBracketHighlight.foreground1'], |
| 49 | + colors['editorBracketHighlight.foreground2'], |
| 50 | + colors['editorBracketHighlight.foreground3'], |
| 51 | + colors['editorBracketHighlight.foreground4'], |
| 52 | + colors['editorBracketHighlight.foreground5'], |
| 53 | + colors['editorBracketHighlight.foreground6'], |
| 54 | + colors['editorBracketHighlight.unexpectedBracket.foreground'], |
| 55 | + ].filter(Boolean) |
| 56 | + themes[t.name] = bracketTheme |
| 57 | + } |
| 58 | + |
| 59 | + const sorted = Object.fromEntries( |
| 60 | + Object.entries(themes).sort((a, b) => a[0].localeCompare(b[0])), |
| 61 | + ) |
| 62 | + |
| 63 | + await fs.writeFile( |
| 64 | + './src/themes.ts', |
| 65 | + `// Generated by scripts/prepare.ts |
| 66 | +export default ${JSON.stringify(sorted, undefined, 2)} as Record<string, string[]> |
| 67 | +`, |
| 68 | + { encoding: 'utf-8' }, |
| 69 | + ) |
| 70 | +} |
| 71 | + |
| 72 | +main() |
0 commit comments