Cleaned up loading config
This commit is contained in:
@@ -29,6 +29,7 @@ exports.load_config = function () {
|
||||
// let config = null;
|
||||
let config_directory = null;
|
||||
let default_config_path = path.join(process.cwd(),'config.json.default');
|
||||
console.log(default_config_path);
|
||||
let config_path = null;
|
||||
|
||||
// Set the config path for macOS or Linux
|
||||
@@ -42,38 +43,41 @@ exports.load_config = function () {
|
||||
|
||||
// Look for the config file and copy the default if not found.
|
||||
if (fs.existsSync(config_directory)) {
|
||||
console.log('Config: '+config_directory);
|
||||
config_path = path.join(config_directory, 'config.json');
|
||||
console.log('Config directory found: '+config_directory);
|
||||
} else {
|
||||
fs.mkdirSync(config_directory);
|
||||
console.log('Config directory created: '+config_directory);
|
||||
|
||||
//default_config_path = path.join(process.cwd(),'config.json.default');
|
||||
config_path = path.join(config_directory, 'config.json');
|
||||
fs.copyFileSync(default_config_path, config_path);
|
||||
console.log('Default config file copied: '+config_directory);
|
||||
// config_path = path.join(config_directory, 'config.json');
|
||||
// fs.copyFileSync(default_config_path, config_path);
|
||||
// console.log('Default config file copied: '+config_directory);
|
||||
}
|
||||
|
||||
// Attempt to open the config file. The preferred location is based on the OS's config directory.
|
||||
if (fs.existsSync(config_path)) {
|
||||
console.log('Config path: '+config_path);
|
||||
console.log('Config file (config.json) found under '+config_directory+'.');
|
||||
config_path = path.join(config_directory, 'config.json');
|
||||
|
||||
config = JSON.parse(fs.readFileSync(config_path));
|
||||
console.log('Config file read.');
|
||||
} else if (!fs.existsSync(config_path)) {
|
||||
// Attempt to open the config file. The preferred location is based on the OS's config directory.
|
||||
// if (fs.existsSync(config_path)) {
|
||||
// console.log(`Config path: ${config_path}`);
|
||||
// console.log(`Config file (config.json) found under ${config_directory}`);
|
||||
|
||||
|
||||
// } else
|
||||
if (!fs.existsSync(config_path) && fs.existsSync(default_config_path)) {
|
||||
fs.copyFileSync(default_config_path, config_path);
|
||||
console.log('Default config file copied: '+config_directory);
|
||||
|
||||
config = JSON.parse(fs.readFileSync(config_path));
|
||||
console.log('Config file read.');
|
||||
// config = JSON.parse(fs.readFileSync(config_path));
|
||||
// console.log('Config file read.');
|
||||
} else if (fs.existsSync('config.json')) {
|
||||
//fs.copyFileSync(default_config_path, config_path);
|
||||
//console.log('Default config file copied: '+config_directory);
|
||||
|
||||
config = JSON.parse(fs.readFileSync('config.json'));
|
||||
console.log('Config file (config.json) not found under '+config_directory+'. Using config in CWD.');
|
||||
console.log('Config file read.');
|
||||
console.log(`Config file (config.json) not found under ${config_directory}. Using config in CWD. ${process.cwd()}`);
|
||||
config_path = 'config.json';
|
||||
|
||||
// config = JSON.parse(fs.readFileSync('config.json'));
|
||||
// console.log('Config file read.');
|
||||
|
||||
//console.log('Config file (config.json) not found under '+config_directory+'. Using config in CWD.');
|
||||
//config = JSON.parse(fs.readFileSync('config.json'));
|
||||
@@ -81,6 +85,9 @@ exports.load_config = function () {
|
||||
//close();
|
||||
}
|
||||
|
||||
config = JSON.parse(fs.readFileSync(config_path));
|
||||
console.log('Config file read.');
|
||||
|
||||
config.home_directory = home_directory; // From the OS platform
|
||||
config.tmp_directory = tmp_directory; // From the OS platform
|
||||
|
||||
|
||||
Reference in New Issue
Block a user