From 1748b1027d09e9ed5f762c3def486eef270e2938 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Sun, 21 Jan 2024 09:54:20 +0100 Subject: [PATCH 1/8] export set_esbuild --- R/utils.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/utils.R b/R/utils.R index e2f25a7..cb96332 100644 --- a/R/utils.R +++ b/R/utils.R @@ -156,7 +156,7 @@ reference_style <- function(path) { #' not exist in old versions. #' #' @return Installs esbuild in node_modules (dev scope), creates srcjs + srcjs/main.js -#' @keywords internal +#' @export set_esbuild <- function(light = FALSE) { pkg_desc <- desc::description$ From dd3c8ee32ad5635e965a0ba0c4fd7f76859237fa Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Sun, 21 Jan 2024 10:04:38 +0100 Subject: [PATCH 2/8] chore(deps): update dependency versions in package.json --- inst/utils/package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/inst/utils/package.json b/inst/utils/package.json index 952bf5f..fc1765e 100644 --- a/inst/utils/package.json +++ b/inst/utils/package.json @@ -17,10 +17,10 @@ "author": "", "license": "<>", "devDependencies": { - "esbuild": "^0.8.46", - "esbuild-sass-plugin": "^2.4.0", - "postcss": "^8.4.18", - "autoprefixer": "^10.4.13", + "autoprefixer": "^10.4.17", + "esbuild": "^0.19.11", + "esbuild-sass-plugin": "^2.16.1", + "postcss": "^8.4.33", "mocha": "^8.3.0" } } From 89f0b6482f94bdb12f0ec8483742edecf52d4183 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Sun, 21 Jan 2024 10:06:27 +0100 Subject: [PATCH 3/8] export set_mocha and document --- DESCRIPTION | 2 +- NAMESPACE | 2 ++ R/utils.R | 2 +- man/set_esbuild.Rd | 1 - man/set_mocha.Rd | 1 - 5 files changed, 4 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 26b576b..4e3237b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -29,7 +29,7 @@ Description: 'charpente' eases the creation of 'shiny' extensions like 'shinydas License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.3 Imports: magrittr, XML, diff --git a/NAMESPACE b/NAMESPACE index 7f777be..463abc9 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -17,6 +17,8 @@ export(get_dependency_versions) export(get_installed_dependency) export(html_2_R) export(js_handler_template) +export(set_esbuild) +export(set_mocha) export(set_pwa) export(test_js) export(update_dependency) diff --git a/R/utils.R b/R/utils.R index cb96332..7604b78 100644 --- a/R/utils.R +++ b/R/utils.R @@ -199,7 +199,7 @@ set_esbuild <- function(light = FALSE) { #' #' @return Installs mocha in node_modules (dev scope), creates srcjs/test folder, #' write basic test im test_basic.js -#' @keywords internal +#' @export set_mocha <- function() { npm::npm_install("mocha", scope = "dev") dir.create("srcjs/test") diff --git a/man/set_esbuild.Rd b/man/set_esbuild.Rd index 304ade4..79c4082 100644 --- a/man/set_esbuild.Rd +++ b/man/set_esbuild.Rd @@ -17,4 +17,3 @@ Installs esbuild in node_modules (dev scope), creates srcjs + srcjs/main.js \description{ Installs esbuild for the local project } -\keyword{internal} diff --git a/man/set_mocha.Rd b/man/set_mocha.Rd index 481107f..7d98c98 100644 --- a/man/set_mocha.Rd +++ b/man/set_mocha.Rd @@ -13,4 +13,3 @@ write basic test im test_basic.js \description{ Installs mocha for the local project } -\keyword{internal} From 180de7d1d4a9eb0f7bd0a6dd10a888bf14832826 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Sun, 21 Jan 2024 10:20:56 +0100 Subject: [PATCH 4/8] charpente 0.5.0 > 0.6.0 --- DESCRIPTION | 2 +- NEWS.md | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4e3237b..1abded0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: charpente Title: Seamlessly design robust 'shiny' extensions -Version: 0.5.0 +Version: 0.6.0 Authors@R: c( person( given = "David", diff --git a/NEWS.md b/NEWS.md index 1c9c283..572a626 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,9 @@ -# charpent 0.5.0 +# charpente 0.6.0 + +## New: +- Allow to initialise `esbuild` and `mocha` in a standalone way, without the need of the full `charpente` workflow. This is useful if you want to use `esbuild` and its plugins in already existing projects. See `?set_esbuild` and `?set_mocha` for more details. + +# charpente 0.5.0 ## Breaking change: - Include Sass handling. SCSS files are sorted in the `/styles`folder and esbuild From 31bd5d8b9ab06521b9378284b4dec57d2616537f Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Sun, 21 Jan 2024 10:26:43 +0100 Subject: [PATCH 5/8] docs: update README with example usage of esbuild and mocha functions --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/README.md b/README.md index 18687c6..a1b0619 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,33 @@ build_js() devtools::load_all() ``` +## Using esbuild and mocha + +If you want to use `esbuild` and `mocha` in an existing project, you can use the functions `set_esbuild()` and `set_mocha()`. A workflow could look as follows: + +```r +# Setup esbuild for JS code management +set_esbuild() + +# Add mocha for tests +set_mocha() + +# Ignore files/folders: srcjs, node_modules, ... +usethis::use_build_ignore( + c( + "srcjs", + "node_modules", + "package.json", + "package-lock.json", + "styles", + "esbuild.dev.json", + "esbuild.prod.json" + ) +) + +usethis::use_git_ignore("node_modules") +``` + ## Acknowledgment The author would like to warmly thank [Victor Perrier](https://twitter.com/_pvictorr?lang=fr), [John Coene](https://twitter.com/jdatap), [Colin Fay](https://twitter.com/_ColinFay), [Alan Dipert](https://twitter.com/alandipert), [Kenton Russel](https://twitter.com/timelyportfolio) for providing many building block and inspiration to this package. From fef1d3c1818e8d549d1b3fe93352f4d297f16cdf Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Sun, 21 Jan 2024 13:23:03 +0100 Subject: [PATCH 6/8] respect existing folder structure --- R/utils.R | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/R/utils.R b/R/utils.R index 7604b78..c57baa3 100644 --- a/R/utils.R +++ b/R/utils.R @@ -185,11 +185,24 @@ set_esbuild <- function(light = FALSE) { # If light, we don't want to recreate srcjs folder # which has always been in charpente since the first release. if (!light) { - dir.create("srcjs") - write("import \"../styles/main.scss\";", "./srcjs/main.js") + + if (!dir.exists("srcjs")) { + dir.create("srcjs") + } + + write("import \"../styles/main.scss\";", + "./srcjs/main.js", + append = file.exists("srcjs/main.js")) + + } + + if (!dir.exists("styles")) { + dir.create("styles") + } + + if (!file.exists("styles/main.scss")) { + file.create("styles/main.scss") } - dir.create("styles") - file.create("styles/main.scss") } @@ -202,17 +215,23 @@ set_esbuild <- function(light = FALSE) { #' @export set_mocha <- function() { npm::npm_install("mocha", scope = "dev") - dir.create("srcjs/test") - file.create("srcjs/test/test_basic.js") - writeLines( - "describe('Basic test', () => { + + if (!dir.exists("srcjs/test")) { + dir.create("srcjs/test") + } + + if (!file.exists("srcjs/test/test_basic.js")) { + file.create("srcjs/test/test_basic.js") + writeLines( + "describe('Basic test', () => { it('should not fail', (done) => { done(); }); }); ", - "srcjs/test/test_basic.js" - ) + "srcjs/test/test_basic.js" + ) + } } From c44bb124bef889cf06a4ca1039e3d3461969a325 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Sun, 21 Jan 2024 15:02:35 +0100 Subject: [PATCH 7/8] replace "js" with "dist" folder --- R/jstools.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/jstools.R b/R/jstools.R index 69794bc..f349053 100644 --- a/R/jstools.R +++ b/R/jstools.R @@ -14,7 +14,7 @@ build_js <- function(dir = "srcjs", mode = c("prod", "dev")) { mode <- match.arg(mode) pkg_desc <- desc::description$new("./DESCRIPTION")$get(c("Package", "Version", "License")) - outputDir <- sprintf("inst/%s-%s/js", pkg_desc[1], pkg_desc[2]) + outputDir <- sprintf("inst/%s-%s/dist", pkg_desc[1], pkg_desc[2]) # run esbuild run_esbuild(mode, outputDir) From c83ad107ea8bba053b4b4b4aab21cec5a306d3a5 Mon Sep 17 00:00:00 2001 From: Veerle van Leemput Date: Mon, 22 Jan 2024 08:10:46 +0100 Subject: [PATCH 8/8] move use_build_ignore() and use_git_ignore() to set_esbuild() --- NEWS.md | 3 +++ R/charpente.R | 13 ------------- R/utils.R | 19 ++++++++++++++++++- README.md | 17 +---------------- man/set_esbuild.Rd | 4 +++- 5 files changed, 25 insertions(+), 31 deletions(-) diff --git a/NEWS.md b/NEWS.md index 572a626..f190326 100644 --- a/NEWS.md +++ b/NEWS.md @@ -3,6 +3,9 @@ ## New: - Allow to initialise `esbuild` and `mocha` in a standalone way, without the need of the full `charpente` workflow. This is useful if you want to use `esbuild` and its plugins in already existing projects. See `?set_esbuild` and `?set_mocha` for more details. +## Improvements: +- Move `use_build_ignore()` and `use_git_ignore()` calls to `set_esbuild()` to enable standalone usage. + # charpente 0.5.0 ## Breaking change: diff --git a/R/charpente.R b/R/charpente.R index 7ae3096..a14615d 100644 --- a/R/charpente.R +++ b/R/charpente.R @@ -67,19 +67,6 @@ create_charpente <- function(path, remote = NULL, private = FALSE, license) { set_esbuild() # Add mocha for tests set_mocha() - # Ignore files/folders: srcjs, node_modules, ... - use_build_ignore( - c( - "srcjs", - "node_modules", - "package.json", - "package-lock.json", - "styles", - "esbuild.dev.json", - "esbuild.prod.json" - ) - ) - use_git_ignore("node_modules") # version control set_version_control(remote, private) diff --git a/R/utils.R b/R/utils.R index c57baa3..946d6b5 100644 --- a/R/utils.R +++ b/R/utils.R @@ -155,7 +155,9 @@ reference_style <- function(path) { #' to workaround a breaking change in charpente where styles does #' not exist in old versions. #' -#' @return Installs esbuild in node_modules (dev scope), creates srcjs + srcjs/main.js +#' @return Installs esbuild in node_modules (dev scope), +#' if not existing, creates srcjs + srcjs/main.js andstyles + styles/main.scss, +#' and sets relevant files and folders in .gitignore. and .Rbuildignore. #' @export set_esbuild <- function(light = FALSE) { @@ -203,6 +205,21 @@ set_esbuild <- function(light = FALSE) { if (!file.exists("styles/main.scss")) { file.create("styles/main.scss") } + + # Ignore files/folders: srcjs, node_modules, ... + use_build_ignore( + c( + "srcjs", + "node_modules", + "package.json", + "package-lock.json", + "styles", + "esbuild.dev.json", + "esbuild.prod.json" + ) + ) + + use_git_ignore("node_modules") } diff --git a/README.md b/README.md index a1b0619..c3ea4b2 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ devtools::load_all() ## Using esbuild and mocha -If you want to use `esbuild` and `mocha` in an existing project, you can use the functions `set_esbuild()` and `set_mocha()`. A workflow could look as follows: +If you want to use `esbuild` and `mocha` in an existing project, you can use the functions `set_esbuild()` and `set_mocha()`. A simple workflow looks as follows: ```r # Setup esbuild for JS code management @@ -75,21 +75,6 @@ set_esbuild() # Add mocha for tests set_mocha() - -# Ignore files/folders: srcjs, node_modules, ... -usethis::use_build_ignore( - c( - "srcjs", - "node_modules", - "package.json", - "package-lock.json", - "styles", - "esbuild.dev.json", - "esbuild.prod.json" - ) -) - -usethis::use_git_ignore("node_modules") ``` ## Acknowledgment diff --git a/man/set_esbuild.Rd b/man/set_esbuild.Rd index 79c4082..223136f 100644 --- a/man/set_esbuild.Rd +++ b/man/set_esbuild.Rd @@ -12,7 +12,9 @@ to workaround a breaking change in charpente where styles does not exist in old versions.} } \value{ -Installs esbuild in node_modules (dev scope), creates srcjs + srcjs/main.js +Installs esbuild in node_modules (dev scope), +if not existing, creates srcjs + srcjs/main.js andstyles + styles/main.scss, +and sets relevant files and folders in .gitignore. and .Rbuildignore. } \description{ Installs esbuild for the local project