1import fs from "fs"
2import path from "path"
3import { ColorScheme, Meta } from "./themes/common/colorScheme"
4
5const colorSchemes: ColorScheme[] = []
6export default colorSchemes
7
8const schemeMeta: Meta[] = []
9export { schemeMeta }
10
11const staffColorSchemes: ColorScheme[] = []
12export { staffColorSchemes }
13
14const experimentalColorSchemes: ColorScheme[] = []
15export { experimentalColorSchemes }
16
17const themes_directory = path.resolve(`${__dirname}/themes`)
18
19function for_all_color_schemes_in(
20 themesPath: string,
21 callback: (module: any, path: string) => void
22) {
23 for (const fileName of fs.readdirSync(themesPath)) {
24 if (fileName == "template.ts") continue
25 const filePath = path.join(themesPath, fileName)
26
27 if (fs.statSync(filePath).isFile()) {
28 const colorScheme = require(filePath)
29 callback(colorScheme, path.basename(filePath))
30 }
31 }
32}
33
34function fillColorSchemes(themesPath: string, colorSchemes: ColorScheme[]) {
35 for_all_color_schemes_in(themesPath, (colorScheme, _path) => {
36 if (colorScheme.dark) colorSchemes.push(colorScheme.dark)
37 if (colorScheme.light) colorSchemes.push(colorScheme.light)
38 })
39}
40
41fillColorSchemes(themes_directory, colorSchemes)
42fillColorSchemes(path.resolve(`${themes_directory}/staff`), staffColorSchemes)
43
44function fillMeta(themesPath: string, meta: Meta[]) {
45 for_all_color_schemes_in(themesPath, (colorScheme, path) => {
46 if (colorScheme.meta) {
47 meta.push(colorScheme.meta)
48 } else {
49 throw Error(`Public theme ${path} must have a meta field`)
50 }
51 })
52}
53
54fillMeta(themes_directory, schemeMeta)