Updated theme compilation to use internal
This commit is contained in:
parent
bdf655d757
commit
3171a0c312
5 changed files with 4637 additions and 24 deletions
2283
assets/themes/internal/cave-internal-dark.json
Normal file
2283
assets/themes/internal/cave-internal-dark.json
Normal file
File diff suppressed because it is too large
Load diff
2283
assets/themes/internal/cave-internal-light.json
Normal file
2283
assets/themes/internal/cave-internal-light.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -2,29 +2,41 @@ import * as fs from "fs";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { tmpdir } from "os";
|
import { tmpdir } from "os";
|
||||||
import app from "./styleTree/app";
|
import app from "./styleTree/app";
|
||||||
import themes from "./themes";
|
import themes, { internalThemes } from "./themes";
|
||||||
import snakeCase from "./utils/snakeCase";
|
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"));
|
const tempDirectory = fs.mkdtempSync(path.join(tmpdir(), "build-themes"));
|
||||||
|
|
||||||
// Clear existing themes
|
// Clear existing themes
|
||||||
for (const file of fs.readdirSync(themeDirectory)) {
|
function clearThemes(themeDirectory: string) {
|
||||||
if (file.endsWith(".json")) {
|
for (const file of fs.readdirSync(themeDirectory)) {
|
||||||
const name = file.replace(/\.json$/, "");
|
if (file.endsWith(".json")) {
|
||||||
if (!themes.find((theme) => theme.name === name)) {
|
const name = file.replace(/\.json$/, "");
|
||||||
fs.unlinkSync(path.join(themeDirectory, file));
|
if (!themes.find((theme) => theme.name === name)) {
|
||||||
|
fs.unlinkSync(path.join(themeDirectory, file));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write new themes to theme directory
|
clearThemes(themeDirectory);
|
||||||
for (let theme of themes) {
|
clearThemes(internalDirectory);
|
||||||
let styleTree = snakeCase(app(theme));
|
|
||||||
let styleTreeJSON = JSON.stringify(styleTree, null, 2);
|
function writeThemes(themes: Theme[], outputDirectory: string) {
|
||||||
let tempPath = path.join(tempDirectory, `${theme.name}.json`);
|
for (let theme of themes) {
|
||||||
let outPath = path.join(themeDirectory, `${theme.name}.json`);
|
let styleTree = snakeCase(app(theme));
|
||||||
fs.writeFileSync(tempPath, styleTreeJSON);
|
let styleTreeJSON = JSON.stringify(styleTree, null, 2);
|
||||||
fs.renameSync(tempPath, outPath);
|
let tempPath = path.join(tempDirectory, `${theme.name}.json`);
|
||||||
console.log(`- ${outPath} created`);
|
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);
|
||||||
|
|
|
@ -5,14 +5,21 @@ import Theme from "./themes/common/theme";
|
||||||
const themes: Theme[] = [];
|
const themes: Theme[] = [];
|
||||||
export default themes;
|
export default themes;
|
||||||
|
|
||||||
const themesPath = path.resolve(`${__dirname}/themes`);
|
const internalThemes: Theme[] = [];
|
||||||
for (const fileName of fs.readdirSync(themesPath)) {
|
export { internalThemes }
|
||||||
if (fileName == "template.ts") continue;
|
|
||||||
const filePath = path.join(themesPath, fileName);
|
|
||||||
|
|
||||||
if (fs.statSync(filePath).isFile()) {
|
function fillThemes(themesPath: string, themes: Theme[]) {
|
||||||
const theme = require(filePath);
|
for (const fileName of fs.readdirSync(themesPath)) {
|
||||||
if (theme.dark) themes.push(theme.dark);
|
if (fileName == "template.ts") continue;
|
||||||
if (theme.light) themes.push(theme.light);
|
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)
|
||||||
|
|
28
styles/src/themes/internal/cave-internal.ts
Normal file
28
styles/src/themes/internal/cave-internal.ts
Normal 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);
|
Loading…
Add table
Add a link
Reference in a new issue