Skip to content

Commit a264ab2

Browse files
author
yaroslav8765
committed
fix: correctly load .env.local in resource command
1 parent 6e873e9 commit a264ab2

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

adminforth/commands/callTsProxy.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,28 @@ import { spawn } from "child_process";
33
import path from "path";
44
import fs from "fs";
55
import chalk from "chalk";
6+
import dotenv from "dotenv";
67

78
const currentFilePath = import.meta.url;
89
const currentFileFolder = path.dirname(currentFilePath).replace("file:", "");
910

1011
export function callTsProxy(tsCode, silent=false) {
1112

13+
const currentDirectory = process.cwd();
14+
const envPath = path.resolve(currentDirectory, ".env");
15+
const envLocalPath = path.resolve(currentDirectory, ".env.local");
16+
if (fs.existsSync(envLocalPath)) {
17+
dotenv.config({ path: envLocalPath, override: true });
18+
}
19+
if (fs.existsSync(envPath)) {
20+
dotenv.config({ path: envPath, override: true });
21+
}
22+
1223
process.env.HEAVY_DEBUG && console.log("🌐 Calling tsproxy with code:", path.join(currentFileFolder, "proxy.ts"));
1324
return new Promise((resolve, reject) => {
14-
const child = spawn("tsx", [
15-
path.join(currentFileFolder, "proxy.ts")
16-
]);
17-
25+
const child = spawn("tsx", [path.join(currentFileFolder, "proxy.ts")], {
26+
env: process.env,
27+
});
1828
let stdout = "";
1929
let stderr = "";
2030

adminforth/commands/createApp/templates/index.ts.hbs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ import AdminForth from 'adminforth';
33
import usersResource from "./resources/adminuser.js";
44
import { fileURLToPath } from 'url';
55
import path from 'path';
6-
import dotenv from "dotenv";
7-
dotenv.config({ path: '.env.local', override: true });
8-
dotenv.config({ path: '.env', override: true });
96

107
const ADMIN_BASE_URL = '';
118

0 commit comments

Comments
 (0)