1- import { fs } from '../constants'
1+ import { getFsModule } from '../constants'
22import { isFunctionTagPath } from '../util/fileUtil'
33import { type FunctionTagJSON , parseDataPackPath } from '../util/minecraftUtil'
44import { getExportPaths } from './exporter'
@@ -14,6 +14,8 @@ export async function cleanupExportedFiles() {
1414 // modelExportFolder,
1515 // displayItemPath,
1616 } = getExportPaths ( )
17+ const { existsSync, promises } = getFsModule ( )
18+ const { unlink, mkdir, copyFile, readFile, writeFile, readdir, rm } = promises
1719
1820 if ( aj . resource_pack_export_mode === 'folder' ) {
1921 const assetsMetaPath = PathModule . join ( resourcePackFolder , 'assets.ajmeta' )
@@ -31,32 +33,32 @@ export async function cleanupExportedFiles() {
3133 const removedFolders = new Set < string > ( )
3234 for ( const file of assetsMeta . previousVersionedFiles ) {
3335 if ( ! isFunctionTagPath ( file ) ) {
34- if ( fs . existsSync ( file ) ) await fs . promises . unlink ( file )
36+ if ( existsSync ( file ) ) await unlink ( file )
3537 } else if ( aj . blueprint_id !== Project ! . last_used_blueprint_id ) {
3638 const resourceLocation = parseDataPackPath ( file ) ! . resourceLocation
3739 if (
3840 resourceLocation . startsWith (
3941 `animated_java:${ Project ! . last_used_blueprint_id } /`
4042 ) &&
41- fs . existsSync ( file )
43+ existsSync ( file )
4244 ) {
4345 const newPath = replacePathPart (
4446 file ,
4547 Project ! . last_used_blueprint_id ,
4648 aj . blueprint_id
4749 )
48- await fs . promises . mkdir ( PathModule . dirname ( newPath ) , { recursive : true } )
49- await fs . promises . copyFile ( file , newPath )
50- await fs . promises . unlink ( file )
50+ await mkdir ( PathModule . dirname ( newPath ) , { recursive : true } )
51+ await copyFile ( file , newPath )
52+ await unlink ( file )
5153 }
5254 }
5355 let folder = PathModule . dirname ( file )
5456 while (
5557 ! removedFolders . has ( folder ) &&
56- fs . existsSync ( folder ) &&
57- ( await fs . promises . readdir ( folder ) ) . length === 0
58+ existsSync ( folder ) &&
59+ ( await readdir ( folder ) ) . length === 0
5860 ) {
59- await fs . promises . rm ( folder , { recursive : true } )
61+ await rm ( folder , { recursive : true } )
6062 removedFolders . add ( folder )
6163 folder = PathModule . dirname ( folder )
6264 if ( PathModule . basename ( folder ) === 'assets' ) break
@@ -82,7 +84,7 @@ export async function cleanupExportedFiles() {
8284 // MAX_PROGRESS.set(dataMeta.oldFiles.size)
8385 const removedFolders = new Set < string > ( )
8486 for ( const file of [ ...dataMeta . previousCoreFiles , ...dataMeta . previousVersionedFiles ] ) {
85- if ( isFunctionTagPath ( file ) && fs . existsSync ( file ) ) {
87+ if ( isFunctionTagPath ( file ) && existsSync ( file ) ) {
8688 if ( aj . blueprint_id !== Project ! . last_used_blueprint_id ) {
8789 const resourceLocation = parseDataPackPath ( file ) ! . resourceLocation
8890 if (
@@ -95,33 +97,31 @@ export async function cleanupExportedFiles() {
9597 Project ! . last_used_blueprint_id ,
9698 aj . blueprint_id
9799 )
98- await fs . promises . mkdir ( PathModule . dirname ( newPath ) , { recursive : true } )
99- await fs . promises . copyFile ( file , newPath )
100- await fs . promises . unlink ( file )
100+ await mkdir ( PathModule . dirname ( newPath ) , { recursive : true } )
101+ await copyFile ( file , newPath )
102+ await unlink ( file )
101103 }
102104 }
103105 // Remove mentions of the export namespace from the file
104- const content : FunctionTagJSON = JSON . parse (
105- ( await fs . promises . readFile ( file ) ) . toString ( )
106- )
106+ const content : FunctionTagJSON = JSON . parse ( ( await readFile ( file ) ) . toString ( ) )
107107 content . values = content . values . filter (
108108 v =>
109109 typeof v === 'string' &&
110110 ( ! v . startsWith ( `animated_java:${ aj . blueprint_id } /` ) ||
111111 ! v . startsWith ( `animated_java:${ Project ! . last_used_blueprint_id } /` ) )
112112 )
113- await fs . promises . writeFile ( file , autoStringify ( content ) )
113+ await writeFile ( file , autoStringify ( content ) )
114114 } else {
115115 // Delete the file
116- if ( fs . existsSync ( file ) ) await fs . promises . unlink ( file )
116+ if ( existsSync ( file ) ) await unlink ( file )
117117 }
118118 let folder = PathModule . dirname ( file )
119119 while (
120120 ! removedFolders . has ( folder ) &&
121- fs . existsSync ( folder ) &&
122- ( await fs . promises . readdir ( folder ) ) . length === 0
121+ existsSync ( folder ) &&
122+ ( await readdir ( folder ) ) . length === 0
123123 ) {
124- await fs . promises . rm ( folder , { recursive : true } )
124+ await rm ( folder , { recursive : true } )
125125 removedFolders . add ( folder )
126126 folder = PathModule . dirname ( folder )
127127 if ( PathModule . basename ( folder ) === 'data' ) break
0 commit comments