From e85ccb0d3e69633572219529f61661f0d6a9efe1 Mon Sep 17 00:00:00 2001 From: ful1e5 <24286590+KaizIqbal@users.noreply.github.com> Date: Sun, 16 Aug 2020 12:19:13 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20.svg=20and=20config=20builder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/round/src/helpers/schema.ts | 70 ++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 packages/round/src/helpers/schema.ts diff --git a/packages/round/src/helpers/schema.ts b/packages/round/src/helpers/schema.ts new file mode 100644 index 00000000..131ad957 --- /dev/null +++ b/packages/round/src/helpers/schema.ts @@ -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 };