Skip to content

Commit

Permalink
Merge pull request #253 from Appsilon/develop
Browse files Browse the repository at this point in the history
Release v1.0.0
  • Loading branch information
kamilzyla authored Apr 19, 2022
2 parents 51229dd + 5638068 commit 1ac142b
Show file tree
Hide file tree
Showing 61 changed files with 552 additions and 403 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
^\.gitignore$
^\.lintr$
^\.Rproj\.user$
^\.whitesource$
^pkgdown$
^README\.md$
^vignettes$
10 changes: 10 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@
This document contains guidelines specific to Rhino. [Appsilon's general contributing
guidelines](https://github.com/Appsilon/.github/blob/main/CONTRIBUTING.md) still apply.

## Contributing to Rhino

Pull requests to Rhino are welcome!

| Tool | Command | `devtools` equivalent | Comment
|----------------|--------------------------|--------------------------|-
| Unit tests | `testthat::test_local()` | `devtools::test()` |
| Linter | `lintr::lint_package()` | `devtools::lint()` |
| `pkgdown` site | `pkgdown::build_site()` | `devtools::build_site()` | If built successfully, the website will be in `docs` directory. Requires `pkgdown` version >= 2.0.0.


## Development Process
1. We follow [Scrum](https://scrumguides.org/).
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: rhino
Title: A Framework for Enterprise Shiny Applications
Version: 0.8.0
Version: 1.0.0
Authors@R:
c(
person("Kamil", "Zyla", role = c("aut", "cre"), email = "[email protected]"),
Expand All @@ -16,12 +16,12 @@ License: LGPL-3
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.1.2
VignetteBuilder: knitr
Depends:
R (>= 2.10)
Imports:
box,
cli,
config,
fs,
glue,
lintr (>= 2.0.0),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ export(init)
export(lint_js)
export(lint_r)
export(lint_sass)
export(log)
export(test_e2e)
export(test_r)
24 changes: 6 additions & 18 deletions R/addins.R
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
create_module <- function() {
rstudioapi::insertText(glue::trim("
box::use(
shiny[moduleServer, NS]
)
#' @export
ui <- function(id) {
ns <- NS(id)
}
#' @export
server <- function(id) {
moduleServer(id, function(input, output, session) {
read_addin <- function(...) {
path <- fs::path_package("rhino", "rstudio", "addins", ...)
readChar(path, file.info(path)$size)
}

})
}"
))
addin_module <- function() {
rstudioapi::insertText(read_addin("module.R"))
}
6 changes: 3 additions & 3 deletions R/app.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
configure_logger <- function() {
log_level <- Sys.getenv("LOG_LEVEL", unset = "INFO")
log_file <- Sys.getenv("LOG_FILE", unset = NA)
config <- config::get()
log_level <- config$rhino_log_level
log_file <- config$rhino_log_file

logger::log_threshold(log_level)
if (!is.na(log_file)) {
Expand Down Expand Up @@ -86,7 +87,6 @@ with_head_tags <- function(ui) {
#' # Your `app.R` should contain nothing but this single call:
#' rhino::app()
#' }
#'
#' @export
app <- function() {
configure_logger()
Expand Down
23 changes: 19 additions & 4 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,30 @@ read_yaml <- function(path) {
}
}

option_validator <- function(...) list(
check = function(value) value %in% c(...),
help = cli::format_inline("Allowed values: {c(...)}.")
)

positive_integer_validator <- list(
check = function(value) is.integer(value) && value > 0,
help = "Expected positive integer."
)

rhino_config_definition <- list(
list(
name = "sass",
options = c("node", "r"),
validator = option_validator("node", "r"),
required = TRUE
),
list(
name = "legacy_entrypoint",
options = c("app_dir", "source", "box_top_level"),
validator = option_validator("app_dir", "source", "box_top_level"),
required = FALSE
),
list(
name = "legacy_max_lint_r_errors",
validator = positive_integer_validator,
required = FALSE
)
)
Expand All @@ -46,10 +61,10 @@ validate_config <- function(definition, config) {
for (field in definition) {
if (field$name %in% names(config)) {
value <- config[[field$name]]
if (!(value %in% field$options)) {
if (!field$validator$check(value)) {
cli::cli_abort(c(
"Invalid value '{value}' for field '{field$name}'.",
i = "Allowed values: {field$options}."
i = field$validator$help
))
}
} else if (field$required) {
Expand Down
2 changes: 1 addition & 1 deletion R/data.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#' Population of rhinos
#'
#' A dataset containing population of 5 species of rhinos
#' A dataset containing population of 5 species of rhinos.
#'
#' @format A data frame with 58 rows and 3 variables:
#' \describe{
Expand Down
44 changes: 44 additions & 0 deletions R/log.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#' Logging functions
#'
#' Convenient way to log messages at a desired severity level.
#'
#' The `log` object is a list of logging functions, in order of decreasing severity:
#' 1. `fatal`
#' 2. `error`
#' 3. `warn`
#' 4. `success`
#' 5. `info`
#' 6. `debug`
#' 7. `trace`
#'
#' Rhino configures logging based on settings read from the `config.yml` file
#' in the root of your project:
#' 1. `rhino_log_level`: The minimum severity of messages to be logged.
#' 2. `rhino_log_file`: The file to save logs to. If `NA`, standard error stream will be used.
#'
#' The default `config.yml` file uses `!expr Sys.getenv()`
#' so that log level and file can also be configured
#' by setting the `RHINO_LOG_LEVEL` and `RHINO_LOG_FILE` environment variables.
#'
#' The functions re-exported by the `log` object are aliases for `{logger}` functions.
#' You can also import the package and use it directly to utilize its full capabilities.
#'
#' @examples
#' \dontrun{
#' box::use(rhino[log])
#'
#' # Messages can be formatted using glue syntax.
#' name <- "Rhino"
#' log$warn("Hello {name}!")
#' log$info("{1:3} + {1:3} = {2 * (1:3)}")
#' }
#' @export
log <- list(
fatal = logger::log_fatal,
error = logger::log_error,
warn = logger::log_warn,
success = logger::log_success,
info = logger::log_info,
debug = logger::log_debug,
trace = logger::log_trace
)
57 changes: 52 additions & 5 deletions R/node.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,65 @@ system_yarn <- function(..., status_ok = 0) {
}
}

add_node <- function() {
link_root_mklink <- function() {
tryCatch({
system2("cmd.exe", input = "mklink root ..\\..", stdout = TRUE, stderr = TRUE)
}, error = function(error) {
cli::cli_abort(c(
"Node.js setup: Failed to create root link with {.code mklink}: {error$message}",
i = "You might need to enable Developer Mode: https://go.appsilon.com/rhino-windows"
))
})
}

link_root_fs <- function() {
tryCatch({
fs::link_create(path = fs::path("..", ".."), new_path = "root")
}, error = function(error) {
cli::cli_abort(
"Node.js setup: Failed to create root link with {.pkg fs}: {error$message}"
)
})
}

is_windows <- function() {
Sys.info()[["sysname"]] == "Windows"
}

add_node <- function(clean = FALSE) {
if (clean && fs::dir_exists(node_path())) {
fs::dir_delete(node_path())
}

copy_template("node", node_path())
fs::link_create(
path = fs::path("..", ".."),
new_path = fs::path(node_path(), "root")
)
withr::with_dir(node_path(), {
if (is_windows()) link_root_mklink()
else link_root_fs()
})
}

yarn <- function(...) {
check_js_dependencies()

if (!fs::dir_exists(node_path())) {
add_node()
system_yarn("install")
}
system_yarn(...)
}

check_js_dependencies <- function() {
documentation_url <- "https://go.appsilon.com/rhino-system-dependencies"

check_system_dependency(
cmd = "node",
dependency_name = "Node.js",
documentation_url = documentation_url
)

check_system_dependency(
cmd = "yarn",
dependency_name = "yarn",
documentation_url = documentation_url
)
}
27 changes: 24 additions & 3 deletions R/rhino.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,32 @@ copy_rproj <- function() {
)
}

system_cmd_version <- function(cmd) {
system_cmd_version <- function(cmd, throw_error = FALSE) {
tryCatch(
system2(cmd, "--version", stdout = TRUE, stderr = TRUE),
error = function(e) e$message
error = function(e) {
if (isTRUE(throw_error)) cli::cli_abort(e)

e$message
}
)
}

check_system_dependency <- function(
cmd,
dependency_name,
documentation_url,
additional_message = NULL
) {
message <- c(
glue::glue("Do you have {dependency_name} installed?"),
glue::glue("Check {documentation_url} for details."),
additional_message
)

tryCatch(
system_cmd_version(cmd, TRUE),
error = function(e) cli::cli_abort(message)
)
}

Expand All @@ -70,7 +92,6 @@ system_cmd_version <- function(cmd) {
#' # Print diagnostic information.
#' diagnostics()
#' }
#'
#' @export
diagnostics <- function() {
writeLines(c(
Expand Down
Loading

0 comments on commit 1ac142b

Please sign in to comment.