(rule
 (deps %{project_root}/staged_dist/slipshow.cdn.min.js)
 (target "slipshow.cdn.min.js.crunch")
 (enabled_if
  (= %{profile} "with-bundle"))
 (mode promote)
 (action
  (copy %{deps} %{target})))

(rule
 (deps %{project_root}/staged_dist/css/slip.css)
 (target "slip.css.crunch")
 (enabled_if
  (= %{profile} "with-bundle"))
 (mode promote)
 (action
  (copy %{deps} %{target})))

(rule
 (deps %{project_root}/staged_dist/css/theorem.css)
 (target "theorem.css.crunch")
 (enabled_if
  (= %{profile} "with-bundle"))
 (mode promote)
 (action
  (copy %{deps} %{target})))

(rule
 (deps %{project_root}/node_modules/mathjax/es5/tex-svg.js)
 (target "tex-svg.js.crunch")
 (enabled_if
  (= %{profile} "with-bundle"))
 (mode promote)
 (action
  (copy %{deps} %{target})))

(rule
 (target highlight-js.css.crunch)
 (enabled_if
  (= %{profile} "with-bundle"))
 (mode promote)
 (action
  (run
   wget
   --output-document
   highlight-js.css.crunch
   https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/default.min.css)))

(rule
 (target highlight-js.js.crunch)
 (enabled_if
  (= %{profile} "with-bundle"))
 (mode promote)
 (action
  (run
   wget
   --output-document
   highlight-js.js.crunch
   https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js)))

(rule
 (target highlight-js.ocaml.js.crunch)
 (enabled_if
  (= %{profile} "with-bundle"))
 (mode promote)
 (action
  (run
   wget
   --output-document
   highlight-js.ocaml.js.crunch
   https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/languages/ocaml.min.js)))

; (rule
;  (target "tailwindcss.js")
;  (enabled_if
;   (= %{profile} "with-bundle"))
;  (mode promote)
;  (action
;   (run
;     wget
;     --output-document
;     tailwindcss.js
;     https://cdn.tailwindcss.com)))

; warning: node modules are not managed by dune
; to generate a new bundle one should run `npm install` before the first build
; The bundle is only re-generated if the profile is `with-bundle`
; If you add new javascript dependency or update the package.json
; you should run `dune build --profile=with-bundle`

(rule
 (aliases runtest data-files)
 (deps
  (:x data_contents.ml)
  (glob_files *.crunch))
 (enabled_if
  (= %{profile} "with-bundle"))
 (action
  (progn
   (setenv
    SOURCE_DATE_EPOCH
    0
    (run ocaml-crunch . -e crunch -o %{x}.corrected -m plain -s))
   (diff? %{x} %{x}.corrected))))

(library
 (name data_files)
 (public_name slipshow.datafiles)
 (preprocess
  (pps ppx_blob))
 (preprocessor_deps
  ../../logo/favicon.ico
  ../engine/slipshow.js
  ../engine/slipshow-internal.css
  ../engine/slipshow-system.css)
 (wrapped false))
