-
Notifications
You must be signed in to change notification settings - Fork 1
/
config-manager.js
31 lines (24 loc) · 1.11 KB
/
config-manager.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
module.exports = {
getConfiguration: function() {
const fs = require('fs');
const readline = require('readline-sync');
const configFile = require('os').homedir() + '/.mail-unmerge-configs.json';
if (!fs.existsSync(configFile)) {
fs.writeFileSync(configFile, '{}', 'utf-8');
}
const configs = require(configFile);
checkAndAskFor("email_id", "What source email address would you like to use? ");
checkAndAskFor("sender_name", "What name would you like to reflect in the email? ");
checkAndAskFor("email_server", "What is your outgoing mail server address? ");
checkAndAskFor("password", "Password for your email address (won't be saved): ", {hideEchoBack: true});
function checkAndAskFor(key, caption, options) {
if (!configs[key]) {
configs[key] = readline.question(caption, options);
if (!options || !options.hideEchoBack) {
fs.writeFileSync(configFile, JSON.stringify(configs), 'utf-8');
}
}
}
return configs;
}
};