Skip to content

Commit 82a8823

Browse files
committed
tweak the download script
1 parent c20ea5f commit 82a8823

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

tools/download_src_files.R

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
# Note: This ensures we always have the most up-to-date DataTables resources
1111
# while maintaining a consistent structure for our download process.
1212

13-
13+
version = "2.1.4" # this must be the same as the version in the html_text
1414
html_text = r"{
1515
<link href="https://cdn.datatables.net/2.1.4/css/dataTables.dataTables.min.css" rel="stylesheet">
16-
<link href="https://cdn.datatables.net/autofill/2.7.0/css/autoFill.dataTables.min.css" rel="stylesheet">
16+
<link href="https://cdn.datatables.net/autofill/2.7.0/css/autoFill.dataTables.css" rel="stylesheet">
1717
<link href="https://cdn.datatables.net/buttons/3.1.1/css/buttons.dataTables.min.css" rel="stylesheet">
1818
<link href="https://cdn.datatables.net/colreorder/2.0.4/css/colReorder.dataTables.min.css" rel="stylesheet">
1919
<link href="https://cdn.datatables.net/datetime/1.5.3/css/dataTables.dateTime.min.css" rel="stylesheet">
@@ -31,7 +31,7 @@ html_text = r"{
3131
3232
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
3333
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script>
34-
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.min.js"></script>
34+
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script>
3535
<script src="https://cdn.datatables.net/2.1.4/js/dataTables.min.js"></script>
3636
<script src="https://cdn.datatables.net/autofill/2.7.0/js/dataTables.autoFill.min.js"></script>
3737
<script src="https://cdn.datatables.net/buttons/3.1.1/js/dataTables.buttons.min.js"></script>
@@ -52,10 +52,14 @@ html_text = r"{
5252
<script src="https://cdn.datatables.net/select/2.0.5/js/dataTables.select.min.js"></script>
5353
<script src="https://cdn.datatables.net/staterestore/1.4.1/js/dataTables.stateRestore.min.js"></script>
5454
}"
55-
5655
download_datatables_files = function(html_text) {
57-
# Create the base directory
58-
dir.create("download/DataTables", recursive = TRUE, showWarnings = FALSE)
56+
# Define the base directory as a variable
57+
base_dir = "download/DataTables"
58+
# Create the base directory and ensure it's empty
59+
if (dir.exists(base_dir)) {
60+
unlink(base_dir, recursive = TRUE)
61+
}
62+
dir.create(base_dir, recursive = TRUE, showWarnings = FALSE)
5963

6064
# Extract URLs from the HTML text
6165
urls = unlist(regmatches(html_text, gregexpr("https://[^\"]+", html_text)))
@@ -66,8 +70,8 @@ download_datatables_files = function(html_text) {
6670
# Use non-minified versions for 'pdfmake.js' and 'vfs_fonts.js'
6771
# This is due to compatibility issues with pdfmake.min.js on Windows for self-contained HTML pages
6872
# Reference: https://github.com/rstudio/DT/issues/774#issuecomment-595277726
69-
urls = gsub("pdfmake\\.min\\.js", "pdfmake.js", urls, fixed = TRUE)
70-
urls = gsub("vfs_fonts\\.min\\.js", "vfs_fonts.js", urls, fixed = TRUE)
73+
urls = gsub("pdfmake.min.js", "pdfmake.js", urls, fixed = TRUE)
74+
urls = gsub("vfs_fonts.min.js", "vfs_fonts.js", urls, fixed = TRUE)
7175

7276
# Download and save each file
7377
for (url in urls) {
@@ -78,7 +82,7 @@ download_datatables_files = function(html_text) {
7882
rel_path = gsub("/[0-9.]+/", "/", rel_path)
7983

8084
# Create the full local path
81-
local_path = file.path("download/DataTables", rel_path)
85+
local_path = file.path(base_dir, rel_path)
8286

8387
# Ensure the directory exists
8488
dir.create(dirname(local_path), recursive = TRUE, showWarnings = FALSE)
@@ -94,6 +98,11 @@ download_datatables_files = function(html_text) {
9498
}
9599
)
96100
}
101+
# should change the download/$version$/* to download/datatables/*
102+
file.rename(
103+
from = sprintf("%s/%s", base_dir, version),
104+
to = sprintf("%s/datatables", base_dir)
105+
)
97106
}
98107

99108
# Run

0 commit comments

Comments
 (0)