let fs = require("fs");
let path = require("path");



function readFile(name) {
  var data = fs.readFileSync(name, 'utf-8');
  let obj = JSON.parse(data);

  delete obj.materials
  if (obj.meshes.length != 1) {
    console.error("================", name)
    return
  } else {
    console.log(name)
  }

  obj.meshes[0].name = "mesh"
  fs.writeFile(name, JSON.stringify(obj), function(err) {
    if (err) return console.error(err);
  });

}

function travel(dir, callback) {
  fs.readdirSync(dir).forEach(function(file) {
    var pathname = path.join(dir, file);

    if (fs.statSync(pathname).isDirectory()) {
      travel(pathname, callback);
    } else {
      callback(pathname);
    }
  });
}

names = []
travel('assets/meshes', function(pathname) {
  if (pathname.endsWith(".gltf")) {
    readFile(pathname);
    // pathname = pathname.replace("assets\\meshes\\", "")
    // pathname = pathname.replace(".gltf", "")
    // names.push(pathname)

  }
});
console.log(JSON.stringify(names))