This repository was archived by the owner on Feb 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathbuild-themes.js
More file actions
92 lines (74 loc) · 2.77 KB
/
build-themes.js
File metadata and controls
92 lines (74 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env node
// Build script to auto-discover themes and update theme-loader.js
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Paths
const themesDir = path.join(__dirname, 'src/styles/themes');
const themeLoaderPath = path.join(__dirname, 'src/utils/theme-loader.js');
function discoverThemeFiles() {
try {
if (!fs.existsSync(themesDir)) {
console.log('❌ Themes directory not found:', themesDir);
return [];
}
const files = fs.readdirSync(themesDir);
const themeFiles = files
.filter(file => file.endsWith('.css'))
.filter(file => !file.startsWith('.')) // Ignore hidden files
.sort();
console.log(`🎨 Discovered ${themeFiles.length} theme files:`, themeFiles);
return themeFiles;
} catch (error) {
console.error('❌ Error discovering theme files:', error);
return [];
}
}
function updateThemeLoader(themeFiles) {
try {
let content = fs.readFileSync(themeLoaderPath, 'utf-8');
// Create the new themes array
const themesArray = themeFiles.map(file => `'${file}'`).join(',\n ');
// Replace the knownThemes array in the file
const newKnownThemes = ` const knownThemes = [
${themesArray}
];`;
// Find and replace the knownThemes array
const knownThemesRegex = /const knownThemes = \[[\s\S]*?\];/;
if (knownThemesRegex.test(content)) {
content = content.replace(knownThemesRegex, newKnownThemes);
fs.writeFileSync(themeLoaderPath, content, 'utf-8');
console.log('✅ Updated theme-loader.js with discovered themes');
return true;
} else {
console.log('⚠️ Could not find knownThemes array in theme-loader.js');
return false;
}
} catch (error) {
console.error('❌ Error updating theme-loader.js:', error);
return false;
}
}
function main() {
console.log('🔧 Starting theme discovery build script...');
const themeFiles = discoverThemeFiles();
if (themeFiles.length === 0) {
console.log('⚠️ No theme files discovered');
return;
}
const success = updateThemeLoader(themeFiles);
if (success) {
console.log('🎉 Theme discovery build completed successfully!');
console.log(`📊 Total themes: ${themeFiles.length}`);
themeFiles.forEach((file, index) => {
console.log(` ${index + 1}. ${file}`);
});
} else {
console.log('❌ Theme discovery build failed');
process.exit(1);
}
}
// Run the script
main();