-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (49 loc) 路 1.93 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const envfile = require('envfile');
const chalk = require('chalk');
const inquirer = require('inquirer');
const questions = [{
type: 'input',
name: 'mainEnvPath',
message: 'Input your main env path',
default: '.env',
}, {
type: 'input',
name: 'comparingEnvPath',
message: 'Input your comparing env path',
default: '.env.dev',
}];
inquirer.prompt(questions).then(answers => {
console.log('\n');
const mainEnvPath = answers['mainEnvPath'];
const comparingEnvPath = answers['comparingEnvPath'];
const mainEnv = envfile.parseFileSync(mainEnvPath);
const comparingEnv = envfile.parseFileSync(comparingEnvPath);
let missingEnvironmentVariables = [];
let differentEnvironmentVariables = [];
for (let key in comparingEnv) {
const comparingValue = comparingEnv[key];
const mainValue = mainEnv[key];
if (mainValue === undefined) {
missingEnvironmentVariables.push(`${key}=${comparingValue}`);
} else if (mainValue !== comparingValue) {
differentEnvironmentVariables.push({
key,
main: mainValue,
comparing: comparingValue,
});
}
}
console.log(
chalk.yellow(`Variables that's missing from ${mainEnvPath} but exists on ${comparingEnvPath}:`),
chalk.red(missingEnvironmentVariables.reduce((accumulator, currentValue) => (`${accumulator}\n${currentValue}`), '')),
);
console.log('\n');
console.log(
chalk.yellow(`Variables that's different from ${mainEnvPath} and ${comparingEnvPath}:`),
differentEnvironmentVariables.reduce((accumulator, currentValue) => {
const main = chalk.green(`${currentValue.main} (${mainEnvPath})`);
const comparing = chalk.magenta(`${currentValue.comparing} (${comparingEnvPath})`);
return `${accumulator}\n${currentValue.key}\n${main}\n${comparing}\n`
}, ''),
);
});