Skip to content

Commit

Permalink
Merge pull request #13 from kennedymwavu/9-publish-v1-to-cran
Browse files Browse the repository at this point in the history
ch: prepare for CRAN
  • Loading branch information
kennedymwavu authored Oct 24, 2024
2 parents 4f3601a + d609787 commit ceb4cde
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 36 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
^pkgdown$
^dev\.R
^\.github$
^cran-comments\.md$
^CRAN-SUBMISSION$
^dev$
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dev.R
docs
dev/
3 changes: 3 additions & 0 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Version: 1.0.0
Date: 2024-08-16 23:28:28 UTC
SHA: b16d4147727f6f6593c99cfc9f20912df7037b74
17 changes: 11 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
Package: rmon
Title: Monitor Changes In Source Code And Auto-restart Your Server
Version: 0.0.0.9000
Title: Monitor Changes in Source Code and Auto-Restart Your Server
Version: 1.0.0
Authors@R:
person("Kennedy", "Mwavu", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0009-0006-3157-7234"))
Description: R's equivalent of 'nodemon'. Monitors changes in your source and automatically restarts/reruns your server.
Description: The 'R' equivalent of 'nodemon'. Watches specified
directories for file changes and reruns a designated 'R' script when
changes are detected. It's designed to automate the process of
reloading your 'R' applications during development, similar to
'nodemon' for 'Node.js'.
License: MIT + file LICENSE
URL: https://github.com/kennedymwavu/rmon
BugReports: https://github.com/kennedymwavu/rmon/issues
Imports:
processx (>= 3.8.4)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.1
Imports:
processx (>= 3.8.4)
URL: https://mwavu.com/rmon/, https://github.com/kennedymwavu/rmon
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# rmon 1.0.0

* Initial CRAN submission.
84 changes: 55 additions & 29 deletions R/monitor.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,38 +54,25 @@
#' ext = c(".R", ".Rmd")
#' )
#' }
#' @return NULL
#' @return `NULL`
#' @export
monitor <- function(
dir = getwd(),
dir = ".",
file,
ext = "*",
monitor_hidden = TRUE,
exclude_files = NULL,
exclude_patterns = NULL,
exclude_dirs = NULL,
delay = 1) {
file <- normalizePath(path = file.path(dir[[1]], file[[1]]))
if (!file.exists(file)) {
msg <- sprintf("File '%s' not found!", file)
stop(msg, call. = FALSE)
}
file <- normalizePath(
path = file.path(dir[[1]], file[[1]]),
mustWork = TRUE
)

patterns <- paste0(ext, "$", collapse = "|")

now <- function() {
format(Sys.time(), "%c")
}

dashes <- function() {
"---------------------------------------------------------"
}

cat(
dashes(),
sprintf("%s Starting rmon...\n", now()),
sep = "\n"
)
dash_and_msg(type = "starting")

get_file_info <- function() {
files <- list.files(
Expand Down Expand Up @@ -120,10 +107,9 @@ monitor <- function(
files <- files[!files %in% files_to_exclude]
}

file.info(files)
file.info(files)$mtime
}


start_new_process <- function() {
processx::process$new(
command = "Rscript",
Expand All @@ -142,17 +128,57 @@ monitor <- function(
changed <- !identical(file_info, new_file_info)
if (changed) {
file_info <- new_file_info

cat(
dashes(),
sprintf("%s Files changed. Restarting...\n", now()),
sep = "\n"
)
dash_and_msg()
p$kill()

p <- start_new_process()
}

Sys.sleep(time = delay)
}
}

#' Get current date and time
#'
#' @details Retrieves current system date and time, formatted in
#' a human-readable way.
#' @examples
#' \dontrun{
#' current_time()
#' }
#' @return String in the format "YYYY-MM-DD H:M:S" with the
#' timezone appended at the end.
#' @noRd
current_time <- function() {
format(x = Sys.time(), format = "%F %T", usetz = TRUE)
}

#' Show starting/restarting message on console
#'
#' @param type String. Type of message to show. Either "restarting"(default) or "starting".
#' @examples
#' \dontrun{
#' dash_and_msg()
#' }
#' @return `NULL`
#' @noRd
dash_and_msg <- function(type = c("restarting", "starting")) {
type <- match.arg(arg = type)

now <- current_time()
restart_msg <- sprintf("%s Files changed. Restarting...", now)
start_msg <- sprintf("%s Starting rmon...", now)
dashes <- strrep(x = "_", times = nchar(restart_msg))

msg <- switch(
EXPR = type,
restarting = restart_msg,
starting = start_msg
)

message(
dashes,
"\n",
msg,
"\n"
)
}
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# rmon

<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/rmon)](https://CRAN.R-project.org/package=rmon)
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
<!-- badges: end -->

R's equivalent of [nodemon](https://nodemon.io/). Designed to make development easier by automatically reloading your R scripts and applications.

can be used to auto-reload:
Expand All @@ -16,6 +21,12 @@ just like nodemon, **rmon** is perfect for development.

# installation

to install the package from CRAN use:

```r
install.packages("rmon")
```

install the dev version from GitHub:

```r
Expand Down
5 changes: 5 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## R CMD check results

0 errors | 0 warnings | 1 note

* This is a new release.
5 changes: 4 additions & 1 deletion man/monitor.Rd

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

0 comments on commit ceb4cde

Please sign in to comment.