Last active
July 19, 2022 14:35
-
-
Save borkdude/909a3b6119dd29e470effda1a007db29 to your computer and use it in GitHub Desktop.
Scriptjure!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
((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