-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #87
- Loading branch information
Showing
7 changed files
with
160 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#' Create a quarto project | ||
#' | ||
#' This function calls `quarto create project <type> <name>`. It will create a | ||
#' new directory with the project name and add some skeletons files for the | ||
#' project type chosen. | ||
#' | ||
#' # Quarto version required | ||
#' | ||
#' This function require Quarto 1.4 or higher. Use [`quarto_version()`]to check | ||
#' the version of Quarto detected. | ||
#' | ||
#' @param type The type of project to create. As of 1.4, it can be one of | ||
#' `r paste0("\\code{", paste(quarto_project_type, collapse = "}, \\code{"),"}")`. | ||
#' @param name The name of the project and the directory that will be created. | ||
#' @param dir The directory where to create the new Quarto project. | ||
#' | ||
#' @seealso Quarto documentation on [Quarto projects](https://quarto.org/docs/projects/quarto-projects.html) | ||
#' | ||
#' @inheritParams quarto_render | ||
quarto_create_project <- function(name, type = "default", dir = ".", no_prompt = FALSE, quiet = FALSE, quarto_args = NULL) { | ||
|
||
check_quarto_version("1.4", "quarto create project", "https://quarto.org/docs/projects/quarto-projects.html") | ||
|
||
if (rlang::is_missing(name)) { | ||
cli::cli_abort("You need to provide {.arg name} for the new project.") | ||
} | ||
|
||
if (rlang::is_interactive() && !no_prompt) { | ||
cli::cli_inform(c( | ||
"This will create a new Quarto {.emph {type}} project as a folder named {.strong {name}} in {.path {xfun::normalize_path(dir)}}." | ||
)) | ||
prompt_value <- tolower(readline(sprintf("Do you want to proceed (Y/n)? "))) | ||
if (!prompt_value %in% "y") { | ||
cli::cli_abort("Operation aborted.") | ||
} | ||
} | ||
|
||
quarto_bin <- find_quarto() | ||
|
||
args <- c("project", type, name, "--no-prompt", "--no-open", if (quiet) cli_arg_quiet(), quarto_args = NULL) | ||
|
||
owd <- setwd(dir) | ||
on.exit(setwd(owd), add = TRUE, after = FALSE) | ||
quarto_create(args, quarto_bin = quarto_bin, echo = TRUE) | ||
|
||
} | ||
|
||
quarto_create <- function(args = character(), ...) { | ||
quarto_run_what("create", args = args, ...) | ||
} | ||
|
||
|
||
# This list is for 1.4 | ||
quarto_project_type <- c( | ||
"default", | ||
"website", | ||
"blog", | ||
"book", | ||
"manuscript", | ||
"confluence" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# create project only available for 1.4 | ||
|
||
Code | ||
quarto_create_project(name = "test") | ||
Condition | ||
Error in `check_quarto_version()`: | ||
! `quarto create project` has been added in Quarto 1.4. See <https://quarto.org/docs/projects/quarto-projects.html>. | ||
i You are using 1.3.433 from '<quarto full path>'. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Create a quarto project | ||
|
||
Code | ||
quarto_create_project() | ||
Condition | ||
Error in `quarto_create_project()`: | ||
! You need to provide `name` for the new project. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
test_that("Create a quarto project", { | ||
skip_if_no_quarto("1.4") | ||
expect_snapshot( | ||
error = TRUE, | ||
quarto_create_project() | ||
) | ||
tempdir <- withr::local_tempdir() | ||
withr::local_dir(tempdir) | ||
expect_no_error(quarto_create_project(name = "test-project", quiet = TRUE)) | ||
expect_true(dir.exists("test-project")) | ||
}) | ||
|
||
test_that("Create a quarto project in another directory", { | ||
skip_if_no_quarto("1.4") | ||
tempdir <- withr::local_tempdir() | ||
curr_wd <- getwd() | ||
expect_no_error(quarto_create_project(name = "test-project", dir = tempdir, quiet = TRUE)) | ||
expect_true(dir.exists(file.path(tempdir, "test-project"))) | ||
expect_identical(curr_wd, getwd()) | ||
}) | ||
|
||
test_that("create project only available for 1.4", { | ||
skip_if_quarto("1.4") | ||
local_reproducible_output(width = 1000) | ||
expect_snapshot( | ||
error = TRUE, | ||
quarto_create_project(name = "test"), | ||
transform = transform_quarto_cli_in_output(full_path = TRUE), | ||
variant = "before-1-4" | ||
) | ||
}) |