-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-rave-launcher-osx.R
72 lines (58 loc) · 2.27 KB
/
build-rave-launcher-osx.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#' @title Build `rave-2.0.app` on OSX
#' @description Build startup application for RAVE. Must run in Mac OSX
#' @returns Nothing
#' @examples
#'
#' # Make sure brew and node.js have been installed to your mac
#' # If you haven't, please open a new bash terminal and run:
#' #
#' # /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
#' # brew install node
#'
#' build <- raveio::load_snippet("build-rave-launcher-osx", local = FALSE)
#' build()
#'
#' END OF DOC
NULL
# Make sure brew exists
if(dipsaus::get_os() != "darwin") {
stop("This script only works on Mac OSX")
}
# make sure brew exists
brew <- raveio::cmd_homebrew(error_on_missing = TRUE)
if(Sys.which("npm") == "") {
system2(brew, "install node")
}
if(Sys.which("npm") == "") {
npm <- file.path(dirname(brew), "npm", fsep = "/")
} else {
npm <- Sys.which("npm")
}
npm <- normalizePath(npm, winslash = "/")
build_path <- normalizePath(file.path(tempdir(), "rave-electron-app-builder"), winslash = "/", mustWork = FALSE)
if(file.exists(build_path)) { unlink(build_path, recursive = TRUE, force = TRUE) }
dir.create(build_path, showWarnings = FALSE, recursive = TRUE)
utils::download.file("https://github.com/dipterix/rave-electron-app/archive/refs/heads/main.zip", destfile = file.path(build_path, "main.zip"))
utils::unzip(file.path(build_path, "main.zip"), exdir = build_path)
src_path <- file.path(build_path, "rave-electron-app-main")
cwd <- getwd()
on.exit({
setwd(cwd)
unlink(build_path, recursive = TRUE, force = TRUE)
}, add = TRUE)
setwd(src_path)
system2(npm, "install")
system2(npm, "run make")
# check if the platform is ARM
# /private/var/folders/bs/n0q8wqv931g89ppshhgp2m2m0000gn/T/RtmplBTv57/rave-electron-app-builder/rave-electron-app-main/out/make
fs <- list.files("./out", pattern = "^rave-2\\.0\\.app$", recursive = TRUE, all.files = TRUE, ignore.case = TRUE, full.names = TRUE, include.dirs = TRUE)
fs <- fs[[1]]
tryCatch({
dir.create("/Applications/RAVE", showWarnings = FALSE, recursive = TRUE)
file.copy(fs, "/Applications/RAVE", overwrite = TRUE, recursive = TRUE, copy.mode = TRUE, copy.date = TRUE)
system2("open", "/Applications/RAVE")
}, error = function(e) {
path <- dirname(normalizePath(fs, winslash = "/"))
system2("open", shQuote(path))
})
invisible()