Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
category info
/*globals require, console, process */
'use strict';
var nconf = require('nconf');
var async = require('async');
nconf.file({
file: 'config.json'
});
nconf.defaults({
base_dir: __dirname,
views_dir: './build/public/templates',
upload_path: 'public/uploads',
});
var db = require('./src/database');
var result = {};
db.init(function(err) {
if (err) {
console.log("NodeBB could not connect to your database. Error: " + err.message);
process.exit();
}
printCategoryTree(function (err) {
if (err) {
console.error(err);
process.exit();
}
console.log('done');
console.log(JSON.stringify(result, null, 4));
process.exit();
});
});
function printCategoryTree(callback) {
async.waterfall([
function (next) {
db.getSortedSetRange('categories:cid', 0, -1, next);
},
function (cids, next) {
async.eachSeries(cids, function (cid, next) {
async.parallel({
category: function (next) {
db.getObject('category:' + cid, next);
},
children: function (next) {
db.getSortedSetRange('cid:' + cid + ':children', 0, -1, next);
},
}, function (err, data) {
if (err) {
return next(err);
}
result[cid] = {
parentCid: data.category.parentCid,
children: data.children,
};
next();
});
}, next);
},
], callback);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment