Skip to content

Instantly share code, notes, and snippets.

@7gano
Created August 23, 2013 00:31
Show Gist options
  • Save 7gano/6314333 to your computer and use it in GitHub Desktop.
Save 7gano/6314333 to your computer and use it in GitHub Desktop.
var fs = require("fs");
var _currentBacking;
exports.setCurrentPage = function(backing){
_currentBacking = backing;
};
exports.getCurrentPage = function(){
var path = './' + _currentBacking + '/info.json';
var jsonString = fs.readFileSync(path, 'utf8');
var pageInfo = JSON.parse(jsonString);
return pageInfo;
};
exports.getPaperJSON = function(backing){
var path = './' + _currentBacking + '/'
+ backing + '/info.json';
var jsonString = fs.readFileSync(path, 'utf8');
try{
var paperJSON = JSON.parse(jsonString);
}catch(e){
console.log(e);
}
return paperJSON;
};
exports.setPaperJSON = function(backing, paperJSON){
var path = './' + _currentBacking + '/'
+ backing + '/info.json';
try{
var jsonString = JSON.stringify(paperJSON);
}catch(e){
console.log(e);
}
var fd = fs.openSync(path, "w");
fs.writeSync(fd, jsonString, 0, "utf8");
fs.closeSync(fd);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment