Skip to content

Commit

Permalink
bb.edn
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Jul 31, 2021
1 parent fa9da6e commit 2f2cef2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
22 changes: 12 additions & 10 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
{:tasks
{#_#_shadow-server (shell "npx shadow-cljs server")
#_#_shadow-compile (shell "npx shadow-cljs compile :app")
#_#_shadow-node-repl (shell "npx shadow-cljs node-repl")
{:requires ([babashka.fs :as fs])
clean (fs/delete-tree "out")
compile (do (shell "npx shadow-cljs --force-spawn compile modules")
(spit "out/nodashka_core.js"
(clojure.string/replace (slurp "out/nodashka_core.js") (re-pattern "self") "globalThis"))
(spit "out/nodashka_main.js"
(str "#!/usr/bin/env node\n\n" (slurp "out/nodashka_main.js")))
(shell "chmod +x out/nodashka_main.js"))
release (do (shell "npx shadow-cljs --force-spawn release modules")
(spit "out/nodashka_core.js"
(clojure.string/replace (slurp "out/nodashka_core.js") (re-pattern "self") "globalThis"))
(spit "out/nodashka_main.js"
(str "#!/usr/bin/env node\n\n" (slurp "out/nodashka_main.js")))
(shell "chmod +x out/nodashka_main.js"))
release {:depends [clean]
:task
(do (shell "npx shadow-cljs --force-spawn release modules")
(spit "out/nodashka_core.js"
(clojure.string/replace (slurp "out/nodashka_core.js") (re-pattern "self") "globalThis"))
(spit "out/nodashka_main.js"
(str "#!/usr/bin/env node\n\n" (slurp "out/nodashka_main.js")))
(shell "chmod +x out/nodashka_main.js"))}
run (shell "out/nodashka_main.js test.cljs")
#_#_publish (shell "npm publish")}}
publish {:depends [release]
:task (shell "npm publish")}}}
1 change: 1 addition & 0 deletions foo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("hello");
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"bin": {
"nodashka": "./out/nodashka_main.js"
},
"version": "0.0.1",
"version": "0.0.4",
"description": "Babashka-like tool for Node.js.",
"scripts": {
"prepare": "bb release"
Expand Down
10 changes: 7 additions & 3 deletions script.cljs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
(ns script
(:require ["csv-parse/lib/sync.js" :default csv-parse]
["fs" :as fs]
["shelljs" :default sh]))
(:require
["csv-parse/lib/sync.js" :default csv-parse]
["fs" :as fs]
["shelljs" :default sh]))

(println (count (str (.readFileSync fs "script.cljs"))))

(prn (.ls sh "."))

(prn (csv-parse "foo,bar"))

;; evaluate local file
(js/eval (str (.readFileSync fs "./foo.js")))
7 changes: 4 additions & 3 deletions src/nodashka/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@

(def cwd (.cwd js/process))

(set! (.-import universe) esm/dynamic-import)
;; (set! (.-import universe) esm/dynamic-import)

(def sci-ctx (atom (sci/init {:namespaces {'clojure.core {'prn prn 'println println}}
:classes {'js universe :allow :all}})))

(def last-ns (atom @sci/ns))

(defn dynamic-import
"This is a workaround for loading local .js and .json file relative to the script itself."
;; "This is a workaround for loading local .js and .json file relative to the script itself."
[s]
(if (str/starts-with? s ".")
(esm/dynamic-import s)
#_(if (str/starts-with? s ".")
(.catch (esm/dynamic-import (str/join "/" [cwd s]))
(fn [_]
(esm/dynamic-import s)))
Expand Down

0 comments on commit 2f2cef2

Please sign in to comment.