R/golem_hook.R

Defines functions golem_hook

Documented in golem_hook

# Generated by fusen: do not edit by hand

#' Golem Hook function
#'
#' @return Used for side effect
#' @inheritParams golem::project_hook
#' @export
#'
#' @examples
#' if (requireNamespace("golem") & interactive()) {
#'   golem::create_golem("myapp", project_hook = golem_hook)
#' }
golem_hook <- function(
  path,
  package_name,
  ...
) {
  unlink("R/run_app.R", TRUE, TRUE)
  unlink("R/app_ui.R", TRUE, TRUE)
  unlink("R/app_server.R", TRUE, TRUE)
  file.copy(
    system.file(
      "golem/run_app.R",
      package = "brochure"
    ),
    "R/run_app.R"
  )

  run_app <- readLines(
    "R/run_app.R"
  )
  run_app <- gsub(
    "REPLACEME",
    package_name,
    run_app
  )
  write(run_app, "R/run_app.R")

  file.copy(
    system.file(
      "golem/mod_home.R",
      package = "brochure"
    ),
    "R/mod_home.R"
  )

  dev_R <- readLines(
    "dev/02_dev.R"
  )
  dev_R[
    which(
      grepl(
        "name_of_module1",
        dev_R
      )
    )
  ] <- 'golem::add_module(name = "name_of_module1", with_test = TRUE, module_template = brochure::new_page) # Name of the module'

  dev_R[
    which(
      grepl(
        "name_of_module2",
        dev_R
      )
    )
  ] <- 'golem::add_module(name = "name_of_module2", with_test = TRUE, module_template = brochure::new_page) # Name of the module'
  unlink("dev/02_dev.R")
  write(dev_R, "dev/02_dev.R")
}
ColinFay/brochure documentation built on March 30, 2022, 5:02 a.m.