mirror of
https://github.com/ful1e5/Bibata_Cursor.git
synced 2025-05-20 10:15:11 -04:00
🔧 .svg and config builder
This commit is contained in:
parent
bd9c2abc7d
commit
e85ccb0d3e
1 changed files with 70 additions and 0 deletions
70
packages/round/src/helpers/schema.ts
Normal file
70
packages/round/src/helpers/schema.ts
Normal file
|
@ -0,0 +1,70 @@
|
|||
import fs from "fs";
|
||||
import path from "path";
|
||||
import rimraf from "rimraf";
|
||||
|
||||
import { staticCursors, animatedCursors, animatedClip } from "../cursors.json";
|
||||
import { rawSvgsDir } from "../config";
|
||||
import { ColorSchemas } from "../types";
|
||||
|
||||
const generateConfigs = (colorSchemes: ColorSchemas) => {
|
||||
const configs: any = [];
|
||||
|
||||
for (let [schema] of Object.entries(colorSchemes)) {
|
||||
const { base, outline } = colorSchemes[schema];
|
||||
const schemaName = `Bibata_${schema}`;
|
||||
|
||||
const schemaSvgsPath = path.resolve("./src/svg", schemaName);
|
||||
|
||||
try {
|
||||
if (fs.existsSync(schemaSvgsPath)) {
|
||||
rimraf(schemaSvgsPath, function () {});
|
||||
} else {
|
||||
fs.mkdirSync(schemaSvgsPath);
|
||||
}
|
||||
|
||||
// Static .svg generation
|
||||
const staticSvgs = staticCursors.map((svgFile: string) => {
|
||||
// Read file
|
||||
const filePath = path.resolve(schemaSvgsPath, svgFile);
|
||||
|
||||
// Replacing colorSchema
|
||||
let content = fs
|
||||
.readFileSync(path.resolve(rawSvgsDir, svgFile), "utf-8")
|
||||
.toString();
|
||||
|
||||
content = content
|
||||
.replace("black", base)
|
||||
.replace("white", outline)
|
||||
.replace("#000000", base)
|
||||
.replace("#ffffff", outline);
|
||||
|
||||
// Writing new svg
|
||||
fs.writeFileSync(filePath, content, "utf-8");
|
||||
|
||||
return filePath;
|
||||
});
|
||||
|
||||
// Out Directory
|
||||
const bitmapsDir = path.resolve(
|
||||
process.cwd(),
|
||||
"bitmaps",
|
||||
`Bibata_${schema}`
|
||||
);
|
||||
if (!fs.existsSync(bitmapsDir)) fs.mkdirSync(bitmapsDir);
|
||||
|
||||
configs.push({
|
||||
svgDir: schemaSvgsPath,
|
||||
staticSvgs,
|
||||
bitmapsDir,
|
||||
animatedCursors,
|
||||
animatedClip
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("An error occurred in .svg files generation.");
|
||||
}
|
||||
}
|
||||
|
||||
return configs;
|
||||
};
|
||||
|
||||
export { generateConfigs };
|
Loading…
Add table
Add a link
Reference in a new issue