@@ -26,29 +26,7 @@ export default async function compileResourcePack(options: {
2626 lastUsedExportNamespace ,
2727 options . resourcePackFolder
2828 )
29- if ( aj . resource_pack_export_mode === 'raw' ) {
30- ajmeta . read ( )
31-
32- PROGRESS_DESCRIPTION . set ( 'Removing Old Resource Pack Files...' )
33- PROGRESS . set ( 0 )
34- MAX_PROGRESS . set ( ajmeta . oldFiles . size )
35-
36- const removedFolders = new Set < string > ( )
37- for ( const file of ajmeta . oldFiles ) {
38- if ( fs . existsSync ( file ) ) await fs . promises . unlink ( file )
39- let folder = PathModule . dirname ( file )
40- while (
41- ! removedFolders . has ( folder ) &&
42- fs . existsSync ( folder ) &&
43- ( await fs . promises . readdir ( folder ) ) . length === 0
44- ) {
45- await fs . promises . rm ( folder , { recursive : true } )
46- removedFolders . add ( folder )
47- folder = PathModule . dirname ( folder )
48- }
49- PROGRESS . set ( PROGRESS . get ( ) + 1 )
50- }
51- }
29+ ajmeta . read ( )
5230
5331 const exportedFiles = new Map < string , string | Buffer > ( )
5432
@@ -65,6 +43,7 @@ export default async function compileResourcePack(options: {
6543 'assets/minecraft/atlases/blocks.json'
6644 )
6745 let blockAtlas : ITextureAtlas = { sources : [ ] }
46+ console . log ( 'Block atlas file:' , blockAtlasFile , fs . existsSync ( blockAtlasFile ) )
6847 if ( fs . existsSync ( blockAtlasFile ) ) {
6948 const content = await fs . promises . readFile ( blockAtlasFile , 'utf-8' ) . catch ( ( ) => {
7049 throw new IntentionalExportError (
@@ -78,6 +57,9 @@ export default async function compileResourcePack(options: {
7857 `Failed to parse block atlas file: ${ e . message as string } `
7958 )
8059 }
60+ console . log ( 'Pre-existing Block atlas:' , blockAtlas )
61+ } else {
62+ console . log ( 'Block atlas file does not exist. Creating a new one.' )
8163 }
8264 if (
8365 blockAtlas . sources . some (
@@ -95,6 +77,7 @@ export default async function compileResourcePack(options: {
9577 prefix : 'blueprint/' ,
9678 } )
9779 }
80+ console . log ( 'Block atlas:' , blockAtlas )
9881 exportedFiles . set ( blockAtlasFile , autoStringify ( blockAtlas ) )
9982
10083 // Internal Models
@@ -180,6 +163,28 @@ export default async function compileResourcePack(options: {
180163 // Do nothing
181164 console . log ( 'Plugin mode enabled. Skipping resource pack export.' )
182165 } else if ( aj . resource_pack_export_mode === 'raw' ) {
166+ // Clean up old files
167+ PROGRESS_DESCRIPTION . set ( 'Removing Old Resource Pack Files...' )
168+ PROGRESS . set ( 0 )
169+ MAX_PROGRESS . set ( ajmeta . oldFiles . size )
170+
171+ const removedFolders = new Set < string > ( )
172+ for ( const file of ajmeta . oldFiles ) {
173+ if ( fs . existsSync ( file ) ) await fs . promises . unlink ( file )
174+ let folder = PathModule . dirname ( file )
175+ while (
176+ ! removedFolders . has ( folder ) &&
177+ fs . existsSync ( folder ) &&
178+ ( await fs . promises . readdir ( folder ) ) . length === 0
179+ ) {
180+ await fs . promises . rm ( folder , { recursive : true } )
181+ removedFolders . add ( folder )
182+ folder = PathModule . dirname ( folder )
183+ }
184+ PROGRESS . set ( PROGRESS . get ( ) + 1 )
185+ }
186+
187+ // Write new files
183188 ajmeta . files = new Set ( exportedFiles . keys ( ) )
184189 ajmeta . write ( )
185190
0 commit comments