From 688317c39037fd8dde569c9b72d6d5fb942131e5 Mon Sep 17 00:00:00 2001 From: ful1e5 <24286590+ful1e5@users.noreply.github.com> Date: Sat, 26 Sep 2020 17:39:05 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=80=20Cursors=20class=20init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/Schema/Cursors.ts | 46 +++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 packages/core/src/Schema/Cursors.ts diff --git a/packages/core/src/Schema/Cursors.ts b/packages/core/src/Schema/Cursors.ts new file mode 100644 index 00000000..a76236b7 --- /dev/null +++ b/packages/core/src/Schema/Cursors.ts @@ -0,0 +1,46 @@ +import fs from "fs"; +import path from "path"; + +export class Cursors { + constructor(private svgDir: string) { + if (!fs.existsSync(this.svgDir)) { + throw new Error(`🚨 .svg files not found in ${this.svgDir}`); + } + } + + getStaticCursors(): string[] | null { + const cursorDir = path.resolve(this.svgDir, "static"); + + if (!fs.existsSync(cursorDir)) { + throw new Error("🚨 Static Cursors directory not found"); + } + + const staticCursors = fs + .readdirSync(cursorDir) + .map((f) => path.resolve(cursorDir, f)); + + if (staticCursors.length == 0) { + return null; + } + + return staticCursors; + } + + getAnimatedCursors(): string[] | null { + const cursorDir = path.resolve(this.svgDir, "animated"); + + if (!fs.existsSync(cursorDir)) { + throw new Error("🚨 Animated Cursors directory not found"); + } + + const animatedCursors = fs + .readdirSync(cursorDir) + .map((f) => path.resolve(cursorDir, f)); + + if (animatedCursors.length == 0) { + return null; + } + + return animatedCursors; + } +}