Skip to content

Commit

Permalink
Allow passing of direct path to app file
Browse files Browse the repository at this point in the history
  • Loading branch information
nstrayer committed Sep 14, 2023
1 parent a3f385a commit c931639
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 42 deletions.
6 changes: 6 additions & 0 deletions R/launch_editor.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,15 @@ launch_editor <- function(app_loc,
# "editing-app". This is used to know what to do on close
server_mode <- "initializing"

# Validate that we're pointing to a directory. If the user has supplied a
# direct file. E.g. a app.R or app.py file we should back up the app loc to
# the parent location
app_loc <- validateAppLoc(app_loc)

# Type of app we're in. Can be "SINGLE-FILE", "MULTI-FILE", or "MISSING"
app_type <- get_app_file_type(app_loc)


# ----------------------------------------------------------------------------
# Initialize classes for controling app preview and polling for updates
# ----------------------------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions R/validateAppLoc.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Validate that we're pointing to a directory. If the user has supplied a
# direct file. E.g. a app.R or app.py file we should back up the app loc to
# the parent location
validateAppLoc <- function(loc) {

# If the file ends in app.R or ui.R or server.R we should back up the
# location to the parent directory
if (fs::path_ext(loc) %in% "R") {
loc <- fs::path_dir(loc)
}

loc
}
6 changes: 3 additions & 3 deletions scratch/start_editor_non_interactive.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
devtools::load_all(".")

launch_editor(
app_loc = here::here("scratch/a-brand-new-app3/"),
app_loc = here::here("scratch/a-brand-new-app3"),
port = 8888,
launch_browser = FALSE,
stop_on_browser_close = FALSE
# launch_browser = FALSE,
# stop_on_browser_close = FALSE
)
13 changes: 13 additions & 0 deletions tests/testthat/test-app-location-validation.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

test_that("Handles being passed path directly to app script, or to folder container app", {

expect_equal(
validateAppLoc("my/app/loc/app.R"),
validateAppLoc("my/app/loc")
)

expect_equal(
validateAppLoc("my/app/loc/ui.R"),
validateAppLoc("my/app/loc")
)
})
39 changes: 0 additions & 39 deletions tests/testthat/test-serialize_ast.R

This file was deleted.

0 comments on commit c931639

Please sign in to comment.