2023-02-25 16:46:33 +00:00
|
|
|
import * as fs from "fs"
|
|
|
|
import { tmpdir } from "os"
|
|
|
|
import * as path from "path"
|
2023-05-30 13:52:32 +00:00
|
|
|
import { colorSchemes, staffColorSchemes } from "./colorSchemes"
|
2023-02-25 16:46:33 +00:00
|
|
|
import app from "./styleTree/app"
|
|
|
|
import { ColorScheme } from "./themes/common/colorScheme"
|
|
|
|
import snakeCase from "./utils/snakeCase"
|
2022-04-01 15:45:11 +00:00
|
|
|
|
2023-01-27 01:27:42 +00:00
|
|
|
const assetsDirectory = `${__dirname}/../../assets`
|
2023-02-25 16:46:33 +00:00
|
|
|
const themeDirectory = `${assetsDirectory}/themes`
|
|
|
|
const staffDirectory = `${themeDirectory}/staff`
|
2022-10-21 17:04:24 +00:00
|
|
|
|
2023-02-25 16:46:33 +00:00
|
|
|
const tempDirectory = fs.mkdtempSync(path.join(tmpdir(), "build-themes"))
|
2022-05-16 22:11:22 +00:00
|
|
|
|
|
|
|
// Clear existing themes
|
2022-09-08 21:34:21 +00:00
|
|
|
function clearThemes(themeDirectory: string) {
|
2023-02-25 16:46:33 +00:00
|
|
|
if (!fs.existsSync(themeDirectory)) {
|
|
|
|
fs.mkdirSync(themeDirectory, { recursive: true })
|
|
|
|
} else {
|
|
|
|
for (const file of fs.readdirSync(themeDirectory)) {
|
|
|
|
if (file.endsWith(".json")) {
|
|
|
|
const name = file.replace(/\.json$/, "")
|
|
|
|
if (
|
|
|
|
!colorSchemes.find(
|
|
|
|
(colorScheme) => colorScheme.name === name
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
fs.unlinkSync(path.join(themeDirectory, file))
|
|
|
|
}
|
|
|
|
}
|
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-02-25 16:46:33 +00:00
|
|
|
clearThemes(themeDirectory)
|
|
|
|
clearThemes(staffDirectory)
|
2022-09-08 21:34:21 +00:00
|
|
|
|
2022-09-21 19:39:59 +00:00
|
|
|
function writeThemes(colorSchemes: ColorScheme[], outputDirectory: string) {
|
2023-02-25 16:46:33 +00:00
|
|
|
for (let colorScheme of colorSchemes) {
|
|
|
|
let styleTree = snakeCase(app(colorScheme))
|
|
|
|
let styleTreeJSON = JSON.stringify(styleTree, null, 2)
|
|
|
|
let tempPath = path.join(tempDirectory, `${colorScheme.name}.json`)
|
|
|
|
let outPath = path.join(outputDirectory, `${colorScheme.name}.json`)
|
|
|
|
fs.writeFileSync(tempPath, styleTreeJSON)
|
|
|
|
fs.renameSync(tempPath, outPath)
|
|
|
|
console.log(`- ${outPath} created`)
|
|
|
|
}
|
2022-04-01 15:45:11 +00:00
|
|
|
}
|
2022-09-08 21:34:21 +00:00
|
|
|
|
|
|
|
// Write new themes to theme directory
|
2023-02-25 16:46:33 +00:00
|
|
|
writeThemes(colorSchemes, themeDirectory)
|
|
|
|
writeThemes(staffColorSchemes, staffDirectory)
|