Skip to content

Commit

Permalink
Implement clean_cache() (#2719)
Browse files Browse the repository at this point in the history
Closes #2718
  • Loading branch information
jayhesselberth authored Jul 14, 2024
1 parent 89c9e51 commit 9779d28
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export(build_site)
export(build_site_github_pages)
export(build_tutorials)
export(check_pkgdown)
export(clean_cache)
export(clean_site)
export(data_template)
export(deploy_site_github)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# pkgdown (development version)

* New `clean_cache()` function removes the contents of the cache directory (#2718).
* pkgdown now depends on R >= 4.0.0 (#2714)

# pkgdown 2.1.0
Expand Down
27 changes: 26 additions & 1 deletion R/clean.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#'
#' @param quiet If `TRUE`, suppresses a message.
#' @inheritParams build_site
#' @rdname clean
#' @export
clean_site <- function(pkg = ".", quiet = FALSE) {

Expand All @@ -27,6 +28,30 @@ clean_site <- function(pkg = ".", quiet = FALSE) {
invisible(TRUE)
}

#' Clean cache
#'
#' Delete all files in the pkgdown cache directory.
#'
#' @rdname clean
#' @export
clean_cache <- function(pkg = ".", quiet = FALSE) {

pkg <- as_pkgdown(pkg)
cache_path <- tools::R_user_dir("pkgdown", "cache")

if (dir_exists(cache_path)) {
if (!quiet) {
cli::cli_inform(
"Cleaning {.pkg {pkg$package}} cache files from {.path {cache_path}}"
)
}

dir_delete(cache_path)
}

invisible(TRUE)
}

check_dest_is_pkgdown <- function(pkg) {
if (file_exists(path(pkg$dst_path, "pkgdown.yml"))) {
return()
Expand All @@ -45,6 +70,6 @@ dest_files <- function(pkg) {
character()
} else {
top_level <- dir_ls(pkg$dst_path)
top_level[!path_file(top_level) %in% c("CNAME", "dev")]
top_level[!path_file(top_level) %in% c("CNAME", "dev")]
}
}
5 changes: 5 additions & 0 deletions man/clean_site.Rd → man/clean.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9779d28

Please sign in to comment.