Files
chuanqi-client-config/tools/lua2json.js
Kubbo 3de79cc1fa refactor(ShopConfig): 移除 ShopConfig 中的冗余配置项
- 删除了 ShopConfig 中的多个冗余 shopid 配置项
- 优化了 ShopConfig 的结构,提高了配置的可读性和维护性
- 同时更新了 lua2json 工具的配置,以适应新的 ShopConfig 结构
2025-02-11 17:11:24 +08:00

39 lines
1.2 KiB
JavaScript

const { log } = require("console");
const fs = require("fs");
const path = require("path");
const { parse } = require("lua-json");
const folderPath = "./luaConfigs";
const scope = [
// "MergeTotal",
// "ActivitiesConf",
"ShopConfig"
].filter(Boolean);
const start = () => {
const files = fs.readdirSync(folderPath);
// 过滤出所有的 JSON 文件
const luaFiles = files.filter((file) => path.extname(file) === ".config").filter((file) => scope.map((e) => `${e}.config`).includes(file));
luaFiles.forEach((file) => {
const luaContent = fs.readFileSync(path.join(folderPath, file), "utf8");
const filename = path.basename(file, path.extname(file));
const content = luaContent.replace(filename, "").slice(1);
const luaConfig = parse(`return ${content}`);
for (const key in luaConfig) {
const item = luaConfig[key];
const arr = [];
Object.entries(item).forEach(([k, v]) => {
if (!isNaN(k) && typeof v === "object") {
arr.push(v);
}
});
if (arr.length > 0) {
luaConfig[key] = arr;
}
}
fs.writeFileSync(`./configs/${filename}.json`, JSON.stringify(luaConfig, "utf-8"));
});
};
start();