-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: generate and host accents (#89)
- Loading branch information
Showing
4 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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}`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters