CursorSvgParser init

This commit is contained in:
ful1e5 2020-09-26 18:00:40 +05:30
parent 688317c390
commit 70d443b394

View file

@ -1,14 +1,18 @@
import fs from "fs"; import fs from "fs";
import path from "path"; import path from "path";
export class Cursors { export class CursorSvgParser {
constructor(private svgDir: string) { constructor(private svgDir: string) {
if (!fs.existsSync(this.svgDir)) { if (!fs.existsSync(this.svgDir)) {
throw new Error(`🚨 .svg files not found in ${this.svgDir}`); throw new Error(`🚨 .svg files not found in ${this.svgDir}`);
} }
} }
getStaticCursors(): string[] | null { /**
* Return all static cursors absolute paths.
* Looking inside <svgDir>/static directory.
*/
public getStaticCursors(): string[] {
const cursorDir = path.resolve(this.svgDir, "static"); const cursorDir = path.resolve(this.svgDir, "static");
if (!fs.existsSync(cursorDir)) { if (!fs.existsSync(cursorDir)) {
@ -20,13 +24,17 @@ export class Cursors {
.map((f) => path.resolve(cursorDir, f)); .map((f) => path.resolve(cursorDir, f));
if (staticCursors.length == 0) { if (staticCursors.length == 0) {
return null; console.warn("Static Cursors directory is empty");
} }
return staticCursors; return staticCursors;
} }
getAnimatedCursors(): string[] | null { /**
* Return all animated cursors absolute paths.
* Looking inside <svgDir>/animated directory.
*/
public getAnimatedCursors(): string[] {
const cursorDir = path.resolve(this.svgDir, "animated"); const cursorDir = path.resolve(this.svgDir, "animated");
if (!fs.existsSync(cursorDir)) { if (!fs.existsSync(cursorDir)) {
@ -38,7 +46,7 @@ export class Cursors {
.map((f) => path.resolve(cursorDir, f)); .map((f) => path.resolve(cursorDir, f));
if (animatedCursors.length == 0) { if (animatedCursors.length == 0) {
return null; console.warn("Animated Cursors directory is empty");
} }
return animatedCursors; return animatedCursors;