From de2b1649c34784db46b886307bd2be58256c68b0 Mon Sep 17 00:00:00 2001 From: Sergei Popinevskii Date: Sun, 24 Sep 2023 01:16:12 +0300 Subject: [PATCH] handle "templates directory doesn't exist" error --- src/metadata/compileViews.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/metadata/compileViews.ts b/src/metadata/compileViews.ts index 1cc5f23..c9333f3 100644 --- a/src/metadata/compileViews.ts +++ b/src/metadata/compileViews.ts @@ -1,15 +1,25 @@ import { PathLike } from 'fs' import fs from 'fs/promises' import { compileTemplate } from './compileTemplates' -import { getTemplate, getTemplates, resetTemplates } from './getTemplates' +import { + Template, + Templates, + getTemplate, + getTemplates, + resetTemplates +} from './getTemplates' export async function* compileViews( viewsPath: PathLike, templatesPath?: PathLike ) { - const templates = templatesPath - ? await getTemplates(templatesPath) - : new Map() + let templates: Templates = new Map() + if (templatesPath) + try { + templates = await getTemplates(templatesPath) + } catch (err) { + if (err.code !== 'ENOENT') throw err + } const unusedTemplates = [] const dir = await fs.opendir(viewsPath) for await (const dirent of dir) {