fix: prevent error if no local config exists

This commit is contained in:
Julien Oculi 2025-02-20 16:21:54 +01:00
parent 64fe0ab3d7
commit 52f9438f6c
3 changed files with 25 additions and 9 deletions

View file

@ -1,3 +1,4 @@
import { exists } from '@std/fs/exists'
import type { JSX } from 'preact'
import { EnumType } from '@cliffy/command'
import type { Template } from '../types.ts'
@ -20,15 +21,17 @@ for (const template of Object.values(defaultTemplates)) {
//Load local templates
const basePath = '/etc/cohabit/mailer'
for await (
const template of Deno.readDir(basePath)
) {
if (!template.isFile) continue
if (!template.name.endsWith('.tsx')) continue
if (template.name.startsWith('_')) continue
if (await exists(basePath)) {
for await (const template of Deno.readDir(basePath)) {
if (!template.isFile) continue
if (!template.name.endsWith('.tsx')) continue
if (template.name.startsWith('_')) continue
const mod = await import(`${basePath}/${template.name}`).catch(checkFsErrors)
templates.set(mod.default.name, mod.default)
const mod = await import(`${basePath}/${template.name}`).catch(
checkFsErrors,
)
templates.set(mod.default.name, mod.default)
}
}
function checkFsErrors(error: Error) {

View file

@ -19,6 +19,7 @@
"imports": {
"@cliffy/command": "jsr:@cliffy/command@^1.0.0-rc.5",
"@cliffy/prompt": "jsr:@cliffy/prompt@^1.0.0-rc.5",
"@std/fs": "jsr:@std/fs@^1.0.13",
"@std/json": "jsr:@std/json@^1.0.1",
"@types/nodemailer": "npm:@types/nodemailer@^6.4.15",
"jsx-email": "npm:jsx-email@^1.10.12",

View file

@ -12,9 +12,11 @@
"jsr:@std/cli@1.0.0-rc.2": "1.0.0-rc.2",
"jsr:@std/encoding@1.0.0-rc.2": "1.0.0-rc.2",
"jsr:@std/fmt@~0.225.4": "0.225.6",
"jsr:@std/fs@^1.0.13": "1.0.13",
"jsr:@std/io@~0.224.2": "0.224.3",
"jsr:@std/json@^1.0.1": "1.0.1",
"jsr:@std/path@1.0.0-rc.2": "1.0.0-rc.2",
"jsr:@std/path@^1.0.8": "1.0.8",
"jsr:@std/streams@^1.0.7": "1.0.9",
"jsr:@std/text@1.0.0-rc.1": "1.0.0-rc.1",
"npm:@types/node@*": "18.16.19",
@ -66,7 +68,7 @@
"jsr:@std/assert",
"jsr:@std/fmt",
"jsr:@std/io",
"jsr:@std/path",
"jsr:@std/path@1.0.0-rc.2",
"jsr:@std/text"
]
},
@ -89,6 +91,12 @@
"@std/fmt@0.225.6": {
"integrity": "aba6aea27f66813cecfd9484e074a9e9845782ab0685c030e453a8a70b37afc8"
},
"@std/fs@1.0.13": {
"integrity": "756d3ff0ade91c9e72b228e8012b6ff00c3d4a4ac9c642c4dac083536bf6c605",
"dependencies": [
"jsr:@std/path@^1.0.8"
]
},
"@std/io@0.224.3": {
"integrity": "b402edeb99c6b3778d9ae3e9927bc9085b170b41e5a09bbb7064ab2ee394ae2f"
},
@ -101,6 +109,9 @@
"@std/path@1.0.0-rc.2": {
"integrity": "39f20d37a44d1867abac8d91c169359ea6e942237a45a99ee1e091b32b921c7d"
},
"@std/path@1.0.8": {
"integrity": "548fa456bb6a04d3c1a1e7477986b6cffbce95102d0bb447c67c4ee70e0364be"
},
"@std/streams@1.0.9": {
"integrity": "a9d26b1988cdd7aa7b1f4b51e1c36c1557f3f252880fa6cc5b9f37078b1a5035"
},
@ -3814,6 +3825,7 @@
"dependencies": [
"jsr:@cliffy/command@^1.0.0-rc.5",
"jsr:@cliffy/prompt@^1.0.0-rc.5",
"jsr:@std/fs@^1.0.13",
"jsr:@std/json@^1.0.1",
"npm:@types/nodemailer@^6.4.15",
"npm:jsx-email@^1.10.12",