-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ts
More file actions
executable file
·75 lines (65 loc) · 2.25 KB
/
build.ts
File metadata and controls
executable file
·75 lines (65 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env -S deno run -A
import * as path from "@std/path";
import * as sass from "sass";
import palette from "palette.json" with { type: "json" };
const __dirname = path.dirname(path.fromFileUrl(import.meta.url));
const accents = Object.entries(palette.winter.colors)
.filter(([_, { accent }]) => accent)
.map(([accentName]) => accentName);
Deno.mkdirSync(path.join(__dirname, "dist"), { recursive: true });
const sassBuilder = (variant: string, accent: string) => `
@import "@everviolet/palette/scss/${variant}.scss";
$accent: $${accent};
$isDark: ${variant !== "summer"};
@import "theme";
`;
const renameColors = (c) => {
return c
.replace(/peach/g, 'orange')
.replace(/lavender/g, 'snow')
.replace(/mauve/g, 'purple')
.replace(/flamingo/g, 'cherry')
.replace(/rosewater/g, 'cherry')
.replace(/sky/g, 'skye')
.replace(/maroon/g, 'red')
.replace(/teal/g, 'aqua');
};
const srcDir = path.join(__dirname, "src");
for await (const dirEntry of Deno.readDir(srcDir)) {
if (dirEntry.isFile) {
const filePath = path.join(srcDir, dirEntry.name);
const content = await Deno.readTextFile(filePath);
const newContent = renameColors(content);
await Deno.writeTextFile(filePath, newContent);
}
}
Object.entries(palette).forEach(([variantName, variant]) => {
if (!variant.colors || Object.keys(variant.colors).length === 0) {
console.warn(`no colors in ${variantName}`);
return;
}
Object.entries(variant.colors)
.filter(([_, { accent }]) => accent)
.forEach(([accentName]) => {
const input = sassBuilder(variantName, accentName);
const result = sass.compileString(input, {
loadPaths: [
path.join(__dirname, "src"),
path.join(__dirname, "node_modules"),
],
});
Deno.writeTextFileSync(
path.join(
__dirname,
"dist",
`theme-evergarden-${variantName}-${accentName}.css`,
),
result.css,
);
Deno.writeTextFileSync(
path.join(__dirname, "dist", `theme-evergarden-${accentName}-auto.css`),
`@import "./theme-evergarden-summer-${accentName}.css" (prefers-color-scheme: light);
@import "./theme-evergarden-winter-${accentName}.css" (prefers-color-scheme: dark);`,
);
});
});