zed/styles/src/buildThemes.ts

28 lines
918 B
TypeScript
Raw Normal View History

import * as fs from "fs";
import * as path from "path";
2022-05-18 21:07:32 +00:00
import { tmpdir } from 'os';
2022-04-02 03:58:04 +00:00
import app from "./styleTree/app";
import themes from "./themes";
import snakeCase from "./utils/snakeCase";
const themeDirectory = `${__dirname}/../../assets/themes/`;
2022-05-18 21:07:32 +00:00
const tempDirectory = fs.mkdtempSync(path.join(tmpdir(), 'build-themes'));
// Clear existing themes
for (const file of fs.readdirSync(themeDirectory)) {
2022-05-18 21:07:32 +00:00
if (file.endsWith('.json')) {
fs.unlinkSync(path.join(themeDirectory, file));
}
}
// Write new themes to theme directory
for (let theme of themes) {
2022-04-06 17:35:29 +00:00
let styleTree = snakeCase(app(theme));
let styleTreeJSON = JSON.stringify(styleTree, null, 2);
2022-05-18 21:07:32 +00:00
let tempPath = path.join(tempDirectory, `${theme.name}.json`);
let outPath = path.join(themeDirectory, `${theme.name}.json`);
fs.writeFileSync(tempPath, styleTreeJSON);
fs.renameSync(tempPath, outPath);
2022-04-06 17:35:29 +00:00
console.log(`- ${outPath} created`);
}