UNPKG

kist

Version:

Package Pipeline Processor

88 lines (87 loc) 3.62 kB
"use strict"; // ============================================================================ // Imports // ============================================================================ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SvgReaderAction = void 0; const fs_1 = require("fs"); const path_1 = __importDefault(require("path")); const Action_1 = require("../../core/pipeline/Action"); // ============================================================================ // Classes // ============================================================================ /** * SvgReaderAction is responsible for reading SVG file contents and * making them available for further processing in the pipeline. */ class SvgReaderAction extends Action_1.Action { constructor() { super(...arguments); this.svgContent = ""; } // Methods // ======================================================================== /** * Executes the SVG reading action. * @param options - The options specifying the SVG file path. * @returns A Promise that resolves when the SVG file is successfully read. */ execute(options) { return __awaiter(this, void 0, void 0, function* () { const { filePath } = options; if (!filePath) { throw new Error("Missing required option: 'filePath'."); } this.logInfo(`Reading SVG file: ${filePath}`); try { this.svgContent = yield this.readSvg(filePath); this.logInfo(`Successfully read SVG file: ${filePath}`); } catch (error) { this.logError(`Error reading SVG file: ${filePath}`, error); throw error; } }); } /** * Reads the content of an SVG file asynchronously. * @param filePath The path to the SVG file. * @returns A promise that resolves to the SVG file content. */ readSvg(filePath) { return __awaiter(this, void 0, void 0, function* () { return fs_1.promises.readFile(path_1.default.resolve(filePath), "utf-8"); }); } /** * Retrieves the last read SVG content. * @returns The last read SVG content. */ getSvgContent() { return this.svgContent; } /** * Provides a description of the action. * @returns A string description of the action. */ describe() { return "Reads an SVG file and stores its content for further processing."; } } exports.SvgReaderAction = SvgReaderAction; // ============================================================================ // Export // ============================================================================ exports.default = SvgReaderAction;