🚀 Cursors class init

This commit is contained in:
ful1e5 2020-09-26 17:39:05 +05:30
parent 82956fe5a3
commit 688317c390

View file

@ -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;
}
}