Files

81 lines
3.2 KiB
JavaScript

/**
* MUTHUR-6000 VS Code Theme Compiler
* Programmatically compiles multiple color theme variants from tokens.js and theme-template.json.
*/
const fs = require('fs');
const path = require('path');
const tokens = require('./tokens');
const TEMPLATE_PATH = path.join(__dirname, 'theme-template.json');
const OUTPUT_DIR = path.join(__dirname, 'themes');
function compile() {
console.log('🤖 Starting MUTHUR-6000 Theme Compilation...');
// 1. Ensure output directory exists
if (!fs.existsSync(OUTPUT_DIR)) {
fs.mkdirSync(OUTPUT_DIR, { recursive: true });
console.log(`📁 Created themes folder at: ${OUTPUT_DIR}`);
}
// 2. Read base template
if (!fs.existsSync(TEMPLATE_PATH)) {
console.error(`❌ Error: Template not found at ${TEMPLATE_PATH}`);
process.exit(1);
}
const templateRaw = fs.readFileSync(TEMPLATE_PATH, 'utf8');
// 3. Compile each theme variant
for (const [key, val] of Object.entries(tokens)) {
let compiled = templateRaw;
// Replace UI tokens
compiled = compiled.replace(/\${themeName}/g, val.themeName);
compiled = compiled.replace(/\${themeBg}/g, val.bg);
compiled = compiled.replace(/\${themeBgAlt}/g, val.bgAlt);
compiled = compiled.replace(/\${themeBorder}/g, val.border);
compiled = compiled.replace(/\${themeBorderActive}/g, val.borderActive);
compiled = compiled.replace(/\${themeText}/g, val.text);
compiled = compiled.replace(/\${themeTextMuted}/g, val.textMuted);
compiled = compiled.replace(/\${themeTextActive}/g, val.textActive);
compiled = compiled.replace(/\${themeCursor}/g, val.cursor);
compiled = compiled.replace(/\${themeLineHighlight}/g, val.lineHighlight);
compiled = compiled.replace(/\${themeSelection}/g, val.selection);
compiled = compiled.replace(/\${themeBadgeBg}/g, val.badgeBg);
compiled = compiled.replace(/\${themeBadgeFg}/g, val.badgeFg);
// Replace Syntax tokens
compiled = compiled.replace(/\${syntaxKeyword}/g, val.keyword);
compiled = compiled.replace(/\${syntaxFunction}/g, val.function);
compiled = compiled.replace(/\${syntaxString}/g, val.string);
compiled = compiled.replace(/\${syntaxNumber}/g, val.number);
compiled = compiled.replace(/\${syntaxType}/g, val.type);
compiled = compiled.replace(/\${syntaxVariable}/g, val.variable);
compiled = compiled.replace(/\${syntaxComment}/g, val.comment);
compiled = compiled.replace(/\${syntaxConstant}/g, val.constant);
compiled = compiled.replace(/\${syntaxOperator}/g, val.operator);
compiled = compiled.replace(/\${syntaxTag}/g, val.tag);
compiled = compiled.replace(/\${syntaxAttribute}/g, val.attribute);
// 4. Validate output JSON format
try {
JSON.parse(compiled);
} catch (e) {
console.error(`❌ Validation Failure for ${val.themeName}: Compiled output is not valid JSON!`);
console.error(e.message);
process.exit(1);
}
// 5. Write output file
const outputFilename = `muthur-6000-${key}-color-theme.json`;
const outputPath = path.join(OUTPUT_DIR, outputFilename);
fs.writeFileSync(outputPath, compiled, 'utf8');
console.log(`✅ Compiled: ${val.themeName} -> themes/${outputFilename}`);
}
console.log('🚀 All theme variants compiled successfully!');
}
compile();