-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprogramConfig.js
More file actions
executable file
·54 lines (45 loc) · 1.51 KB
/
Copy pathprogramConfig.js
File metadata and controls
executable file
·54 lines (45 loc) · 1.51 KB
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
const {homedir} = require('os');
const fs = require('fs');
const defaultConfigPath = `${homedir()}/.midnightServiceBus.config`;
const SetConnectionsString = ({operationArgs}) => {
let config = {}
try {
if (fs.existsSync(defaultConfigPath)) {
let configData = fs.readFileSync(defaultConfigPath);
config = JSON.parse(configData);
}
} catch(err) {
console.log('Config not found: adding new config file');
}
let [envName, connectionString ] = operationArgs;
config[envName] = connectionString;
fs.writeFileSync(defaultConfigPath, JSON.stringify(config, null, 4), );
};
const ListConfiguredConnections = ({configPath = defaultConfigPath}) => {
try {
if (fs.existsSync(configPath)) {
const configData = fs.readFileSync(configPath);
const loadedConfig = JSON.parse(configData);
const configKeys = Object.keys(loadedConfig);
console.log(`Available configs: ${configKeys}`)
}
} catch(err) {
throw new Error('Required');
}
}
const LoadConnectionString = ({configPath = defaultConfigPath, connectionSettingName}) => {
try {
if (fs.existsSync(configPath)) {
let configData = fs.readFileSync(configPath);
let loadedConfig = JSON.parse(configData);
return loadedConfig[connectionSettingName]
}
} catch(err) {
throw new Error('Required');
}
}
module.exports = {
SetConnectionsString,
ListConfiguredConnections,
LoadConnectionString
};