//生成res.json

//遍历资源文件夹，生成
var fs = require('fs');
var path = require("path");
var readPath = "./resource/"
var files = fs.readdirSync(readPath);
var obj = { groups: [] };//没项包括keys合name

files.forEach(function (file) {
    //路径
    let fPath = path.join(readPath, file);
    //只处理文件夹
    if (fs.statSync(fPath).isDirectory()) {
        //继续读每个子文件夹，json和png名字有相同的，只留json，
        var sonFiles = fs.readdirSync(fPath);
        //没有文件
        if (!sonFiles.length) return
        //取出所有json
        var jsons = sonFiles.filter((f) => { return f.substr(-5) == ".json" })
        sonFiles = sonFiles.filter((f) => { return jsons.indexOf(f.substring(0, f.length - 4) + ".json") == -1 })
        var group = {
            keys: "",
            name: file
        }
        for (var i = 0; i < sonFiles.length; i++) {
            if (i != 0) group.keys += ",";
            group.keys += sonFiles[i]
        }
        obj.groups.push(group)
    }
})
console.log("资源更新完成")
//生成json
fs.writeFileSync(readPath + "res.json", JSON.stringify(obj, "", "\t"));