|
1 | 1 | #!/usr/bin/env Rscript
|
2 |
| - |
3 |
| -# This script copies resources from Bootstrap Datepicker to shiny's inst |
4 |
| -# directory. The bootstrap-datepicker/ project directory should be on the same |
5 |
| -# level as the shiny/ project directory. |
6 |
| - |
7 |
| -# It is necessary to run Grunt after running this script: This copies the |
8 |
| -# un-minified JS file over, and running Grunt minifies it and inlines the locale |
9 |
| -# files into the minified JS. |
10 |
| - |
11 |
| -# This script can be sourced from RStudio, or run with Rscript. |
12 |
| - |
13 |
| -# Returns the file currently being sourced or run with Rscript |
14 |
| -thisFile <- function() { |
15 |
| - cmdArgs <- commandArgs(trailingOnly = FALSE) |
16 |
| - needle <- "--file=" |
17 |
| - match <- grep(needle, cmdArgs) |
18 |
| - if (length(match) > 0) { |
19 |
| - # Rscript |
20 |
| - return(normalizePath(sub(needle, "", cmdArgs[match]))) |
21 |
| - } else { |
22 |
| - # 'source'd via R console |
23 |
| - return(normalizePath(sys.frames()[[1]]$ofile)) |
24 |
| - } |
| 2 | +# Retrieves a particular version of bootstrap-datepicker: |
| 3 | +# https://github.com/uxsolutions/bootstrap-datepicker |
| 4 | +# After retrieving, applies the series of patches contained |
| 5 | +# in tools/datepicker-patches to inst/www/shared/datepicker/ |
| 6 | + |
| 7 | +library(rprojroot) |
| 8 | + |
| 9 | +version <- "1.6.4" |
| 10 | +patch_dir <- rprojroot::find_package_root_file("tools/datepicker-patches") |
| 11 | +dest_dir <- rprojroot::find_package_root_file("inst/www/shared/datepicker") |
| 12 | + |
| 13 | +fetch_datepicker <- function() { |
| 14 | + tag <- paste0("v", version) |
| 15 | + dest_file <- file.path(tempdir(), paste0("bootstrap-datepicker-", version, ".zip")) |
| 16 | + url <- sprintf("https://github.com/uxsolutions/bootstrap-datepicker/releases/download/%s/bootstrap-datepicker-%s-dist.zip", tag, version) |
| 17 | + download.file(url, dest_file) |
| 18 | + unzip( |
| 19 | + dest_file, |
| 20 | + files = c( |
| 21 | + "js/bootstrap-datepicker.js", |
| 22 | + "css/bootstrap-datepicker3.css", |
| 23 | + "css/bootstrap-datepicker3.min.css" |
| 24 | + ), |
| 25 | + exdir = dest_dir |
| 26 | + ) |
25 | 27 | }
|
26 | 28 |
|
27 |
| -srcdir <- normalizePath(file.path(dirname(thisFile()), "../../bootstrap-datepicker/dist")) |
28 |
| -destdir <- normalizePath(file.path(dirname(thisFile()), "../inst/www/shared/datepicker")) |
29 |
| - |
30 |
| -file.copy( |
31 |
| - file.path(srcdir, "js", "bootstrap-datepicker.js"), |
32 |
| - file.path(destdir, "js"), |
33 |
| - overwrite = TRUE |
34 |
| -) |
35 |
| - |
36 |
| -file.copy( |
37 |
| - dir(file.path(srcdir, "locales"), "\\.js$", full.names = TRUE), |
38 |
| - file.path(destdir, "js", "locales"), |
39 |
| - overwrite = TRUE |
40 |
| -) |
| 29 | +apply_patches <- function() { |
| 30 | +} |
41 | 31 |
|
42 |
| -file.copy( |
43 |
| - dir(file.path(srcdir, "css"), "^bootstrap-datepicker3(\\.min)?\\.css$", |
44 |
| - full.names = TRUE), |
45 |
| - file.path(destdir, "css"), |
46 |
| - overwrite = TRUE |
47 |
| -) |
| 32 | +fetch_datepicker() |
| 33 | +apply_patches() |
0 commit comments