From e9b2ec0f59864696fdf369083e9382f046e73a82 Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Sat, 15 Mar 2025 13:57:21 +0000 Subject: [PATCH] fix(paths): Update directory paths to use a dedicated data directory and add ensureDirectories function for proper directory creation. --- changelog.md | 7 +++++++ ts/paths.ts | 29 +++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/changelog.md b/changelog.md index 37ccb03..d220c37 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2025-03-15 - 1.1.1 - fix(paths) +Update directory paths to use a dedicated 'data' directory and add ensureDirectories function for proper directory creation. + +- Refactored ts/paths.ts to define a base data directory using process.cwd(). +- Reorganized MTA directories (keys, dns, emails sent/received/failed, logs) under the data directory. +- Added ensureDirectories function to create missing directories at runtime. + ## 2025-03-15 - 1.1.1 - fix(mta) Refactor API Manager and DKIMCreator: remove Express dependency in favor of Node's native HTTP server, add an HttpResponse helper to improve request handling, update path and authentication logic, and expose previously private DKIMCreator methods for API access. diff --git a/ts/paths.ts b/ts/paths.ts index 7683e09..a50b0dc 100644 --- a/ts/paths.ts +++ b/ts/paths.ts @@ -1,12 +1,29 @@ import * as plugins from './plugins.js'; +// Base directories +export const baseDir = process.cwd(); export const packageDir = plugins.path.join( plugins.smartpath.get.dirnameFromImportMetaUrl(import.meta.url), '../' ); -export const assetsDir = plugins.path.join(packageDir, './assets'); -export const keysDir = plugins.path.join(assetsDir, './keys'); -export const dnsRecordsDir = plugins.path.join(assetsDir, './dns-records'); -export const sentEmailsDir = plugins.path.join(assetsDir, './sent-emails'); -export const receivedEmailsDir = plugins.path.join(assetsDir, './received-emails'); -plugins.smartfile.fs.ensureDirSync(keysDir); \ No newline at end of file +export const dataDir = plugins.path.join(baseDir, 'data'); + +// MTA directories +export const keysDir = plugins.path.join(dataDir, 'keys'); +export const dnsRecordsDir = plugins.path.join(dataDir, 'dns'); +export const sentEmailsDir = plugins.path.join(dataDir, 'emails', 'sent'); +export const receivedEmailsDir = plugins.path.join(dataDir, 'emails', 'received'); +export const failedEmailsDir = plugins.path.join(dataDir, 'emails', 'failed'); // For failed emails +export const logsDir = plugins.path.join(dataDir, 'logs'); // For logs + +// Create directories if they don't exist +export function ensureDirectories() { + // Ensure data directories + plugins.smartfile.fs.ensureDirSync(dataDir); + plugins.smartfile.fs.ensureDirSync(keysDir); + plugins.smartfile.fs.ensureDirSync(dnsRecordsDir); + plugins.smartfile.fs.ensureDirSync(sentEmailsDir); + plugins.smartfile.fs.ensureDirSync(receivedEmailsDir); + plugins.smartfile.fs.ensureDirSync(failedEmailsDir); + plugins.smartfile.fs.ensureDirSync(logsDir); +} \ No newline at end of file