-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.js
148 lines (121 loc) · 3.4 KB
/
template.js
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
const { exec } = require("child_process");
/**
* All of the colors that are available to use in the template.
*
* Color values can refer to another color's name to point to that color.
* This works recursively, see `resolveColor`.
*/
const colors = {
black: "#141414",
blackGray: "#1C1C1C",
darkerGray: "#242424",
darkGray: "#404040",
gray: "#6E6E6E",
lightGray: "#CECECE",
lighterGray: "#D6D6D6",
whiteGray: "#DEDEDE",
white: "#E5E5E5",
realwhite: "#FFFFFF",
blue: "#5caeef",
lightBlue: "#ABB2C0",
yellow: "#CCC47A",
pink: "#E52E71",
lightPink: "#DB6165",
green: "#9CCC3D",
lightGreen: "#97C26C",
cyan: "#6CC7D9",
lightCyan: "#4FB1BC",
orange: "#D9882B",
lightOrange: "#DFB976",
purple: "#A082D9",
lightPurple: "#C172D9",
transparent: "#FFFFFF00",
};
const dawn = {
type: "light",
// Background colors
darkBackground: "white",
background: "realwhite",
lightBackground: "whiteGray",
highlightBackground: "black15",
activeBackground: "black25",
selectionBackground: "yellow40",
inactiveSelectionBackground: "yellow30",
inactiveBackground: "yellow20",
border: "lightGray",
// Foregrounds
brightForeground: "black",
foreground: "darkGray",
inactiveForeground: "gray",
...colors,
yellow: "#7E7630",
// pink: "",
green: "#618122",
cyan: "#24798A",
// orange: "",
purple: "#673ABB",
};
const dusk = {
type: "dark",
// Background colors
darkBackground: "black",
background: "blackGray",
lightBackground: "darkerGray",
highlightBackground: "white29",
activeBackground: "white40",
selectionBackground: "yellow40",
inactiveSelectionBackground: "yellow20",
inactiveBackground: "yellow10",
border: "darkGray",
// Foregrounds
brightForeground: "white",
foreground: "lightGray",
inactiveForeground: "gray",
...colors,
};
/**
* Resolve the name of a color into a hex value.
*
* Example: background -> blackGray -> #1C1C1C.
*
* @param {string} key Name of the color.
* @param {string} value Value of the color's name.
*/
function resolveColor(key, value) {
let valueFormat = /^([a-zA-Z]+)(\d{2})?$/;
let matches = value.match(valueFormat);
if (matches === null) {
// Hex color.
return value;
}
let [_fullMatch, colorName, opacity, ..._] = matches;
if (!(colorName in colors)) {
return value;
}
let resolvedColor = resolveColor(value, colors[colorName]);
if (opacity === undefined) {
return resolvedColor;
}
if (colorName in colors) {
return resolveColor(value, colors[colorName]) + opacity;
}
return value;
}
const themeTemplates = {
Rubecula: dusk,
"Rubecula Dawn": dawn,
};
// Generate a sed replacement command that will replace the colors in the
// template color scheme and save it as a different file.
//
// Example:
// sed -e "s/\": \"black/\": \"#141414/" themes/Rubecula.template.json > themes/Rubecula.json
Object.entries(themeTemplates).forEach(([templateName, templateColors]) => {
var command = "sed ";
Object.entries(templateColors).forEach(([key, value]) => {
const color = resolveColor(key, value);
command += `-e "s/\\": \\"${key}/\\": \\"${color}/" `;
});
command += `"themes/Rubecula.template.json" > "themes/${templateName}.json"`;
exec(command);
});