2023-02-25 16:46:33 +00:00
|
|
|
import * as fs from "fs"
|
|
|
|
import { tmpdir } from "os"
|
|
|
|
import * as path from "path"
|
2023-06-28 22:20:43 +00:00
|
|
|
import app from "./style_tree/app"
|
2023-06-29 06:16:21 +00:00
|
|
|
import { ColorScheme, create_color_scheme } from "./theme/color_scheme"
|
2023-06-07 15:10:02 +00:00
|
|
|
import { themes } from "./themes"
|
2023-07-04 04:13:04 +00:00
|
|
|
import { useThemeStore } from "./theme"
|
2022-04-01 15:45:11 +00:00
|
|
|
|
2023-06-29 05:48:40 +00:00
|
|
|
const assets_directory = `${__dirname}/../../assets`
|
|
|
|
const temp_directory = fs.mkdtempSync(path.join(tmpdir(), "build-themes"))
|
2022-05-16 22:11:22 +00:00
|
|
|
|
2023-06-29 05:48:40 +00:00
|
|
|
function clear_themes(theme_directory: string) {
|
|
|
|
if (!fs.existsSync(theme_directory)) {
|
|
|
|
fs.mkdirSync(theme_directory, { recursive: true })
|
2023-02-25 16:46:33 +00:00
|
|
|
} else {
|
2023-06-29 05:48:40 +00:00
|
|
|
for (const file of fs.readdirSync(theme_directory)) {
|
2023-02-25 16:46:33 +00:00
|
|
|
if (file.endsWith(".json")) {
|
2023-06-29 05:48:40 +00:00
|
|
|
fs.unlinkSync(path.join(theme_directory, file))
|
2023-02-25 16:46:33 +00:00
|
|
|
}
|
2022-10-21 17:19:44 +00:00
|
|
|
}
|
2022-05-18 21:17:26 +00:00
|
|
|
}
|
2022-05-16 22:11:22 +00:00
|
|
|
}
|
|
|
|
|
2023-07-04 04:13:04 +00:00
|
|
|
const all_themes: ColorScheme[] = themes.map((theme) =>
|
|
|
|
create_color_scheme(theme)
|
|
|
|
)
|
|
|
|
|
2023-06-29 15:41:51 +00:00
|
|
|
function write_themes(themes: ColorScheme[], output_directory: string) {
|
2023-06-29 05:48:40 +00:00
|
|
|
clear_themes(output_directory)
|
2023-06-29 15:41:51 +00:00
|
|
|
for (const color_scheme of themes) {
|
2023-07-04 04:13:04 +00:00
|
|
|
const { setTheme } = useThemeStore.getState()
|
|
|
|
setTheme(color_scheme)
|
|
|
|
|
|
|
|
const style_tree = app()
|
2023-06-29 05:48:40 +00:00
|
|
|
const style_tree_json = JSON.stringify(style_tree, null, 2)
|
|
|
|
const temp_path = path.join(temp_directory, `${color_scheme.name}.json`)
|
2023-06-29 15:41:51 +00:00
|
|
|
const out_path = path.join(
|
|
|
|
output_directory,
|
|
|
|
`${color_scheme.name}.json`
|
|
|
|
)
|
2023-06-29 05:48:40 +00:00
|
|
|
fs.writeFileSync(temp_path, style_tree_json)
|
|
|
|
fs.renameSync(temp_path, out_path)
|
|
|
|
console.log(`- ${out_path} created`)
|
2023-02-25 16:46:33 +00:00
|
|
|
}
|
2022-04-01 15:45:11 +00:00
|
|
|
}
|
2022-09-08 21:34:21 +00:00
|
|
|
|
2023-06-29 15:41:51 +00:00
|
|
|
write_themes(all_themes, `${assets_directory}/themes`)
|