diff --git a/.Rbuildignore b/.Rbuildignore index b0dba58..7c6536c 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -1,3 +1,5 @@ ^LICENSE\.md$ ^README\.Rmd$ ^Makefile$ +node_modules +^\.github$ diff --git a/.github/.gitignore b/.github/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.github/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..27bc4e5 --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,29 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: [push, pull_request] +name: R CMD check + +permissions: read-all + +jobs: + R-CMD-check: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true + build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' diff --git a/.github/workflows/check-demo.yaml b/.github/workflows/check-demo.yaml new file mode 100644 index 0000000..14ae130 --- /dev/null +++ b/.github/workflows/check-demo.yaml @@ -0,0 +1,42 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: [push, pull_request] +name: Check demo + +permissions: read-all + +jobs: + run-sampler: + runs-on: ubuntu-latest + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + steps: + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck, local::. + needs: check + + - uses: pnpm/action-setup@v4 + with: + version: 9.12 + + # the rest of this must run from tests/testthat/sampler + - run: pnpm install --frozen-lockfile + working-directory: tests/testthat/sampler + + - run: pnpm build + working-directory: tests/testthat/sampler + + - name: Start Rserve + run: pnpm rserve & + working-directory: tests/testthat/sampler + + - run: pnpm start + working-directory: tests/testthat/sampler diff --git a/DESCRIPTION b/DESCRIPTION index 3da4cb1..828b6e7 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -10,11 +10,9 @@ License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE) RoxygenNote: 7.3.1 -Suggests: - testthat (>= 3.0.0) Config/testthat/edition: 3 Imports: - cli, - js, rlang, Rserve +Suggests: + testthat (>= 3.0.0) diff --git a/Makefile b/Makefile index 9c45c42..ff55248 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,9 @@ document: install: document R CMD INSTALL . +check: + Rscript -e "devtools::check()" + README.md: README.Rmd install Rscript -e "rmarkdown::render('README.Rmd')" @rm README.html diff --git a/R/compile.R b/R/compile.R index 2a9aa7e..d3d11cd 100644 --- a/R/compile.R +++ b/R/compile.R @@ -50,10 +50,6 @@ ts_compile.character <- function( sprintf("export default {\n %s\n};", paste(ls(e), collapse = ",\n ")) ) - # if (file != "" && file.exists(file)) { - # stop(sprintf("File exists: %s", file)) - # return() - # } cat(src, file = file, sep = "\n") invisible() diff --git a/R/function.R b/R/function.R index 40d17c4..41825bf 100644 --- a/R/function.R +++ b/R/function.R @@ -82,19 +82,18 @@ ts_function <- function(f, ..., result = ts_void()) { } - #' @export print.ts_function <- function(x, ...) { - cli::cli_h3("Ocap function") + h3("Ocap function") - cli::cli_text("Arguments:") + cat("Arguments:\n") args <- lapply(x$args, \(z) z$input_type) lapply(names(args), \(n) { cat("- ", n, ": ", args[[n]], "\n", sep = "") }) - cli::cli_text("\n\n") + cat("\n\n") - cli::cli_text("Return type:") + cat("Return type:\n") cat(x$result$return_type) } diff --git a/R/helpers.R b/R/helpers.R new file mode 100644 index 0000000..e0a7d11 --- /dev/null +++ b/R/helpers.R @@ -0,0 +1,9 @@ +h3 <- function(x) { + cat("\n---", x, "\n") +} + + +# TODO: figure out how to format (modern) JS code from R? +format_js <- function(x) { + x +} diff --git a/R/types.R b/R/types.R index 5bef6c0..ee02868 100644 --- a/R/types.R +++ b/R/types.R @@ -27,21 +27,20 @@ ts_object <- function(input_type = "any", #' @export print.ts_object <- function(x, ...) { # name <- deparse(substitute(x)) - cli::cli_ul() - cli::cli_h3("Input type: ") + h3("Input type: ") if (nchar(x$input_type) > 50) { - cat(js::uglify_reformat(x$input_type, beautify = TRUE), "\n") + cat(format_js(x$input_type), "\n") } else { cat(x$input_type, "\n") } - cli::cli_h3("Return type: ") + h3("Return type: ") if (nchar(x$return_type) > 50) { print(x$return_type) - cat(js::uglify_reformat(x$return_type, beautify = TRUE), "\n") + cat(format_js(x$return_type), "\n") } else { cat(x$return_type, "\n") } - cli::cli_end() + cat("\n") } #' @describeIn ts_object Check if an object is a ts object diff --git a/README.Rmd b/README.Rmd index ab8caf5..4f752a0 100644 --- a/README.Rmd +++ b/README.Rmd @@ -16,6 +16,8 @@ knitr::opts_chunk$set( # ts +[![R-CMD-check](https://github.com/tmelliott/ts/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tmelliott/ts/actions/workflows/R-CMD-check.yaml) +[![Demo](https://github.com/tmelliott/ts/actions/workflows/check-demo.yaml/badge.svg)](https://github.com/tmelliott/ts/actions/workflows/check-demo.yaml) The **ts** package makes it easy for users to write functions that can be used in [**rserve-ts**](https://www.npmjs.com/package/rserve-ts) applications. diff --git a/README.md b/README.md index e5cf272..3a2f842 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ +[![R-CMD-check](https://github.com/tmelliott/ts/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tmelliott/ts/actions/workflows/R-CMD-check.yaml) +[![Demo](https://github.com/tmelliott/ts/actions/workflows/check-demo.yaml/badge.svg)](https://github.com/tmelliott/ts/actions/workflows/check-demo.yaml) The **ts** package makes it easy for users to write functions that can