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

feat: create_golem no longer calls usethis::create_project #1177

Merged
merged 6 commits into from
Sep 6, 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
3 changes: 1 addition & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: golem
Title: A Framework for Robust Shiny Applications
Version: 0.5.1.9003
Version: 0.5.1.9004
Authors@R: c(
person("Colin", "Fay", , "[email protected]", role = c("cre", "aut"),
comment = c(ORCID = "0000-0001-7343-1846")),
Expand Down Expand Up @@ -68,7 +68,6 @@ Suggests:
VignetteBuilder:
knitr
Config/testthat/edition: 3
Config/testthat/parallel: true
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE)
Expand Down
8 changes: 7 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@

## Breaking change

- Creating a `golem` doesn't use `set_here()` anymore. `here::here()` should be able to find its way based using `DESCRIPTION`.
- Creating a `golem` doesn't call `set_here()` nor `usethis::create_project()` anymore. It used to be because we wanted to be able to use `here::here()`, but the function should be able to find its way based using `DESCRIPTION`. It gives a lighter implementation of golem projects creation as it doesn't mess up with where `here()` is anymore.

- The `add_*_files` and `use_*_files` now fail when:
- The directory where the user tries to add the file doesn't exist. `{golem}` used to try to create the directory but that's not the function job — use_*_file functions should only be there to add file (Singe responsabily )
- The file that the user tries to create already exists

- Creating a golem with `create_golem(overwrite = TRUE)` will now __delete the old folder__ and replace with the golem skeleton.

## Bug fix

- Removing the comments on golem creation didn't work fully, this has been fixed.

## Internal changes

- Full refactoring of the `add_*_files` and `use_*_files` functions that now all share the same behavior
Expand Down
6 changes: 5 additions & 1 deletion R/boostrap_fs.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,16 @@ fs_dir_create <- function(
)
}


fs_file_create <- function(where) {
check_fs_installed()
fs::file_create(where)
}

fs_dir_delete <- function(path) {
check_fs_installed()
fs::dir_delete(path)
}

fs_file_delete <- function(path) {
check_fs_installed()
fs::file_delete(path)
Expand Down
26 changes: 0 additions & 26 deletions R/bootstrap_usethis.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,32 +35,6 @@ usethis_use_package <- function(
)
}

usethis_create_project <- function(
path,
rstudio = rstudioapi::isAvailable(), # rstudioap is usethis Imports, so its ok
open = rlang::is_interactive()
) {
check_usethis_installed(
reason = "to create a project."
)
usethis::create_project(
path,
rstudio,
open
)
}
usethis_use_latest_dependencies <- function(
overwrite = FALSE,
source = c("local", "CRAN")
) {
check_usethis_installed(
reason = "to set dependency version."
)
usethis::use_latest_dependencies(
overwrite,
source
)
}

usethis_proj_set <- function(
path = ".",
Expand Down
34 changes: 8 additions & 26 deletions R/create_golem.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ copy_golem_skeleton_and_replace_name <- function(
#' @param check_name Should we check that the package name is
#' correct according to CRAN requirements.
#' @param open Boolean. Open the created project?
#' @param overwrite Boolean. Should the already existing project be overwritten ?
#' @param overwrite Boolean. Should the already existing project be deleted and replaced?
#' @param package_name Package name to use. By default, `{golem}` uses
#' `basename(path)`. If `path == '.'` & `package_name` is
#' not explicitly set, then `basename(getwd())` will be used.
Expand Down Expand Up @@ -124,23 +124,17 @@ create_golem <- function(
if (!isTRUE(overwrite)) {
stop(
paste(
"Project directory already exists. \n",
"Set `create_golem(overwrite = TRUE)` to overwrite anyway.\n",
"Be careful this will restore a brand new golem. \n",
"You might be at risk of losing your work !"
"The directory already exists.\n",
"Set `create_golem(overwrite = TRUE)` to delete and replace.\n",
"Be careful this will delete the old folder.\n",
"You might be at risk of losing your work!"
),
call. = FALSE
)
} else {
cat_red_bullet("Overwriting existing project.")
cat_green_tick("Deleting existing project.")
fs_dir_delete(path_to_golem)
}
} else {
cli_cat_rule("Creating dir")
usethis_create_project(
path = path_to_golem,
open = FALSE
)
cat_green_tick("Created package directory")
}

copy_golem_skeleton_and_replace_name(
Expand Down Expand Up @@ -182,7 +176,6 @@ create_golem <- function(
}
}


if (isTRUE(with_git)) {
cli_cat_rule("Initializing git repository")
git_output <- system(
Expand All @@ -191,22 +184,12 @@ create_golem <- function(
ignore.stderr = TRUE
)
if (git_output) {
cat_red_bullet("Error initializing git epository")
cat_red_bullet("Error initializing git repository")
} else {
cat_green_tick("Initialized git repository")
}
}

# lets not use latest deps for now

# old <- setwd(path_to_golem)

# if (!requireNamespace("desc", quietly = TRUE)) {
# check_desc_installed()
# } # incase of {desc} not installed by {usethis}

# usethis_use_latest_dependencies()

setwd(old)

cli_cat_rule("Done")
Expand All @@ -224,7 +207,6 @@ create_golem <- function(

check_dev_deps_are_installed()


if (isTRUE(open)) {
if (
rlang::is_installed("rstudioapi") &&
Expand Down
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ remove_comments <- function(file) {
lines_without_comment <- append(
lines_without_comment,
gsub(
"(\\s*#+[^'@].*$| #+[^#].*$)",
"(\\s*#+[^'@].*$| #+[^#].*$|^#+$)",
"",
line
)
Expand Down
2 changes: 1 addition & 1 deletion man/create_golem.Rd

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

142 changes: 11 additions & 131 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,37 +112,24 @@ expect_exists <- function(fls) {
}

create_dummy_golem <- function() {
# we're using this fun to do a
# minimal reprex of a golem
# without having to go through the
# create_golem() function
path_to_golem <- file.path(
tempdir(),
"dummygolem"
)
if (dir.exists(path_to_golem)) {
unlink(path_to_golem, recursive = TRUE, force = TRUE)
}
dir.create(
path_to_golem,
recursive = TRUE
)
file.copy(
golem_sys(
"shinyexample/DESCRIPTION"
),
file.path(
path_to_golem,
"DESCRIPTION"
)
)
dir.create(
file.path(
path_to_golem,
"R"
),
recursive = TRUE
withr::with_options(
c("usethis.quiet" = TRUE),
{
create_golem(
path_to_golem,
open = FALSE,
package_name = "shinyexample"
)
}
)

dir.create(
file.path(
path_to_golem,
Expand Down Expand Up @@ -174,114 +161,7 @@ test_check(\"shinyexample\")",
"tests/testthat.R"
)
)
dir.create(
file.path(
path_to_golem,
"dev"
),
recursive = TRUE
)
file.copy(
golem_sys(
"shinyexample/dev/01_start.R"
),
file.path(
path_to_golem,
"dev/01_start.R"
)
)
file.copy(
golem_sys(
"shinyexample/dev/02_dev.R"
),
file.path(
path_to_golem,
"dev/02_dev.R"
)
)
file.copy(
golem_sys(
"shinyexample/dev/03_deploy.R"
),
file.path(
path_to_golem,
"dev/03_deploy.R"
)
)
file.copy(
golem_sys(
"shinyexample/dev/run_dev.R"
),
file.path(
path_to_golem,
"dev/run_dev.R"
)
)
dir.create(
file.path(
path_to_golem,
"inst/app/www/"
),
recursive = TRUE
)
file.create(
file.path(
path_to_golem,
"inst/app/www/favicon.ico"
)
)
file.copy(
golem_sys(
"shinyexample/inst/golem-config.yml"
),
file.path(
path_to_golem,
"inst/golem-config.yml"
)
)
file.copy(
golem_sys(
"shinyexample/R/app_config.R"
),
file.path(
path_to_golem,
"R/app_config.R"
)
)
file.copy(
golem_sys(
"shinyexample/R/app_ui.R"
),
file.path(
path_to_golem,
"R/app_ui.R"
)
)
file.copy(
golem_sys(
"shinyexample/R/app_server.R"
),
file.path(
path_to_golem,
"R/app_server.R"
)
)
file.copy(
golem_sys(
"shinyexample/R/run_app.R"
),
file.path(
path_to_golem,
"R/run_app.R"
)
)
dir.create(
file.path(
path_to_golem,
"man"
),
recursive = TRUE
)

dir.create(
file.path(
path_to_golem,
Expand Down
Loading
Loading