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

Fix 110 add rscignore #1049

Closed
Closed
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 @@ -18,6 +18,7 @@ export(add_module)
export(add_partial_html_template)
export(add_positconnect_file)
export(add_resource_path)
export(add_rscignore_file)
export(add_rstudioconnect_file)
export(add_sass_file)
export(add_shinyappsio_file)
Expand Down
81 changes: 74 additions & 7 deletions R/add_rstudio_files.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_rstudio_files <- function(
"Shiny Server",
"ShinyApps.io"
)
) {
) {
service <- match.arg(service)
where <- fs_path(pkg, "app.R")

Expand Down Expand Up @@ -55,27 +55,46 @@ add_rstudio_files <- function(
)
)

add_rscignore_file(pkg = pkg, open = open)

open_or_go_to(where, open)
} else {
file_already_there_dance(
cat_green_tick("The 'app.R'-file already exists.")
open_or_go_to(
where = where,
open_file = open
)
}
}

#' Add an app.R at the root of your package to deploy on RStudio Connect
#' Add an `app.R` at the root of your package to deploy on RStudio Connect
#'
#' Additionally, adds a `.rscignore` at the root of the `{golem}` project if the
#' `rsconnect` package version is `>= 0.8.25`.
#'
#' @note
#' In previous versions, this function was called add_rconnect_file and add_rstudioconnect_file.
#' @section List of excluded files in `.rscignore`:
#' * .here
#' * CODE_OF_CONDUCT.md
#' * LICENSE\{.md\}
#' * LICENCE\{.md\}
#' * NEWS\{.md\}
#' * README\{.md,.Rmd,.HTML\}
#' * dev
#' * man
#' * tests
#' * vignettes
#'
#'
#' @inheritParams add_module
#' @aliases add_rconnect_file add_rstudioconnect_file add_positconnect_file
#' @export
#'
#' @rdname rstudio_deploy
#'
#' @return The path to the file, invisibly.
#' @return Side-effect functions for file creation returning the path to the
#' file, invisibly.
#'
#' @examples
#' # Add a file for Connect
Expand All @@ -93,7 +112,7 @@ add_rstudio_files <- function(
add_positconnect_file <- function(
pkg = get_golem_wd(),
open = TRUE
) {
) {
add_rstudio_files(
pkg = pkg,
open = open,
Expand All @@ -116,7 +135,7 @@ add_rstudioconnect_file <- function(pkg = get_golem_wd(),
add_shinyappsio_file <- function(
pkg = get_golem_wd(),
open = TRUE
) {
) {
add_rstudio_files(
pkg = pkg,
open = open,
Expand All @@ -129,10 +148,58 @@ add_shinyappsio_file <- function(
add_shinyserver_file <- function(
pkg = get_golem_wd(),
open = TRUE
) {
) {
add_rstudio_files(
pkg = pkg,
open = open,
service = "Shiny Server"
)
}
#' @inheritParams add_module
#' @rdname rstudio_deploy
#' @export
add_rscignore_file <- function(pkg = get_golem_wd(), open = TRUE) {
min_rsc <- "0.8.25"
check_min_rsc <- rlang::is_installed("rsconnect", version = min_rsc)
if (isFALSE(check_min_rsc)) {
cat_red_bullet(
sprintf(
"Not creating '.rscignore'. Required 'rsconnect' version >= %s!",
min_rsc
)
)
return(invisible(pkg))
}

where <- fs_path(pkg, ".rscignore")
if (isTRUE(fs_file_exists(where))) {
cat_green_tick("The '.rscignore'-file already exists.")
open_or_go_to(
where = where,
open_file = open
)
return(invisible(pkg))
}
list_exclusion_defaults <- c(
".here",
"CODE_OF_CONDUCT.md",
"LICENSE",
"LICENCE",
"LICENSE.md",
"LICENCE.md",
"NEWS",
"NEWS.md",
"README.md",
"README.Rmd",
"README.HTML",
"dev",
"man",
"vignettes",
"tests"
)
writeLines(text = list_exclusion_defaults, con = where)
usethis_use_build_ignore(".rscignore")

cat_created(where)
return(invisible(pkg))
}
27 changes: 24 additions & 3 deletions man/rstudio_deploy.Rd

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

30 changes: 29 additions & 1 deletion tests/testthat/test-add_deploy_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,39 @@ test_that("add_rstudio_files", {
expect_exists("app.R")
test <- stringr::str_detect(
output,
"ile created at .*/app.R"
"File created at .*/app.R"
)
expect_true(test)
}
)
}
})
})

test_that("add_rscignore_file", {
with_dir(pkg, {
burn_after_reading(
".rscignore",
{
withr::with_options(
c("golem.quiet" = FALSE),
{
output <- testthat::capture_output(
add_rscignore_file(
pkg = pkg,
open = FALSE
)
)
}
)
expect_exists(".rscignore")
test <- stringr::str_detect(
output,
"File created at .*/.rscignore"
)
expect_true(test)
}
)
}
)
})