mirror of
https://github.com/ful1e5/Bibata_Cursor.git
synced 2024-10-19 05:50:38 -04:00
🔧 Dynamic .svg generation with Schema
This commit is contained in:
parent
c53544d882
commit
4405467b23
1 changed files with 54 additions and 21 deletions
|
@ -1,35 +1,68 @@
|
|||
import path from "path";
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import rimraf from "rimraf";
|
||||
|
||||
import { staticCursors, animatedCursors, animatedClip } from "./cursors.json";
|
||||
import { ColorSchemas } from "./types";
|
||||
|
||||
// Source Directory
|
||||
export const rawSvgsDir = path.resolve("./src/svg/raw");
|
||||
if (!fs.existsSync(rawSvgsDir))
|
||||
console.error("🚨🚨 Source files not Found 🚨🚨");
|
||||
|
||||
// --------------------------------------- 🌈 Cursors Variants 🌈
|
||||
|
||||
export const colorSchemes = {
|
||||
ice: {
|
||||
const colorSchemes: ColorSchemas = {
|
||||
Ice: {
|
||||
base: "#ffffff",
|
||||
outline: "#000000"
|
||||
}
|
||||
};
|
||||
|
||||
// --------------------------------------- 🔧 Cursors Config 🔧
|
||||
// --------------------------------------- 🔧 Render Configs 🔧
|
||||
const configs: any = [];
|
||||
|
||||
// Source Directory
|
||||
const svgsDir = path.resolve("./src/svg");
|
||||
if (!fs.existsSync(svgsDir)) console.error("🚨🚨 Source files not Found 🚨🚨");
|
||||
for (let [schema] of Object.entries(colorSchemes)) {
|
||||
const { base, outline } = colorSchemes[schema];
|
||||
const schemaName = `Bibata_${schema}`;
|
||||
|
||||
// Resolve Paths for svg
|
||||
const staticSvgs = staticCursors.map((svg: string) =>
|
||||
path.resolve(svgsDir, svg)
|
||||
);
|
||||
const schemaSvgsPath = path.resolve("./src/svg", schemaName);
|
||||
|
||||
// Out Directory
|
||||
const bitmapsDir = path.resolve(process.cwd(), "bitmaps");
|
||||
if (!fs.existsSync(bitmapsDir)) fs.mkdirSync(bitmapsDir);
|
||||
if (fs.existsSync(schemaSvgsPath)) {
|
||||
rimraf(schemaSvgsPath, function () {});
|
||||
} else {
|
||||
fs.mkdirSync(schemaSvgsPath);
|
||||
}
|
||||
|
||||
export const config = {
|
||||
animatedCursors,
|
||||
animatedClip,
|
||||
staticSvgs,
|
||||
bitmapsDir,
|
||||
svgsDir
|
||||
};
|
||||
// Resolve Paths for svg
|
||||
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);
|
||||
|
||||
// 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
|
||||
});
|
||||
}
|
||||
|
||||
export { configs };
|
||||
|
|
Loading…
Reference in a new issue