@schemavaults/dbh 0.8.3 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/utils/loadEnvFile.d.ts +5 -0
- package/dist/utils/loadEnvFile.js +36 -0
- package/dist/utils/loadEnvFile.js.map +1 -0
- package/dist-cli/cli.js +16 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -20,7 +20,7 @@ Ensure that you have both `postgres` and a `postgres-ws-proxy` containers runnin
|
|
|
20
20
|
|
|
21
21
|
You'll likely want to replace the `build:` sections for the services in the e2e test example `.yml` file with `image:`. For example, use `image: postgres:17.7` for the `postgres` service. For the proxy, you can pull the docker image from `ghcr.io/schemavaults/dbh/postgres-ws-proxy`; use the version number equal to your `@schemavaults/dbh` npm package installation:
|
|
22
22
|
```md
|
|
23
|
-
# NPM Package: @schemavaults/dbh@0.8.
|
|
23
|
+
# NPM Package: @schemavaults/dbh@0.8.5 => ghcr.io/schemavaults/dbh/postgres-ws-proxy:0.8.5
|
|
24
24
|
```
|
|
25
25
|
|
|
26
26
|
### In your application server code
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
/**
|
|
4
|
+
* Reads a .env file and injects its variables into process.env.
|
|
5
|
+
* Existing environment variables take precedence (are NOT overwritten).
|
|
6
|
+
*/
|
|
7
|
+
export function loadEnvFile(filePath) {
|
|
8
|
+
const resolved = path.resolve(filePath);
|
|
9
|
+
if (!fs.existsSync(resolved)) {
|
|
10
|
+
throw new Error(`Env file not found: ${resolved}`);
|
|
11
|
+
}
|
|
12
|
+
const content = fs.readFileSync(resolved, "utf-8");
|
|
13
|
+
for (const line of content.split("\n")) {
|
|
14
|
+
const trimmed = line.trim();
|
|
15
|
+
// Skip blank lines and comments
|
|
16
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
17
|
+
continue;
|
|
18
|
+
}
|
|
19
|
+
const eqIndex = trimmed.indexOf("=");
|
|
20
|
+
if (eqIndex === -1) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const key = trimmed.slice(0, eqIndex).trim();
|
|
24
|
+
let value = trimmed.slice(eqIndex + 1).trim();
|
|
25
|
+
// Strip matching quotes
|
|
26
|
+
if ((value.startsWith('"') && value.endsWith('"')) ||
|
|
27
|
+
(value.startsWith("'") && value.endsWith("'"))) {
|
|
28
|
+
value = value.slice(1, -1);
|
|
29
|
+
}
|
|
30
|
+
// Don't override existing env vars
|
|
31
|
+
if (process.env[key] === undefined) {
|
|
32
|
+
process.env[key] = value;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=loadEnvFile.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadEnvFile.js","sourceRoot":"","sources":["../../src/utils/loadEnvFile.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB;;;GAGG;AACH,MAAM,UAAU,WAAW,CAAC,QAAgB;IAC1C,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAExC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,uBAAuB,QAAQ,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,MAAM,OAAO,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAEnD,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAE5B,gCAAgC;QAChC,IAAI,CAAC,OAAO,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,C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