@puls-atlas/cli
Version:
The Puls Atlas CLI tool for managing Atlas projects
34 lines • 992 B
JavaScript
import fs from 'fs';
const stripWrappingQuotes = value => {
if (value.length < 2) {
return value;
}
const firstCharacter = value[0];
const lastCharacter = value[value.length - 1];
if (firstCharacter === '"' && lastCharacter === '"' || firstCharacter === "'" && lastCharacter === "'") {
return value.slice(1, -1);
}
return value;
};
export const parseEnv = path => {
const env = {};
const file = fs.readFileSync(path, 'utf-8');
const lines = file.split(/\r?\n/);
for (const line of lines) {
const trimmedLine = line.trim();
if (trimmedLine.length === 0 || trimmedLine.startsWith('#')) {
continue;
}
const separatorIndex = trimmedLine.indexOf('=');
if (separatorIndex === -1) {
continue;
}
const key = trimmedLine.slice(0, separatorIndex).trim();
const value = trimmedLine.slice(separatorIndex + 1).trim();
if (key.length === 0) {
continue;
}
env[key] = stripWrappingQuotes(value);
}
return env;
};