Last active
August 3, 2017 10:40
-
-
Save yesoreyeram/448ab06f3841c5554581fd20cf9e5f26 to your computer and use it in GitHub Desktop.
Configuration Manager
This file contains 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
var fs = require('fs'); | |
var _ = require("lodash"); | |
var ini = require('ini'); | |
var baseConfig, overrideConfig; | |
var replaceIniConfig = function(configuration) { | |
try { | |
fs.readFile(configuration.base, function(err, content) { | |
if (err) { | |
console.log("File Reading Error", configuration.base); | |
} else { | |
baseConfig = ini.parse(content.toString()); | |
fs.readFile(configuration.override, function(err, content1) { | |
if (err) { | |
console.log("File Reading Error", configuration.override); | |
} else { | |
overrideConfig = ini.parse(content1.toString()); | |
fs.writeFile(configuration.destination, ini.stringify(_.merge(baseConfig, overrideConfig)), function(err, res) { | |
if (err) console.log("Error while writing the file", configuration.destination); | |
else console.log("Done", configuration.override, configuration.destination); | |
}) | |
} | |
}); | |
} | |
}); | |
} catch (ex) { | |
console.log(ex); | |
} | |
} | |
if (process.argv[2]) { | |
if (process.argv[2].toLowerCase() === "general") { | |
if (process.argv[3] && process.argv[4] && process.argv[5]) { | |
var c = { | |
type: process.argv[2], | |
base: process.argv[3], | |
override: process.argv[4], | |
destination: process.argv[5], | |
} | |
replaceIniConfig(c); | |
} else console.log("No enouogh arguments"); | |
} | |
} else console.log("No enough arguments"); |
This file contains 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
{ | |
"name": "configuration-manager", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
}, | |
"author": "", | |
"license": "ISC", | |
"dependencies": { | |
"ini": "^1.3.4", | |
"lodash": "^4.17.4" | |
} | |
} |
This file contains 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
[supervisord] | |
nodaemon = true | |
[supervisorctl] | |
serverurl=unix:///var/run/supervisor.sock | |
[inet_http_server] | |
port = 9001 | |
username = user | |
password = pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment