20 lines
507 B
TypeScript
20 lines
507 B
TypeScript
|
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);
|