Convert a directory tree to a JS object.