From 083142330c5eb5451b232fb911f411e8b94a5f52 Mon Sep 17 00:00:00 2001 From: Alexander Cerutti Date: Sat, 1 Jun 2019 13:58:40 +0200 Subject: [PATCH] Added management for non-existing folder-model bundle files --- src/factory.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/factory.ts b/src/factory.ts index 584787b..06ee3fa 100644 --- a/src/factory.ts +++ b/src/factory.ts @@ -130,12 +130,18 @@ async function getModelFolderContents(model: string): Promise // Getting all the buffers from file paths return Promise.all([ - ...validFiles.map(file => readFile(file)) + ...validFiles.map(file => + readFile(file).catch(() => Buffer.alloc(0)) + ) ]).then(buffers => // Assigning each file path to its buffer - Object.assign({}, ...validFiles.map((file, index) => - ({ [file]: buffers[index] }) - )) as BundleUnit + validFiles.reduce((acc, file, index) => { + if (!buffers[index].length) { + return acc; + } + + return { ...acc, [file]: buffers[index] }; + }, {}) ); }); })