doccam-pi/out/src_utility_config.js.html
Hiro Protagonist d451ea6dd4 compatibility
2017-04-27 17:43:06 +12:00

94 lines
2.6 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JSDoc: Source: src/utility/config.js</title>
<script src="scripts/prettify/prettify.js"> </script>
<script src="scripts/prettify/lang-css.js"> </script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
<link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>
<body>
<div id="main">
<h1 class="page-title">Source: src/utility/config.js</h1>
<section>
<article>
<pre class="prettyprint source linenums"><code>/** Config read/write utilities.
* @module Utilities/Config
*/
const Promise = require('promise');
const fs = require('fs');
const logger = require('./logger.js');
// TODO: Config path in defs
module.exports = {};
// TODO Default CFG
/**
* Read the JSON config file.
* @returns { Object | bool } Returns the parsed config or false in case of an error.
*/
module.exports.read = function() {
try {
return JSON.parse(fs.readFileSync(__dirname + '/config.js'));
} catch (e) {
logger.dbgmsg(e);
return false;
}
};
/**
* Writes the config to disk.
* @param {Object} state A function to retrieve the current state. This makes it harder to accidentially write arbitrary code.
* @returns { Promise } A promise for writing the configuration.
*/
module.exports.write = function( getState ){
return new Promise((resolve, reject) => {
fs.writeFile(__dirname + '/config.js',
JSON.stringify(getState().config, undefined, 2),
err => {
if(err)
reject(err);
else
resolve();
});
});
};
</code></pre>
</article>
</section>
</div>
<nav>
<h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-Actions.html">Actions</a></li><li><a href="module-Commander.html">Commander</a></li><li><a href="module-Main.html">Main</a></li><li><a href="module-Reducers.html">Reducers</a></li><li><a href="module-Streamer.html">Streamer</a></li><li><a href="module-Utilities_Config.html">Utilities/Config</a></li></ul><h3>Classes</h3><ul><li><a href="module-Commander-Commander.html">Commander</a></li><li><a href="module-Streamer-Streamer.html">Streamer</a></li></ul>
</nav>
<br class="clear">
<footer>
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.4.3</a> on Mon Apr 24 2017 18:52:45 GMT+1200 (NZST)
</footer>
<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>