Created
June 24, 2020 13:40
-
-
Save valonhaliti/65720619c2cb45429b2a07d9e0f71763 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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