Skip to content

Commit c175b9b

Browse files
committed
update doc sources and flow and add justfile
1 parent f6e2704 commit c175b9b

File tree

7 files changed

+61
-45
lines changed

7 files changed

+61
-45
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ This repository contains the public facing source of https://developers.arcgis.c
44

55
We use this repository to build out the internal docs infrastructure. This way, you, the community can contribute.
66

7-
## Building the docs
7+
## Building docs
88

9-
To build **API Reference** run `dev/generate-api-ref.R`. This will clone all of the repositories and build the documentation using pkgdown and some other magic.
9+
```bash
10+
# update api reference
11+
just doc-ref
12+
13+
# update articles
14+
just doc-pages
15+
```
1016

11-
## Building the articles
17+
To build **API Reference** run `dev/generate-api-ref.R`. This will clone all of the repositories and build the documentation using pkgdown and some other magic.
1218

13-
To build all other documentation run `dev/generate-docs.R`. This will render `.qmd` files using R Markdown and perform syntax hilighting with downlit.
19+
To build all other documentation run `dev/generate-docs.R`. This will render `.qmd` files using R Markdown and perform syntax hilighting with downlit.

_docs.zip

17.5 MB
Binary file not shown.

api-ref.zip

36.3 KB
Binary file not shown.

dev/attachments.qmd

Lines changed: 0 additions & 30 deletions
This file was deleted.

dev/generate-api-ref.R

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,28 @@ pkgs <- c(
1616
)
1717

1818
generate_api_ref <- function(pkg) {
19+
cli::cli_h1("Processing {.pkg {pkg}}")
20+
1921
tmp <- tempdir()
2022
clone_dir <- file.path(tmp, pkg)
2123

2224
if (file.exists(clone_dir)) {
2325
unlink(clone_dir, recursive = TRUE)
2426
}
27+
2528
# clone into a temporary directory
29+
cli::cli_progress_step("Cloning {.pkg {pkg}} from GitHub")
2630
gert::git_clone(
2731
sprintf("https://github.com/r-arcgis/%s", pkg),
2832
path = clone_dir
2933
)
3034

3135
# init pkgdown in the temporary folder
36+
cli::cli_progress_step("Initialising pkgdown site")
3237
pkgdown::init_site(clone_dir)
38+
3339
# generate reference docs
40+
cli::cli_progress_step("Building reference docs")
3441
pkgdown::build_reference(clone_dir, preview = FALSE)
3542

3643
all_pkg_files <- list.files(
@@ -40,6 +47,7 @@ generate_api_ref <- function(pkg) {
4047
)
4148

4249
# create the api reference directory for the package
50+
cli::cli_progress_step("Creating output directories")
4351
dir.create(
4452
file.path("_api_ref", pkg),
4553
recursive = TRUE
@@ -73,6 +81,7 @@ generate_api_ref <- function(pkg) {
7381
vapply(strsplit(to_copy, "reference/"), `[[`, character(1), 2)
7482
)
7583

84+
cli::cli_progress_step("Copying {length(to_copy)} non-HTML asset{?s}")
7685
file.copy(to_copy, copy_dest, overwrite = TRUE)
7786

7887
# this function extract the html content
@@ -83,20 +92,20 @@ generate_api_ref <- function(pkg) {
8392
}
8493

8594
# apply to all html files
95+
cli::cli_progress_step("Extracting content from {length(fn_ref_html)} HTML file{?s}")
8696
extracted <- lapply(fn_ref_html, extract_fn_ref)
8797
out_ref_paths <- file.path("_api_ref", pkg, basename(fn_ref_html))
8898

8999
# write the html files
100+
cli::cli_progress_step("Writing {length(out_ref_paths)} reference page{?s}")
90101
Map(
91-
function(.html, .path) {
92-
cli::cli_alert_info("Writing {.file {(.path)}}")
93-
writeLines(.html, .path)
94-
},
102+
function(.html, .path) writeLines(.html, .path),
95103
extracted,
96104
out_ref_paths
97105
)
98106

99107
# Process the index file
108+
cli::cli_progress_step("Processing package index")
100109
index_html <-
101110
rvest::read_html(file.path(clone_dir, "docs", "reference", "index.html")) |>
102111
rvest::html_nodes("#main") |>
@@ -110,11 +119,14 @@ generate_api_ref <- function(pkg) {
110119
)
111120

112121
unlink(tmp)
122+
cli::cli_alert_success("Done with {.pkg {pkg}}")
113123
}
114124

125+
cli::cli_h1("Generating API references")
115126
for (pkg in pkgs) {
116127
generate_api_ref(pkg)
117128
}
129+
cli::cli_alert_success("All packages processed")
118130

119131
# NOTE url paths are adjusted manually using find and replace all w/ regex in vs code
120132
# search: https://r\.esri\.com/([^/]+)/reference/([^/]+)\.html
@@ -190,10 +202,15 @@ as_topic_nav <- function(pkg_indices) {
190202
yaml::as.yaml(indent.mapping.sequence = TRUE)
191203
}
192204

205+
cli::cli_h1("Building topic navigation")
206+
cli::cli_progress_step("Generating nav YAML from {length(pkg_indices)} package index{?es}")
193207
as_topic_nav(pkg_indices) |>
194208
brio::write_file("_api_ref/nav.yml")
209+
cli::cli_alert_success("Written {.file _api_ref/nav.yml}")
195210

211+
cli::cli_progress_step("Zipping {.file api-ref.zip}")
196212
zip::zip(
197213
"api-ref.zip",
198214
list.files("_api_ref", recursive = TRUE, full.names = TRUE)
199215
)
216+
cli::cli_alert_success("Done — {.file api-ref.zip} created")

dev/generate-docs.R

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ render_qmd_to_md <- function(in_path, out_path, work_dir = dirname(in_path)) {
1919
# #> [1] "Hello world"
2020

2121
# extract header from the .qmd file
22+
cli::cli_progress_step("Extracting YAML front matter")
2223
header <- rmarkdown::yaml_front_matter(in_path)
2324
if (length(header) > 0) {
2425
md_header <- c("---", paste(names(header), header, sep = ": "), "---", "")
@@ -32,6 +33,7 @@ render_qmd_to_md <- function(in_path, out_path, work_dir = dirname(in_path)) {
3233
knitr::opts_chunk$set(comment = "#>")
3334

3435
# render the section alone
36+
cli::cli_progress_step("Rendering {.file {in_path}} via rmarkdown")
3537
out <- rmarkdown::render(
3638
in_path,
3739
rmarkdown::github_document(),
@@ -46,17 +48,19 @@ render_qmd_to_md <- function(in_path, out_path, work_dir = dirname(in_path)) {
4648

4749
md_body <- NULL
4850
# add autolinking and syntax highlighting (we will have to choose colors manually later)
51+
cli::cli_progress_step("Applying downlit autolinking")
4952
tryCatch(
5053
{
5154
downlit::downlit_md_path(tmp, out_path = out_path)
5255
md_body <- readLines(out_path)
5356
},
5457
error = function(e) {
55-
cli::cli_alert_danger("Failed apply downlit to {.file {in_path}}")
58+
cli::cli_alert_danger("Failed to apply downlit to {.file {in_path}}")
5659
md_body <<- readLines(tmp)
5760
# file.copy(tmp, out_path, TRUE)
5861
}
5962
)
63+
cli::cli_progress_step("Writing {.file {out_path}}")
6064
final_content <- c(md_header, "", md_body)
6165
writeLines(final_content, out_path)
6266
}
@@ -92,6 +96,8 @@ render_with_retries <- function(
9296
return(success)
9397
}
9498

99+
cli::cli_h1("Collecting files")
100+
95101
all_files <- list.files(
96102
c("images", "docs"),
97103
full.names = TRUE,
@@ -101,6 +107,7 @@ all_files <- list.files(
101107

102108
# all quarto docs
103109
in_fps <- list.files(pattern = "*.qmd", recursive = TRUE)
110+
cli::cli_alert_info("Found {length(in_fps)} .qmd file{?s} and {length(all_files)} total asset{?s}")
104111

105112
# remove quarto docs from all_files
106113
to_copy <- setdiff(all_files, in_fps)
@@ -116,33 +123,38 @@ out_fps <- paste0(
116123
)
117124

118125
# create directories
126+
cli::cli_progress_step("Creating output directories")
119127
for (dirp in unique(dirname(c(out_fps, copy_dest)))) {
120128
if (!dir.exists(dirp)) {
121129
dir.create(dirp, recursive = TRUE)
122130
}
123131
}
124132

125133
# copy all of the non-quarto files
134+
cli::cli_progress_step("Copying {length(to_copy)} non-Quarto asset{?s}")
126135
file.copy(
127136
to_copy,
128137
copy_dest,
129138
overwrite = TRUE
130139
)
131140

141+
cli::cli_progress_step("Processing images")
132142
source("dev/imgs.R")
133143

144+
cli::cli_h1("Rendering documents")
134145

135146
# render all of the files
136147
failed_files <- c()
137-
for (i in 1:length(in_fps)) {
148+
n <- length(in_fps)
149+
for (i in seq_along(in_fps)) {
138150
ip <- in_fps[[i]]
139151
op <- out_fps[[i]]
140152
# check if rendered md already exists
141153
if (file.exists(op)) {
142-
cli::cli_alert_info("Skipping {.file {ip}}. Output exists at {.file {op}}")
154+
cli::cli_alert_info("[{i}/{n}] Skipping {.file {ip}} — output already exists")
143155
next
144156
}
145-
cli::cli_alert_info("Rendering # file {i}: {.file {ip}} to {.file {op}}")
157+
cli::cli_h2("[{i}/{n}] {ip}")
146158
# always unset the arcgis token first
147159
arcgisutils::unset_arc_token()
148160
# render and retry up to 3 times (default) if it fails
@@ -153,13 +165,15 @@ for (i in 1:length(in_fps)) {
153165
}
154166
}
155167

168+
cli::cli_h1("Summary")
156169
if (length(failed_files) > 0) {
157-
cli::cli_alert_danger("The following files failed after retries:")
158-
print(failed_files)
170+
cli::cli_alert_danger("{length(failed_files)} file{?s} failed after retries:")
171+
cli::cli_ul(failed_files)
159172
} else {
160-
cli::cli_alert_success("All files rendered or copied successfully.")
173+
cli::cli_alert_success("All {n} file{?s} rendered or skipped successfully")
161174
}
162175

176+
cli::cli_progress_step("Zipping {.file _docs.zip}")
163177
zip::zip(
164178
"_docs.zip",
165179
list.files(
@@ -168,3 +182,4 @@ zip::zip(
168182
recursive = TRUE
169183
)
170184
)
185+
cli::cli_alert_success("Done — {.file _docs.zip} created")

justfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
default:
2+
just --list
3+
4+
doc-ref:
5+
R -f dev/generate-api-ref.R
6+
7+
doc-pages:
8+
R -f dev/generate-docs.R

0 commit comments

Comments
 (0)