You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.0 KiB
46 lines
1.0 KiB
var fs = require('fs');
|
|
var chalk = require('chalk');
|
|
|
|
/**
|
|
* File IO, error reporting.
|
|
*/
|
|
module.exports = {
|
|
/**
|
|
*
|
|
*/
|
|
read: function(file) {
|
|
return new Promise(function(resolve) {
|
|
fs.readFile(file, 'utf8', function(err, str) {
|
|
console.log('Read ' + file);
|
|
module.exports.error(err);
|
|
resolve(str || '');
|
|
});
|
|
});
|
|
},
|
|
|
|
/**
|
|
*
|
|
*/
|
|
write: function(file, str) {
|
|
return new Promise(function(resolve) {
|
|
if (str) {
|
|
fs.writeFile(file, str, module.exports.error, resolve);
|
|
console.log('Write ' + file);
|
|
}
|
|
else {
|
|
resolve();
|
|
}
|
|
});
|
|
},
|
|
|
|
/**
|
|
*
|
|
*/
|
|
error: function(e) {
|
|
if (e !== null) {
|
|
// Gotcha: Promise.all() will not execute unless all promises are resolved.
|
|
// http://stackoverflow.com/questions/28250680/
|
|
console.log(chalk.yellow(e));
|
|
}
|
|
}
|
|
};
|
|
|