From 7513ea83a3c9397a89a0fc9934175d10c2b48c41 Mon Sep 17 00:00:00 2001 From: Jay Hesselberth Date: Fri, 29 Nov 2024 13:19:14 -0700 Subject: [PATCH] Provide a way to force site cleaning Fixes #2699 --- R/clean.R | 7 ++++--- man/clean.Rd | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/R/clean.R b/R/clean.R index b8472fb34..6ed83b5b8 100644 --- a/R/clean.R +++ b/R/clean.R @@ -3,10 +3,11 @@ #' Delete all files in `docs/` (except for `CNAME`). #' #' @param quiet If `TRUE`, suppresses a message. +#' @param force If `TRUE`, delete contents of `docs` even if it is not a pkgdown site. #' @inheritParams build_site #' @rdname clean #' @export -clean_site <- function(pkg = ".", quiet = FALSE) { +clean_site <- function(pkg = ".", quiet = FALSE, force = FALSE) { pkg <- as_pkgdown(pkg) @@ -17,7 +18,7 @@ clean_site <- function(pkg = ".", quiet = FALSE) { if (!dir_exists(pkg$dst_path)) return(invisible()) top_level <- dest_files(pkg) - if (length(top_level) > 0) { + if (length(top_level) > 0 && !force) { check_dest_is_pkgdown(pkg) } @@ -60,7 +61,7 @@ check_dest_is_pkgdown <- function(pkg) { cli::cli_abort(c( "{.file {pkg$dst_path}} is non-empty and not built by pkgdown", "!" = "Make sure it contains no important information \\ - and use {.run pkgdown::clean_site()} to delete its contents." + and use {.run pkgdown::clean_site(force = TRUE)} to delete its contents." ) ) } diff --git a/man/clean.Rd b/man/clean.Rd index b6d8b0710..43572143a 100644 --- a/man/clean.Rd +++ b/man/clean.Rd @@ -5,7 +5,7 @@ \alias{clean_cache} \title{Clean site} \usage{ -clean_site(pkg = ".", quiet = FALSE) +clean_site(pkg = ".", quiet = FALSE, force = FALSE) clean_cache(pkg = ".", quiet = FALSE) } @@ -13,6 +13,8 @@ clean_cache(pkg = ".", quiet = FALSE) \item{pkg}{Path to package.} \item{quiet}{If \code{TRUE}, suppresses a message.} + +\item{force}{If \code{TRUE}, delete contents of \code{docs} even if it is not a pkgdown site.} } \description{ Delete all files in \verb{docs/} (except for \code{CNAME}).