Skip to content

Commit

Permalink
Implement clean_cache()
Browse files Browse the repository at this point in the history
Closes #2718
  • Loading branch information
jayhesselberth committed Jul 13, 2024
1 parent 1407329 commit ae36cba
Show file tree
Hide file tree
Showing 3 changed files with 32 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
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")

Check warning on line 40 in R/clean.R

View check run for this annotation

Codecov / codecov/patch

R/clean.R#L39-L40

Added lines #L39 - L40 were not covered by tests

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

Check warning on line 46 in R/clean.R

View check run for this annotation

Codecov / codecov/patch

R/clean.R#L42-L46

Added lines #L42 - L46 were not covered by tests
}

dir_delete(cache_path)

Check warning on line 49 in R/clean.R

View check run for this annotation

Codecov / codecov/patch

R/clean.R#L49

Added line #L49 was not covered by tests
}

invisible(TRUE)

Check warning on line 52 in R/clean.R

View check run for this annotation

Codecov / codecov/patch

R/clean.R#L52

Added line #L52 was not covered by tests
}

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 ae36cba

Please sign in to comment.