-
Notifications
You must be signed in to change notification settings - Fork 172
/
build.js
59 lines (54 loc) · 1.43 KB
/
build.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
const fs = require("fs").promises;
const path = require("path");
const sourceFiles = [
"src/catppuccin-frappe.theme.scss",
"src/catppuccin-latte.theme.scss",
"src/catppuccin-macchiato.theme.scss",
"src/catppuccin-mocha.theme.scss",
];
const accents = [
"rosewater",
"flamingo",
"pink",
"mauve",
"red",
"maroon",
"peach",
"yellow",
"green",
"teal",
"sky",
"sapphire",
"blue",
"lavender",
];
(async () => {
await Promise.all(sourceFiles.map(generateAccents));
console.log("Generated all accents for all flavours");
})();
// read sourceFile and generate all accents for it
async function generateAccents(sourceFilePath) {
const _sourceFilePath = path.join(__dirname, sourceFilePath);
const sourceFileData = await fs.readFile(_sourceFilePath, {
encoding: "utf8",
});
return Promise.all(
accents.map((accent) =>
generateAccent(sourceFileData, sourceFilePath, accent)
)
);
}
// replace brand and write to separate file
async function generateAccent(sourceFileData, sourceFilePath, accent) {
const modifiedFileContent = sourceFileData.replace(
/\$brand: .*;/gm,
`$brand: \$${accent};`
);
const outputFileName = sourceFilePath
.split(".")
.map((s, i) => (i === 0 ? s.concat(`-${accent}`) : s))
.join(".");
const outputFilePath = path.join(__dirname, outputFileName);
await fs.writeFile(outputFilePath, modifiedFileContent);
console.log(`Generated: ${outputFileName}`);
}