-
Notifications
You must be signed in to change notification settings - Fork 239
/
Copy pathupdate-ace.R
67 lines (53 loc) · 1.58 KB
/
update-ace.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
(function() {
owd <- getwd()
on.exit({setwd(owd)})
ROOT <- rprojroot::find_package_root_file()
ACE_VERSION <- "1.10.1"
ACE_FILES <- c(
"ace.js",
"ext-language_tools.js",
"mode-css.js",
"mode-html.js",
"mode-javascript.js",
"mode-julia.js",
"mode-plain_text.js",
"mode-python.js",
"mode-r.js",
"mode-rdoc.js",
"mode-rhtml.js",
"mode-sql.js",
"mode-text.js",
"mode-xml.js"
)
ACE_THEME_PREFIX <- "theme-"
url <- sprintf(
"https://github.com/ajaxorg/ace-builds/archive/v%s.tar.gz",
ACE_VERSION
)
destfile <- tempfile("ace-tarball-")
on.exit({unlink(destfile)}, add = TRUE)
download.file(url, destfile = destfile)
exdir <- tempfile("ace-")
on.exit({unlink(exdir, recursive = TRUE)}, add = TRUE)
dir.create(exdir)
untar(tarfile = destfile, exdir = exdir)
setwd(exdir)
setwd(sprintf("ace-builds-%s", ACE_VERSION))
source <- c(
file.path("src-min", ACE_FILES),
dir("src-min", pattern = ACE_THEME_PREFIX, full.names = TRUE)
)
contents <- paste(lapply(source, function(file) {
readChar(file, file.info(file)$size, TRUE)
}), collapse = "\n")
target <- file.path(ROOT, "inst/lib/ace/ace.js")
writeLines(contents, con = target, sep = "\n", useBytes = TRUE)
themes <- sub("^theme-", "", sub("\\.js$", "", dir("src", "^theme-")))
metadata <- c(
"# This file was autogenerated by 'tools/update-ace.R'",
paste0("ACE_VERSION <- ", shQuote(ACE_VERSION, "cmd")),
paste0("ACE_THEMES <- c(", paste0(shQuote(themes, "cmd"), collapse = ", "), ")")
)
cat("Saving metadata:\n\n", paste0(metadata, collapse = '\n'), "\n")
writeLines(metadata, con = file.path(ROOT, "R/ace.R"))
})()