2023-02-25 16:46:33 +00:00
|
|
|
import * as fs from "fs"
|
|
|
|
import { tmpdir } from "os"
|
|
|
|
import * as path from "path"
|
|
|
|
import app from "./styleTree/app"
|
2023-06-07 16:50:37 +00:00
|
|
|
import { ColorScheme, createColorScheme } from "./theme/colorScheme"
|
2023-02-25 16:46:33 +00:00
|
|
|
import snakeCase from "./utils/snakeCase"
|
2023-06-07 15:10:02 +00:00
|
|
|
import { themes } from "./themes"
|
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 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")) {
|
2023-06-07 15:10:02 +00:00
|
|
|
fs.unlinkSync(path.join(themeDirectory, 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
|
|
|
}
|
|
|
|
|
2022-09-21 19:39:59 +00:00
|
|
|
function writeThemes(colorSchemes: ColorScheme[], outputDirectory: string) {
|
2023-06-07 15:10:02 +00:00
|
|
|
clearThemes(outputDirectory)
|
2023-06-28 20:44:18 +00:00
|
|
|
for (const colorScheme of colorSchemes) {
|
|
|
|
const styleTree = snakeCase(app(colorScheme))
|
|
|
|
const styleTreeJSON = JSON.stringify(styleTree, null, 2)
|
|
|
|
const tempPath = path.join(tempDirectory, `${colorScheme.name}.json`)
|
|
|
|
const outPath = path.join(outputDirectory, `${colorScheme.name}.json`)
|
2023-02-25 16:46:33 +00:00
|
|
|
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
|
|
|
|
2023-06-07 16:50:37 +00:00
|
|
|
const colorSchemes: ColorScheme[] = themes.map((theme) =>
|
|
|
|
createColorScheme(theme)
|
|
|
|
)
|
2023-06-07 16:40:49 +00:00
|
|
|
|
2022-09-08 21:34:21 +00:00
|
|
|
// Write new themes to theme directory
|
2023-06-07 16:40:49 +00:00
|
|
|
writeThemes(colorSchemes, `${assetsDirectory}/themes`)
|