Skip to content

Instantly share code, notes, and snippets.

@valonhaliti
Created June 24, 2020 13:40
Show Gist options
  • Save valonhaliti/65720619c2cb45429b2a07d9e0f71763 to your computer and use it in GitHub Desktop.
Save valonhaliti/65720619c2cb45429b2a07d9e0f71763 to your computer and use it in GitHub Desktop.
const fs = require('fs');
function getKeysFromFile(filename) {
const file = fs.readFileSync(filename, 'utf-8');
const rows = file.split('\n');
return getKeysFromRows(rows);
}
function getKeysFromRows(rows) {
let keys = [];
for (const row of rows) {
let rowSplitted = row.split('=');
if (rowSplitted.length > 1) {
keys.push(rowSplitted[0]);
}
}
return keys;
}
function compareKeys(keysOfEnv, keysOfExample) {
for (const key of keysOfEnv) {
if (!keysOfExample.includes(key)) {
console.log(`Missing ${key} in .env.example.`);
}
}
}
compareKeys(getKeysFromFile('.env'), getKeysFromFile('.env.example'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment