This commit is contained in:
Benjamin Toby 2025-05-22 10:04:18 +01:00
parent 0fc2c7fb3e
commit 2618d472dc
4 changed files with 65 additions and 28 deletions

View File

@ -1,3 +1,3 @@
export default function parseEnv(/** Env File Path */ envPath: string): {
export default function parseEnv(envFile: string): {
[k: string]: string;
};
} | undefined;

View File

@ -5,17 +5,36 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = parseEnv;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
function parseEnv(/** Env File Path */ envPath) {
let obj = {};
const finalEnvPath = path_1.default.resolve(process.cwd(), envPath);
const envFile = fs_1.default.readFileSync(finalEnvPath, "utf-8");
const envLinesArr = envFile
.split(/\r\n|\n|\r/)
.filter((ln) => ln.match(/\=/));
envLinesArr.forEach((ln) => {
const keyValArr = ln.split("=");
obj[keyValArr[0]] = keyValArr[1] || "";
function parseEnv(envFile) {
if (!fs_1.default.existsSync(envFile))
return undefined;
const envTextContent = fs_1.default.readFileSync(envFile, "utf-8");
const envLines = envTextContent
.split("\n")
.map((ln) => ln.trim())
.filter((ln) => {
const commentLine = ln.match(/^\#/);
const validEnv = ln.match(/.*\=/);
if (commentLine)
return false;
if (validEnv)
return true;
return false;
});
return obj;
const newEnvObj = {};
for (let i = 0; i < envLines.length; i++) {
const emvLine = envLines[i];
const envLineArr = emvLine.split("=");
const envTitle = envLineArr[0];
const envValue = envLineArr[1];
if (!(envTitle === null || envTitle === void 0 ? void 0 : envTitle.match(/./)))
continue;
if (envValue === null || envValue === void 0 ? void 0 : envValue.match(/./)) {
newEnvObj[envTitle] = envValue;
}
else {
newEnvObj[envTitle] = "";
}
}
return newEnvObj;
}

View File

@ -1,18 +1,36 @@
import fs from "fs";
import path from "path";
export default function parseEnv(/** Env File Path */ envPath: string) {
let obj: { [k: string]: string } = {};
const finalEnvPath = path.resolve(process.cwd(), envPath);
const envFile = fs.readFileSync(finalEnvPath, "utf-8");
const envLinesArr = envFile
.split(/\r\n|\n|\r/)
.filter((ln) => ln.match(/\=/));
export default function parseEnv(envFile: string) {
if (!fs.existsSync(envFile)) return undefined;
const envTextContent = fs.readFileSync(envFile, "utf-8");
const envLines = envTextContent
.split("\n")
.map((ln) => ln.trim())
.filter((ln) => {
const commentLine = ln.match(/^\#/);
const validEnv = ln.match(/.*\=/);
envLinesArr.forEach((ln) => {
const keyValArr = ln.split("=");
obj[keyValArr[0]] = keyValArr[1] || "";
});
if (commentLine) return false;
if (validEnv) return true;
return false;
});
return obj;
const newEnvObj: { [k: string]: string } = {};
for (let i = 0; i < envLines.length; i++) {
const emvLine = envLines[i];
const envLineArr = emvLine.split("=");
const envTitle = envLineArr[0];
const envValue = envLineArr[1] as string | undefined;
if (!envTitle?.match(/./)) continue;
if (envValue?.match(/./)) {
newEnvObj[envTitle] = envValue;
} else {
newEnvObj[envTitle] = "";
}
}
return newEnvObj;
}

View File

@ -1,6 +1,6 @@
{
"name": "@moduletrace/datasquirel",
"version": "4.6.2",
"version": "4.6.3",
"description": "Cloud-based SQL data management tool",
"main": "dist/index.js",
"bin": {