dsql-admin/dsql-app/docker/utils/env-to-json.ts

20 lines
507 B
TypeScript
Raw Normal View History

2025-01-13 21:50:42 +00:00
import fs from "fs";
import path from "path";
const targetPath = path.resolve(
process.cwd(),
process.argv[process.argv.length - 1]
);
try {
let obj: any = {};
const envFile = fs.readFileSync(targetPath, "utf-8");
const envLinesArr = envFile.split(/\r\n/).filter((ln) => ln.match(/\=/));
envLinesArr.forEach((ln) => {
const keyValArr = ln.split("=");
obj[keyValArr[0]] = keyValArr[1] || "";
});
console.log(obj);
} catch (error) {}
console.log(targetPath);