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

Standalone usage of set_esbuild and set_mocha functions #23

Merged
merged 8 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
43 changes: 31 additions & 12 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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$
Expand Down Expand Up @@ -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")
}


Expand All @@ -199,20 +212,26 @@ 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")
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"
)
}
}


Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(
DivadNojnarg marked this conversation as resolved.
Show resolved Hide resolved
c(
"srcjs",
"node_modules",
"package.json",
"package-lock.json",
"styles",
"esbuild.dev.json",
"esbuild.prod.json"
)
)

usethis::use_git_ignore("node_modules")
DivadNojnarg marked this conversation as resolved.
Show resolved Hide resolved
```

## 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.
Expand Down
8 changes: 4 additions & 4 deletions inst/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
"author": "",
"license": "<<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"
}
}
1 change: 0 additions & 1 deletion man/set_esbuild.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion man/set_mocha.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading