Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: pkg_* Utilities #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
^noclocksrtools\.Rproj$
^\.Rproj\.user$
^dev$
^examples$
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.Rproj.user
.Rhistory
.RData
.Ruserdata
31 changes: 31 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
Package: noclocksrtools
Title: Internal Development R Tools for No Clocks, LLC
Version: 0.0.0.9000
Authors@R: c(
person("Jimmy", "Briggs", , "jimmy.briggs@noclocks.dev", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-7489-8787")),
person("Patrick", "Howard", , "patrick.howard@noclocks.dev", role = c("aut", "rev"),
comment = c(ORCID = "0000-0000-0000-0000")),
person("No Clocks, LLC", , , "dev@noclocks.dev", role = c("fnd", "cph"))
)
Description: A collection of internal development tools for No Clocks,
LLC.
License: MIT + file LICENSE
Imports:
covr,
covrpage,
fs,
gitdown,
glue,
httr2,
jsonlite,
markdown,
pkgdown,
purrr,
rlang,
testdown,
utils
Encoding: UTF-8
Language: en-US
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2.9000
33 changes: 33 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by roxygen2: do not edit by hand

export(build_pkgdown)
export(get_opts)
export(pkg_sys)
export(pkg_sys_assets)
export(pkg_sys_config)
export(pkg_sys_css)
export(pkg_sys_examples)
export(pkg_sys_extdata)
export(pkg_sys_fonts)
export(pkg_sys_img)
export(pkg_sys_js)
export(pkg_sys_logos)
export(pkg_sys_scripts)
export(pkg_sys_scss)
export(pkg_sys_styles)
export(pkg_sys_templates)
export(system_file)
importFrom(covr,package_coverage)
importFrom(covr,report)
importFrom(covrpage,covrpage)
importFrom(fs,dir_create)
importFrom(fs,file_move)
importFrom(gitdown,git_down)
importFrom(glue,glue)
importFrom(jsonlite,fromJSON)
importFrom(markdown,markdownToHTML)
importFrom(pkgdown,build_site)
importFrom(purrr,partial)
importFrom(testdown,test_down)
importFrom(utils,globalVariables)
importFrom(utils,packageVersion)
Empty file added R/pkg_data.R
Empty file.
25 changes: 25 additions & 0 deletions R/pkg_deps.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

# ------------------------------------------------------------------------
#
# Title : Package Dependency Functions
# By : Jimmy Briggs
# Date : 2024-08-05
#
# ------------------------------------------------------------------------


# internal ----------------------------------------------------------------



# utility -----------------------------------------------------------------



# package dependencies ----------------------------------------------------



# system requirements -----------------------------------------------------


Empty file added R/pkg_desc.R
Empty file.
191 changes: 191 additions & 0 deletions R/pkg_down.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@

# ------------------------------------------------------------------------
#
# Title : Package Documentation via `pkgdown`
# By : Jimmy Briggs
# Date : 2024-08-05
#
# ------------------------------------------------------------------------


# build -------------------------------------------------------------------

#' No Clocks `pkgdown`
#'
#' @description
#' Build a [pkgdown::pkgdown()] site with additional options to include
#' extra reports.
#'
#' The reports that can be included are:
#' - Test Results Report via [testdown::test_down()]
#' - Test Coverage Results via [covrpage::covrpage()]
#' - Git Reports via [gitdown::git_down()]
#'
#' @param pkg (character) Path to the package in development
#' @param pkgdown_path (character) Relative path inside the package to store
#' the final `pkgdown` site
#' @param assets_path (character) Relative path within the package to store
#' the `pkgdown` assets
#' @param reports (character) Vector of reports to be produced. Must be a subset
#' of `c("testdown","gitdown", "coverage")`. The default is
#' `c("coverage", "testdown", "gitdown")`.
#' @param git_branch_ref (character) Git branch to use. `main' by default
#' @param overwrite_assets (logical) Whether the assets directory should be
#' overwritten. Default is `TRUE`.
#' @param ... Additional arguments to pass to `pkgdown::build_site()`
#'
#' @return A `pkgdown` site in the specified `pkgdown_path` directory
#'
#' @export
#'
#' @importFrom fs dir_create file_move
#' @importFrom pkgdown build_site
#' @importFrom covr package_coverage report
#' @importFrom covrpage covrpage
#' @importFrom testdown test_down
#' @importFrom gitdown git_down
#' @importFrom markdown markdownToHTML
#' @importFrom jsonlite fromJSON
#' @importFrom glue glue
#'
#' @example examples/ex_pkgdown.R
build_pkgdown <- function(
pkg,
pkgdown_path = "pkgdown",
assets_path = "pkgdown/assets",
reports = c("coverage", "testdown", "gitdown"),
git_branch_ref = "main",
overwrite_assets = TRUE,
...
) {

reports <- rlang::arg_match(reports, multiple = TRUE)

if (isTRUE(overwrite)) { unlink(file.path(pkg, assets_path), recursive = TRUE) }

# initialize navbar report
menu <- list()
if (length(reports) != 0) {
fs::dir_create(file.path(pkg, assets_path))
}

# generate covr report in a tmp folder and move it to assets path
if (isTRUE("coverage" %in% reports)) {
if (!requireNamespace("covr", quietly = TRUE)) {
stop(
"{covr} needs to be installed"
)
}
if (!requireNamespace("DT", quietly = TRUE)) {
stop(
"{DT} needs to be installed"
)
}
if (!requireNamespace("htmltools", quietly = TRUE)) {
stop(
"{htmltools} needs to be installed"
)
}
if (!requireNamespace("markdown", quietly = TRUE)) {
stop(
"{markdown} needs to be installed"
)
}
covr_pkg <- covr::package_coverage(
path = pkg,
install_path = file.path(pkg, "covr")
)
covr::report(
x = covr_pkg,
file = file.path(assets_path, "coverage", "coverage.html"),
browse = FALSE
)

# file_move(file.path(pkg, "coverage"), file.path(assets_path, "coverage"))
menu[[length(menu) + 1]] <- list(text = "coverage", href = "coverage/coverage.html")
# Add coverage explanation
markdown::markdownToHTML(
file = system.file(
"templates/markdown/coverage_report_explanation.md",
package = "noclocksr"
),
output = file.path(assets_path, "coverage", "codecoverage_explanation.html")
)
menu[[length(menu) + 1]] <- list(
text = "coverage explained",
href = "coverage/codecoverage_explanation.html"
)
}

# generate testdown report in assets path
if (isTRUE("testdown" %in% reports)) {
if (!requireNamespace("testdown", quietly = TRUE)) {
stop(
"{testdown} needs to be installed"
)
}

testdown::test_down(
pkg = pkg,
book_path = file.path(assets_path, "testdown"),
open = FALSE
)
menu[[length(menu) + 1]] <- list(text = "testdown", href = "testdown/index.html")
}

# generate gitdown report in assets path
if (isTRUE("gitdown" %in% reports)) {
if (!requireNamespace("gitdown", quietly = TRUE)) {
stop(
"{gitdown} needs to be installed"
)
}

gitdown::git_down(
repo = pkg,
book_path = file.path(assets_path, "gitdown"),
ref = git_branch_ref,
open = FALSE
)
homepage <- file.path(
"gitdown",
list.files(
pattern = "^gitbook-for",
file.path(assets_path, "gitdown")
)[1]
)
menu[[length(menu) + 1]] <- list(text = "gitdown", href = homepage)
}

# prepare yaml settings to add reports in navbar
yaml_settings <- list(
destination = pkgdown_path,
template = list(
assets = assets_path
),
navbar = list(
structure = list(
left = c("intro", "reference", "articles", "tutorials", "news", "reports")
),
components = list(
reports = list(
text = "Reports",
menu = menu
)
)
)
)

# build site without preview
pkgdown::build_site(
pkg = pkg,
override = yaml_settings,
preview = FALSE,
devel = TRUE,
install = FALSE,
new_process = TRUE,
...
)


}
18 changes: 18 additions & 0 deletions R/pkg_env.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

# ------------------------------------------------------------------------
#
# Title : Package Environment
# By : Jimmy Briggs
# Date : 2024-08-05
#
# ------------------------------------------------------------------------

# initialize package environment
.pkgenv <- new.env(parent = emptyenv())

# initialize environment variables
.pkgenv$init <- FALSE
.pkgenv$options <- list()
.pkgenv$globals <- list()

.pkgenv$encryption_key <- NULL
21 changes: 21 additions & 0 deletions R/pkg_globals.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

# ------------------------------------------------------------------------
#
# Title : Package Globals
# By : Jimmy Briggs
# Date : 2024-08-05
#
# ------------------------------------------------------------------------

# internal ----------------------------------------------------------------

#' @keywords internal
#' @noRd
#' @importFrom utils globalVariables
.pkg_globals <- function() {
if (getRversion() >= "2.15.1") {
utils::globalVariables(c(
# PACKAGE GLOBALS #
))
}
}
10 changes: 10 additions & 0 deletions R/pkg_imports.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

# ------------------------------------------------------------------------
#
# Title : Package Imports
# By : Jimmy Briggs
# Date : 2024-08-05
#
# ------------------------------------------------------------------------


Empty file added R/pkg_meta.R
Empty file.
Loading