console.log("正在监听 en-US.json 文件的变化");
const fs = require("fs");
const enUSPath = "./src/locales/en-US.json";
const zhCNPath = "./src/locales/zh-CN.json";
fs.watchFile(enUSPath, (curr, prev) => {
fs.readFile(enUSPath, "utf-8", (err, data) => {
if (err) {
console.error(err);
return;
}
const enUS = JSON.parse(data);
const zhCN = {};
for (const key in enUS) {
zhCN[key] = key;
}
fs.writeFile(zhCNPath, JSON.stringify(zhCN, null, 2), "utf-8", (err) => {
if (err) {
console.error(err);
return;
}
console.log("zh-CN.json 同步成功");
});
});
});