UNPKG

@ipp/cli

Version:

An image build orchestrator for the modern web

46 lines (45 loc) 1.62 kB
"use strict"; /** * Image Processing Pipeline - Copyright (c) Marcus Cemes * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.processImages = void 0; const common_1 = require("@ipp/common"); const core_1 = require("@ipp/core"); const fs_1 = require("fs"); const path_1 = require("path"); const metadata_1 = require("../lib/metadata"); const map_parallel_1 = require("../lib/stream/operators/map_parallel"); const types_1 = require("./types"); function processImages(pipeline, concurrency) { return (0, map_parallel_1.mapParallel)(concurrency, async (item) => { if (!(0, types_1.isTaskSource)(item)) return item; const { fullPath, initialMeta } = generatePaths(item); const buffer = await fs_1.promises.readFile(fullPath); try { return { ...item, result: await (0, core_1.executePipeline)(pipeline, buffer, initialMeta), }; } catch (err) { if (err instanceof common_1.Exception) return err; return new common_1.Exception(`Unexpected processing error: ${err.message}`).extend(err); } }); } exports.processImages = processImages; function generatePaths(item) { const relativePath = item.file; const fullPath = (0, path_1.resolve)(item.root, relativePath); const initialMeta = (0, metadata_1.pathMetadata)(relativePath); return { fullPath, initialMeta, }; }