Comparing version 1.0.115 to 1.0.116
const fs = require('fs'); | ||
const Path = require('path'); | ||
const mkpath = require('./mkpath.js'); | ||
const fileExists = require('./fileExists.js'); | ||
module.exports = function loadConfig(fileName) { | ||
let configFile = ''; | ||
let config = {}; | ||
let configFile = ''; | ||
let config = {}; | ||
function load(fileName) { | ||
@@ -12,20 +14,28 @@ if (fileName == undefined) | ||
try { | ||
if (!fs.existsSync(configFile)) { | ||
configFile = Path.join(Path.dirname(process.argv[1]), fileName); | ||
} | ||
if (!fileExists(configFile)) { | ||
configFile = Path.join(Path.dirname(process.argv[1]), fileName); | ||
} | ||
if (!fileExists(configFile)) { | ||
configFile = Path.resolve(process.cwd(), fileName); | ||
} | ||
if (!fs.existsSync(configFile)) { | ||
configFile = Path.resolve(process.cwd(), fileName); | ||
} | ||
if (fs.existsSync(configFile)) { | ||
config = JSON.parse(fs.readFileSync(configFile)); | ||
} | ||
if (fileExists(configFile)) { | ||
config = JSON.parse(fs.readFileSync(configFile)); | ||
} | ||
catch(error) { | ||
console.error(error); | ||
} | ||
return config; | ||
} | ||
function save() { | ||
if (!fileExists(configFile)) { | ||
mkpath(Path.dirname(configFile)); | ||
} | ||
fs.writeFileSync(configFile, JSON.stringify(config, null, '\t')); | ||
} | ||
module.exports = load; | ||
module.exports.load = load; | ||
module.exports.save = save; |
{ | ||
"name": "yow", | ||
"version": "1.0.115", | ||
"version": "1.0.116", | ||
"description": "You Only Wish module", | ||
@@ -5,0 +5,0 @@ "main": "yow.js", |
18302
429