You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.1KB

  1. #! /usr/bin/env Rscript
  2. library(sass)
  3. library(fs)
  4. library(purrr)
  5. library(cliapp)
  6. render_sass <- function(file, output = NULL, outdir = "dist") {
  7. if (is.null(output)) {
  8. output <- path_file(file)
  9. path_ext(output) <- "rstheme"
  10. }
  11. output <- path(outdir, output)
  12. cli_alert_success("{path {path_rel(file, getwd())}}")
  13. sass(sass_file(paste(file)), output = output)
  14. }
  15. dir_create("dist")
  16. cli_alert_info("Compiling themes...")
  17. dir_ls("src", regexp = "^[^_].+\\.scss") %>%
  18. walk(render_sass)
  19. get_theme_name <- function(file) {
  20. x <- readLines(file, warn = FALSE)
  21. x <- grep("rs-theme-name", x, value = TRUE)
  22. if (!length(x)) return("")
  23. x <- sub("^\\s*/\\*\\s*rs-theme-name:\\s", "", x)
  24. x <- sub("\\s*\\*/\\s*$", "", x)
  25. x
  26. }
  27. cp_to_rstudio <- function(file) {
  28. cli_alert("{emph {get_theme_name(file)}}")
  29. file_copy(
  30. file,
  31. path_home_r(".R", "rstudio", "themes", path_file(file)),
  32. overwrite = TRUE
  33. )
  34. }
  35. cli_alert_info('Installing themes to {path {path_home_r(".R", "rstudio", "themes")}}')
  36. dir_ls("dist", regexp = "\\.rstheme") %>%
  37. walk(cp_to_rstudio)