diff options
| author | Leo Goetz <dev@leogtz.de> | 2026-05-08 15:48:37 +0200 |
|---|---|---|
| committer | Leo Goetz <dev@leogtz.de> | 2026-05-08 15:48:37 +0200 |
| commit | c3cb0ca317a52a740bf9625ca9df43f5c2306548 (patch) | |
| tree | aa8877dc2d651f16d23a629c4054043cae8be156 /src/utils | |
inital commit
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/config.ts | 48 | ||||
| -rw-r--r-- | src/utils/email.ts | 18 |
2 files changed, 66 insertions, 0 deletions
diff --git a/src/utils/config.ts b/src/utils/config.ts new file mode 100644 index 0000000..62080f7 --- /dev/null +++ b/src/utils/config.ts @@ -0,0 +1,48 @@ +import os from "os"; +import fs from "fs/promises"; +import type { Config } from "../types.js"; + +const configPath: string = new URL( + `${os.homedir()}/.config/dephelp/`, + import.meta.url, +).pathname; + +const configFile: string = `${configPath}/config.json`; + +const sampleConfig: Config = { + path: "/your/projects/ (absolute path!)", + email: { + host: "mail.example.com", + port: 587, + secure: true, + auth: { + user: "example", + pass: "example-password", + }, + senderEmail: "audit@example.com", + senderName: "Dependency Reporter", + subject: "Your Project(s) are insecure!", + reciever: "your@beautiful.email", + }, +}; + +export const getConfig = async (): Promise<Config> => { + const content = await fs.readFile(configFile, { encoding: "utf8" }); + const config: Config = JSON.parse(content); + return config; +}; + +export const initConfig = async () => { + try { + await fs.access(configPath); + } catch { + await fs.mkdir(configPath); + } + + try { + await fs.writeFile(`${configFile}`, JSON.stringify(sampleConfig, null, 2)); + console.log(`Config got generated in /.config/dephelp/config.json`); + } catch (error) { + console.error(error); + } +}; diff --git a/src/utils/email.ts b/src/utils/email.ts new file mode 100644 index 0000000..828603b --- /dev/null +++ b/src/utils/email.ts @@ -0,0 +1,18 @@ +import type { Config, EmailConfig } from "../types.js"; +import { getConfig } from "./config.js"; + +const config: Config = await getConfig(); + +export const emailConfig: EmailConfig = { + host: config.email!.host, + port: config.email!.port, + secure: config.email!.secure, + auth: { + user: config.email!.auth.user, + pass: config.email!.auth.pass, + }, + senderEmail: config.email!.senderEmail, + senderName: config.email!.senderName, + subject: config.email!.subject, + reciever: config.email!.reciever, +}; |
