Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement clean_cache() #2719

Merged
merged 3 commits into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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.

Loading