Skip to content

Commit

Permalink
feat(wip): sepuku ready
Browse files Browse the repository at this point in the history
doc to be made
one test failing in non interactive
#257
  • Loading branch information
ymansiaux committed Jun 6, 2024
1 parent 7fe214f commit c4eaf83
Show file tree
Hide file tree
Showing 6 changed files with 538 additions and 111 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export(list_flat_files)
export(load_flat_functions)
export(register_all_to_config)
export(rename_flat_file)
export(sepuku)
importFrom(attachment,att_amend_desc)
importFrom(cli,cat_rule)
importFrom(cli,cli_alert_danger)
Expand Down
101 changes: 101 additions & 0 deletions R/sepuku.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# WARNING - Generated by {fusen} from dev/flat_sepuku.Rmd: do not edit by hand

#' sepuku Title
#'
#' @return 1
#' @export
#'
#' @examples
#' sepuku()
sepuku <- function(
pkg = ".",
force = FALSE) {
if (!dir.exists(file.path(pkg, "dev"))) {
cli::cli_abort("No dev/ folder have been found. Are you sure that your package has been initiated with fusen ?")
}

config_file <- getOption("fusen.config_file", default = "dev/config_fusen.yaml")

if (!file.exists(config_file)) {
cli::cli_alert_info("No fusen configuration file found. The flat files to be deleted will be identified as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders.")
} else {
cli::cli_alert_info("A fusen configuration file was found. The flat files to be deleted will be identified as files listed in this configuration file as well as rmd or qmd files starting with 'flat' in the dev/ and dev/flat_history folders. The configuration file will also be deleted.")
}

flat_files <- list_flat_files(pkg = pkg)

if (length(flat_files) == 0) {
cli::cli_alert_info("No flat files were detected.")
} else {
cli::cli_alert_info(
paste0(
"The following flat files were detected and will therefore be deleted from your package:\n",
paste0(flat_files, collapse = "\n")
)
)
}

files_to_be_modified <- find_files_with_fusen_tags(pkg = pkg)
if (length(files_to_be_modified) == 0) {
cli::cli_alert_info("No fusen-related tags have been found in any files located in R/, tests/ and vignettes/ folders.")
} else {
cli::cli_alert_info(
paste0(
"The following files have been identified as containing fusen-related tags and will therefore be modified:\n",
paste0(files_to_be_modified, collapse = "\n")
)
)
}

if (length(flat_files) == 0 && length(files_to_be_modified) == 0) {
return(invisible(NULL))
}

do_it <- force

if (!force) {
cli::cli_alert_danger("Some files are about to be deleted or modified. This operation is irreversible.")
sure <- paste(
"\nAre you sure of what you are doing? (y/n)\n"
)
clean <- readline(sure) == "y" || readline(sure) == "yes"
if (isTRUE(clean) || clean == "yes") {
do_it <- TRUE
} else if (isFALSE(clean) || clean == "no") {
do_it <- FALSE
} else {
stop("clean should be TRUE, FALSE, 'yes'or 'no'")
}
}

if (isTRUE(do_it)) {
if (length(flat_files) > 0) {
invisible(
lapply(
flat_files,
function(f) {
file.remove(file.path(pkg, f))
}
)
)
}

if (length(files_to_be_modified) > 0) {
invisible(
lapply(
files_to_be_modified,
function(f) {
clean_fusen_tags_in_files(pkg = pkg, files_to_clean = f)
}
)
)
}
if (file.exists(config_file)) {
file.remove(config_file)
}
}

cli::cli_alert_info("Cleaning is done !")

return(invisible(TRUE))
}
14 changes: 14 additions & 0 deletions dev/config_fusen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ flat_register_config_file.Rmd:
document: true
overwrite: 'yes'
clean: ask
flat_sepuku.Rmd:
path: dev/flat_sepuku.Rmd
state: active
R: R/sepuku.R
tests: tests/testthat/test-sepuku.R
vignettes: []
inflate:
flat_file: dev/flat_sepuku.Rmd
vignette_name: .na
open_vignette: false
check: false
document: true
overwrite: 'yes'
clean: ask
flat_sepuku-utils.Rmd:
path: dev/flat_sepuku-utils.Rmd
state: active
Expand Down
Loading

0 comments on commit c4eaf83

Please sign in to comment.