diff --git a/packages/round/src/helpers/schema.ts b/packages/round/src/helpers/schema.ts index 41f16389..35e2347f 100644 --- a/packages/round/src/helpers/schema.ts +++ b/packages/round/src/helpers/schema.ts @@ -24,9 +24,63 @@ const generateConfigs = ( const schemaSvgsPath = path.resolve(schemesPath, schemaName); fs.mkdirSync(schemaSvgsPath, { recursive: true }); - generateStaticSchema(rawSvgsDir, customize, base, outline, schemaSvgsPath); + staticCursors.map((cursor: string) => { + // Read file + let content = fs + .readFileSync(path.resolve(rawSvgsDir, cursor), "utf-8") + .toString(); - generateAnimatedSchema(rawSvgsDir, base, outline, watch, schemaSvgsPath); + // try => replace `customize` colors + // onError => replace `schema` main colors + try { + let { base: b, outline: o } = customize![cursor]; + if (!b) b = base; + if (!o) o = outline; + content = content.replace("#00FF00", b).replace("#0000FF", o); + } catch (error) { + content = content.replace("#00FF00", base).replace("#0000FF", outline); + } + + // Save Schema + const cursorPath = path.resolve(schemaSvgsPath, cursor); + fs.writeFileSync(cursorPath, content, "utf-8"); + }); + + for (let [cursor] of Object.entries(animatedCursors)) { + // Read file + let content = fs + .readFileSync(path.resolve(rawSvgsDir, cursor), "utf-8") + .toString(); + + // Animated Cursors have two parts: + // 1) Cursor Color + // 2) Watch Color + + content = content.replace("#00FF00", base).replace("#0000FF", outline); + + // try => replace `customize` colors + // onError => replace `schema` main colors + try { + if (!watch) throw new Error(""); + const { + background: b, + color1: c1, + color2: c2, + color3: c3, + color4: c4 + } = watch; + content = content.replace("#TODO", b); //Inter watch circle + content = content + .replace("#TODO", c1) + .replace("#TODO", c2) + .replace("#TODO", c3) + .replace("#TODO", c4); + } catch (error) {} + + // Save Schema + const cursorPath = path.resolve(schemaSvgsPath, cursor); + fs.writeFileSync(cursorPath, content, "utf-8"); + } // Creating Dir for store bitmaps const bitmapsDir = path.resolve(process.cwd(), "bitmaps", schemaName); @@ -46,91 +100,3 @@ const generateConfigs = ( }; export { generateConfigs }; - -function generateAnimatedSchema( - rawSvgsDir: string, - base: string, - outline: string, - watch: - | { - background: string; - color1: string; - color2: string; - color3: string; - color4: string; - } - | undefined, - schemaSvgsPath: string -) { - for (let [cursor] of Object.entries(animatedCursors)) { - // Read file - let content = fs - .readFileSync(path.resolve(rawSvgsDir, cursor), "utf-8") - .toString(); - - // Animated Cursors have two parts: - // 1) Cursor Color - // 2) Watch Color - content = content.replace("#00FF00", base).replace("#0000FF", outline); - - // try => replace `customize` colors - // onError => replace `schema` main colors - try { - if (!watch) throw new Error(""); - const { - background: b, - color1: c1, - color2: c2, - color3: c3, - color4: c4 - } = watch; - content = content.replace("#TODO", b); //Inter watch circle - content = content - .replace("#TODO", c1) - .replace("#TODO", c2) - .replace("#TODO", c3) - .replace("#TODO", c4); - } catch (error) {} - - // Save Schema - const cursorPath = path.resolve(schemaSvgsPath, cursor); - fs.writeFileSync(cursorPath, content, "utf-8"); - } -} - -function generateStaticSchema( - rawSvgsDir: string, - customize: - | { - [name: string]: { - outline?: string | undefined; - base?: string | undefined; - }; - } - | undefined, - base: string, - outline: string, - schemaSvgsPath: string -) { - staticCursors.map((cursor: string) => { - // Read file - let content = fs - .readFileSync(path.resolve(rawSvgsDir, cursor), "utf-8") - .toString(); - - // try => replace `customize` colors - // onError => replace `schema` main colors - try { - let { base: b, outline: o } = customize![cursor]; - if (!b) b = base; - if (!o) o = outline; - content = content.replace("#00FF00", b).replace("#0000FF", o); - } catch (error) { - content = content.replace("#00FF00", base).replace("#0000FF", outline); - } - - // Save Schema - const cursorPath = path.resolve(schemaSvgsPath, cursor); - fs.writeFileSync(cursorPath, content, "utf-8"); - }); -}