This repository has been archived by the owner on Jul 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
261 additions
and
0 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
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,141 @@ | ||
#' Install gepetto | ||
#' | ||
#' This function verifies you have what you need to install `gepetto` then | ||
#' does so (globally). Ideally, you'll have `Node.js` and `npm` already on your | ||
#' system (since this function will not install them). | ||
#' | ||
#' While you _can_ try to install gepetto this way, it is highly recommended that | ||
#' you follow the instructions (<https://gitlab.com/hrbrmstr/gepetto>) manually | ||
#' since many Node.js/npm installations have permissions issues due to errant | ||
#' historical use of `sudo`. | ||
#' | ||
#' @md | ||
#' @export | ||
install_gepetto <- function() { | ||
|
||
node <- Sys.which("node") | ||
npm <- Sys.which("npm") | ||
|
||
if (node == "") { | ||
message( | ||
"Could not locate Node.js. Please visit <https://nodejs.org/en/download/package-manager/> ", | ||
"and obtain it via one of the methods described there then try installing gepetto from ", | ||
"a fresh R session.", sep="" | ||
) | ||
return() | ||
} | ||
|
||
if (npm == "") { | ||
message( | ||
"Could not local npm. Please visit <https://www.npmjs.com/get-npm> to ensure ", | ||
"you have installed both Node.js and npm correctly, then try installing gepetto ", | ||
"from a fresh R session.", sep="" | ||
) | ||
return() | ||
} | ||
|
||
res <- processx::run(node, "--version", error_on_status = FALSE) | ||
if (res$status != 0) { | ||
message( | ||
"An error occurred while trying to determine the version of Node.js that is ", | ||
"installed on the system. Please ensure you have it installed correctly and ", | ||
"try installing gepetto again from a fresh R session.", sep="" | ||
) | ||
return() | ||
} | ||
|
||
node_vers <- unlist(strsplit(res$stdout, "\\."))[1] | ||
if (!(node_vers %in% c("v10", "v9"))) { | ||
message( | ||
"You have a very old installation of Node.js. Please update it and try installing ", | ||
"gepetto again from a fresh R session.", sep="" | ||
) | ||
return() | ||
} | ||
|
||
res <- processx::run(npm, "--version", error_on_status = FALSE) | ||
if (res$status != 0) { | ||
message( | ||
"An error occurred while trying to determine the version of npm that is ", | ||
"installed on the system. Please ensure you have it installed correctly and ", | ||
"try installing gepetto again from a fresh R session.", sep="" | ||
) | ||
return() | ||
} | ||
|
||
npm_vers <- unlist(strsplit(res$stdout, "\\."))[1] | ||
if (!(npm_vers %in% c("6"))) { | ||
message( | ||
"You have an old installation of npm. Please update it and try installing ", | ||
"gepetto again from a fresh R session.", sep="" | ||
) | ||
return() | ||
} | ||
|
||
message("Attemping to install gepetto") | ||
|
||
processx::run( | ||
command = "npm", | ||
args = c("install", "https://gitlab.com/hrbrmstr/gepetto.git", "--global"), | ||
error_on_status = FALSE, | ||
echo_cmd = TRUE, | ||
echo = TRUE | ||
) -> res | ||
|
||
if (res$status == 0) { | ||
message("gepetto has been installed.") | ||
} else { | ||
message( | ||
"There was an error installing gepetto. Check the error log and make sure ", | ||
"permissions are set correctly or for other errors that occurred which ", | ||
"prevented the installation frombeing successful and try again or follow the ", | ||
"manual instructions at <https://gitlab.com/hrbrmstr/gepetto>.", sep="" | ||
) | ||
} | ||
|
||
} | ||
|
||
#' Start/stop gepetto | ||
#' | ||
#' These functions can help start/stop gepetto instances. You must remember to | ||
#' save the object returned by [start_gepetto()]. | ||
#' | ||
#' Note that [stop_gepetto()] kills the process. You can/should consider using | ||
#' [gep_stop()] instead. | ||
#' | ||
#' @md | ||
#' @param host IP/host to use instead of `localhost` | ||
#' @param port port to use besides the default (`8080`) | ||
#' @param pxobj the `processx` object of a running gepetto instance generated by [start_gepetto()] | ||
#' @return [start_gepetto()] returns a `processx` object | ||
#' @export | ||
#' @examples \dontrun{ | ||
#' pid <- start_gepetto() | ||
#' # ... do stuff | ||
#' stop_gepetto(pid) | ||
#' } | ||
start_gepetto <- function(host = "localhost", port = 8080) { | ||
|
||
gep <- Sys.which("gepetto") | ||
if (gep == "") stop("gepetto not found.", call.=FALSE) | ||
|
||
HOST <- Sys.getenv("HOST") | ||
on.exit(Sys.setenv(HOST=HOST), add=TRUE) | ||
PORT <- Sys.getenv("PORT") | ||
on.exit(Sys.setenv(PORT=PORT), add=TRUE) | ||
|
||
Sys.setenv(HOST=host) | ||
Sys.setenv(PORT=port) | ||
processx::process$new( | ||
command = "gepetto", stdout = "|", stderr = "|" | ||
) -> res | ||
|
||
res | ||
|
||
} | ||
|
||
#' @rdname start_gepetto | ||
#' @export | ||
stop_gepetto <- function(pxobj) { | ||
pxobj$kill() | ||
} |
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
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.