Skip to content

Instantly share code, notes, and snippets.

@foxx
Created July 28, 2015 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foxx/006ec0ff7324af7a9eb6 to your computer and use it in GitHub Desktop.
Save foxx/006ec0ff7324af7a9eb6 to your computer and use it in GitHub Desktop.
(function() {
var fs = require('fs');
var path = require('path');
var current_dir = path.dirname(fs.realpathSync(__filename));
var design_docs_dir = path.join(current_dir, 'design_docs');
var files = fs.readdirSync(design_docs_dir);
var json = {};
files.forEach(function(fpath) {
fpath = path.join(design_docs_dir, fpath);
var o = require(fpath);
var doc_name = path.basename(fpath, '.js');
json[doc_name] = {};
Object.keys(o).forEach(function(key) {
var map_func = (o[key]['map'] ? o[key]['map'].toString() : null);
var reduce_func = (o[key]['reduce'] ? o[key]['reduce'].toString() : null);
var obj = {map: map_func, reduce: reduce_func};
json[doc_name][key] = obj;
});
});
console.log(JSON.stringify(json, null, 2));
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment