nesh
Version:
An enhanced, extensible shell for Node.js
63 lines (47 loc) • 1.3 kB
JavaScript
// Generated by CoffeeScript 1.11.1
/*
Nesh Configuration. Implements a basic configuration system
which can load and save state via JSON. By default this data
is stored in ~/.nesh_config.json, but a custom path can be
passed to the load and save functions.
*/
(function() {
var _config, config, fs, log, path;
fs = require('fs');
log = require('./log');
path = require('path');
_config = {};
config = exports;
config.home = process.env.HOME || process.env.USERPROFILE;
config.path = path.join(config.home, '.nesh_config.json');
config.reset = function() {
return _config = {};
};
config.load = function(path) {
var e;
if (path == null) {
path = config.path;
}
if (fs.existsSync(path)) {
log.debug("Loading config from " + path);
try {
return _config = require(path);
} catch (error) {
e = error;
throw "Error loading Nesh config from " + path + ": " + e;
}
} else {
return log.debug("No config found at " + path);
}
};
config.save = function(path) {
if (path == null) {
path = config.path;
}
return fs.writeFileSync(path, JSON.stringify(_config));
};
config.get = function() {
return _config;
};
}).call(this);
//# sourceMappingURL=config.js.map