Skip to content

Commit

Permalink
chore: fix ignored adapters path
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmarqs committed Feb 4, 2024
1 parent 0bc972a commit 97e31d0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ out

# Dist
dist
*-adapter/

# Gatsby files
.cache/
Expand Down
36 changes: 36 additions & 0 deletions src/lib/adapters/dotenv-adapter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { parse } from "dotenv";
import { readFile } from "fs/promises";
import { Adapter } from "../../../types";
import { filterByPrefixKey } from "../utils";

export type DotEnvAdapterProps = {
path: string;
prefixKey?: string;
};

const ADAPTER_NAME = "dotenv adapter";

export const dotEnvAdapter = ({ path, prefixKey }: DotEnvAdapterProps): Adapter => {
return {
name: ADAPTER_NAME,
read: async () => {
try {
const data = await readFile(path, "utf-8");

const parsedData = parse(data) || {};

if (prefixKey) {
return filterByPrefixKey(parsedData, prefixKey);
}

return parsedData;
} catch (error) {
throw new Error(
`Failed to parse / read .env file at ${path}: ${
error instanceof Error ? error.message : error
}`,
);
}
},
};
};

0 comments on commit 97e31d0

Please sign in to comment.