Skip to content

Instantly share code, notes, and snippets.

@borkdude
Last active July 19, 2022 14:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save borkdude/909a3b6119dd29e470effda1a007db29 to your computer and use it in GitHub Desktop.
Save borkdude/909a3b6119dd29e470effda1a007db29 to your computer and use it in GitHub Desktop.
Scriptjure!
((requiring-resolve 'babashka.deps/add-deps)
'{:deps {scriptjure/scriptjure #_{:mvn/version "0.1.24"}
{:git/url "https://github.com/borkdude/scriptjure"
:git/sha "8d1f303557a0f4a021f33f2b01eb10b33509f46e"
:deps/manifest :deps}
#_{:local/root "/tmp/scriptjure" :deps/manifest :deps}}})
(ns scriptjure
{:clj-kondo/config
'{:config-in-call {com.reasonr.scriptjure/js
{:linters {:unresolved-symbol {:level :off}
:invalid-arity {:level :off}}}}}}
(:require
[babashka.process :as p]
[com.reasonr.scriptjure :refer [js]]))
;; clear file
(spit "out.mjs" "")
(defn emit [code-str]
(spit "out.mjs" (str code-str "\n") :append true))
(emit
(js
(defn ^:async foo [url]
(console.log "Fetching:" url)
(let [resp (await (fetch url))
status (await resp.status)]
(console.log "Status:" status)))
(foo "https://clojure.org")))
#_(p/shell "bat out.mjs")
#_(p/shell "bun out.mjs")
(p/shell "node --experimental-fetch out.mjs")
nil
;; On Node 17.8.0:
;; $ bb /tmp/scriptjure.clj
;; (node:40482) ExperimentalWarning: Fetch is an experimental feature. This feature could change at any time
;; (Use `node --trace-warnings ...` to show where the warning was created)
;; Status: 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment