UNPKG

@ipp/cli

Version:

An image build orchestrator for the modern web

46 lines (45 loc) 1.4 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.saveManifest = void 0; const common_1 = require("@ipp/common"); const fs_1 = require("fs"); const map_1 = require("../lib/stream/operators/map"); const types_1 = require("./types"); function saveManifest(path, mappings) { let manifestStream = null; let first = true; return (0, map_1.map)((item) => { if (!(0, types_1.isSavedResult)(item)) return item; if (!manifestStream) manifestStream = createManifestStream(path); const manifest = (0, common_1.createManifestItem)(item.savedResult, mappings); if (first) { first = false; } else { manifestStream.write(","); } manifestStream.write(JSON.stringify(manifest)); return null; }, () => new Promise((res) => { if (manifestStream !== null) { manifestStream.end("]", () => res()); } else { res(); } })); } exports.saveManifest = saveManifest; function createManifestStream(path) { const stream = (0, fs_1.createWriteStream)(path); stream.write("["); return stream; }