Updated theme compilation to use internal

This commit is contained in:
Mikayla Maki 2022-09-08 14:34:21 -07:00
parent bdf655d757
commit 3171a0c312
5 changed files with 4637 additions and 24 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -2,29 +2,41 @@ import * as fs from "fs";
import * as path from "path";
import { tmpdir } from "os";
import app from "./styleTree/app";
import themes from "./themes";
import themes, { internalThemes } from "./themes";
import snakeCase from "./utils/snakeCase";
import Theme from "./themes/common/theme";
const themeDirectory = `${__dirname}/../../assets/themes/`;
const themeDirectory = `${__dirname}/../../assets/themes`;
const internalDirectory = `${themeDirectory}/internal`;
const tempDirectory = fs.mkdtempSync(path.join(tmpdir(), "build-themes"));
// Clear existing themes
for (const file of fs.readdirSync(themeDirectory)) {
if (file.endsWith(".json")) {
const name = file.replace(/\.json$/, "");
if (!themes.find((theme) => theme.name === name)) {
fs.unlinkSync(path.join(themeDirectory, file));
function clearThemes(themeDirectory: string) {
for (const file of fs.readdirSync(themeDirectory)) {
if (file.endsWith(".json")) {
const name = file.replace(/\.json$/, "");
if (!themes.find((theme) => theme.name === name)) {
fs.unlinkSync(path.join(themeDirectory, file));
}
}
}
}
// Write new themes to theme directory
for (let theme of themes) {
let styleTree = snakeCase(app(theme));
let styleTreeJSON = JSON.stringify(styleTree, null, 2);
let tempPath = path.join(tempDirectory, `${theme.name}.json`);
let outPath = path.join(themeDirectory, `${theme.name}.json`);
fs.writeFileSync(tempPath, styleTreeJSON);
fs.renameSync(tempPath, outPath);
console.log(`- ${outPath} created`);
clearThemes(themeDirectory);
clearThemes(internalDirectory);
function writeThemes(themes: Theme[], outputDirectory: string) {
for (let theme of themes) {
let styleTree = snakeCase(app(theme));
let styleTreeJSON = JSON.stringify(styleTree, null, 2);
let tempPath = path.join(tempDirectory, `${theme.name}.json`);
let outPath = path.join(outputDirectory, `${theme.name}.json`);
fs.writeFileSync(tempPath, styleTreeJSON);
fs.renameSync(tempPath, outPath);
console.log(`- ${outPath} created`);
}
}
// Write new themes to theme directory
writeThemes(themes, themeDirectory);
writeThemes(internalThemes, internalDirectory);

View file

@ -5,14 +5,21 @@ import Theme from "./themes/common/theme";
const themes: Theme[] = [];
export default themes;
const themesPath = path.resolve(`${__dirname}/themes`);
for (const fileName of fs.readdirSync(themesPath)) {
if (fileName == "template.ts") continue;
const filePath = path.join(themesPath, fileName);
const internalThemes: Theme[] = [];
export { internalThemes }
if (fs.statSync(filePath).isFile()) {
const theme = require(filePath);
if (theme.dark) themes.push(theme.dark);
if (theme.light) themes.push(theme.light);
function fillThemes(themesPath: string, themes: Theme[]) {
for (const fileName of fs.readdirSync(themesPath)) {
if (fileName == "template.ts") continue;
const filePath = path.join(themesPath, fileName);
if (fs.statSync(filePath).isFile()) {
const theme = require(filePath);
if (theme.dark) themes.push(theme.dark);
if (theme.light) themes.push(theme.light);
}
}
}
fillThemes(path.resolve(`${__dirname}/themes`), themes)
fillThemes(path.resolve(`${__dirname}/themes/internal`), internalThemes)

View file

@ -0,0 +1,28 @@
import chroma from "chroma-js";
import { colorRamp, createTheme } from "../common/base16";
const name = "cave-internal";
const ramps = {
neutral: chroma.scale([
"#111111",
"#222222",
"#333333",
"#444444",
"#555555",
"#888888",
"#999999",
"#000000",
]),
red: colorRamp(chroma("#aaaaaa")),
orange: colorRamp(chroma("#bbbbbb")),
yellow: colorRamp(chroma("#cccccc")),
green: colorRamp(chroma("#dddddd")),
cyan: colorRamp(chroma("#eeeeee")),
blue: colorRamp(chroma("#ffffff")),
violet: colorRamp(chroma("#ababab")),
magenta: colorRamp(chroma("#cdcdcd")),
};
export const dark = createTheme(`${name}-dark`, false, ramps);
export const light = createTheme(`${name}-light`, true, ramps);