Skip to content

Commit

Permalink
Improve bootstrap-datepicker update tools, add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
alandipert committed Mar 27, 2019
1 parent 4cd92a1 commit 20329fe
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 25 deletions.
12 changes: 11 additions & 1 deletion inst/www/shared/datepicker/js/bootstrap-datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,17 @@
},

_utc_to_local: function(utc){
return utc && new Date(utc.getTime() + (utc.getTimezoneOffset()*60000));

if (!utc) return utc;

var local = new Date(utc.getTime() + (utc.getTimezoneOffset() * 60000));

if (local.getTimezoneOffset() != utc.getTimezoneOffset())
{
local = new Date(utc.getTime() + (local.getTimezoneOffset() * 60000));
}

return utc && local;
},
_local_to_utc: function(local){
return local && new Date(local.getTime() - (local.getTimezoneOffset()*60000));
Expand Down
24 changes: 24 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,27 @@ To update the version of babel-polyfill:
* Run `yarn add --dev babel-polyfill --exact`.
* Edit R/shinyui.R. The `renderPage` function has an `htmlDependency` for
`babel-polyfill`. Update this to the new version number.

# Updating and patching `bootstrap-datepicker`

## Updating

[bootstrap-datepicker](https://github.com/uxsolutions/bootstrap-datepicker) can be updated with the script `updateBootstrapDatepicker.R`.

After updating, our patches to `bootstrap-datepicker` must be applied using the script `applyDatepickerPatches.R`

After updating and applying patches, `yarn grunt` should be run per the instructions above.

## Making a new patch

To create a new patch:

1. Make any necessary changes to files in `inst/www/shared/datepicker`
1. **Do not commit your changes.**
1. Instead, create a patch with a command like `git diff > tools/datepicker-patches/012-a-description.patch`
1. Add the new `.patch` file to the repo with a descriptive commit message
1. Revert `bootstrap-datepicker` to its unpatched state by running `updateBootstrapDatepicker.R`
1. Apply all patches, including the one you just made, by running `applyDatepickerPatches.R`
1. Run `yarn grunt`
1. Test your changes
1. `git add` the new `.patch` and any resulting changes
18 changes: 18 additions & 0 deletions tools/applyDatepickerPatches.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env Rscript
# Applies patches stored in tools/datepicker-patches
# Should be run after running tools/updateBootstrapDatepicker.R

library(rprojroot)

patch_dir <- rprojroot::find_package_root_file("tools/datepicker-patches")

for (patch in list.files(patch_dir, full.names = TRUE)) {
tryCatch({
message(sprintf("Applying %s", basename(patch)))
system(sprintf("git apply '%s'", patch))
},
error = function(e) {
quit(save = "no", status = 1)
}
)
}
39 changes: 15 additions & 24 deletions tools/updateBootstrapDatepicker.R
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
#!/usr/bin/env Rscript
# Retrieves a particular version of bootstrap-datepicker:
# https://github.com/uxsolutions/bootstrap-datepicker
# After retrieving, applies the series of patches contained
# in tools/datepicker-patches to inst/www/shared/datepicker/
# After retrieving, you can apply patches stored in
# tools/datepicker-patches with applyDatepickerPatches.R

library(rprojroot)

version <- "1.6.4"
patch_dir <- rprojroot::find_package_root_file("tools/datepicker-patches")
dest_dir <- rprojroot::find_package_root_file("inst/www/shared/datepicker")
tag <- paste0("v", version)
dest_file <- file.path(tempdir(), paste0("bootstrap-datepicker-", version, ".zip"))
url <- sprintf("https://github.com/uxsolutions/bootstrap-datepicker/releases/download/%s/bootstrap-datepicker-%s-dist.zip", tag, version)

fetch_datepicker <- function() {
tag <- paste0("v", version)
dest_file <- file.path(tempdir(), paste0("bootstrap-datepicker-", version, ".zip"))
url <- sprintf("https://github.com/uxsolutions/bootstrap-datepicker/releases/download/%s/bootstrap-datepicker-%s-dist.zip", tag, version)
download.file(url, dest_file)
unzip(
dest_file,
files = c(
"js/bootstrap-datepicker.js",
"css/bootstrap-datepicker3.css",
"css/bootstrap-datepicker3.min.css"
),
exdir = dest_dir
)
}

apply_patches <- function() {
}

fetch_datepicker()
apply_patches()
download.file(url, dest_file)
unzip(
dest_file,
files = c(
"js/bootstrap-datepicker.js",
"css/bootstrap-datepicker3.css",
"css/bootstrap-datepicker3.min.css"
),
exdir = dest_dir
)

0 comments on commit 20329fe

Please sign in to comment.