(env
 (dev
  (flags
   (:standard -w -7-9 -warn-error -33))))

(data_only_dirs .scripts)

(library
 (name liquidsoap_js)
 (public_name liquidsoap-js)
 (optional)
 (modules)
 (js_of_ocaml
  (javascript_files runtime.js))
 (preprocess
  (pps js_of_ocaml-ppx))
 (libraries liquidsoap_lang liquidsoap_tooling))

(install
 (files index.html)
 (section share)
 (package liquidsoap-js))

(rule
 (target playground.bundle.js)
 (enabled_if %{bin-available:npm})
 (deps .scripts/bundle-playground.sh)
 (action
  (run sh %{deps} %{target})))

(rule
 (target playground.bundle.js)
 (enabled_if
  (not %{bin-available:npm}))
 (action
  (write-file
   %{target}
   "console.error('Playground bundle not available - npm was not installed during build');")))

(executable
 (name interactive_js)
 (modes js)
 (optional)
 (modules interactive_js)
 (js_of_ocaml
  (javascript_files filesystem.js))
 (preprocess
  (pps ppx_string js_of_ocaml-ppx))
 (libraries liquidsoap_lang liquidsoap_js))

(rule
 (target filesystem.js)
 (enabled_if
  (not %{bin-available:js_of_ocaml}))
 (action
  (write-file %{target} "console.log(\"no js_of_ocaml available!\")")))

(rule
 (target filesystem.js)
 (enabled_if %{bin-available:js_of_ocaml})
 (deps
  ./stdlib_js.liq
  (glob_files ../libs/*.liq))
 (action
  (run js_of_ocaml build-fs -I . -I ../libs -o %{target} %{deps})))

(rule
 (alias serve-playground)
 (deps
  interactive_js.bc.js
  index.html
  playground.bundle.js
  .scripts/serve-playground.sh)
 (action
  (run sh .scripts/serve-playground.sh)))
