Repository navigation
Expand file tree
/
Copy pathbuild.ts
More file actions
134 lines (122 loc) · 4.18 KB
/
Copy pathbuild.ts
File metadata and controls
134 lines (122 loc) · 4.18 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// src/build.ts
import { writeFileSync, mkdirSync } from "node:fs";
import { light as rolesLight, lightSoft as rolesLightSoft, dark as rolesDark, darkSoft as rolesDarkSoft } from "./palette";
import { makeTheme } from "./theme";
import { makeZedThemeFamily } from "./zed-theme";
import { convertRolesToP3 } from "./color-p3";
mkdirSync("themes", { recursive: true });
mkdirSync("zed/themes", { recursive: true });
// Convert palettes to Display P3 color space
const rolesLightP3 = convertRolesToP3(rolesLight);
const rolesDarkP3 = convertRolesToP3(rolesDark);
// ============================================
// VS Code Themes
// ============================================
const vscodeThemes = [
{
file: "themes/pierre-light.json",
theme: makeTheme({
name: "pierre-light",
displayName: "Pierre Light",
type: "light",
roles: rolesLight
})
},
{
file: "themes/pierre-light-soft.json",
theme: makeTheme({
name: "pierre-light-soft",
displayName: "Pierre Light Soft",
type: "light",
roles: rolesLightSoft
})
},
{
file: "themes/pierre-dark.json",
theme: makeTheme({
name: "pierre-dark",
displayName: "Pierre Dark",
type: "dark",
roles: rolesDark
})
},
{
file: "themes/pierre-dark-soft.json",
theme: makeTheme({
name: "pierre-dark-soft",
displayName: "Pierre Dark Soft",
type: "dark",
roles: rolesDarkSoft
})
},
{
file: "themes/pierre-light-vibrant.json",
theme: makeTheme({
name: "pierre-light-vibrant",
displayName: "Pierre Light Vibrant",
type: "light",
roles: rolesLightP3
})
},
{
file: "themes/pierre-dark-vibrant.json",
theme: makeTheme({
name: "pierre-dark-vibrant",
displayName: "Pierre Dark Vibrant",
type: "dark",
roles: rolesDarkP3
})
}
];
for (const {file, theme} of vscodeThemes) {
writeFileSync(file, JSON.stringify(theme, null, 2), "utf8");
console.log("Wrote", file);
}
// ============================================
// Zed Theme Family
// ============================================
const zedTheme = makeZedThemeFamily("Pierre", "pierrecomputer", [
{ name: "Pierre Light", appearance: "light", roles: rolesLight },
{ name: "Pierre Light Soft", appearance: "light", roles: rolesLightSoft },
{ name: "Pierre Dark", appearance: "dark", roles: rolesDark },
{ name: "Pierre Dark Soft", appearance: "dark", roles: rolesDarkSoft },
]);
writeFileSync("zed/themes/pierre.json", JSON.stringify(zedTheme, null, 2), "utf8");
console.log("Wrote zed/themes/pierre.json");
// ============================================
// ESM wrapper modules (for npm / Shiki consumers)
// ============================================
mkdirSync("dist", { recursive: true });
const themeNames: string[] = [];
/** VS Code / Shiki theme shape exposed by each per-theme module. */
const themeDts = `/** VS Code / TextMate theme object (frozen at runtime). */
interface PierreTheme {
readonly name: string;
readonly displayName: string;
readonly type: "light" | "dark";
readonly colors: Readonly<Record<string, string>>;
readonly tokenColors: ReadonlyArray<{
readonly name?: string;
readonly scope?: string | string[];
readonly settings: Readonly<Record<string, string>>;
}>;
readonly semanticTokenColors: Readonly<Record<string, string | Record<string, string>>>;
}
declare const theme: PierreTheme;
export default theme;
`;
for (const { file, theme } of vscodeThemes) {
const name = file.replace("themes/", "").replace(".json", "");
themeNames.push(name);
const json = JSON.stringify(theme);
const escaped = json.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
const mjs = `export default Object.freeze(JSON.parse('${escaped}'))\n`;
writeFileSync(`dist/${name}.mjs`, mjs, "utf8");
writeFileSync(`dist/${name}.d.mts`, themeDts, "utf8");
console.log("Wrote", `dist/${name}.mjs`, `+ .d.mts`);
}
const indexMjs = `export const themeNames = ${JSON.stringify(themeNames)}\n`;
const indexDts = `export declare const themeNames: readonly string[];\n`;
writeFileSync("dist/index.mjs", indexMjs, "utf8");
writeFileSync("dist/index.d.mts", indexDts, "utf8");
console.log("Wrote dist/index.mjs + .d.mts");