diff --git a/project.hxp b/project.hxp index 4904e15a4..1deec5c75 100644 --- a/project.hxp +++ b/project.hxp @@ -1228,6 +1228,9 @@ class Project extends HXProject function configureAssets() { + // Delete the assets folder from the export folder before adding anything. + clearAssets(); + var exclude = EXCLUDE_ASSETS.concat(isWeb() ? EXCLUDE_ASSETS_WEB : EXCLUDE_ASSETS_NATIVE); var shouldPreload = PRELOAD_ALL.isEnabled(this); var shouldEmbed = EMBED_ASSETS.isEnabled(this); @@ -1309,6 +1312,62 @@ class Project extends HXProject } } + function clearAssets():Void + { + var exportPath:Null = app.path ?? ""; + + // mac target uses `macos` for the export folder instead of `mac` + var platform:String = (!isMacHost() ? System.hostPlatform : 'macos'); + var basePath:String = Path.join([exportPath, platform, "bin"]); + var assetsPath:String = ""; + + if (isMacHost()) + { + assetsPath = Path.join([basePath, '${this.app.file}.app', "Contents", "Resources", "assets"]); + } + else + { + assetsPath = Path.join([basePath, "assets"]); + } + + if (sys.FileSystem.exists(assetsPath)) + { + info('Deleting assets folder from export folder ($assetsPath)'); + + // this is fucking shitty i know but you can't just delete the whole assets folder with `sys.FileSystem.deleteDirectory` + // this is because the assets folder is usually not empty.....deleting a folder that isn't empty throws an error i fucking hate lime......grrr...... + deleteDirectoryRecursive(assetsPath); + } + else + { + info('Assets folder does not exist ($assetsPath)'); + } + } + + /** + * Recursively delete a directory and its contents. + * @param path The path to the directory to delete. + */ + function deleteDirectoryRecursive(path:String):Void + { + if (!sys.FileSystem.exists(path)) return; + + for (file in sys.FileSystem.readDirectory(path)) + { + var fullPath:String = Path.join([path, file]); + if (sys.FileSystem.isDirectory(fullPath)) + { + deleteDirectoryRecursive(fullPath); + } + else + { + sys.FileSystem.deleteFile(fullPath); + } + } + + sys.FileSystem.deleteDirectory(path); + } + /** * Configure the application's favicon and executable icon. */ @@ -1378,12 +1437,16 @@ class Project extends HXProject { if (envConfig == null) return; - if (FEATURE_MOBILE_ADVERTISEMENTS.isEnabled(this)) { + if (FEATURE_MOBILE_ADVERTISEMENTS.isEnabled(this)) + { var appId:Null = Std.string(envConfig.get('ADMOB_APP_ID')); - if (appId != null && appId != "null") { + if (appId != null && appId != "null") + { setenv("ADMOB_APPID", appId); - } else { + } + else + { error("ADMOB_APP_ID is not defined in the environment. Populate the .env file in your project root or build with -DNO_FEATURE_MOBILE_ADVERTISEMENTS"); } } @@ -1763,8 +1826,7 @@ class Project extends HXProject { var commitHash:String = readLibraryGitCommitHash(libraryName); - if (commitHash != library.ref && commitHash != "") - outdatedLibraries.set(libraryName, [commitHash, library.ref]); + if (commitHash != library.ref && commitHash != "") outdatedLibraries.set(libraryName, [commitHash, library.ref]); } } } @@ -1796,8 +1858,7 @@ class Project extends HXProject { var path = haxe.io.Path.join([haxe.io.Path.addTrailingSlash(Sys.getCwd()), '.haxelib', libraryName, '.current']); - if (sys.FileSystem.exists(path)) - return sys.io.File.getContent(path); + if (sys.FileSystem.exists(path)) return sys.io.File.getContent(path); return ''; } @@ -1806,8 +1867,7 @@ class Project extends HXProject { var path = haxe.io.Path.join([haxe.io.Path.addTrailingSlash(Sys.getCwd()), '.haxelib', libraryName, '.dev']); - if (sys.FileSystem.exists(path)) - return sys.io.File.getContent(path); + if (sys.FileSystem.exists(path)) return sys.io.File.getContent(path); return ''; }