18 lines
1.2 KiB
JavaScript
18 lines
1.2 KiB
JavaScript
import { mkdirSync, readdirSync, writeFileSync, unlinkSync } from "node:fs"
|
|
import { read, repositoryRoot, validateDocument } from "./theme-contract.mjs"
|
|
|
|
// Independent Theme artifact. Does not build UI/Graphic or generate package CSS.
|
|
// Only top-level themes/*.json are published; historic drafts stay out.
|
|
const directory = new URL("../themes/", import.meta.url)
|
|
const themes = readdirSync(directory).filter(file => file.endsWith(".json")).sort()
|
|
if (!themes.includes("default.json")) throw Error("Missing themes/default.json")
|
|
const documents = themes.map(file => [file, validateDocument(JSON.parse(read(`themes/${file}`)), file === "default.json")])
|
|
const output = new URL("theme-dist/themes/", repositoryRoot)
|
|
mkdirSync(output, { recursive: true })
|
|
// Only generated top-level JSON artifacts in this explicit workspace output.
|
|
for (const file of readdirSync(output).filter(file => file.endsWith(".json") && !themes.includes(file))) unlinkSync(new URL(file, output))
|
|
for (const [file, theme] of documents) {
|
|
writeFileSync(new URL(file, output), JSON.stringify(theme, null, 2) + "\n")
|
|
}
|
|
console.log(`Validated/exported ${themes.length} independent Theme artifacts to theme-dist/themes/`)
|