Skip to content

Commit a788773

Browse files
author
Clean Bot
committed
Fix: 1) Chinese encoding in plugins.json 2) Include all plugin folder contents in zip
1 parent 60fd467 commit a788773

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

src/plugins/generate-api.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ async function generatePluginsAPI() {
6060
fs.mkdirSync(outputApiDir, { recursive: true });
6161
}
6262

63-
fs.writeFileSync(outputFile, JSON.stringify(plugins, null, 2));
63+
// 自定义 JSON 序列化,保持中文字符不转义
64+
const jsonStr = JSON.stringify(plugins, null, 2);
65+
// 将 Unicode 转义序列还原为中文
66+
const chineseJson = jsonStr.replace(/\\u([0-9a-fA-F]{4})/g, (match, hex) => String.fromCharCode(parseInt(hex, 16)));
67+
fs.writeFileSync(outputFile, chineseJson);
6468
console.log(`插件 API 已生成: ${outputFile}`);
6569
console.log(`共 ${plugins.length} 个插件`);
6670
} catch (error) {

src/plugins/generate-zip.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,25 @@ const __dirname = path.dirname(__filename);
1111
const sourcePluginsDir = path.join(__dirname, '..', '..', 'main', 'plugins');
1212
const outputPluginsDir = path.join(__dirname, '..', '..', 'dist', 'plugins');
1313

14+
// 递归添加文件夹内容到 zip
15+
function addFolderToZip(zip, folderPath, zipPath = '') {
16+
const items = fs.readdirSync(folderPath);
17+
18+
for (const item of items) {
19+
const fullPath = path.join(folderPath, item);
20+
const relativePath = zipPath ? `${zipPath}/${item}` : item;
21+
const stat = fs.statSync(fullPath);
22+
23+
if (stat.isDirectory()) {
24+
// 递归处理子文件夹
25+
addFolderToZip(zip, fullPath, relativePath);
26+
} else {
27+
// 添加文件到 zip
28+
zip.file(relativePath, fs.readFileSync(fullPath));
29+
}
30+
}
31+
}
32+
1433
async function generatePluginsZip() {
1534
try {
1635
// 动态获取插件文件夹列表
@@ -36,15 +55,16 @@ async function generatePluginsZip() {
3655
}
3756

3857
const zip = new JSZip();
39-
zip.file('main.java', fs.readFileSync(mainJavaPath));
40-
zip.file('info.prop', fs.readFileSync(infoPropPath));
58+
59+
// 递归添加插件文件夹内的所有内容
60+
addFolderToZip(zip, pluginDir);
4161

4262
const content = await zip.generateAsync({ type: 'nodebuffer' });
4363
fs.writeFileSync(zipPath, content);
4464

4565
console.log(`已生成: ${folder}.zip`);
4666
} else {
47-
console.warn(`插件 ${folder} 缺少文件`);
67+
console.warn(`插件 ${folder} 缺少必要文件 (main.java 或 info.prop)`);
4868
}
4969
}
5070

0 commit comments

Comments
 (0)