summaryrefslogtreecommitdiff
path: root/src/utils/config.ts
diff options
context:
space:
mode:
authorLeo Goetz <dev@leogtz.de>2026-05-08 15:48:37 +0200
committerLeo Goetz <dev@leogtz.de>2026-05-08 15:48:37 +0200
commitc3cb0ca317a52a740bf9625ca9df43f5c2306548 (patch)
treeaa8877dc2d651f16d23a629c4054043cae8be156 /src/utils/config.ts
inital commit
Diffstat (limited to 'src/utils/config.ts')
-rw-r--r--src/utils/config.ts48
1 files changed, 48 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);
+ }
+};