@@ -11,6 +11,25 @@ const __dirname = path.dirname(__filename);
1111const sourcePluginsDir = path . join ( __dirname , '..' , '..' , 'main' , 'plugins' ) ;
1212const 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+
1433async 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