Skip to content

Commit

Permalink
create zip file of pre-compiled application files
Browse files Browse the repository at this point in the history
  • Loading branch information
rpodcast committed May 3, 2024
1 parent 82e68e7 commit 4b0f9f8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-ectd-bundle.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

- name: Compile ECTD Bundle (custom)
run: |
source("utils.R"); create_ectd_bundle()
source("utils.R"); create_app_bundle(); create_ectd_bundle()
shell: Rscript {0}

- name: Check out ECTD bundle destination repo
Expand Down
32 changes: 31 additions & 1 deletion utils.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
app_dir_exists <- function(dir = "_site") {
fs::dir_exists(dir) && length(fs::dir_ls(dir) > 0)
}

build_app <- function(dir_source = "app", dir_build = "_site", overwrite = TRUE) {
if (isFALSE(overwrite) && fs::dir_exists(dir_build)) {
withr::with_options(
Expand Down Expand Up @@ -41,7 +45,7 @@ run_app_webassembly <- function(dir = "_site", port = 7654) {
list(rlang_backtrace_on_error = "none"),
cli::cli_abort(
c("Webassembly application not detected in directory {dir}.",
"Run {.code build_app()} and try again"
"Run {.code build_app()} or {.code extract_app_bundle()} and try again"
),
call = NULL
)
Expand Down Expand Up @@ -72,6 +76,7 @@ create_ectd_bundle <- function(archive_name = "r4app.zip") {
archive = fs::path("ectd_bundle", archive_name),
files = c(
fs::dir_ls("app", recurse = TRUE),
fs::dir_ls("app_bundle", recurse = TRUE),
"renv/.gitignore",
"renv/activate.R",
"renv/settings.json",
Expand All @@ -83,4 +88,29 @@ create_ectd_bundle <- function(archive_name = "r4app.zip") {
format = "zip"
)
invisible(TRUE)
}

create_app_bundle <- function(archive_name = "shinyapp.zip", dir_build = "_site") {
if (!app_dir_exists(dir_build)) {
build_app()
}
archive::archive_write_files(
archive = fs::path("app_bundle", archive_name),
files = c(
fs::dir_ls("_site", recurse = TRUE)
),
format = "zip"
)
invisible(TRUE)
}

extract_app_bundle <- function(archive_name = "shinyapp.zip", dir_build = "_site", overwrite = TRUE) {
if (isTRUE(overwrite) && fs::dir_exists(dir_build)) {
fs::dir_delete(dir_build)
}
archive::archive_extract(
archive = fs::path("app_bundle", archive_name),
dir = "."
)
invisible(TRUE)
}

0 comments on commit 4b0f9f8

Please sign in to comment.